Search in sources :

Example 61 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class InkManager method read.

@Override
public void read(Json json, JsonValue jsonData) {
    BladeJson bjson = (BladeJson) json;
    World w = bjson.getWorld();
    final String name = json.readValue("storyName", String.class, jsonData);
    if (bjson.getMode() == Mode.MODEL) {
        story = null;
        storyName = name;
        // game and we will load the story in the STATE mode.
        if (bjson.getInit()) {
            loadThreaded(name, null);
        }
    } else {
        wasInCutmode = json.readValue("wasInCutmode", Boolean.class, jsonData);
        // READ STORY
        final String storyString = json.readValue("story", String.class, jsonData);
        if (storyString != null) {
            loadThreaded(name, storyString);
        }
        // FOR BACKWARD COMPATIBILITY
        if (jsonData.has("actions")) {
            String sCb = json.readValue("cb", String.class, jsonData);
            // READ ACTIONS
            JsonValue actionsValue = jsonData.get("actions");
            InkVerbRunner inkVerbRunner = new InkVerbRunner(w, this, StoryState.kDefaultFlowName, null, sCb);
            verbRunners.put(StoryState.kDefaultFlowName, inkVerbRunner);
            for (int i = 0; i < actionsValue.size; i++) {
                JsonValue aValue = actionsValue.get(i);
                Action a = ActionUtils.readJson(w, json, aValue);
                inkVerbRunner.getActions().add(a);
            }
            inkVerbRunner.setIP(json.readValue("ip", Integer.class, jsonData));
            actionsValue = jsonData.get("actionsSer");
            int i = 0;
            for (Action a : inkVerbRunner.getActions()) {
                if (a instanceof Serializable && i < actionsValue.size) {
                    if (actionsValue.get(i) == null)
                        break;
                    ((Serializable) a).read(json, actionsValue.get(i));
                    i++;
                }
            }
        } else {
            for (int i = 0; i < jsonData.get("verbRunners").size; i++) {
                JsonValue jRunner = jsonData.get("verbRunners").get(i);
                InkVerbRunner inkVerbRunner = new InkVerbRunner(w, this, jRunner.name, null, null);
                verbRunners.put(jRunner.name, inkVerbRunner);
                inkVerbRunner.read(json, jRunner);
            }
        }
    }
}
Also used : Action(com.bladecoder.engine.actions.Action) Serializable(com.badlogic.gdx.utils.Json.Serializable) BladeJson(com.bladecoder.engine.serialization.BladeJson) JsonValue(com.badlogic.gdx.utils.JsonValue) World(com.bladecoder.engine.model.World)

Example 62 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class CharacterActor method read.

@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    BladeJson bjson = (BladeJson) json;
    if (bjson.getMode() == Mode.MODEL) {
        dialogs = json.readValue("dialogs", HashMap.class, Dialog.class, jsonData);
        if (dialogs != null) {
            for (Dialog d : dialogs.values()) d.setActor(this);
        }
    } else {
        if (dialogs != null) {
            JsonValue dialogsValue = jsonData.get("dialogs");
            for (Dialog d : dialogs.values()) {
                String id = d.getId();
                JsonValue dValue = dialogsValue.get(id);
                if (dValue != null)
                    d.read(json, dValue);
            }
        }
        standAnim = json.readValue("standAnim", String.class, DEFAULT_STAND_ANIM, jsonData);
        walkAnim = json.readValue("walkAnim", String.class, DEFAULT_WALK_ANIM, jsonData);
        talkAnim = json.readValue("talkAnim", String.class, DEFAULT_TALK_ANIM, jsonData);
    }
    textStyle = json.readValue("textStyle", String.class, textStyle, jsonData);
    walkingSpeed = json.readValue("walkingSpeed", float.class, walkingSpeed, jsonData);
    textColor = json.readValue("textColor", Color.class, textColor, jsonData);
    talkingTextPos = json.readValue("talkingTextPos", Vector2.class, talkingTextPos, jsonData);
    if (talkingTextPos != null) {
        float worldScale = EngineAssetManager.getInstance().getScale();
        talkingTextPos.x *= worldScale;
        talkingTextPos.y *= worldScale;
    }
}
Also used : HashMap(java.util.HashMap) Vector2(com.badlogic.gdx.math.Vector2) BladeJson(com.bladecoder.engine.serialization.BladeJson) Color(com.badlogic.gdx.graphics.Color) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 63 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class Dialog method read.

