Ejemplo n.º 1
0
 /** order the minions by id and return the previous one, or the first if none were active! */
 public static void getPreviousMinion(boolean deleteactive) {
   EntityManager entman = CoreRegistry.get(EntityManager.class);
   List<Integer> sortedlist = new ArrayList<Integer>();
   for (EntityRef minion : entman.iteratorEntities(MinionComponent.class)) {
     if (!minion.getComponent(MinionComponent.class).dying) {
       sortedlist.add(minion.getId());
     }
   }
   if (sortedlist.size() == 0) {
     return;
   } else if (deleteactive && sortedlist.size() == 1) {
     activeminion = null;
     return;
   }
   Collections.sort(sortedlist);
   int index = 0;
   if (activeminion != null) {
     index = sortedlist.indexOf(activeminion.getId());
   }
   if (index == 0) {
     index = sortedlist.size() - 1;
   } else {
     index--;
   }
   index = sortedlist.get(index);
   for (EntityRef minion : entman.iteratorEntities(MinionComponent.class)) {
     if (minion.getId() == index) {
       setActiveMinion(minion);
     }
   }
 }
  private EntityData.Entity serializeEntityDelta(EntityRef entityRef, Prefab prefab) {
    EntityData.Entity.Builder entity = EntityData.Entity.newBuilder();
    entity.setId(entityRef.getId());
    entity.setParentPrefab(prefab.getName());
    for (Component component : entityRef.iterateComponents()) {
      if (component.getClass().equals(EntityInfoComponent.class)) continue;

      Component prefabComponent = prefab.getComponent(component.getClass());
      EntityData.Component componentData;
      if (prefabComponent == null) {
        componentData = serializeComponent(component);
      } else {
        componentData = serializeComponent(prefabComponent, component);
      }

      if (componentData != null) {
        entity.addComponent(componentData);
      }
    }
    for (Component prefabComponent : prefab.listComponents()) {
      if (!entityRef.hasComponent(prefabComponent.getClass())) {
        entity.addRemovedComponent(ComponentUtil.getComponentClassName(prefabComponent.getClass()));
      }
    }
    return entity.build();
  }
  private EntityData.Entity serializeEntityFull(EntityRef entityRef) {
    EntityData.Entity.Builder entity = EntityData.Entity.newBuilder();
    entity.setId(entityRef.getId());
    for (Component component : entityRef.iterateComponents()) {
      if (component.getClass().equals(EntityInfoComponent.class)) continue;

      EntityData.Component componentData = serializeComponent(component);
      if (componentData != null) {
        entity.addComponent(componentData);
      }
    }
    return entity.build();
  }