Commits

Michael Ludwig committed c012a4e

Add toString() implementations to Entity, Component, and ComponentData.

  • Participants
  • Parent commits 50a1ada

Comments (0)

Files changed (3)

File src/main/java/com/lhkbob/entreri/Component.java

     public Owner getOwner() {
         return delegate.getOwner();
     }
+
+    @Override
+    public String toString() {
+        if (index == 0) {
+            return "Component(" + getType().getSimpleName() + ")";
+        } else {
+            int entityId = owner.getEntitySystem()
+                                .getEntityByIndex(owner.getEntityIndex(index)).getId();
+            return "Component(" + getType().getSimpleName() + ", entity=" + entityId + ")";
+        }
+    }
 }

File src/main/java/com/lhkbob/entreri/ComponentData.java

         }
     }
 
+    @Override
+    public String toString() {
+        if (index == 0) {
+            return "ComponentData(" + getClass().getSimpleName() + ")";
+        } else {
+            int entityId = owner.getEntitySystem()
+                                .getEntityByIndex(owner.getEntityIndex(index)).getId();
+            return "ComponentData(" + getClass().getSimpleName() + ", entity=" + entityId + ")";
+        }
+    }
+
     /**
      * Event hook called when this ComponentData is assigned to a valid
      * component at the provided non-zero index.

File src/main/java/com/lhkbob/entreri/Entity.java

     public Owner getOwner() {
         return delegate.getOwner();
     }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("Entity(");
+        sb.append(id);
+
+        Iterator<Component<?>> it = iterator();
+        while (it.hasNext()) {
+            sb.append(", ");
+            sb.append(it.next().getType().getSimpleName());
+        }
+
+        sb.append(")");
+        return sb.toString();
+    }
 }