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;
}
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();
}
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);
}
}
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));
}
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");
}
}
Aggregations