Search in sources :

Example 1 with SayAction

use of com.bladecoder.engine.actions.SayAction 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)

Example 2 with SayAction

use of com.bladecoder.engine.actions.SayAction in project bladecoder-adventure-engine by bladecoder.

the class ModelTools method fixSaySubtitleActor.

public static final void fixSaySubtitleActor() {
    Map<String, Scene> scenes = World.getInstance().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("SUBTITLE"))
                            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("SUBTITLE"))
                                    ActionUtils.setParam(act, "actor", "$PLAYER");
                            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                                EditorLogger.printStackTrace(e);
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    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) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SayAction(com.bladecoder.engine.actions.SayAction) Scene(com.bladecoder.engine.model.Scene) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor)

Example 3 with SayAction

use of com.bladecoder.engine.actions.SayAction in project bladecoder-adventure-engine by bladecoder.

the class ModelTools method extractDialogs.

public static final void extractDialogs() {
    Map<String, Scene> scenes = World.getInstance().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.getTitle() != null ? Ctx.project.getTitle().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) {
        }
    }
}
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) FileWriter(java.io.FileWriter) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SayAction(com.bladecoder.engine.actions.SayAction) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BufferedWriter(java.io.BufferedWriter) Dialog(com.bladecoder.engine.model.Dialog) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor) File(java.io.File) DialogOption(com.bladecoder.engine.model.DialogOption)

Aggregations

Action (com.bladecoder.engine.actions.Action)3 LookAtAction (com.bladecoder.engine.actions.LookAtAction)3 SayAction (com.bladecoder.engine.actions.SayAction)3 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)3 BaseActor (com.bladecoder.engine.model.BaseActor)3 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)3 Scene (com.bladecoder.engine.model.Scene)3 Verb (com.bladecoder.engine.model.Verb)3 CharacterActor (com.bladecoder.engine.model.CharacterActor)1 Dialog (com.bladecoder.engine.model.Dialog)1 DialogOption (com.bladecoder.engine.model.DialogOption)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1