@Test public void testDeserialize() throws Exception { BehaviorTemplate theBehavior = mock(BehaviorTemplate.class); BehaviorTemplateUnmarshaller theUnmarshaller = mock(BehaviorTemplateUnmarshaller.class); when(theUnmarshaller.deserialize(any(GameEventManager.class), any(GameObject.class), anyMap())).thenReturn(theBehavior); IORegistry theRegistry = mock(IORegistry.class); when(theRegistry.getBehaviorTemplateUnmarshallerFor(eq(new BehaviorType("behav")))).thenReturn(theUnmarshaller); GameEventManager theEventManager = mock(GameEventManager.class); GameRuntime theRuntime = mock(GameRuntime.class); when(theRuntime.getIORegistry()).thenReturn(theRegistry); when(theRuntime.getEventManager()).thenReturn(theEventManager); GameScene theScene = mock(GameScene.class); when(theScene.getRuntime()).thenReturn(theRuntime); Map<String, Object> theData = new HashMap<>(); theData.put(GameObject.NAME_PROPERTY, "Test"); theData.put(GameObject.UUID_PROPERTY, "UID"); theData.put(GameObject.VISIBLE_PROPERTY, "false"); theData.put(GameObject.SIZE_PROPERTY, new Size(17, 18).serialize()); List<Map<String, Object>> theTemplates = new ArrayList<>(); Map<String, Object> theSingleBehavior = new HashMap<>(); theSingleBehavior.put(Behavior.TYPE_ATTRIBUTE, "behav"); theTemplates.add(theSingleBehavior); theData.put("templates", theTemplates); GameObject theObject = GameObject.deserialize(theRuntime, theScene, theData); assertEquals("Test", theObject.nameProperty().get()); assertEquals("UID", theObject.uuidProperty().get()); assertEquals(new Size(17, 18), theObject.sizeProperty().get()); assertFalse(theObject.visibleProperty().get()); assertEquals(1, theObject.getBehaviorTemplates().size()); assertTrue(theObject.getBehaviorTemplates().contains(theBehavior)); }
public static GameObject deserialize(GameRuntime aGameRuntime, GameScene aGameScene, Map<String, Object> theSerializedData) { String theName = (String) theSerializedData.get(NAME_PROPERTY); String theUUID = (String) theSerializedData.get(UUID_PROPERTY); GameObject theObject = new GameObject(aGameScene, theName, theUUID); String theVisible = (String) theSerializedData.get(VISIBLE_PROPERTY); if (theVisible != null) { theObject.visibleProperty().setQuietly(Boolean.valueOf(theVisible)); } Map<String, Object> theSize = (Map<String, Object>) theSerializedData.get(SIZE_PROPERTY); if (theSize != null) { theObject.size.setQuietly(Size.deserialize(theSize)); } List<Map<String, Object>> theTemplates = (List<Map<String, Object>>) theSerializedData.get("templates"); for (Map<String, Object> theTemplate : theTemplates) { BehaviorType theTypeKey = new BehaviorType((String) theTemplate.get(Behavior.TYPE_ATTRIBUTE)); theObject.add(aGameRuntime.getIORegistry().getBehaviorTemplateUnmarshallerFor(theTypeKey).deserialize(aGameRuntime.getEventManager(), theObject, theTemplate)); } return theObject; }
GameObject implements Reflectable<GameObjectClassInformation> { public static GameObject deserialize(GameRuntime aGameRuntime, GameScene aGameScene, Map<String, Object> theSerializedData) { String theName = (String) theSerializedData.get(NAME_PROPERTY); String theUUID = (String) theSerializedData.get(UUID_PROPERTY); GameObject theObject = new GameObject(aGameScene, theName, theUUID); String theVisible = (String) theSerializedData.get(VISIBLE_PROPERTY); if (theVisible != null) { theObject.visibleProperty().setQuietly(Boolean.valueOf(theVisible)); } Map<String, Object> theSize = (Map<String, Object>) theSerializedData.get(SIZE_PROPERTY); if (theSize != null) { theObject.size.setQuietly(Size.deserialize(theSize)); } List<Map<String, Object>> theTemplates = (List<Map<String, Object>>) theSerializedData.get("templates"); for (Map<String, Object> theTemplate : theTemplates) { BehaviorType theTypeKey = new BehaviorType((String) theTemplate.get(Behavior.TYPE_ATTRIBUTE)); theObject.add(aGameRuntime.getIORegistry().getBehaviorTemplateUnmarshallerFor(theTypeKey).deserialize(aGameRuntime.getEventManager(), theObject, theTemplate)); } return theObject; } }
GameObject implements Reflectable<GameObjectClassInformation> { public static GameObject deserialize(GameRuntime aGameRuntime, GameScene aGameScene, Map<String, Object> theSerializedData) { String theName = (String) theSerializedData.get(NAME_PROPERTY); String theUUID = (String) theSerializedData.get(UUID_PROPERTY); GameObject theObject = new GameObject(aGameScene, theName, theUUID); String theVisible = (String) theSerializedData.get(VISIBLE_PROPERTY); if (theVisible != null) { theObject.visibleProperty().setQuietly(Boolean.valueOf(theVisible)); } Map<String, Object> theSize = (Map<String, Object>) theSerializedData.get(SIZE_PROPERTY); if (theSize != null) { theObject.size.setQuietly(Size.deserialize(theSize)); } List<Map<String, Object>> theTemplates = (List<Map<String, Object>>) theSerializedData.get("templates"); for (Map<String, Object> theTemplate : theTemplates) { BehaviorType theTypeKey = new BehaviorType((String) theTemplate.get(Behavior.TYPE_ATTRIBUTE)); theObject.add(aGameRuntime.getIORegistry().getBehaviorTemplateUnmarshallerFor(theTypeKey).deserialize(aGameRuntime.getEventManager(), theObject, theTemplate)); } return theObject; } GameObject(GameScene aScene, String aName);   GameObject(GameScene aScene, String aName, String aUUID); }
GameObject implements Reflectable<GameObjectClassInformation> { public static GameObject deserialize(GameRuntime aGameRuntime, GameScene aGameScene, Map<String, Object> theSerializedData) { String theName = (String) theSerializedData.get(NAME_PROPERTY); String theUUID = (String) theSerializedData.get(UUID_PROPERTY); GameObject theObject = new GameObject(aGameScene, theName, theUUID); String theVisible = (String) theSerializedData.get(VISIBLE_PROPERTY); if (theVisible != null) { theObject.visibleProperty().setQuietly(Boolean.valueOf(theVisible)); } Map<String, Object> theSize = (Map<String, Object>) theSerializedData.get(SIZE_PROPERTY); if (theSize != null) { theObject.size.setQuietly(Size.deserialize(theSize)); } List<Map<String, Object>> theTemplates = (List<Map<String, Object>>) theSerializedData.get("templates"); for (Map<String, Object> theTemplate : theTemplates) { BehaviorType theTypeKey = new BehaviorType((String) theTemplate.get(Behavior.TYPE_ATTRIBUTE)); theObject.add(aGameRuntime.getIORegistry().getBehaviorTemplateUnmarshallerFor(theTypeKey).deserialize(aGameRuntime.getEventManager(), theObject, theTemplate)); } return theObject; } 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 static GameObject deserialize(GameRuntime aGameRuntime, GameScene aGameScene, Map<String, Object> theSerializedData) { String theName = (String) theSerializedData.get(NAME_PROPERTY); String theUUID = (String) theSerializedData.get(UUID_PROPERTY); GameObject theObject = new GameObject(aGameScene, theName, theUUID); String theVisible = (String) theSerializedData.get(VISIBLE_PROPERTY); if (theVisible != null) { theObject.visibleProperty().setQuietly(Boolean.valueOf(theVisible)); } Map<String, Object> theSize = (Map<String, Object>) theSerializedData.get(SIZE_PROPERTY); if (theSize != null) { theObject.size.setQuietly(Size.deserialize(theSize)); } List<Map<String, Object>> theTemplates = (List<Map<String, Object>>) theSerializedData.get("templates"); for (Map<String, Object> theTemplate : theTemplates) { BehaviorType theTypeKey = new BehaviorType((String) theTemplate.get(Behavior.TYPE_ATTRIBUTE)); theObject.add(aGameRuntime.getIORegistry().getBehaviorTemplateUnmarshallerFor(theTypeKey).deserialize(aGameRuntime.getEventManager(), theObject, theTemplate)); } return theObject; } 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; }