use of com.badlogic.gdx.utils.JsonValue in project Mindustry by Anuken.
the class Changelogs method getChangelog.
public static void getChangelog(Consumer<Array<VersionInfo>> success, Consumer<Throwable> fail) {
Net.http(releasesURL, "GET", result -> {
Json j = new Json();
Array<JsonValue> list = j.fromJson(null, result);
Array<VersionInfo> out = new Array<>();
for (JsonValue value : list) {
String name = value.getString("name");
String description = value.getString("body").replace("\r", "");
int id = value.getInt("id");
int build = Integer.parseInt(value.getString("tag_name").substring(1));
out.add(new VersionInfo(name, description, id, build));
}
success.accept(out);
}, fail);
}
use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.
the class ModelTools method extractInkTextsInternal.
private static void extractInkTextsInternal(JsonValue v, StringBuilder sb, NewOrderedProperties prop) {
if (v.isArray() || v.isObject()) {
for (int i = 0; i < v.size; i++) {
JsonValue aValue = v.get(i);
extractInkTextsInternal(aValue, sb, prop);
}
} else if (v.isString() && v.asString().charAt(0) == '^') {
String value = v.asString().substring(1).trim();
if (value.length() == 0 || value.charAt(0) == '>')
return;
int idx = value.indexOf('>');
String charName = "";
if (idx != -1) {
charName = value.substring(0, idx).trim();
value = value.substring(idx + 1).trim();
}
String key = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] bytes = value.getBytes(("UTF-8"));
md.update(bytes);
byte[] digest = md.digest();
key = Base64Coder.encodeLines(digest).substring(0, 10);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
EditorLogger.error("Error encoding key." + e);
return;
}
// Ctx.project.getI18N().setTranslation(key, value);
prop.setProperty(key, value);
sb.append(key + "\t" + charName + "\t" + value + "\n");
if (charName.isEmpty())
v.set("^" + I18N.PREFIX + key);
else
v.set("^" + charName + '>' + I18N.PREFIX + key);
}
}
use of com.badlogic.gdx.utils.JsonValue 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);
}
}
use of com.badlogic.gdx.utils.JsonValue 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.JsonValue 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