com.bladecoder.engine.model.Verb.getActions() - java examples

Here are the examples of the java api com.bladecoder.engine.model.Verb.getActions() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

15 Examples 7

19 View Complete Implementation : CheckCutmodeEnd.java
Copyright Apache License 2.0
Author : bladecoder
@Override
public void visit(Scene s, InteractiveActor a, Verb v) {
    ArrayList<Action> actions = v.getActions();
    if (actions.size() > 0) {
        Action action = actions.get(actions.size() - 1);
        if (action instanceof SetCutmodeAction) {
            try {
                String val = ActionUtils.getStringValue(action, "value");
                if ("true".equals(val)) {
                    StringBuilder sb = new StringBuilder("CheckCutmodeEnd: Cutmode ends with value=true! - ");
                    if (s != null) {
                        sb.append(s.getId());
                        sb.append(".");
                    }
                    if (a != null) {
                        sb.append(a.getId());
                        sb.append(".");
                    }
                    sb.append(v.getId());
                    EditorLogger.error(sb.toString());
                }
            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
            }
        }
    }
}

19 View Complete Implementation : VerbList.java
Copyright Apache License 2.0
Author : bladecoder
private void addActions() {
    int pos = list.getSelectedIndex();
    Verb v = null;
    if (pos != -1) {
        v = list.gereplacedems().get(pos);
        actionList.setScope(scopePanel.getScope());
        actionList.addElements(v, v.getActions());
    } else {
        actionList.addElements(null, null);
        actionList.setScope(null);
    }
}

19 View Complete Implementation : RunVerbAction.java
Copyright Apache License 2.0
Author : bladecoder
@Override
public ArrayList<Action> getActions() {
    Verb v = getVerb();
    if (v == null) {
        if (actor != null)
            EngineLogger.error(MessageFormat.format("Verb ''{0}'' not found for actor ''{1}({3})'' and target ''{2}''.", verb, actor, target, ((InteractiveActor) w.getCurrentScene().getActor(actor, true)).getState()));
        else
            EngineLogger.error(MessageFormat.format("Verb ''{0}'' not found.", verb));
        return new ArrayList<Action>(0);
    }
    return v.getActions();
}

18 View Complete Implementation : ActionCallbackSerializer.java
Copyright Apache License 2.0
Author : bladecoder
private static String find(ActionCallback cb, Verb v) {
    String id = v.getHashKey();
    if (cb == v)
        return id;
    int pos = 0;
    for (Action a : v.getActions()) {
        if (cb == a) {
            StringBuilder stringBuilder = new StringBuilder(id);
            stringBuilder.append(SEPARATION_SYMBOL).append(pos);
            return stringBuilder.toString();
        }
        pos++;
    }
    return null;
}

18 View Complete Implementation : ActionCallbackSerializer.java
Copyright Apache License 2.0
Author : bladecoder
/**
 * Searches for the ActionCallback represented by the id string.
 *
 * @param id
 */
public static ActionCallback find(World w, Scene s, String id) {
    if (id == null)
        return null;
    String[] split = id.split(SEPARATION_SYMBOL);
    if (id.startsWith(INK_MANAGER_TAG)) {
        if (split.length == 1)
            return w.getInkManager().getVerbRunner();
        int actionPos = Integer.parseInt(split[1]);
        Action action = w.getInkManager().getVerbRunner().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 = w.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;
}

17 View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
public void extractStrings(String sceneid, String actorid, Verb v) {
    ArrayList<Action> actions = v.getActions();
    for (int i = 0; i < actions.size(); i++) {
        Action a = actions.get(i);
        extractStrings(sceneid, actorid, v.getHashKey(), i, a);
    }
}

17 View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
public void putTranslationsInElement(Verb v, boolean worldScope) {
    ArrayList<Action> actions = v.getActions();
    for (Action a : actions) {
        putTranslationsInElement(a, worldScope);
    }
}

17 View Complete Implementation : UndoDeleteAction.java
Copyright Apache License 2.0
Author : bladecoder
@Override
public void undo() {
    v.getActions().add(idx, a);
    Ctx.project.setModified(this, Project.NOTIFY_ELEMENT_CREATED, null, a);
}

16 View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
private void getUsedKeys(Verb v, ArrayList<String> usedKeys) {
    for (Action a : v.getActions()) {
        if (a instanceof DisableActionAction)
            a = ((DisableActionAction) a).getAction();
        String[] fieldNames = ActionUtils.getFieldNames(a);
        for (String name : fieldNames) {
            if (name.toLowerCase().endsWith("text")) {
                String value = null;
                try {
                    value = ActionUtils.getStringValue(a, name);
                } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                    EditorLogger.error(e.getMessage());
                }
                if (value != null && !value.isEmpty() && value.charAt(0) == I18N.PREFIX) {
                    usedKeys.add(value.substring(1));
                }
            }
        }
    }
}

