Search in sources :

Example 1 with Timers

use of com.bladecoder.engine.anim.Timers in project bladecoder-adventure-engine by bladecoder.

the class World method read.

@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
    if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
        String version = json.readValue(Config.BLADE_ENGINE_VERSION_PROP, String.class, jsonData);
        if (version != null && !version.equals(Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
            EngineLogger.debug("Model Engine Version v" + version + " differs from Current Engine Version v" + Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
        }
        sounds = json.readValue("sounds", HashMap.class, SoundDesc.class, jsonData);
        // For backwards compatibility
        if (sounds == null)
            sounds = new HashMap<String, SoundDesc>();
        scenes = json.readValue("scenes", HashMap.class, Scene.class, jsonData);
        initScene = json.readValue("initScene", String.class, jsonData);
        if (initScene == null && scenes.size() > 0) {
            initScene = scenes.keySet().toArray(new String[0])[0];
        }
        for (Scene s : scenes.values()) {
            s.resetCamera(width, height);
        }
        setCurrentScene(initScene);
        // Add sounds to cache
        cacheSounds();
    } else {
        String bladeVersion = json.readValue(Config.BLADE_ENGINE_VERSION_PROP, String.class, jsonData);
        if (bladeVersion != null && !bladeVersion.equals(Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
            EngineLogger.debug("Saved Game Engine Version v" + bladeVersion + " differs from Current Engine Version v" + Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
        }
        String version = json.readValue(Config.VERSION_PROP, String.class, jsonData);
        if (version == null)
            version = "TEST";
        currentChapter = json.readValue("chapter", String.class, jsonData);
        try {
            loadChapter(currentChapter);
        } catch (IOException e1) {
            EngineLogger.error("Error Loading Chapter");
            return;
        }
        // restore the state after loading the model
        SerializationHelper.getInstance().setMode(Mode.STATE);
        currentScene = scenes.get(json.readValue("currentScene", String.class, jsonData));
        // scenes and verbs tweens
        if (jsonData.get("inkManager") != null) {
            getInkManager().read(json, jsonData.get("inkManager"));
        }
        // inventories have to be put in the hash to find the actors when
        // reading saved data
        currentInventory = json.readValue("currentInventory", String.class, jsonData);
        JsonValue jsonInventories = jsonData.get("inventories");
        inventories = new HashMap<String, Inventory>();
        for (int i = 0; i < jsonInventories.size; i++) {
            JsonValue jsonValue = jsonInventories.get(i);
            Inventory inv = new Inventory();
            inventories.put(jsonValue.name, inv);
            inv.read(json, jsonValue);
        }
        if (jsonData.get("uiActors") != null) {
            getUIActors().read(json, jsonData.get("uiActors"));
        }
        for (Scene s : scenes.values()) {
            JsonValue jsonValue = jsonData.get("scenes").get(s.getId());
            if (jsonValue != null)
                s.read(json, jsonValue);
            else
                EngineLogger.debug("LOAD WARNING: Scene not found in saved game: " + s.getId());
        }
        timeOfGame = json.readValue("timeOfGame", long.class, 0L, jsonData);
        cutMode = json.readValue("cutmode", boolean.class, false, jsonData);
        verbs.read(json, jsonData);
        timers = json.readValue("timers", Timers.class, jsonData);
        textManager = json.readValue("textmanager", TextManager.class, jsonData);
        customProperties = json.readValue("customProperties", HashMap.class, String.class, jsonData);
        customProperties.put(WorldProperties.SAVED_GAME_VERSION.toString(), version);
        String actorId = json.readValue("dialogActor", String.class, jsonData);
        String dialogId = json.readValue("currentDialog", String.class, jsonData);
        if (dialogId != null) {
            CharacterActor actor = (CharacterActor) getCurrentScene().getActor(actorId, false);
            currentDialog = actor.getDialog(dialogId);
        }
        transition = json.readValue("transition", Transition.class, jsonData);
        musicManager = json.readValue("musicEngine", MusicManager.class, jsonData);
        if (musicManager == null)
            musicManager = new MusicManager();
        ActionCallbackQueue.read(json, jsonData);
        I18N.loadChapter(EngineAssetManager.MODEL_DIR + instance.currentChapter);
    }
}
Also used : HashMap(java.util.HashMap) JsonValue(com.badlogic.gdx.utils.JsonValue) IOException(java.io.IOException) Timers(com.bladecoder.engine.anim.Timers)

Aggregations

JsonValue (com.badlogic.gdx.utils.JsonValue)1 Timers (com.bladecoder.engine.anim.Timers)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1