Search in sources :

Example 31 with BaseActor

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

the class ScreenPositionAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = actor.getScene();
    BaseActor a = s.getActor(actor.getActorId(), true);
    if (position != null) {
        float scale = EngineAssetManager.getInstance().getScale();
        Viewport viewport = ((SceneScreen) BladeEngine.getAppUI().getScreen(Screens.SCENE_SCREEN)).getViewport();
        Vector3 v = new Vector3(position.x * scale, position.y * scale, 0);
        if (anchor == Anchor.CENTER) {
            v.x += viewport.getWorldWidth() / 2;
            v.y += viewport.getWorldHeight() / 2;
        } else if (anchor == Anchor.TOP_LEFT) {
            v.x += 0;
            v.y += viewport.getWorldHeight();
        } else if (anchor == Anchor.TOP_RIGHT) {
            v.x += viewport.getWorldWidth();
            v.y += viewport.getWorldHeight();
        } else if (anchor == Anchor.BOTTOM_RIGHT) {
            v.x += viewport.getWorldWidth();
            v.y += 0;
        } else if (anchor == Anchor.BOTTOM_LEFT) {
            v.x += 0;
            v.y += 0;
        } else if (anchor == Anchor.TOP) {
            v.x += viewport.getWorldWidth() / 2;
            v.y += viewport.getWorldHeight();
        } else if (anchor == Anchor.BOTTOM) {
            v.x += viewport.getWorldWidth() / 2;
            v.y += 0;
        } else if (anchor == Anchor.LEFT) {
            v.x += 0;
            v.y += viewport.getWorldHeight() / 2;
        } else if (anchor == Anchor.RIGHT) {
            v.x += viewport.getWorldWidth();
            v.y += viewport.getWorldHeight() / 2;
        }
        // viewport.project(v);
        v.x *= viewport.getScreenWidth() / viewport.getWorldWidth();
        v.y *= viewport.getScreenHeight() / viewport.getWorldHeight();
        // v.y = viewport.getScreenHeight() - v.y;
        v.y = Gdx.graphics.getHeight() - v.y;
        World.getInstance().getCurrentScene().getCamera().unproject(v, 0, 0, viewport.getScreenWidth(), viewport.getScreenHeight());
        a.setPosition(v.x, v.y);
    }
    return false;
}
Also used : SceneScreen(com.bladecoder.engine.ui.SceneScreen) Viewport(com.badlogic.gdx.utils.viewport.Viewport) Vector3(com.badlogic.gdx.math.Vector3) BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene)

Example 32 with BaseActor

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

the class SetPlayerAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = actor.getScene();
    BaseActor a = s.getActor(actor.getActorId(), true);
    s.setPlayer((CharacterActor) a);
    if (inventory != null) {
        World w = World.getInstance();
        w.getInventory().dispose();
        w.setInventory(inventory);
        w.getInventory().loadAssets();
        EngineAssetManager.getInstance().finishLoading();
        w.getInventory().retrieveAssets();
    }
    return false;
}
Also used : BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene) World(com.bladecoder.engine.model.World)

Example 33 with BaseActor

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

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

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

the class I18NHandler method getUsedKeys.

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));
            }
        }
    }
}
Also used : Dialog(com.bladecoder.engine.model.Dialog) Verb(com.bladecoder.engine.model.Verb) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) CharacterActor(com.bladecoder.engine.model.CharacterActor) DialogOption(com.bladecoder.engine.model.DialogOption) TextRenderer(com.bladecoder.engine.model.TextRenderer)

Aggregations

BaseActor (com.bladecoder.engine.model.BaseActor)40 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)26 Scene (com.bladecoder.engine.model.Scene)16 SpriteActor (com.bladecoder.engine.model.SpriteActor)13 CharacterActor (com.bladecoder.engine.model.CharacterActor)12 Vector2 (com.badlogic.gdx.math.Vector2)8 Verb (com.bladecoder.engine.model.Verb)8 Polygon (com.badlogic.gdx.math.Polygon)7 World (com.bladecoder.engine.model.World)7 Rectangle (com.badlogic.gdx.math.Rectangle)5 Action (com.bladecoder.engine.actions.Action)5 AnchorActor (com.bladecoder.engine.model.AnchorActor)5 LookAtAction (com.bladecoder.engine.actions.LookAtAction)4 SayAction (com.bladecoder.engine.actions.SayAction)4 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)4 Dialog (com.bladecoder.engine.model.Dialog)4 DialogOption (com.bladecoder.engine.model.DialogOption)4 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)4 SceneLayer (com.bladecoder.engine.model.SceneLayer)4 Color (com.badlogic.gdx.graphics.Color)3