Search in sources :

Example 16 with CharacterActor

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

the class SayDialogAction method run.

@Override
public boolean run(VerbRunner cb) {
    World w = World.getInstance();
    if (w.getCurrentDialog() == null || w.getCurrentDialog().getCurrentOption() == null) {
        EngineLogger.debug("SayDialogAction WARNING: Current dialog doesn't found.");
        return false;
    }
    setVerbCb(cb);
    DialogOption o = w.getCurrentDialog().getCurrentOption();
    String playerText = o.getText();
    responseText = o.getResponseText();
    responseVoiceId = o.getResponseVoiceId();
    characterName = w.getCurrentDialog().getActor();
    characterTurn = true;
    previousAnim = null;
    // If the player or the character is talking restore to 'stand' pose
    restoreStandPose(w.getCurrentScene().getPlayer());
    if (w.getCurrentScene().getActor(characterName, false) instanceof SpriteActor)
        restoreStandPose((CharacterActor) w.getCurrentScene().getActor(characterName, false));
    if (playerText != null) {
        CharacterActor player = w.getCurrentScene().getPlayer();
        Rectangle boundingRectangle = player.getBBox().getBoundingRectangle();
        float x = boundingRectangle.getX() + boundingRectangle.getWidth() / 2;
        float y = boundingRectangle.getY() + boundingRectangle.getHeight();
        w.getTextManager().addText(playerText, x, y, false, Text.Type.TALK, player.getTextColor(), null, player.getId(), o.getVoiceId(), this);
        startTalkAnim(player);
    } else {
        resume();
    }
    return getWait();
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) SpriteActor(com.bladecoder.engine.model.SpriteActor) World(com.bladecoder.engine.model.World) CharacterActor(com.bladecoder.engine.model.CharacterActor) DialogOption(com.bladecoder.engine.model.DialogOption)

Example 17 with CharacterActor

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

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

the class IfSceneAttrAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = (scene != null && !scene.isEmpty()) ? World.getInstance().getScene(scene) : World.getInstance().getCurrentScene();
    if (attr == SceneAttr.STATE) {
        if (!ActionUtils.compareNullStr(value, s.getState())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr == SceneAttr.CURRENT_SCENE) {
        String scn = World.getInstance().getCurrentScene().getId();
        if (!ActionUtils.compareNullStr(value, scn)) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr == SceneAttr.PLAYER) {
        CharacterActor player = s.getPlayer();
        String id = player != null ? player.getId() : null;
        if (!ActionUtils.compareNullStr(value, id)) {
            gotoElse((VerbRunner) cb);
        }
    }
    return false;
}
Also used : VerbRunner(com.bladecoder.engine.model.VerbRunner) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 19 with CharacterActor

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

Example 20 with CharacterActor

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

the class I18NHandler method extractStrings.

public void extractStrings(String sceneid, BaseActor a) {
    if (a instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) a;
        // 1. DESC attribute
        if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) != I18N.PREFIX) {
            String key = genKey(sceneid, a.getId(), "desc");
            String value = ia.getDesc();
            ia.setDesc(key);
            setTranslation(key, value);
        }
        // 2. ACTIONS
        HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
        for (Verb v : verbs.values()) extractStrings(sceneid, a.getId(), v);
        // 3. DIALOGS
        if (a instanceof CharacterActor) {
            HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
            if (dialogs != null)
                for (Dialog d : dialogs.values()) extractStrings(sceneid, a.getId(), d);
        }
        // 4. Text for TextRenderer
        if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof TextRenderer) {
            TextRenderer r = (TextRenderer) ((SpriteActor) a).getRenderer();
            String v = r.getText();
            if (v != null && !v.isEmpty() && v.charAt(0) != I18N.PREFIX) {
                String key = genKey(sceneid, a.getId(), "text");
                r.setText(key, r.getText());
                setTranslation(key, v);
            }
        }
    }
}
Also used : Dialog(com.bladecoder.engine.model.Dialog) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Verb(com.bladecoder.engine.model.Verb) SpriteActor(com.bladecoder.engine.model.SpriteActor) CharacterActor(com.bladecoder.engine.model.CharacterActor) TextRenderer(com.bladecoder.engine.model.TextRenderer)

Aggregations

CharacterActor (com.bladecoder.engine.model.CharacterActor)21 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)13 BaseActor (com.bladecoder.engine.model.BaseActor)11 SpriteActor (com.bladecoder.engine.model.SpriteActor)10 Dialog (com.bladecoder.engine.model.Dialog)7 Scene (com.bladecoder.engine.model.Scene)7 Verb (com.bladecoder.engine.model.Verb)7 DialogOption (com.bladecoder.engine.model.DialogOption)6 Vector2 (com.badlogic.gdx.math.Vector2)5 TextRenderer (com.bladecoder.engine.model.TextRenderer)5 Rectangle (com.badlogic.gdx.math.Rectangle)3 Action (com.bladecoder.engine.actions.Action)3 World (com.bladecoder.engine.model.World)3 LookAtAction (com.bladecoder.engine.actions.LookAtAction)2 SayAction (com.bladecoder.engine.actions.SayAction)2 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)2 AnchorActor (com.bladecoder.engine.model.AnchorActor)2 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)2 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)2 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)2