/*******************************************************************************
 * Copyright 2014 Rafael Garcia Moreno.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.bladecoder.engine.actions;

import com.bladecoder.engine.anim.Tween;
import com.bladecoder.engine.model.SpriteActor;
import com.bladecoder.engine.model.VerbRunner;
import com.bladecoder.engine.model.World;

@ActionDescription("Sets the animation for an actor")
public class AnimationAction implements Action {

	@ActionProperty(required = true)
	@ActionPropertyDescription("The Animation to set")
	private ActorAnimationRef animation;

	@ActionProperty(required = true, defaultValue = "-1")
	@ActionPropertyDescription("The times to repeat. -1 to infinity repeat")
	private int count = -1;

	@ActionProperty(required = true)
	@ActionPropertyDescription("Waits to finish the animation.")
	private boolean wait = true;

	@ActionProperty(required = true, defaultValue = "SPRITE_DEFINED")
	@ActionPropertyDescription("The repeat mode")
	private Tween.Type repeat = Tween.Type.SPRITE_DEFINED;

	@Override
	public boolean run(VerbRunner cb) {
//		EngineLogger.debug(MessageFormat.format("ANIMATION_ACTION: {0}.{1}", animation.getActorId(), animation.getAnimationId()));
		
		String actorId = animation.getActorId();
		
		SpriteActor a = (SpriteActor) World.getInstance().getCurrentScene().getActor(actorId, true);

		a.startAnimation(animation.getAnimationId(), repeat, count, wait?cb:null);

		return wait;
	}

}

@@ -828,21 +828,124 @@
 ne.anim.
-Tween
+AnimationDesc;%0Aimport com.bladecoder.engine.anim.Tween;%0Aimport com.bladecoder.engine.model.AnimationRenderer
 ;%0Aimport
@@ -1756,16 +1756,192 @@
 DEFINED;
+%0A%09%0A%09@ActionProperty(required = true, defaultValue = %22false%22)%0A%09@ActionPropertyDescription(%22Keeps the current actor animation direction.%22)%0A%09private boolean keepDirection = false;
 %0A%0A%09@Over
@@ -2252,16 +2252,375 @@
 , true);
+%0A%09%09%0A%09%09String anim = animation.getAnimationId();%0A%09%09%0A%09%09if(keepDirection) %7B%0A%09%09%09String c = ((AnimationRenderer)a.getRenderer()).getCurrentAnimationId();%0A%09%09%09%0A%09%09%09if(anim.endsWith(AnimationDesc.LEFT) && c.endsWith(AnimationDesc.RIGHT) %7C%7C %0A%09%09%09%09%09anim.endsWith(AnimationDesc.RIGHT) && c.endsWith(AnimationDesc.LEFT)) %7B%0A%09%09%09%09anim = AnimationDesc.getFlipId(anim);%0A%09%09%09%7D%0A%09%09%7D
 %0A%0A%09%09a.st
@@ -2636,38 +2636,16 @@
 ion(anim
-ation.getAnimationId()
 , repeat

Add keepDirection parameter to Animation action.