Added support for invisible entities

Added support for invisible entities, e.g., placeholders for actual entities
Added some logging for unknown DS1 objects (when no backing id can be found)
This commit is contained in:
Collin Smith 2019-03-09 17:12:27 -08:00
parent d818d97900
commit 77c851a5ce
3 changed files with 28 additions and 8 deletions

View File

@ -3,12 +3,14 @@ package com.riiablo.entity;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetDescriptor; import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectIntMap; import com.badlogic.gdx.utils.ObjectIntMap;
import com.badlogic.gdx.utils.Pools;
import com.riiablo.Riiablo; import com.riiablo.Riiablo;
import com.riiablo.codec.Animation; import com.riiablo.codec.Animation;
import com.riiablo.codec.COF; import com.riiablo.codec.COF;
@ -24,6 +26,8 @@ import com.riiablo.map.MapRenderer;
import com.riiablo.screen.GameScreen; import com.riiablo.screen.GameScreen;
import com.riiablo.widget.Label; import com.riiablo.widget.Label;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
@ -447,10 +451,19 @@ public abstract class Entity {
shapes.end(); shapes.end();
batch.begin(); batch.begin();
batch.setShader(null); batch.setShader(null);
Riiablo.fonts.consolas12.draw(batch, String.format("%s%n%s %s %s%n%02d/%02d %d", StringBuilder builder = new StringBuilder(64)
classname, token, type.MODE[mode], WCLASS[wclass], .append(classname).append('\n')
animation.getFrame(), (animation.getNumFramesPerDir() - 1), animation.getFrameDelta()), .append(token).append(' ').append(type.MODE[mode]).append(' ').append(WCLASS[wclass]).append('\n');
x, y - Tile.SUBTILE_HEIGHT50, 0, Align.center, false); if (animation != null) {
builder
.append(StringUtils.leftPad(Integer.toString(animation.getFrame()), 2))
.append('/')
.append(StringUtils.leftPad(Integer.toString(animation.getNumFramesPerDir() - 1), 2))
.append(' ')
.append(animation.getFrameDelta());
}
GlyphLayout layout = Riiablo.fonts.consolas12.draw(batch, builder.toString(), x, y - Tile.SUBTILE_HEIGHT50, 0, Align.center, false);
Pools.free(layout);
batch.end(); batch.end();
batch.setShader(Diablo.shader); batch.setShader(Diablo.shader);
shapes.begin(ShapeRenderer.ShapeType.Line); shapes.begin(ShapeRenderer.ShapeType.Line);

View File

@ -1,5 +1,6 @@
package com.riiablo.entity; package com.riiablo.entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
@ -50,7 +51,10 @@ public class Monster extends Entity {
assert object.type == DS1.Object.DYNAMIC_TYPE; assert object.type == DS1.Object.DYNAMIC_TYPE;
String id = Riiablo.files.obj.getType1(ds1.getAct(), object.id); String id = Riiablo.files.obj.getType1(ds1.getAct(), object.id);
MonStats.Entry monstats = Riiablo.files.monstats.get(id); MonStats.Entry monstats = Riiablo.files.monstats.get(id);
if (monstats == null) return null; // TODO: Which ones fall under this case? if (monstats == null) {
Gdx.app.error(TAG, "Unknown dynamic entity id: " + id + "; object=" + object);
return null;
}
Monster monster = new Monster(map, zone, object, monstats); Monster monster = new Monster(map, zone, object, monstats);
if (monstats.AI.equalsIgnoreCase("Idle")) { if (monstats.AI.equalsIgnoreCase("Idle")) {

View File

@ -37,8 +37,11 @@ public class Object extends Entity {
assert object.type == DS1.Object.STATIC_TYPE; assert object.type == DS1.Object.STATIC_TYPE;
int id = Riiablo.files.obj.getType2(ds1.getAct(), object.id); int id = Riiablo.files.obj.getType2(ds1.getAct(), object.id);
Objects.Entry base = Riiablo.files.objects.get(id); Objects.Entry base = Riiablo.files.objects.get(id);
if (base == null) return null; // TODO: Which ones fall under this case? if (base == null) {
if (!base.Draw) return null; // TODO: Not yet Gdx.app.error(TAG, "Unknown static entity id: " + id + "; object=" + object);
return null;
}
//if (!base.Draw) return null;
return new Object(map, zone, object, base); return new Object(map, zone, object, base);
} }
@ -83,7 +86,7 @@ public class Object extends Entity {
@Override @Override
public void drawShadow(PaletteIndexedBatch batch) { public void drawShadow(PaletteIndexedBatch batch) {
if (base.BlocksLight[mode]) super.drawShadow(batch); if (base.Draw && base.BlocksLight[mode]) super.drawShadow(batch);
} }
@Override @Override