Search in sources :

Example 6 with InteractiveActor

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;
}
Also used : Action(com.bladecoder.engine.actions.Action) ActionCallback(com.bladecoder.engine.actions.ActionCallback) Verb(com.bladecoder.engine.model.Verb) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Scene(com.bladecoder.engine.model.Scene)

Example 7 with InteractiveActor

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();
}
Also used : Color(com.badlogic.gdx.graphics.Color) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Rectangle(com.badlogic.gdx.math.Rectangle)

Example 8 with InteractiveActor

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;
}
Also used : SceneCamera(com.bladecoder.engine.model.SceneCamera) Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor)

Example 9 with InteractiveActor

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;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) VerbRunner(com.bladecoder.engine.model.VerbRunner) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 10 with InteractiveActor

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;
}
Also used : SceneLayer(com.bladecoder.engine.model.SceneLayer) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Aggregations

InteractiveActor (com.bladecoder.engine.model.InteractiveActor)43 BaseActor (com.bladecoder.engine.model.BaseActor)25 Scene (com.bladecoder.engine.model.Scene)17 SpriteActor (com.bladecoder.engine.model.SpriteActor)16 Verb (com.bladecoder.engine.model.Verb)14 CharacterActor (com.bladecoder.engine.model.CharacterActor)13 Vector2 (com.badlogic.gdx.math.Vector2)11 Rectangle (com.badlogic.gdx.math.Rectangle)7 Polygon (com.badlogic.gdx.math.Polygon)6 Action (com.bladecoder.engine.actions.Action)6 AnchorActor (com.bladecoder.engine.model.AnchorActor)6 Dialog (com.bladecoder.engine.model.Dialog)6 World (com.bladecoder.engine.model.World)6 TextRenderer (com.bladecoder.engine.model.TextRenderer)5 Color (com.badlogic.gdx.graphics.Color)4 LookAtAction (com.bladecoder.engine.actions.LookAtAction)4 SayAction (com.bladecoder.engine.actions.SayAction)4 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)4 DialogOption (com.bladecoder.engine.model.DialogOption)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)3