@Override public EntityData.Prefab serializePrefab(Prefab prefab) { EntityData.Prefab.Builder prefabData = EntityData.Prefab.newBuilder(); prefabData.setName(prefab.getName()); for (Prefab parent : prefab.getParents()) { prefabData.addParentName(parent.getName()); } for (Component component : prefab.listOwnComponents()) { EntityData.Component componentData = serializeComponent(component); if (componentData != null) { prefabData.addComponent(componentData); } } return prefabData.build(); }
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(); }