Search in sources :

Example 1 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class ActionCallbackSerialization method find.

private static String find(ActionCallback cb, InteractiveActor a) {
    if (a == null)
        return null;
    String id = a.getId();
    for (Verb v : a.getVerbManager().getVerbs().values()) {
        String result = find(cb, v);
        if (result != null) {
            StringBuilder stringBuilder = new StringBuilder(id);
            stringBuilder.append(SEPARATION_SYMBOL).append(result);
            return stringBuilder.toString();
        }
    }
    return null;
}
Also used : Verb(com.bladecoder.engine.model.Verb)

Example 2 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class ActionCallbackSerialization method find.

/**
 * Generates a String for serialization that allows locate the
 * ActionCallback
 *
 * @param cb
 *            The ActionCallback to serialize
 * @return The generated location string
 */
public static String find(ActionCallback cb) {
    String id = null;
    if (cb == null)
        return null;
    // search in UIActors
    id = find(cb, World.getInstance().getUIActors());
    if (id != null)
        return id;
    // search in inventory
    id = find(cb, World.getInstance().getInventory());
    if (id != null)
        return id;
    // search in inkManager actions
    id = find(cb, World.getInstance().getInkManager());
    if (id != null)
        return id;
    // search in scene verbs
    Scene s = World.getInstance().getCurrentScene();
    id = find(cb, s);
    if (id != null)
        return id;
    // search in player
    id = find(cb, s.getPlayer());
    if (id != null)
        return id;
    // search in actors
    for (BaseActor a : s.getActors().values()) {
        if (!(a instanceof InteractiveActor))
            continue;
        id = find(cb, (InteractiveActor) a);
        if (id != null)
            return id;
    }
    // search in worldVerbs
    for (Verb v : World.getInstance().getVerbManager().getVerbs().values()) {
        id = find(cb, v);
        if (id != null) {
            StringBuilder stringBuilder = new StringBuilder(DEFAULT_VERB_TAG);
            stringBuilder.append(SEPARATION_SYMBOL).append(id);
            return stringBuilder.toString();
        }
    }
    return null;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene)

Example 3 with Verb

use of com.bladecoder.engine.model.Verb 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 4 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class RunVerbAction method run.

@Override
public void run(String currentTarget, ActionCallback cb) {
    Verb v = getVerb();
    v.run(currentTarget, cb);
}
Also used : Verb(com.bladecoder.engine.model.Verb)

Example 5 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class ModelTools method addCutMode.

public static final void addCutMode() {
    Map<String, Scene> scenes = World.getInstance().getScenes();
    for (Scene scn : scenes.values()) {
        Map<String, BaseActor> actors = scn.getActors();
        for (BaseActor a : actors.values()) {
            if (a instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) a;
                HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
                for (Verb v : verbs.values()) {
                    ArrayList<Action> actions = v.getActions();
                    // Don't process verbs for inventory
                    if (v.getState() != null && v.getState().equalsIgnoreCase("INVENTORY"))
                        continue;
                    if (actions.size() == 1) {
                        Action act = actions.get(0);
                        if (act instanceof LookAtAction || act instanceof SayAction) {
                            actions.clear();
                            SetCutmodeAction cma1 = new SetCutmodeAction();
                            SetCutmodeAction cma2 = new SetCutmodeAction();
                            try {
                                ActionUtils.setParam(cma1, "value", "true");
                                ActionUtils.setParam(cma2, "value", "false");
                            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                                EditorLogger.printStackTrace(e);
                            }
                            actions.add(cma1);
                            actions.add(act);
                            actions.add(cma2);
                        }
                    }
                }
            }
        }
    }
    Ctx.project.setModified();
}
Also used : LookAtAction(com.bladecoder.engine.actions.LookAtAction) SayAction(com.bladecoder.engine.actions.SayAction) SetCutmodeAction(com.bladecoder.engine.actions.SetCutmodeAction) Action(com.bladecoder.engine.actions.Action) LookAtAction(com.bladecoder.engine.actions.LookAtAction) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SayAction(com.bladecoder.engine.actions.SayAction) Scene(com.bladecoder.engine.model.Scene) SetCutmodeAction(com.bladecoder.engine.actions.SetCutmodeAction) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor)

Aggregations

Verb (com.bladecoder.engine.model.Verb)26 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)14 Scene (com.bladecoder.engine.model.Scene)9 Action (com.bladecoder.engine.actions.Action)8 BaseActor (com.bladecoder.engine.model.BaseActor)8 CharacterActor (com.bladecoder.engine.model.CharacterActor)7 Dialog (com.bladecoder.engine.model.Dialog)6 SpriteActor (com.bladecoder.engine.model.SpriteActor)5 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 TextRenderer (com.bladecoder.engine.model.TextRenderer)4 UndoDeleteVerb (com.bladecoder.engineeditor.undo.UndoDeleteVerb)4 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 AbstractControlAction (com.bladecoder.engine.actions.AbstractControlAction)2 AbstractIfAction (com.bladecoder.engine.actions.AbstractIfAction)2 CommentAction (com.bladecoder.engine.actions.CommentAction)2 DisableActionAction (com.bladecoder.engine.actions.DisableActionAction)2