Skip to content

Commit 68e0a13

Browse files
committed
Use PolygonUtils::isPointInside on IfActorAttr to avoid precision errors when using with goTo
1 parent 257ee42 commit 68e0a13

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.bladecoder.engine.model.World;
2626
import com.bladecoder.engine.util.ActionUtils;
2727
import com.bladecoder.engine.util.EngineLogger;
28+
import com.bladecoder.engine.util.PolygonUtils;
2829

2930
@ActionDescription(name = "IfActorAttr", value = "Execute the actions inside the If/EndIf if the attribute has the specified value.")
3031
public class IfAttrAction extends AbstractIfAction {
@@ -58,14 +59,13 @@ public boolean run(VerbRunner cb) {
5859
Scene s = actor.getScene(w);
5960

6061
final String actorId = actor.getActorId();
61-
if (actorId == null) {
62-
// if called inside a scene verb and no actor is specified, return
63-
EngineLogger.error(getClass() + ": No actor specified");
62+
BaseActor a = s.getActor(actorId, true);
63+
64+
if (a == null) {
65+
EngineLogger.error(getClass() + "- No not found: " + actorId);
6466
return false;
6567
}
6668

67-
BaseActor a = s.getActor(actorId, true);
68-
6969
if (attr.equals(ActorAttribute.STATE) && a instanceof InteractiveActor) {
7070
InteractiveActor ia = (InteractiveActor) a;
7171
if (!ActionUtils.compareNullStr(value, ia.getState())) {
@@ -153,12 +153,13 @@ public boolean run(VerbRunner cb) {
153153
}
154154
} else if (attr.equals(ActorAttribute.INSIDE)) {
155155
BaseActor insideActor = w.getCurrentScene().getActor(value, false);
156-
boolean inside = false;
157156

158-
if (a != null && insideActor != null)
159-
inside = insideActor.getBBox().contains(a.getX(), a.getY());
160-
else
157+
if (insideActor == null) {
161158
EngineLogger.debug("Actor for inside test not found: " + value);
159+
return false;
160+
}
161+
162+
boolean inside = PolygonUtils.isPointInside(insideActor.getBBox(), a.getX(), a.getY(), true);
162163

163164
if (!inside) {
164165
gotoElse(cb);

0 commit comments

Comments
 (0)