com.bladecoder.engine.model.Scene.getVerbManager() - java examples

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

9 Examples 7

18 View Complete Implementation : ActionCallbackSerializer.java
Copyright Apache License 2.0
Author : bladecoder
private static String find(ActionCallback cb, Scene s) {
    if (s == null)
        return null;
    String id = s.getId();
    for (Verb v : s.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;
}

17 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);
}

13 View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
public void putTranslationsInElement(Scene scn) {
    HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
    for (Verb v : verbs.values()) putTranslationsInElement(v, false);
    for (BaseActor a : scn.getActors().values()) {
        putTranslationsInElement(a);
    }
}

12 View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
public void extractStrings(Scene scn) {
    HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
    for (Verb v : verbs.values()) extractStrings(scn.getId(), null, v);
    for (BaseActor a : scn.getActors().values()) {
        extractStrings(scn.getId(), a);
    }
}

7 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);
                    }
                }
            }
        }
    }
}

6 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();
}

5 View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
private void getUsedKeys(Scene s, ArrayList<String> usedKeys) {
    for (Verb v : s.getVerbManager().getVerbs().values()) getUsedKeys(v, usedKeys);
    for (BaseActor a : s.getActors().values()) {
        if (a instanceof InteractiveActor) {
            InteractiveActor ia = (InteractiveActor) a;
            if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) == I18N.PREFIX)
                usedKeys.add(ia.getDesc().substring(1));
            for (Verb v : ia.getVerbManager().getVerbs().values()) getUsedKeys(v, usedKeys);
            if (a instanceof CharacterActor) {
                CharacterActor ca = (CharacterActor) a;
                if (ca.getDialogs() != null) {
                    for (Dialog d : ca.getDialogs().values()) {
                        for (DialogOption o : d.getOptions()) {
                            if (o.getText() != null && !o.getText().isEmpty() && o.getText().charAt(0) == I18N.PREFIX)
                                usedKeys.add(o.getText().substring(1));
                            if (o.getResponseText() != null && !o.getResponseText().isEmpty() && o.getResponseText().charAt(0) == I18N.PREFIX)
                                usedKeys.add(o.getResponseText().substring(1));
                        }
                    }
                }
            }
            if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof TextRenderer) {
                TextRenderer r = (TextRenderer) ((SpriteActor) a).getRenderer();
                String k = r.getText();
                if (k != null && !k.isEmpty() && k.charAt(0) == I18N.PREFIX)
                    usedKeys.add(k.substring(1));
            }
        }
    }
}

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) {
        }
    }
}