Search in sources :

Example 6 with JsonReader

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

the class DisableActionAction method getAction.

public Action getAction() {
    if (action == null) {
        Json json = new Json();
        JsonValue root = new JsonReader().parse(serializedAction);
        action = ActionUtils.readJson(json, root);
    }
    return action;
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) Json(com.badlogic.gdx.utils.Json)

Example 7 with JsonReader

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

the class ModelTools method extractInkTexts.

public static void extractInkTexts(String story, String lang) throws IOException {
    String file = Ctx.project.getModelPath() + "/" + story + EngineAssetManager.INK_EXT;
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
    StringBuilder sb = new StringBuilder();
    try {
        String line = br.readLine();
        // Replace the BOM mark
        if (line != null)
            line = line.replace('\uFEFF', ' ');
        while (line != null) {
            sb.append(line);
            sb.append("\n");
            line = br.readLine();
        }
    } finally {
        br.close();
    }
    JsonValue root = new JsonReader().parse(sb.toString());
    StringBuilder tsvString = new StringBuilder();
    OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder();
    builder.withSuppressDateInComment(true);
    NewOrderedProperties prop = builder.build();
    extractInkTextsInternal(root, tsvString, prop);
    FileUtils.writeStringToFile(new File(file + ".tsv"), tsvString.toString());
    String json = root.toJson(OutputType.json);
    FileUtils.writeStringToFile(new File(file + ".new"), json);
    FileUtils.copyFile(new File(file), new File(file + ".old"));
    FileUtils.copyFile(new File(file + ".new"), new File(file));
    new File(file + ".new").delete();
    try {
        String file2 = file.substring(0, file.length() - EngineAssetManager.INK_EXT.length());
        if (lang.equals("default"))
            file2 += "-ink.properties";
        else
            file2 += "-ink" + "_" + lang + ".properties";
        FileOutputStream os = new FileOutputStream(file2);
        Writer out = new OutputStreamWriter(os, I18N.ENCODING);
        prop.store(out, null);
    } catch (IOException e) {
        EditorLogger.error("ERROR WRITING BUNDLE: " + file + ".properties");
    }
// Ctx.project.setModified();
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonValue(com.badlogic.gdx.utils.JsonValue) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) JsonReader(com.badlogic.gdx.utils.JsonReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 8 with JsonReader

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

the class ElementUtils method cloneElement.

public static Object cloneElement(Object e) {
    Json json = new Json();
    if (e instanceof Action) {
        StringWriter buffer = new StringWriter();
        json.setWriter(buffer);
        ActionUtils.writeJson((Action) e, json);
        String str = buffer.toString();
        EditorLogger.debug(str);
        JsonValue root = new JsonReader().parse(str);
        return ActionUtils.readJson(json, root);
    } else {
        SerializationHelper.getInstance().setMode(Mode.MODEL);
        String str = json.toJson(e, (Class<?>) null);
        return json.fromJson(e.getClass(), str);
    }
}
Also used : Action(com.bladecoder.engine.actions.Action) StringWriter(java.io.StringWriter) JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) Json(com.badlogic.gdx.utils.Json)

Example 9 with JsonReader

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

the class World method loadChapter.

public void loadChapter(String chapterName) throws IOException {
    if (!disposed)
        dispose();
    init();
    long initTime = System.currentTimeMillis();
    SerializationHelper.getInstance().setMode(Mode.MODEL);
    if (chapterName == null)
        chapterName = initChapter;
    currentChapter = chapterName;
    if (EngineAssetManager.getInstance().getModelFile(chapterName + EngineAssetManager.CHAPTER_EXT).exists()) {
        JsonValue root = new JsonReader().parse(EngineAssetManager.getInstance().getModelFile(chapterName + EngineAssetManager.CHAPTER_EXT).reader("UTF-8"));
        Json json = new Json();
        json.setIgnoreUnknownFields(true);
        read(json, root);
        I18N.loadChapter(EngineAssetManager.MODEL_DIR + chapterName);
        customProperties.put(WorldProperties.CURRENT_CHAPTER.toString(), chapterName);
        customProperties.put(WorldProperties.PLATFORM.toString(), Gdx.app.getType().toString());
    } else {
        EngineLogger.error("ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager.CHAPTER_EXT + " doesn't exists.");
        dispose();
        throw new IOException("ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager.CHAPTER_EXT + " doesn't exists.");
    }
    EngineLogger.debug("MODEL LOADING TIME (ms): " + (System.currentTimeMillis() - initTime));
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) Json(com.badlogic.gdx.utils.Json) IOException(java.io.IOException)

Example 10 with JsonReader

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

the class World method loadGameState.

public void loadGameState(FileHandle savedFile) throws IOException {
    EngineLogger.debug("LOADING GAME STATE");
    if (!disposed)
        dispose();
    init();
    if (savedFile.exists()) {
        SerializationHelper.getInstance().setMode(Mode.STATE);
        JsonValue root = new JsonReader().parse(savedFile.reader("UTF-8"));
        Json json = new Json();
        json.setIgnoreUnknownFields(true);
        read(json, root);
        assetState = AssetState.LOAD_ASSETS;
    } else {
        throw new IOException("LOADGAMESTATE: no saved game exists");
    }
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) Json(com.badlogic.gdx.utils.Json) IOException(java.io.IOException)

Aggregations

JsonReader (com.badlogic.gdx.utils.JsonReader)10 JsonValue (com.badlogic.gdx.utils.JsonValue)7 Json (com.badlogic.gdx.utils.Json)5 IOException (java.io.IOException)4 ModelLoader (com.badlogic.gdx.assets.loaders.ModelLoader)1 com.badlogic.gdx.graphics (com.badlogic.gdx.graphics)1 Environment (com.badlogic.gdx.graphics.g3d.Environment)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 G3dModelLoader (com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader)1 NodePart (com.badlogic.gdx.graphics.g3d.model.NodePart)1 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 Matrix4 (com.badlogic.gdx.math.Matrix4)1 Vector3 (com.badlogic.gdx.math.Vector3)1 com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld (com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld)1 Action (com.bladecoder.engine.actions.Action)1 OrderedPropertiesBuilder (com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder)1 BroadphaseInterface (com.bulletphysics.collision.broadphase.BroadphaseInterface)1 DbvtBroadphase (com.bulletphysics.collision.broadphase.DbvtBroadphase)1 CollisionDispatcher (com.bulletphysics.collision.dispatch.CollisionDispatcher)1