14 View Complete Implementation : ModelWalker.java
Copyright Apache License 2.0
Author : bladecoder
public void walk(World w) {
    Map<String, Scene> scenes = Ctx.project.getWorld().getScenes();
    for (StartVisitor sv : startVisitors) sv.start(w);
    for (Scene scn : scenes.values()) {
        for (SceneVisitor sv : sceneVisitors) sv.visit(scn);
        Map<String, BaseActor> actors = scn.getActors();
        // SCENE VERBS
        HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
        for (Verb v : verbs.values()) {
            for (VerbVisitor vv : verbVisitors) vv.visit(scn, null, v);
            ArrayList<Action> actions = v.getActions();
            for (Action act : actions) {
                for (ActionVisitor av : actionVisitors) av.visit(scn, null, v, act);
            }
        }
        for (BaseActor a : actors.values()) {
            for (ActorVisitor av : actorVisitors) av.visit(a);
            if (a instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) a;
                // ACTOR VERBS
                verbs = ia.getVerbManager().getVerbs();
                for (Verb v : verbs.values()) {
                    for (VerbVisitor vv : verbVisitors) vv.visit(scn, ia, v);
                    ArrayList<Action> actions = v.getActions();
                    for (Action act : actions) {
                        for (ActionVisitor av : actionVisitors) av.visit(scn, ia, v, act);
                    }
                }
            }
            // DIALOGS
            if (a instanceof CharacterActor) {
                HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
                if (dialogs != null) {
                    for (Dialog d : dialogs.values()) {
                        for (DialogVisitor dv : dialogVisitors) dv.visit((CharacterActor) a, d);
                        ArrayList<DialogOption> options = d.getOptions();
                        for (DialogOption o : options) {
                            for (DialogOptionVisitor ov : optionVisitors) ov.visit((CharacterActor) a, d, o);
                        }
                    }
                }
            }
        }
    }
    for (EndVisitor ev : endVisitors) ev.end(w);
}

