use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class ActionCallbackSerialization method find.
/**
* Searches for the ActionCallback represented by the id string.
*
* @param id
*/
public static ActionCallback find(String id) {
if (id == null)
return null;
Scene s = World.getInstance().getCurrentScene();
String[] split = id.split(SEPARATION_SYMBOL);
if (id.startsWith(INK_MANAGER_TAG)) {
if (split.length == 1)
return World.getInstance().getInkManager();
int actionPos = Integer.parseInt(split[1]);
Action action = World.getInstance().getInkManager().getActions().get(actionPos);
if (action instanceof ActionCallback)
return (ActionCallback) action;
}
if (split.length < 2)
return null;
String actorId;
String verbId;
int actionPos = -1;
if (id.startsWith(UIACTORS_TAG) || id.startsWith(INVENTORY_TAG)) {
actorId = split[1];
verbId = split[2];
if (split.length > 3)
actionPos = Integer.parseInt(split[3]);
} else {
actorId = split[0];
verbId = split[1];
if (split.length > 2)
actionPos = Integer.parseInt(split[2]);
}
Verb v = null;
if (actorId.equals(DEFAULT_VERB_TAG)) {
v = World.getInstance().getVerbManager().getVerb(verbId, null, null);
} else {
InteractiveActor a;
if (actorId.equals(s.getId())) {
v = s.getVerbManager().getVerbs().get(verbId);
} else {
a = (InteractiveActor) s.getActor(actorId, true);
if (a == null) {
EngineLogger.error("ActionCallbackSerialization - Actor not found: " + actorId + " cb: " + id);
return null;
}
v = a.getVerbManager().getVerbs().get(verbId);
}
}
if (v == null) {
EngineLogger.error("ActionCallbackSerialization - Verb not found: " + verbId + " cb: " + id);
return null;
}
if (actionPos == -1)
return v;
Action action = v.getActions().get(actionPos);
if (action instanceof ActionCallback)
return (ActionCallback) action;
EngineLogger.error("ActionCallbackSerialization - CB not found: " + id);
return null;
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class SayAction method run.
@Override
public boolean run(VerbRunner cb) {
float x = TextManager.POS_SUBTITLE, y = TextManager.POS_SUBTITLE;
Color color = null;
if (text == null)
return false;
setVerbCb(cb);
InteractiveActor a = (InteractiveActor) World.getInstance().getCurrentScene().getActor(actor, false);
if (type == Text.Type.TALK && a != null) {
Rectangle boundingRectangle = a.getBBox().getBoundingRectangle();
x = boundingRectangle.getX() + boundingRectangle.getWidth() / 2;
y = boundingRectangle.getY() + boundingRectangle.getHeight();
color = ((CharacterActor) a).getTextColor();
restoreStandPose((CharacterActor) a);
startTalkAnim((CharacterActor) a);
}
World.getInstance().getTextManager().addText(text, x, y, queue, type, color, style, a != null ? a.getId() : actor, voiceId, this);
return getWait();
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class CameraAction method run.
@Override
public boolean run(VerbRunner cb) {
Vector2 pos2 = null;
Float zoom2 = zoom;
if (pos != null)
pos2 = new Vector2(pos);
float scale = EngineAssetManager.getInstance().getScale();
SceneCamera camera = World.getInstance().getSceneCamera();
if (zoom2 == null || zoom2 < 0)
zoom2 = 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(zoom2);
camera.setPosition(pos2.x * scale, pos2.y * scale);
return false;
} else {
camera.startAnimation(pos2.x * scale, pos2.y * scale, zoom2, duration, interpolation, wait ? cb : null);
}
return wait;
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class IfAttrAction method run.
@Override
public boolean run(VerbRunner cb) {
Scene s = actor.getScene();
final String actorId = actor.getActorId();
if (actorId == null) {
// if called inside a scene verb and no actor is specified, return
EngineLogger.error(getClass() + ": No actor specified");
return false;
}
BaseActor a = s.getActor(actorId, true);
if (attr.equals(ActorAttribute.STATE) && a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
if (!ActionUtils.compareNullStr(value, ia.getState())) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.VISIBLE)) {
boolean val = Boolean.parseBoolean(value);
if (val != a.isVisible()) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.INTERACTIVE)) {
boolean val = Boolean.parseBoolean(value);
if (a instanceof InteractiveActor) {
if (val != ((InteractiveActor) a).getInteraction()) {
gotoElse((VerbRunner) cb);
}
} else if (val == true) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.IN_INVENTORY)) {
boolean val = Boolean.parseBoolean(value);
SpriteActor item = null;
if (a != null)
item = World.getInstance().getInventory().get(a.getId());
if ((val && item == null) || (!val && item != null)) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.TARGET)) {
if (!ActionUtils.compareNullStr(value, cb.getCurrentTarget())) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.IN_SCENE)) {
boolean val = Boolean.parseBoolean(value);
BaseActor a2 = s.getActor(actorId, false);
if ((val && a2 == null) || (!val && a2 != null))
gotoElse((VerbRunner) cb);
} else if (attr.equals(ActorAttribute.LAYER) && a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
if (!ActionUtils.compareNullStr(value, ia.getLayer())) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.DIRECTION) && a instanceof SpriteActor) {
SpriteActor sa = (SpriteActor) a;
if (sa.getRenderer() instanceof AnimationRenderer) {
String dir = null;
String anim = ((AnimationRenderer) sa.getRenderer()).getCurrentAnimationId();
int idx = anim.lastIndexOf('.');
if (idx != -1)
dir = anim.substring(idx + 1);
if (!ActionUtils.compareNullStr(value, dir)) {
gotoElse((VerbRunner) cb);
}
}
}
return false;
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class SetActorAttrAction method run.
@Override
public boolean run(VerbRunner cb) {
Scene s = actor.getScene();
BaseActor a = s.getActor(actor.getActorId(), true);
if (a == null) {
EngineLogger.error("SetActorAttr - Actor not found:" + this.actor.getActorId());
return false;
}
if (visible != null)
a.setVisible(visible);
if (interaction != null) {
if (a instanceof InteractiveActor)
((InteractiveActor) a).setInteraction(interaction);
else
EngineLogger.error("'Interaction' property not supported for actor:" + a.getId());
}
if (layer != null) {
if (a instanceof InteractiveActor) {
InteractiveActor iActor = (InteractiveActor) a;
String oldLayer = iActor.getLayer();
s.getLayer(oldLayer).remove(iActor);
iActor.setLayer(layer);
SceneLayer l = s.getLayer(layer);
l.add(iActor);
if (!l.isDynamic())
l.orderByZIndex();
} else
EngineLogger.error("'layer' property not supported for actor:" + a.getId());
}
if (zIndex != null) {
if (a instanceof InteractiveActor) {
InteractiveActor iActor = (InteractiveActor) a;
iActor.setZIndex(zIndex);
SceneLayer l = s.getLayer(iActor.getLayer());
if (!l.isDynamic())
l.orderByZIndex();
} else
EngineLogger.error("'zIndex' property not supported for actor:" + a.getId());
}
if (scale != null) {
if (a instanceof SpriteActor)
((SpriteActor) a).setScale(scale);
else
EngineLogger.error("'scale' property not supported for actor:" + a.getId());
}
if (rotation != null) {
if (a instanceof SpriteActor)
((SpriteActor) a).setRot(rotation);
else
EngineLogger.error("'rotation' property not supported for actor:" + a.getId());
}
if (tint != null) {
if (a instanceof SpriteActor)
((SpriteActor) a).setTint(tint);
else
EngineLogger.error("'tint' property not supported for actor:" + a.getId());
}
if (fakeDepth != null) {
if (a instanceof SpriteActor) {
((SpriteActor) a).setFakeDepth(fakeDepth);
} else
EngineLogger.error("'fakeDepth' property not supported for actor:" + a.getId());
}
if (standAnimation != null) {
if (a instanceof CharacterActor)
((CharacterActor) a).setStandAnim(standAnimation);
else
EngineLogger.error("'standAnimation' property not supported for actor:" + a.getId());
}
if (walkAnimation != null) {
if (a instanceof CharacterActor)
((CharacterActor) a).setWalkAnim(walkAnimation);
else
EngineLogger.error("'walkAnimation' property not supported for actor:" + a.getId());
}
if (talkAnimation != null) {
if (a instanceof CharacterActor)
((CharacterActor) a).setTalkAnim(talkAnimation);
else
EngineLogger.error("'talkAnimation' property not supported for actor:" + a.getId());
}
if (walkingSpeed != null) {
if (a instanceof CharacterActor)
((CharacterActor) a).setWalkingSpeed(walkingSpeed);
else
EngineLogger.error("'walkingSpeed' property not supported for actor:" + a.getId());
}
if (uiActor != null) {
if (a instanceof InteractiveActor) {
if (uiActor)
setUIActor(s, (InteractiveActor) a);
else
removeUIActor(s, (InteractiveActor) a);
} else
EngineLogger.error("'uiActor' property not supported for actor:" + a.getId());
}
return false;
}
Aggregations