use of com.badlogic.gdx.utils.Json.Serializable in project bladecoder-adventure-engine by bladecoder.
the class InkManager method read.
@Override
public void read(Json json, JsonValue jsonData) {
wasInCutmode = json.readValue("wasInCutmode", Boolean.class, jsonData);
sCb = json.readValue("cb", String.class, jsonData);
// READ ACTIONS
actions.clear();
JsonValue actionsValue = jsonData.get("actions");
for (int i = 0; i < actionsValue.size; i++) {
JsonValue aValue = actionsValue.get(i);
Action a = ActionUtils.readJson(json, aValue);
actions.add(a);
}
ip = json.readValue("ip", Integer.class, jsonData);
actionsValue = jsonData.get("actionsSer");
int i = 0;
for (Action a : actions) {
if (a instanceof Serializable && i < actionsValue.size) {
if (actionsValue.get(i) == null)
break;
((Serializable) a).read(json, actionsValue.get(i));
i++;
}
}
// READ STORY
String storyName = json.readValue("storyName", String.class, jsonData);
String storyString = json.readValue("story", String.class, jsonData);
if (storyString != null) {
try {
newStory(storyName);
long initTime = System.currentTimeMillis();
story.getState().loadJson(storyString);
EngineLogger.debug("INK SAVED STATE LOADING TIME (ms): " + (System.currentTimeMillis() - initTime));
} catch (Exception e) {
EngineLogger.error(e.getMessage(), e);
}
}
}
use of com.badlogic.gdx.utils.Json.Serializable in project bladecoder-adventure-engine by bladecoder.
the class Verb method read.
@Override
public void read(Json json, JsonValue jsonData) {
if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
id = json.readValue("id", String.class, jsonData);
target = json.readValue("target", String.class, (String) null, jsonData);
state = json.readValue("state", String.class, (String) null, jsonData);
icon = json.readValue("icon", String.class, (String) null, jsonData);
actions.clear();
JsonValue actionsValue = jsonData.get("actions");
for (int i = 0; i < actionsValue.size; i++) {
JsonValue aValue = actionsValue.get(i);
String clazz = aValue.getString("class");
try {
Action a = ActionUtils.readJson(json, aValue);
actions.add(a);
} catch (SerializationException e) {
EngineLogger.error("Error loading action: " + clazz + " " + aValue.toString());
throw e;
}
}
} else {
// MUTABLE
currentTarget = json.readValue("currentTarget", String.class, (String) null, jsonData);
ip = json.readValue("ip", Integer.class, jsonData);
String sCb = json.readValue("cb", String.class, jsonData);
cb = ActionCallbackSerialization.find(sCb);
JsonValue actionsValue = jsonData.get("actions");
int i = 0;
for (Action a : actions) {
if (a instanceof Serializable && i < actionsValue.size) {
if (actionsValue.get(i) == null)
break;
((Serializable) a).read(json, actionsValue.get(i));
i++;
}
}
}
}
use of com.badlogic.gdx.utils.Json.Serializable in project bladecoder-adventure-engine by bladecoder.
the class Verb method write.
@Override
public void write(Json json) {
if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
json.writeValue("id", id);
if (target != null)
json.writeValue("target", target);
if (state != null)
json.writeValue("state", state);
if (icon != null)
json.writeValue("icon", icon);
json.writeArrayStart("actions");
for (Action a : actions) {
ActionUtils.writeJson(a, json);
}
json.writeArrayEnd();
} else {
json.writeValue("ip", ip);
json.writeValue("cb", ActionCallbackSerialization.find(cb));
if (currentTarget != null)
json.writeValue("currentTarget", currentTarget);
json.writeArrayStart("actions");
for (Action a : actions) {
if (a instanceof Serializable) {
json.writeObjectStart();
((Serializable) a).write(json);
json.writeObjectEnd();
}
}
json.writeArrayEnd();
}
}
use of com.badlogic.gdx.utils.Json.Serializable in project bladecoder-adventure-engine by bladecoder.
the class InkManager method write.
@Override
public void write(Json json) {
json.writeValue("wasInCutmode", wasInCutmode);
if (cb == null && sCb != null)
cb = ActionCallbackSerialization.find(sCb);
json.writeValue("cb", ActionCallbackSerialization.find(cb));
// SAVE ACTIONS
json.writeArrayStart("actions");
for (Action a : actions) {
ActionUtils.writeJson(a, json);
}
json.writeArrayEnd();
json.writeValue("ip", ip);
json.writeArrayStart("actionsSer");
for (Action a : actions) {
if (a instanceof Serializable) {
json.writeObjectStart();
((Serializable) a).write(json);
json.writeObjectEnd();
}
}
json.writeArrayEnd();
// SAVE STORY
json.writeValue("storyName", storyName);
if (story != null) {
try {
json.writeValue("story", story.getState().toJson());
} catch (Exception e) {
EngineLogger.error(e.getMessage(), e);
}
}
}
Aggregations