@Test public void testReplaceAnimation() throws Exception { GameEventManager theEventManager = mock(GameEventManager.class); GameObject theOwner = mock(GameObject.class); GameScene theScene = mock(GameScene.class); when(theOwner.getGameScene()).thenReturn(theScene); SpriteBehaviorTemplate theTemplate = new SpriteBehaviorTemplate(theEventManager, theOwner); Animation theOldAnimation = new Animation("Lala"); Animation theOldAnimation2 = new Animation("Lala2"); theTemplate.addAnimation(theOldAnimation); theTemplate.addAnimation(theOldAnimation2); Animation theNewAnimation = theOldAnimation.changeName("Lala3"); theTemplate.replaceAnimation(theOldAnimation, theNewAnimation); assertEquals(2, theTemplate.getAnimations().length); assertSame(theNewAnimation, theTemplate.getAnimations()[0]); assertSame(theOldAnimation2, theTemplate.getAnimations()[1]); verify(theEventManager, times(3)).fire(any(GameObjectConfigurationChanged.class)); }
public void replaceAnimation(Animation aOldAnimation, Animation aNewAnimation) { if (aOldAnimation == aNewAnimation) { return; } List<Animation> theNewList = new ArrayList<>(); for (Animation theAnim : animations) { if (aOldAnimation.getUuid().equals(theAnim.getUuid())) { theNewList.add(aNewAnimation); } else { theNewList.add(theAnim); } } animations.clear(); animations.addAll(theNewList); Animation theCurrent = currentAnimation.get(); if (theCurrent != null) { if (theCurrent.getUuid().equals(aOldAnimation.getUuid())) { currentAnimation.set(aNewAnimation); } } eventManager.fire(new GameObjectConfigurationChanged(getOwner())); }
SpriteBehaviorTemplate implements BehaviorTemplate<SpriteBehavior>, Sprite, Reflectable<SpriteClassInformation> { public void replaceAnimation(Animation aOldAnimation, Animation aNewAnimation) { if (aOldAnimation == aNewAnimation) { return; } List<Animation> theNewList = new ArrayList<>(); for (Animation theAnim : animations) { if (aOldAnimation.getUuid().equals(theAnim.getUuid())) { theNewList.add(aNewAnimation); } else { theNewList.add(theAnim); } } animations.clear(); animations.addAll(theNewList); Animation theCurrent = currentAnimation.get(); if (theCurrent != null) { if (theCurrent.getUuid().equals(aOldAnimation.getUuid())) { currentAnimation.set(aNewAnimation); } } eventManager.fire(new GameObjectConfigurationChanged(getOwner())); } }
SpriteBehaviorTemplate implements BehaviorTemplate<SpriteBehavior>, Sprite, Reflectable<SpriteClassInformation> { public void replaceAnimation(Animation aOldAnimation, Animation aNewAnimation) { if (aOldAnimation == aNewAnimation) { return; } List<Animation> theNewList = new ArrayList<>(); for (Animation theAnim : animations) { if (aOldAnimation.getUuid().equals(theAnim.getUuid())) { theNewList.add(aNewAnimation); } else { theNewList.add(theAnim); } } animations.clear(); animations.addAll(theNewList); Animation theCurrent = currentAnimation.get(); if (theCurrent != null) { if (theCurrent.getUuid().equals(aOldAnimation.getUuid())) { currentAnimation.set(aNewAnimation); } } eventManager.fire(new GameObjectConfigurationChanged(getOwner())); } SpriteBehaviorTemplate(GameEventManager aEventManager, GameObject aOwner); }
SpriteBehaviorTemplate implements BehaviorTemplate<SpriteBehavior>, Sprite, Reflectable<SpriteClassInformation> { public void replaceAnimation(Animation aOldAnimation, Animation aNewAnimation) { if (aOldAnimation == aNewAnimation) { return; } List<Animation> theNewList = new ArrayList<>(); for (Animation theAnim : animations) { if (aOldAnimation.getUuid().equals(theAnim.getUuid())) { theNewList.add(aNewAnimation); } else { theNewList.add(theAnim); } } animations.clear(); animations.addAll(theNewList); Animation theCurrent = currentAnimation.get(); if (theCurrent != null) { if (theCurrent.getUuid().equals(aOldAnimation.getUuid())) { currentAnimation.set(aNewAnimation); } } eventManager.fire(new GameObjectConfigurationChanged(getOwner())); } SpriteBehaviorTemplate(GameEventManager aEventManager, GameObject aOwner); @Override BehaviorType getType(); @Override SpriteClassInformation getClassInformation(); @Override GameObject getOwner(); @Override SpriteBehavior create(GameObjectInstance aInstance, GameRuntime aGameRuntime); @Override Property<Animation> currentAnimationProperty(); @Override Property<Integer> speedProperty(); void addAnimation(Animation aAnimation); @Override Map<String, Object> serialize(); @Override void delete(); @Override GameScene getGameScene(); @Override Animation[] getAnimations(); void replaceAnimation(Animation aOldAnimation, Animation aNewAnimation); static SpriteBehaviorTemplate deserialize(GameEventManager aEventManager, GameObject aOwner, Map<String, Object> aSerializedData); }
SpriteBehaviorTemplate implements BehaviorTemplate<SpriteBehavior>, Sprite, Reflectable<SpriteClassInformation> { public void replaceAnimation(Animation aOldAnimation, Animation aNewAnimation) { if (aOldAnimation == aNewAnimation) { return; } List<Animation> theNewList = new ArrayList<>(); for (Animation theAnim : animations) { if (aOldAnimation.getUuid().equals(theAnim.getUuid())) { theNewList.add(aNewAnimation); } else { theNewList.add(theAnim); } } animations.clear(); animations.addAll(theNewList); Animation theCurrent = currentAnimation.get(); if (theCurrent != null) { if (theCurrent.getUuid().equals(aOldAnimation.getUuid())) { currentAnimation.set(aNewAnimation); } } eventManager.fire(new GameObjectConfigurationChanged(getOwner())); } SpriteBehaviorTemplate(GameEventManager aEventManager, GameObject aOwner); @Override BehaviorType getType(); @Override SpriteClassInformation getClassInformation(); @Override GameObject getOwner(); @Override SpriteBehavior create(GameObjectInstance aInstance, GameRuntime aGameRuntime); @Override Property<Animation> currentAnimationProperty(); @Override Property<Integer> speedProperty(); void addAnimation(Animation aAnimation); @Override Map<String, Object> serialize(); @Override void delete(); @Override GameScene getGameScene(); @Override Animation[] getAnimations(); void replaceAnimation(Animation aOldAnimation, Animation aNewAnimation); static SpriteBehaviorTemplate deserialize(GameEventManager aEventManager, GameObject aOwner, Map<String, Object> aSerializedData); static final BehaviorType TYPE; }