@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
    BladeJson bjson = (BladeJson) json;
    if (bjson.getMode() == Mode.MODEL) {
        id = json.readValue("id", String.class, jsonData);
        // actor = json.readValue("actor", String.class, jsonData);
        options = json.readValue("options", ArrayList.class, DialogOption.class, jsonData);
    } else {
        JsonValue optionsValue = jsonData.get("options");
        int i = 0;
        for (DialogOption o : options) {
            JsonValue jsonValue = optionsValue.get(i);
            if (jsonValue == null)
                break;
            o.read(json, jsonValue);
            i++;
        }
        currentOption = json.readValue("currentOption", int.class, jsonData);
    }
}
Also used : BladeJson(com.bladecoder.engine.serialization.BladeJson) ArrayList(java.util.ArrayList) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 64 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class Inventory method read.

@Override
public void read(Json json, JsonValue jsonData) {
    BladeJson bjson = (BladeJson) json;
    visible = json.readValue("visible", Boolean.class, jsonData);
    items.clear();
    JsonValue jsonValueActors = jsonData.get("items");
    SceneActorRef actorRef;
    // GET ACTORS FROM HIS INIT SCENE.
    for (int i = 0; i < jsonValueActors.size; i++) {
        JsonValue jsonValueAct = jsonValueActors.get(i);
        actorRef = new SceneActorRef(jsonValueAct.name);
        Scene sourceScn = bjson.getWorld().getScene(actorRef.getSceneId());
        BaseActor actor = sourceScn.getActor(actorRef.getActorId(), false);
        sourceScn.removeActor(actor);
        addItem((SpriteActor) actor);
    }
    // The state must be retrieved after getting actors from his init scene to restore verb cb properly.
    for (int i = 0; i < jsonValueActors.size; i++) {
        JsonValue jsonValueAct = jsonValueActors.get(i);
        actorRef = new SceneActorRef(jsonValueAct.name);
        SpriteActor actor = items.get(i);
        actor.read(json, jsonValueAct);
    }
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef) BladeJson(com.bladecoder.engine.serialization.BladeJson) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 65 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class UIActors method read.

@Override
public void read(Json json, JsonValue jsonData) {
    actors.clear();
    JsonValue jsonValueActors = jsonData.get("actors");
    SceneActorRef actorRef;
    // GET ACTORS FROM HIS INIT SCENE.
    for (int i = 0; i < jsonValueActors.size; i++) {
        JsonValue jsonValueAct = jsonValueActors.get(i);
        actorRef = new SceneActorRef(jsonValueAct.name);
        Scene sourceScn = w.getScene(actorRef.getSceneId());
        BaseActor actor = sourceScn.getActor(actorRef.getActorId(), false);
        sourceScn.removeActor(actor);
        addActor((InteractiveActor) actor);
    }
    // to restore verb cb properly.
    for (int i = 0; i < jsonValueActors.size; i++) {
        JsonValue jsonValueAct = jsonValueActors.get(i);
        InteractiveActor actor = actors.get(i);
        actor.read(json, jsonValueAct);
    }
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef) JsonValue(com.badlogic.gdx.utils.JsonValue)

Aggregations

JsonValue (com.badlogic.gdx.utils.JsonValue)148 JsonReader (com.badlogic.gdx.utils.JsonReader)27 IOException (java.io.IOException)21 Array (com.badlogic.gdx.utils.Array)20 Json (com.badlogic.gdx.utils.Json)15 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)14 FileHandle (com.badlogic.gdx.files.FileHandle)11 ReflectionException (com.badlogic.gdx.utils.reflect.ReflectionException)10 BladeJson (com.bladecoder.engine.serialization.BladeJson)9 HashMap (java.util.HashMap)8 Color (com.badlogic.gdx.graphics.Color)7 GraphBoxImpl (com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl)7 ArrayList (java.util.ArrayList)7 Vector2 (com.badlogic.gdx.math.Vector2)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Action (com.bladecoder.engine.actions.Action)6 File (java.io.File)6 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 SerializationException (com.badlogic.gdx.utils.SerializationException)5