Skip to content

Commit

Permalink
action refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bladecoder committed Oct 3, 2014
1 parent f465ff2 commit 6aae6d8
Show file tree
Hide file tree
Showing 27 changed files with 105 additions and 139 deletions.
14 changes: 6 additions & 8 deletions blade-engine/src/com/bladecoder/engine/actions/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@
import com.bladecoder.engine.actions.Param;

public interface Action {
public void run();

public void setParams(HashMap<String, String> params);

/**
* If this method returns true, the verb must stops the execution and wait
* for the action to call the cb.resume()
* Execute the action
*
* @param cb
* @return
* @return If returns true, the verb must stops the execution and wait
* for the action to call the cb.resume()
*/
public boolean waitForFinish(ActionCallback cb);
public boolean run(ActionCallback cb);

public void setParams(HashMap<String, String> params);

public String getInfo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ public void resume() {
cb2.resume();
}
}

@Override
public boolean waitForFinish(ActionCallback cb) {

public void setVerbCb(ActionCallback cb) {
this.verbCb = cb;

return wait;
}
}

public void setWait(boolean wait) {
this.wait = wait;
Expand Down
10 changes: 4 additions & 6 deletions blade-engine/src/com/bladecoder/engine/actions/CameraAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

import java.util.HashMap;

import com.bladecoder.engine.actions.BaseCallbackAction;
import com.bladecoder.engine.actions.Param;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
Expand All @@ -28,7 +25,6 @@
import com.bladecoder.engine.model.SceneCamera;
import com.bladecoder.engine.model.SpriteActor;
import com.bladecoder.engine.model.World;
import com.bladecoder.engine.util.EngineLogger;

public class CameraAction extends BaseCallbackAction {
public static final String INFO = "Set/Animates the camera position and zoom. Also can stablish the follow character parameter";
Expand Down Expand Up @@ -73,8 +69,8 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
EngineLogger.debug("CAMERA_ACTION");
public boolean run(ActionCallback cb) {
setVerbCb(cb);

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

Expand Down Expand Up @@ -103,6 +99,8 @@ public void run() {
} else {
camera.startAnimation(pos.x * scale, pos.y * scale, zoom, duration, getWait()?this:null);
}

return getWait();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
public boolean run(ActionCallback cb) {

if(actorId != null) {
Actor actor = World.getInstance().getCurrentScene().getActor(actorId, true);

Expand All @@ -59,6 +60,8 @@ public void run() {
Scene s = World.getInstance().getCurrentScene();
s.getVerbManager().cancelVerb(verb, s.getState(), target);
}

return false;
}

@Override
Expand All @@ -71,9 +74,4 @@ public Param[] getParams() {
return PARAMS;
}

@Override
public boolean waitForFinish(ActionCallback cb) {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
public boolean run(ActionCallback cb) {

SpriteActor actor = (SpriteActor) World.getInstance().getCurrentScene()
.getActor(actorId, false);
Dialog d = actor.getDialog(dialog);

if (d == null) {
EngineLogger.error("DialogOptionAction: Dialog '" + dialog + "' not found");
return;
return false;
}

DialogOption o = null;
Expand All @@ -80,7 +80,7 @@ public void run() {

if (o == null) {
EngineLogger.error("DialogOptionAction: Option '" + option + "' not found");
return;
return false;
}
}

Expand All @@ -91,6 +91,8 @@ public void run() {
World.getInstance().setCurrentDialog(actor.getDialog(dialog));
d.setCurrentOption(o);
}

return false;
}


Expand All @@ -103,9 +105,4 @@ public String getInfo() {
public Param[] getParams() {
return PARAMS;
}

@Override
public boolean waitForFinish(ActionCallback cb) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
public boolean run(ActionCallback cb) {
float scale = EngineAssetManager.getInstance().getScale();

Actor actor = World.getInstance().getInventory().getItem(itemId);

if(actor==null) {
EngineLogger.error(MessageFormat.format("DropItemAction - Item not found: {0}", itemId));
return;
return false;
}

World.getInstance().getInventory().removeItem(itemId);
Expand All @@ -66,6 +66,8 @@ public void run() {

if(pos != null)
((SpriteActor)actor).setPosition(pos.x * scale, pos.y * scale);

return false;
}

@Override
Expand All @@ -77,9 +79,4 @@ public String getInfo() {
public Param[] getParams() {
return PARAMS;
}

@Override
public boolean waitForFinish(ActionCallback cb) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.bladecoder.engine.actions.Action;
import com.bladecoder.engine.actions.BaseCallbackAction;
import com.bladecoder.engine.actions.Param;

import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
import com.bladecoder.engine.actions.Param.Type;
Expand Down Expand Up @@ -99,7 +98,8 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
public boolean run(ActionCallback cb) {
setVerbCb(cb);
EngineLogger.debug(MessageFormat.format("SET_FRAMEANIMATION_ACTION: {0}", fa));

float scale = EngineAssetManager.getInstance().getScale();
Expand All @@ -113,6 +113,8 @@ else if (setPos == SET_POS_RELATIVE) {
}

actor.startFrameAnimation(fa, repeat, count, getWait()?this:null);

return getWait();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.bladecoder.engine.actions.BaseCallbackAction;
import com.bladecoder.engine.actions.Param;

import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Json;
Expand All @@ -44,7 +43,9 @@ public class GotoAction extends BaseCallbackAction {
private String targetId;

@Override
public void run() {
public boolean run(ActionCallback cb) {
setVerbCb(cb);

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

SpriteActor actor = (SpriteActor) World.getInstance().getCurrentScene().getActor(actorId, false);
Expand All @@ -59,6 +60,8 @@ public void run() {
}
} else
actor.goTo(new Vector2(pos.x * scale, pos.y * scale), getWait()?this:null);

return getWait();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ public class LeaveAction implements Action {
String chapter;

@Override
public void run() {
public boolean run(ActionCallback cb) {

EngineLogger.debug("LEAVE ACTION");

if(chapter == null || chapter.isEmpty())
World.getInstance().setCurrentScene(scene);
else
World.getInstance().loadXMLChapter(chapter, scene);

return false;
}

@Override
Expand All @@ -63,8 +66,4 @@ public Param[] getParams() {
return PARAMS;
}

@Override
public boolean waitForFinish(ActionCallback cb) {
return false;
}
}
10 changes: 4 additions & 6 deletions blade-engine/src/com/bladecoder/engine/actions/LookAtAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
public boolean run(ActionCallback cb) {

EngineLogger.debug("LOOKAT ACTION");
Actor actor = (Actor) World.getInstance().getCurrentScene().getActor(actorId, true);

Expand All @@ -81,6 +82,8 @@ else if(actor!=null && player != null) {
if(text !=null)
World.getInstance().getTextManager().addSubtitle(text, TextManager.POS_SUBTITLE,
TextManager.POS_SUBTITLE, false, Text.Type.RECTANGLE, Color.BLACK, null);

return false;
}


Expand All @@ -93,9 +96,4 @@ public String getInfo() {
public Param[] getParams() {
return PARAMS;
}

@Override
public boolean waitForFinish(ActionCallback cb) {
return false;
}
}
10 changes: 4 additions & 6 deletions blade-engine/src/com/bladecoder/engine/actions/MusicAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
public boolean run(ActionCallback cb) {

boolean p = Boolean.parseBoolean(play);

if (p)
World.getInstance().getCurrentScene().playMusic();
else
World.getInstance().getCurrentScene().stopMusic();

return false;
}

@Override
Expand All @@ -55,9 +58,4 @@ public String getInfo() {
public Param[] getParams() {
return PARAMS;
}

@Override
public boolean waitForFinish(ActionCallback cb) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
public boolean run(ActionCallback cb) {

Actor actor = null;

Scene scn;
Expand Down Expand Up @@ -75,6 +76,8 @@ public void run() {

World.getInstance().getInventory().addItem(a);
}

return false;
}


Expand All @@ -88,8 +91,4 @@ public Param[] getParams() {
return PARAMS;
}

@Override
public boolean waitForFinish(ActionCallback cb) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.bladecoder.engine.actions.BaseCallbackAction;
import com.bladecoder.engine.actions.Param;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
Expand Down Expand Up @@ -78,14 +77,17 @@ public void setParams(HashMap<String, String> params) {
}

@Override
public void run() {
public boolean run(ActionCallback cb) {
setVerbCb(cb);
EngineLogger.debug("SET_POSANIMATION_ACTION");

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

SpriteActor actor = (SpriteActor) World.getInstance().getCurrentScene().getActor(actorId, false);

actor.startPosAnimation(repeat, count, speed, pos.x * scale, pos.y * scale, getWait()?this:null);

return getWait();
}

@Override
Expand Down
Loading

0 comments on commit 6aae6d8

Please sign in to comment.