Added support for invisible object entities

Objects tagged with no draw will no longer have CofComponent and AnimationComponent added and will have the INVISIBLE flag set
This commit is contained in:
Collin Smith 2019-11-05 15:42:44 -08:00
parent 0321d769bf
commit 19ab19d4e0
2 changed files with 24 additions and 8 deletions

View File

@ -138,16 +138,28 @@ public class Engine extends PooledEngine {
name = base.Name.equalsIgnoreCase("dummy") ? base.Description : Riiablo.string.lookup(base.Name);
}
boolean draw = base.Draw;
TypeComponent typeComponent = createComponent(TypeComponent.class);
typeComponent.type = TypeComponent.Type.OBJ;
CofComponent cofComponent = createComponent(CofComponent.class);
cofComponent.token = base.Token;
cofComponent.mode = Object.MODE_NU;
cofComponent.wclass = CofComponent.WEAPON_HTH;
Arrays.fill(cofComponent.component, CofComponent.COMPONENT_NULL);
CofComponent cofComponent;
if (draw) {
cofComponent = createComponent(CofComponent.class);
cofComponent.token = base.Token;
cofComponent.mode = Object.MODE_NU;
cofComponent.wclass = CofComponent.WEAPON_HTH;
Arrays.fill(cofComponent.component, CofComponent.COMPONENT_NULL);
} else {
cofComponent = null;
}
AnimationComponent animationComponent = createComponent(AnimationComponent.class);
AnimationComponent animationComponent;
if (draw) {
animationComponent = createComponent(AnimationComponent.class);
} else {
animationComponent = null;
}
BBoxComponent boxComponent = createComponent(BBoxComponent.class);
@ -171,8 +183,8 @@ public class Engine extends PooledEngine {
Entity entity = createEntity(base.Description);
entity.add(typeComponent);
entity.add(cofComponent);
entity.add(animationComponent);
if (draw) entity.add(cofComponent);
if (draw) entity.add(animationComponent);
entity.add(boxComponent);
entity.add(positionComponent);
entity.add(mapComponent);
@ -182,6 +194,8 @@ public class Engine extends PooledEngine {
labelComponent.actor.setUserObject(entity);
if (!draw) entity.flags |= Flags.INVISIBLE;
return entity;
}

View File

@ -5,6 +5,7 @@ public final class Flags {
public static final int DEBUG = 1 << 0;
public static final int SELECTABLE = 1 << 1;
public static final int SELECTED = 1 << 2;
public static final int INVISIBLE = 1 << 3;
public static String toString(int bits) {
StringBuilder builder = new StringBuilder();
@ -14,6 +15,7 @@ public final class Flags {
if ((bits & DEBUG) == DEBUG) builder.append("DEBUG").append("|");
if ((bits & SELECTABLE) == SELECTABLE) builder.append("SELECTABLE").append("|");
if ((bits & SELECTED) == SELECTED) builder.append("SELECTED").append("|");
if ((bits & INVISIBLE) == INVISIBLE) builder.append("INVISIBLE").append("|");
if (builder.length() > 0) builder.setLength(builder.length() - 1);
}
return builder.toString();