Skip to content

Commit

Permalink
work on #16
Browse files Browse the repository at this point in the history
  • Loading branch information
methusalah committed Mar 5, 2016
1 parent a4e9f7e commit 4bb67c0
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.simsilica.es.EntityId;

import javafx.application.Platform;
import util.LogUtil;

/***
* A Specialized EntityData that maintain a tree of nodes representing the hierarchy of the entities and their components.
Expand Down Expand Up @@ -66,6 +67,11 @@ public EntityNode getRootNode() {
* @return
*/
public EntityNode getNode(EntityId eid){
if(!entityNodes.containsKey(eid)){
EntityNode ep = new EntityNode(eid, "Just created. Should not be seen.");
rootEntityNode.childrenListProperty().add(ep);
entityNodes.put(ep.getEntityId(), ep);
}
return entityNodes.get(eid);
}

Expand All @@ -80,22 +86,23 @@ private void removeNodeFromParent(EntityNode ep, Parenting parenting){
}

private void handleComponentChange(EntityId eid, Class<? extends EntityComponent> compClass, EntityComponent lastComp, EntityComponent newComp){
Platform.runLater(() -> {
if(!entityNodes.containsKey(eid)){
EntityNode ep = new EntityNode(eid, "Just created. Should not be seen.");
rootEntityNode.childrenListProperty().add(ep);
entityNodes.put(ep.getEntityId(), ep);
}
});

Platform.runLater(() -> {
EntityNode node = getNode(eid);
if(compClass == Parenting.class){
Parenting parenting = (Parenting)newComp;
removeNodeFromParent(node, (Parenting)lastComp);
if(newComp != null){
// The entity has a new parent. We register the entity in the new parent's presenter's children list
EntityNode newParent = entityNodes.get(parenting.getParent());
EntityNode newParent = getNode(parenting.getParent());
if(newParent == null) {
LogUtil.warning("We try to set a new parent but we can't find the parent entity node.");
LogUtil.warning(" Component class : " + compClass.getSimpleName());
LogUtil.warning(" last component : " + lastComp);
LogUtil.warning(" new component : " + newComp);
LogUtil.warning(" new parent : " + parenting.getParent() + " / name : " + (getComponent(parenting.getParent(), Naming.class) != null? getComponent(parenting.getParent(), Naming.class).getName() : "unnamed"));
Naming naming = getComponent(eid, Naming.class);
LogUtil.warning(" entity : " + eid + (naming != null? naming.getName() : "unamed."));
}
newParent.childrenListProperty().add(node);
}
else
Expand All @@ -113,6 +120,14 @@ private void handleComponentChange(EntityId eid, Class<? extends EntityComponent
} else if(lastComp != null && newComp != null){
// component is replaced
int index = node.componentListProperty().indexOf(lastComp);
if(index == -1){
LogUtil.warning("We need to replace a component in an entity node, but the old component can't be found in the entity node's comp list.");
LogUtil.warning(" Component class : " + compClass.getSimpleName());
LogUtil.warning(" last component : " + lastComp);
LogUtil.warning(" new component : " + newComp);
Naming naming = getComponent(eid, Naming.class);
LogUtil.warning(" entity : " + eid + naming != null? naming.getName() : "unamed.");
}
node.componentListProperty().set(index, newComp);
} else if(lastComp == null && newComp != null){
// component is added
Expand Down

0 comments on commit 4bb67c0

Please sign in to comment.