Skip to content

Commit 98d94a7

Browse files
committed
Better error msg.
1 parent aca1a4b commit 98d94a7

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

blade-engine/src/com/bladecoder/engine/actions/GotoAction.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.bladecoder.engine.model.InteractiveActor;
2525
import com.bladecoder.engine.model.VerbRunner;
2626
import com.bladecoder.engine.model.World;
27+
import com.bladecoder.engine.util.EngineLogger;
2728

2829
@ActionDescription("Walks to the selected position")
2930
public class GotoAction implements Action {
@@ -32,27 +33,27 @@ public enum Align {
3233
}
3334

3435
@ActionPropertyDescription("The walking actor")
35-
@ActionProperty(type = Type.CHARACTER_ACTOR, required=true)
36+
@ActionProperty(type = Type.CHARACTER_ACTOR, required = true)
3637
private String actor;
3738

3839
@ActionPropertyDescription("Walks to this actor")
3940
@ActionProperty(type = Type.ACTOR)
4041
private String target;
41-
42+
4243
@ActionProperty
4344
@ActionPropertyDescription("The absolute position to walk to if no target actor is selected. Relative to target if selected.")
4445
private Vector2 pos;
45-
46-
@ActionProperty(required=true, defaultValue = "false")
46+
47+
@ActionProperty(required = true, defaultValue = "false")
4748
@ActionPropertyDescription("Ignore the walking zone and walk in a straight line.")
4849
private boolean ignoreWalkZone = false;
4950

5051
@ActionProperty(required = true, defaultValue = "true")
5152
@ActionPropertyDescription("If this param is 'false' the text is showed and the action continues inmediatly")
5253
private boolean wait = true;
53-
54+
5455
private World w;
55-
56+
5657
@Override
5758
public void init(World w) {
5859
this.w = w;
@@ -62,35 +63,40 @@ public void init(World w) {
6263
public boolean run(VerbRunner cb) {
6364

6465
CharacterActor actor = (CharacterActor) w.getCurrentScene().getActor(this.actor, false);
65-
66+
6667
float x = actor.getX();
6768
float y = actor.getY();
6869

6970
if (target != null) {
70-
BaseActor target = w.getCurrentScene().getActor(this.target, false);
71-
72-
x = target.getX();
73-
y = target.getY();
74-
75-
if(target instanceof InteractiveActor && target != actor) {
76-
Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
77-
x+= refPoint.x;
78-
y+= refPoint.y;
71+
BaseActor targetActor = w.getCurrentScene().getActor(target, false);
72+
73+
if (targetActor == null) {
74+
EngineLogger.error(target + " not found in the current scene.");
75+
return false;
7976
}
80-
81-
if(pos != null){
77+
78+
x = targetActor.getX();
79+
y = targetActor.getY();
80+
81+
if (targetActor instanceof InteractiveActor && targetActor != actor) {
82+
Vector2 refPoint = ((InteractiveActor) targetActor).getRefPoint();
83+
x += refPoint.x;
84+
y += refPoint.y;
85+
}
86+
87+
if (pos != null) {
8288
float scale = EngineAssetManager.getInstance().getScale();
83-
89+
8490
x += pos.x * scale;
8591
y += pos.y * scale;
8692
}
87-
} else if(pos != null){
93+
} else if (pos != null) {
8894
float scale = EngineAssetManager.getInstance().getScale();
89-
95+
9096
x = pos.x * scale;
9197
y = pos.y * scale;
9298
}
93-
99+
94100
actor.goTo(new Vector2(x, y), wait ? cb : null, ignoreWalkZone);
95101

96102
return wait;

0 commit comments

Comments
 (0)