@Test public void testSerialize() throws Exception { GameEventManager theEventManager = mock(GameEventManager.class); GameRuntime theRuntime = mock(GameRuntime.class); when(theRuntime.getEventManager()).thenReturn(theEventManager); GameScene theScene = mock(GameScene.class); when(theScene.getRuntime()).thenReturn(theRuntime); BehaviorTemplate theBehavior = mock(BehaviorTemplate.class); GameObject theObject = new GameObject(theScene, "Test"); theObject.add(theBehavior); Map<String, Object> theData = theObject.serialize(); assertEquals(5, theData.size()); assertNotNull(theData.get(GameObject.UUID_PROPERTY)); assertEquals("Test", theData.get(GameObject.NAME_PROPERTY)); assertEquals("true", theData.get(GameObject.VISIBLE_PROPERTY)); Map<String, Object> theSize = (Map<String, Object>) theData.get(GameObject.SIZE_PROPERTY); assertEquals(new Size(64, 64), Size.deserialize(theSize)); List<Map<String, Object>> theTemplates = (List<Map<String, Object>>) theData.get("templates"); assertEquals(1, theTemplates.size()); assertTrue(theTemplates.get(0) instanceof Map); verify(theBehavior).serialize(); }
public Map<String, Object> serialize() { Map<String, Object> theResult = new HashMap<>(); theResult.put(NAME_PROPERTY, name.get()); theResult.put(UUID_PROPERTY, uuid.get()); theResult.put(VISIBLE_PROPERTY, Boolean.toString(visible.get())); theResult.put(SIZE_PROPERTY, size.get().serialize()); List<Map<String, Object>> theTemplates = new ArrayList<>(); for (BehaviorTemplate theTemplate : behaviors.values()) { theTemplates.add(theTemplate.serialize()); } theResult.put("templates", theTemplates); return theResult; }
GameObject implements Reflectable<GameObjectClassInformation> { public Map<String, Object> serialize() { Map<String, Object> theResult = new HashMap<>(); theResult.put(NAME_PROPERTY, name.get()); theResult.put(UUID_PROPERTY, uuid.get()); theResult.put(VISIBLE_PROPERTY, Boolean.toString(visible.get())); theResult.put(SIZE_PROPERTY, size.get().serialize()); List<Map<String, Object>> theTemplates = new ArrayList<>(); for (BehaviorTemplate theTemplate : behaviors.values()) { theTemplates.add(theTemplate.serialize()); } theResult.put("templates", theTemplates); return theResult; } }
GameObject implements Reflectable<GameObjectClassInformation> { public Map<String, Object> serialize() { Map<String, Object> theResult = new HashMap<>(); theResult.put(NAME_PROPERTY, name.get()); theResult.put(UUID_PROPERTY, uuid.get()); theResult.put(VISIBLE_PROPERTY, Boolean.toString(visible.get())); theResult.put(SIZE_PROPERTY, size.get().serialize()); List<Map<String, Object>> theTemplates = new ArrayList<>(); for (BehaviorTemplate theTemplate : behaviors.values()) { theTemplates.add(theTemplate.serialize()); } theResult.put("templates", theTemplates); return theResult; } GameObject(GameScene aScene, String aName);   GameObject(GameScene aScene, String aName, String aUUID); }
GameObject implements Reflectable<GameObjectClassInformation> { public Map<String, Object> serialize() { Map<String, Object> theResult = new HashMap<>(); theResult.put(NAME_PROPERTY, name.get()); theResult.put(UUID_PROPERTY, uuid.get()); theResult.put(VISIBLE_PROPERTY, Boolean.toString(visible.get())); theResult.put(SIZE_PROPERTY, size.get().serialize()); List<Map<String, Object>> theTemplates = new ArrayList<>(); for (BehaviorTemplate theTemplate : behaviors.values()) { theTemplates.add(theTemplate.serialize()); } theResult.put("templates", theTemplates); return theResult; } GameObject(GameScene aScene, String aName);   GameObject(GameScene aScene, String aName, String aUUID); GameScene getGameScene(); @ReflectiveField Property<String> uuidProperty(); @ReflectiveField Property<String> nameProperty(); @ReflectiveField Property<Size> sizeProperty(); @ReflectiveField Property<Boolean> visibleProperty(); @Override boolean equals(Object o); @Override int hashCode(); void add(BehaviorTemplate aBehaviorTemplate); void remove(BehaviorTemplate aBehaviorTemplate); T getBehaviorTemplate(BehaviorType aType); @Override GameObjectClassInformation getClassInformation(); Set<BehaviorTemplate> getBehaviorTemplates(); Map<String, Object> serialize(); static GameObject deserialize(GameRuntime aGameRuntime, GameScene aGameScene, Map<String, Object> theSerializedData); }
GameObject implements Reflectable<GameObjectClassInformation> { public Map<String, Object> serialize() { Map<String, Object> theResult = new HashMap<>(); theResult.put(NAME_PROPERTY, name.get()); theResult.put(UUID_PROPERTY, uuid.get()); theResult.put(VISIBLE_PROPERTY, Boolean.toString(visible.get())); theResult.put(SIZE_PROPERTY, size.get().serialize()); List<Map<String, Object>> theTemplates = new ArrayList<>(); for (BehaviorTemplate theTemplate : behaviors.values()) { theTemplates.add(theTemplate.serialize()); } theResult.put("templates", theTemplates); return theResult; } GameObject(GameScene aScene, String aName);   GameObject(GameScene aScene, String aName, String aUUID); GameScene getGameScene(); @ReflectiveField Property<String> uuidProperty(); @ReflectiveField Property<String> nameProperty(); @ReflectiveField Property<Size> sizeProperty(); @ReflectiveField Property<Boolean> visibleProperty(); @Override boolean equals(Object o); @Override int hashCode(); void add(BehaviorTemplate aBehaviorTemplate); void remove(BehaviorTemplate aBehaviorTemplate); T getBehaviorTemplate(BehaviorType aType); @Override GameObjectClassInformation getClassInformation(); Set<BehaviorTemplate> getBehaviorTemplates(); Map<String, Object> serialize(); static GameObject deserialize(GameRuntime aGameRuntime, GameScene aGameScene, Map<String, Object> theSerializedData); static final String UUID_PROPERTY; static final String NAME_PROPERTY; static final String SIZE_PROPERTY; static final String VISIBLE_PROPERTY; }