5 View Complete Implementation : ModelTools.java
Copyright Apache License 2.0
Author : bladecoder
public static final void fixSaySubreplacedleActor() {
    Map<String, Scene> scenes = Ctx.project.getWorld().getScenes();
    for (Scene scn : scenes.values()) {
        Map<String, BaseActor> actors = scn.getActors();
        HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
        for (Verb v : verbs.values()) {
            ArrayList<Action> actions = v.getActions();
            for (Action act : actions) {
                if (act instanceof SayAction) {
                    try {
                        String stringValue = ActionUtils.getStringValue(act, "type");
                        if (stringValue.equals("SUBreplacedLE"))
                            ActionUtils.setParam(act, "actor", "$PLAYER");
                    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                        EditorLogger.printStackTrace(e);
                        return;
                    }
                }
            }
        }
        for (BaseActor a : actors.values()) {
            if (a instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) a;
                verbs = ia.getVerbManager().getVerbs();
                for (Verb v : verbs.values()) {
                    ArrayList<Action> actions = v.getActions();
                    for (Action act : actions) {
                        if (act instanceof SayAction) {
                            try {
                                String stringValue = ActionUtils.getStringValue(act, "type");
                                if (stringValue.equals("SUBreplacedLE"))
                                    ActionUtils.setParam(act, "actor", "$PLAYER");
                            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                                EditorLogger.printStackTrace(e);
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    Ctx.project.setModified();
}

3 View Complete Implementation : ModelTools.java
Copyright Apache License 2.0
Author : bladecoder
public static final void addCutMode() {
    Map<String, Scene> scenes = Ctx.project.getWorld().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();
}

0 View Complete Implementation : ModelTools.java
Copyright Apache License 2.0
Author : bladecoder
public static final void checkI18NMissingKeys() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    Map<String, Scene> scenes = Ctx.project.getWorld().getScenes();
    for (Scene scn : scenes.values()) {
        Map<String, BaseActor> actors = scn.getActors();
        // SCENE VERBS
        HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
        for (Verb v : verbs.values()) {
            ArrayList<Action> actions = v.getActions();
            for (Action act : actions) {
                String[] params = ActionUtils.getFieldNames(act);
                for (String p : params) {
                    String val = ActionUtils.getStringValue(act, p);
                    if (val != null && !val.isEmpty() && val.charAt(0) == I18N.PREFIX) {
                        String trans = Ctx.project.translate(val);
                        if (trans == val) {
                            EditorLogger.error("Key not found: " + val);
                        }
                    }
                }
            }
        }
        for (BaseActor a : actors.values()) {
            if (a instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) a;
                // DESC
                if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) == I18N.PREFIX) {
                    String trans = Ctx.project.translate(ia.getDesc());
                    if (trans == ia.getDesc()) {
                        EditorLogger.error("Key not found: " + ia.getDesc());
                    }
                }
                // ACTOR VERBS
                verbs = ia.getVerbManager().getVerbs();
                for (Verb v : verbs.values()) {
                    ArrayList<Action> actions = v.getActions();
                    for (Action act : actions) {
                        String[] params = ActionUtils.getFieldNames(act);
                        for (String p : params) {
                            String val = ActionUtils.getStringValue(act, p);
                            if (val != null && !val.isEmpty() && val.charAt(0) == I18N.PREFIX) {
                                String trans = Ctx.project.translate(val);
                                if (trans == val) {
                                    EditorLogger.error("Key not found: " + val);
                                }
                            }
                        }
                    }
                }
            }
            // DIALOGS
            if (a instanceof CharacterActor) {
                HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
                if (dialogs != null) {
                    for (Dialog d : dialogs.values()) {
                        ArrayList<DialogOption> options = d.getOptions();
                        for (DialogOption o : options) {
                            if (o.getText() != null && !o.getText().isEmpty() && o.getText().charAt(0) == I18N.PREFIX) {
                                String trans = Ctx.project.translate(o.getText());
                                if (trans == o.getText()) {
                                    EditorLogger.error("Key not found: " + o.getText());
                                }
                            }
                            if (o.getResponseText() != null && !o.getResponseText().isEmpty() && o.getResponseText().charAt(0) == I18N.PREFIX) {
                                String trans = Ctx.project.translate(o.getResponseText());
                                if (trans == o.getResponseText()) {
                                    EditorLogger.error("Key not found: " + o.getResponseText());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

0 View Complete Implementation : ModelTools.java
Copyright Apache License 2.0
Author : bladecoder
public static final void extractDialogs() {
    Map<String, Scene> scenes = Ctx.project.getWorld().getScenes();
    BufferedWriter writer = null;
    try {
        // create a temporary file
        File dFile = new File(Ctx.project.getProjectPath() + "/" + "DIALOGS.md");
        writer = new BufferedWriter(new FileWriter(dFile));
        writer.write("# DIALOGS - " + (Ctx.project.getreplacedle() != null ? Ctx.project.getreplacedle().toUpperCase() : "") + "\n\n");
        for (Scene scn : scenes.values()) {
            Map<String, BaseActor> actors = scn.getActors();
            writer.write("\n## SCENE: " + scn.getId() + "\n\n");
            HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
            // Process SayAction of TALK type
            for (Verb v : verbs.values()) {
                ArrayList<Action> actions = v.getActions();
                for (Action act : actions) {
                    if (act instanceof SayAction) {
                        String type = ActionUtils.getStringValue(act, "type");
                        if ("TALK".equals(type)) {
                            String actor = ActionUtils.getStringValue(act, "actor").toUpperCase();
                            String rawText = ActionUtils.getStringValue(act, "text");
                            String text = Ctx.project.translate(rawText).replace("\\n\\n", "\n").replace("\\n", "\n");
                            writer.write(actor + ": " + text + "\n");
                        }
                    }
                }
            }
            for (BaseActor a : actors.values()) {
                if (a instanceof InteractiveActor) {
                    InteractiveActor ia = (InteractiveActor) a;
                    verbs = ia.getVerbManager().getVerbs();
                    // Process SayAction of TALK type
                    for (Verb v : verbs.values()) {
                        ArrayList<Action> actions = v.getActions();
                        for (Action act : actions) {
                            if (act instanceof SayAction) {
                                String type = ActionUtils.getStringValue(act, "type");
                                if ("TALK".equals(type)) {
                                    String actor = ActionUtils.getStringValue(act, "actor").toUpperCase();
                                    String rawText = ActionUtils.getStringValue(act, "text");
                                    String text = Ctx.project.translate(rawText).replace("\\n\\n", "\n").replace("\\n", "\n");
                                    writer.write(actor + ": " + text + "\n");
                                }
                            }
                        }
                    }
                }
                if (a instanceof CharacterActor) {
                    CharacterActor ca = (CharacterActor) a;
                    HashMap<String, Dialog> dialogs = ca.getDialogs();
                    if (dialogs == null)
                        continue;
                    // Process SayAction of TALK type
                    for (Dialog d : dialogs.values()) {
                        ArrayList<DialogOption> options = d.getOptions();
                        if (options.size() > 0)
                            writer.write("\n**" + ca.getId().toUpperCase() + " - " + d.getId() + "**\n\n");
                        for (DialogOption o : options) {
                            String text = o.getText();
                            String response = o.getResponseText();
                            writer.write(scn.getPlayer().getId().toUpperCase() + ": " + Ctx.project.translate(text).replace("\\n\\n", "\n").replace("\\n", "\n") + "\n");
                            if (response != null)
                                writer.write(ca.getId().toUpperCase() + ": " + Ctx.project.translate(response).replace("\\n\\n", "\n").replace("\\n", "\n") + "\n\n");
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        EditorLogger.printStackTrace(e);
    } finally {
        try {
            // Close the writer regardless of what happens...
            writer.close();
        } catch (Exception e) {
        }
    }
}

0 View Complete Implementation : WorldSerialization.java
Copyright Apache License 2.0
Author : bladecoder
private void cacheSounds() {
    for (Scene s : w.getScenes().values()) {
        HashMap<String, Verb> verbs = s.getVerbManager().getVerbs();
        // Search SoundAction and PlaySoundAction
        for (Verb v : verbs.values()) {
            ArrayList<Action> actions = v.getActions();
            for (int i = 0; i < actions.size(); i++) {
                Action act = actions.get(i);
                try {
                    if (act instanceof SoundAction) {
                        String actor = ActionUtils.getStringValue(act, "actor");
                        String play = ActionUtils.getStringValue(act, "play");
                        if (play != null) {
                            SoundDesc sd = w.getSounds().get(actor + "_" + play);
                            if (sd != null)
                                s.getSoundManager().addSoundToLoad(sd);
                            HashMap<String, String> params = new HashMap<>();
                            params.put("sound", sd.getId());
                            try {
                                Action a2 = ActionFactory.create(PlaySoundAction.clreplaced.getName(), params);
                                actions.set(i, a2);
                                a2.init(w);
                            } catch (ClreplacedNotFoundException | ReflectionException e) {
                                e.printStackTrace();
                            }
                            EngineLogger.debug("Converting SoundAction:" + s.getId() + "." + v.getId());
                        } else {
                            EngineLogger.debug("WARNING: Cannot convert SoundAction:" + s.getId() + "." + v.getId());
                        }
                    } else if (act instanceof PlaySoundAction) {
                        String sound = ActionUtils.getStringValue(act, "sound");
                        SoundDesc sd = w.getSounds().get(sound);
                        if (sd != null && sd.isPreload())
                            s.getSoundManager().addSoundToLoad(sd);
                    }
                } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                }
            }
        }
        for (BaseActor a : s.getActors().values()) {
            if (a instanceof InteractiveActor) {
                HashMap<String, Verb> actorVerbs = ((InteractiveActor) a).getVerbManager().getVerbs();
                for (Verb v : actorVerbs.values()) {
                    ArrayList<Action> actions = v.getActions();
                    for (int i = 0; i < actions.size(); i++) {
                        Action act = actions.get(i);
                        try {
                            if (act instanceof SoundAction) {
                                String actor = ActionUtils.getStringValue(act, "actor");
                                String play = ActionUtils.getStringValue(act, "play");
                                if (play != null) {
                                    SoundDesc sd = w.getSounds().get(actor + "_" + play);
                                    if (sd != null)
                                        s.getSoundManager().addSoundToLoad(sd);
                                    HashMap<String, String> params = new HashMap<>();
                                    params.put("sound", sd.getId());
                                    try {
                                        Action a2 = ActionFactory.create(PlaySoundAction.clreplaced.getName(), params);
                                        actions.set(i, a2);
                                        a2.init(w);
                                    } catch (ClreplacedNotFoundException | ReflectionException e) {
                                        e.printStackTrace();
                                    }
                                    EngineLogger.debug("Converting SoundAction in:" + s.getId() + "." + a.getId() + "." + v.getId());
                                } else {
                                    EngineLogger.debug("WARNING: Cannot convert SoundAction:" + s.getId() + "." + a.getId() + "." + v.getId());
                                }
                            } else if (act instanceof PlaySoundAction) {
                                String sound = ActionUtils.getStringValue(act, "sound");
                                SoundDesc sd = w.getSounds().get(sound);
                                if (sd != null && sd.isPreload())
                                    s.getSoundManager().addSoundToLoad(sd);
                            }
                        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                        }
                    }
                }
            }
            if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof AnimationRenderer) {
                HashMap<String, AnimationDesc> anims = ((AnimationRenderer) ((SpriteActor) a).getRenderer()).getAnimations();
                for (AnimationDesc ad : anims.values()) {
                    if (ad.sound != null) {
                        String sid = ad.sound;
                        SoundDesc sd = w.getSounds().get(sid);
                        if (sd == null)
                            sid = a.getId() + "_" + sid;
                        sd = w.getSounds().get(sid);
                        if (sd != null) {
                            if (sd.isPreload())
                                s.getSoundManager().addSoundToLoad(sd);
                        } else
                            EngineLogger.error(a.getId() + ": SOUND not found: " + ad.sound + " in animation: " + ad.id);
                    }
                }
            }
        }
    }
}