/*******************************************************************************
 * 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.badlogic.gdx.math.Vector2;
import com.bladecoder.engine.actions.Param.Type;
import com.bladecoder.engine.assets.EngineAssetManager;
import com.bladecoder.engine.model.BaseActor;
import com.bladecoder.engine.model.InteractiveActor;
import com.bladecoder.engine.model.SceneCamera;
import com.bladecoder.engine.model.SpriteActor;
import com.bladecoder.engine.model.VerbRunner;
import com.bladecoder.engine.model.World;
import com.bladecoder.engine.util.InterpolationMode;

@ActionDescription("Set/Animates the camera position and zoom. Also can stablish the follow character parameter")
public class CameraAction implements Action {
	@ActionPropertyDescription("Sets the camera position relative to this actor.")
	@ActionProperty(type = Type.ACTOR)
	private String target;
	
	@ActionProperty
	@ActionPropertyDescription("The target position")
	private Vector2 pos;

	@ActionProperty
	@ActionPropertyDescription("The target 'zoom'. If not set, the current zoom is used.")
	private Float zoom;

	@ActionProperty
	@ActionPropertyDescription("Duration of the animation in seconds. If not '0' and animation is triggered")
	private Float duration;

	@ActionPropertyDescription("Sets the actor to follow. 'none' puts no actor to follow")
	@ActionProperty(type = Type.ACTOR)
	private String followActor;
	
	@ActionProperty
	@ActionPropertyDescription("The interpolation mode")
	private InterpolationMode interpolation;

	@ActionProperty(defaultValue = "true", required = true)
	@ActionPropertyDescription("If this param is 'false' the text is showed and the action continues inmediatly")
	private boolean wait = true;

	@Override
	public boolean run(VerbRunner cb) {
		
		Vector2 pos2 = null;
		
		if(pos != null)
			pos2 = new Vector2(pos);

		float scale = EngineAssetManager.getInstance().getScale();

		SceneCamera camera = World.getInstance().getSceneCamera();
		
		if(zoom == null || zoom < 0)
			zoom = camera.getZoom();
		
		if(pos == null && target == null) {
			pos2 = new Vector2(camera.getPosition());
			pos2.x /= scale;
			pos2.y /= scale;
		}
		
		if (target != null) {
			BaseActor target = World.getInstance().getCurrentScene().getActor(this.target, false);
			
			float x = target.getX();
			float y = target.getY();
			
			if(target instanceof InteractiveActor) {
				Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
				x+= refPoint.x;
				y+= refPoint.y;
			}
			
			if(pos2 != null){
				pos2.x += x;
				pos2.y += y;
			} else {
				pos2 = new Vector2(x,y);
			}
		} 

		if (followActor != null) {
			if (followActor.equals("none"))
				World.getInstance().getCurrentScene().setCameraFollowActor(null);
			else {
				World.getInstance().getCurrentScene().setCameraFollowActor((SpriteActor) World.getInstance().getCurrentScene()
						.getActor(followActor, false));
			}
		}

		if (duration == null || duration == 0) {
			camera.setZoom(zoom);
			camera.setPosition(pos.x * scale, pos.y * scale);
			return false;
		} else {
			camera.startAnimation(pos.x * scale, pos.y * scale, zoom, duration, interpolation, wait?cb:null);
		}
		
		return wait;
	}

}

@@ -2486,24 +2486,49 @@
  = null;%0A%09%09%0A
+%09%09Float zoom2 = zoom;%0A%09%09%0A
 %09%09if(pos != 
@@ -2697,16 +2697,17 @@
 %09if(zoom
+2
  == null
@@ -2714,16 +2714,17 @@
  %7C%7C zoom
+2
  %3C 0)%0A%09%09
@@ -2728,16 +2728,17 @@
 %0A%09%09%09zoom
+2
  = camer
@@ -3699,16 +3699,17 @@
 oom(zoom
+2
 );%0A%09%09%09ca
@@ -3720,32 +3720,33 @@
 .setPosition(pos
+2
 .x * scale, pos.
@@ -3736,32 +3736,33 @@
 2.x * scale, pos
+2
 .y * scale);%0A%09%09%09
@@ -3814,16 +3814,17 @@
 tion(pos
+2
 .x * sca
@@ -3830,16 +3830,17 @@
 ale, pos
+2
 .y * sca
@@ -3847,16 +3847,17 @@
 le, zoom
+2
 , durati

Fix lastest commit in CameraAction.