Search in sources :

Example 31 with InteractiveActor

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

the class TextAction method run.

@Override
public boolean run(VerbRunner cb) {
    if (text == null)
        return false;
    float x = TextManager.POS_CENTER, y = TextManager.POS_CENTER;
    if (target != null) {
        Scene ts = target.getScene();
        BaseActor anchorActor = ts.getActor(target.getActorId(), true);
        x = anchorActor.getX();
        y = anchorActor.getY();
        if (anchorActor instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) anchorActor).getRefPoint();
            x += refPoint.x;
            y += refPoint.y;
        }
        if (pos != null) {
            float scale = EngineAssetManager.getInstance().getScale();
            x += pos.x * scale;
            y += pos.y * scale;
        }
    } else if (pos != null) {
        float scale = EngineAssetManager.getInstance().getScale();
        if (pos.x != TextManager.POS_CENTER)
            x = pos.x * scale;
        if (pos.y != TextManager.POS_CENTER)
            y = pos.y * scale;
    } else {
        if (type == Text.Type.SUBTITLE) {
            x = y = TextManager.POS_SUBTITLE;
        }
    }
    World.getInstance().getTextManager().addText(text, x, y, queue, type, color, style, null, voiceId, wait ? cb : null);
    return wait;
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene)

Example 32 with InteractiveActor

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

the class GotoAction method run.

@Override
public boolean run(VerbRunner cb) {
    CharacterActor actor = (CharacterActor) World.getInstance().getCurrentScene().getActor(this.actor, false);
    float x = actor.getX();
    float y = actor.getY();
    if (target != null) {
        BaseActor target = World.getInstance().getCurrentScene().getActor(this.target, false);
        x = target.getX();
        y = target.getY();
        if (target instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
            x += refPoint.x;
            y += refPoint.y;
        }
        if (pos != null) {
            float scale = EngineAssetManager.getInstance().getScale();
            x += pos.x * scale;
            y += pos.y * scale;
        }
    } else if (pos != null) {
        float scale = EngineAssetManager.getInstance().getScale();
        x = pos.x * scale;
        y = pos.y * scale;
    }
    actor.goTo(new Vector2(x, y), wait ? cb : null, ignoreWalkZone);
    return wait;
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 33 with InteractiveActor

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

the class SetStateAction method run.

@Override
public boolean run(VerbRunner cb) {
    final Scene s = actor.getScene();
    String actorId = actor.getActorId();
    if (actorId == null) {
        // if called in a scene verb and no actor is specified, set the state of the scene
        s.setState(state);
        return false;
    }
    InteractiveActor a = (InteractiveActor) s.getActor(actorId, false);
    if (a == null) {
        // search in inventory
        a = World.getInstance().getInventory().get(actorId);
    }
    if (a != null)
        a.setState(state);
    else
        EngineLogger.error("SetState - Actor not found: " + actorId);
    return false;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Scene(com.bladecoder.engine.model.Scene)

Example 34 with InteractiveActor

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

use of com.bladecoder.engine.model.InteractiveActor 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

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