use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.
the class Verb method read.
@Override
public void read(Json json, JsonValue jsonData) {
BladeJson bjson = (BladeJson) json;
if (bjson.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(bjson.getWorld(), 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);
cb = ActionCallbackSerializer.find(bjson.getWorld(), bjson.getScene(), json.readValue("cb", String.class, jsonData));
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.JsonValue in project bladecoder-adventure-engine by bladecoder.
the class VerbManager method read.
@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
BladeJson bjson = (BladeJson) json;
if (bjson.getMode() == Mode.MODEL) {
this.w = bjson.getWorld();
verbs = json.readValue("verbs", HashMap.class, Verb.class, jsonData);
} else {
for (String v : verbs.keySet()) {
Verb verb = verbs.get(v);
JsonValue jsonValue = jsonData.get("verbs").get(v);
if (jsonValue != null)
verb.read(json, jsonValue);
else
EngineLogger.debug("LOAD WARNING: Verb not found in saved game: " + jsonData.name + "." + v);
}
}
}
use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.
the class ActionUtils method readJson.
public static Action readJson(World w, Json json, JsonValue jsonData) {
String className = jsonData.getString("class", null);
Action action = null;
if (className != null) {
jsonData.remove("class");
try {
action = ActionFactory.create(className, null);
} catch (ClassNotFoundException | ReflectionException e1) {
throw new SerializationException(e1);
}
for (int j = 0; j < jsonData.size; j++) {
JsonValue v = jsonData.get(j);
try {
if (v.isNull())
ActionUtils.setParam(action, v.name, null);
else
ActionUtils.setParam(action, v.name, v.asString());
} catch (NoSuchFieldException e) {
EngineLogger.error("Action field not found - class: " + className + " field: " + v.name);
} catch (IllegalArgumentException | IllegalAccessException e) {
EngineLogger.error("Action field error - class: " + className + " field: " + v.name + " value: " + (v == null ? "null" : v.asString()));
}
}
action.init(w);
}
return action;
}
use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.
the class GradientColorModule method read.
@Override
public void read(Json json, JsonValue jsonData) {
super.read(json, jsonData);
points.clear();
final JsonValue jsonPpoints = jsonData.get("points");
for (JsonValue point : jsonPpoints) {
createPoint(new Color(point.getFloat("r"), point.getFloat("g"), point.getFloat("b"), 1f), point.getFloat("pos"));
}
}
use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.
the class CurveModule method read.
@Override
public void read(Json json, JsonValue jsonData) {
super.read(json, jsonData);
points.clear();
final JsonValue points = jsonData.get("points");
for (JsonValue point : points) {
createPoint(point.get(0).asFloat(), point.get(1).asFloat());
}
}
Aggregations