use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.
the class ActionUtils method setParam.
@SuppressWarnings("unchecked")
public static void setParam(Action action, String param, String value) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Class<?> clazz = action.getClass();
Field field = getField(clazz, param);
if (field == null)
throw new NoSuchFieldException(param);
final boolean accessible = field.isAccessible();
field.setAccessible(true);
if (field.getType().isAssignableFrom(String.class)) {
field.set(action, value);
} else if (field.getType().isAssignableFrom(boolean.class)) {
field.setBoolean(action, Boolean.parseBoolean(value));
} else if (field.getType().isAssignableFrom(Boolean.class)) {
Boolean b = null;
if (value != null)
b = Boolean.valueOf(value);
field.set(action, b);
} else if (field.getType().isAssignableFrom(float.class)) {
try {
field.setFloat(action, Float.parseFloat(value));
} catch (NumberFormatException ignored) {
}
} else if (field.getType().isAssignableFrom(Float.class)) {
try {
Float f = null;
if (value != null)
f = Float.valueOf(value);
field.set(action, f);
} catch (NumberFormatException ignored) {
}
} else if (field.getType().isAssignableFrom(int.class)) {
try {
Integer i = null;
if (value != null) {
i = Integer.parseInt(value);
field.setInt(action, i);
}
} catch (NumberFormatException ignored) {
}
} else if (field.getType().isAssignableFrom(Integer.class)) {
try {
Float f = null;
if (value != null)
f = Float.valueOf(value);
field.set(action, f);
} catch (NumberFormatException ignored) {
}
} else if (field.getType().isAssignableFrom(Vector2.class)) {
field.set(action, Param.parseVector2(value));
} else if (field.getType().isAssignableFrom(SceneActorRef.class)) {
if (value == null)
field.set(action, null);
else
field.set(action, new SceneActorRef(value));
} else if (field.getType().isAssignableFrom(ActorAnimationRef.class)) {
if (value == null)
field.set(action, null);
else
field.set(action, new ActorAnimationRef(value));
} else if (field.getType().isAssignableFrom(Color.class)) {
Color a = Param.parseColor(value);
field.set(action, a);
} else if (field.getType().isEnum()) {
field.set(action, Enum.valueOf(field.getType().asSubclass(Enum.class), value.toUpperCase(Locale.ENGLISH)));
} else {
EngineLogger.error("ACTION FIELD TYPE NOT SUPPORTED - type: " + field.getType());
}
field.setAccessible(accessible);
}
use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.
the class ActionUtils method writeJson.
public static void writeJson(Action a, Json json) {
Class<?> clazz = a.getClass();
json.writeObjectStart(clazz, null);
while (clazz != null && clazz != Object.class) {
for (Field field : clazz.getDeclaredFields()) {
final ActionProperty property = field.getAnnotation(ActionProperty.class);
if (property == null) {
continue;
}
// json.writeField(a, field.getName());
final boolean accessible = field.isAccessible();
field.setAccessible(true);
try {
Object o = field.get(a);
// doesn't write null fields
if (o == null)
continue;
if (o instanceof SceneActorRef) {
SceneActorRef sceneActor = (SceneActorRef) o;
json.writeValue(field.getName(), sceneActor.toString());
} else if (o instanceof ActorAnimationRef) {
ActorAnimationRef aa = (ActorAnimationRef) o;
json.writeValue(field.getName(), aa.toString());
} else if (o instanceof Color) {
json.writeValue(field.getName(), ((Color) o).toString());
} else if (o instanceof Vector2) {
json.writeValue(field.getName(), Param.toStringParam((Vector2) o));
} else {
json.writeValue(field.getName(), o);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
}
field.setAccessible(accessible);
}
clazz = clazz.getSuperclass();
}
json.writeObjectEnd();
}
use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.
the class SceneActorInputPanel method setText.
public void setText(String s) {
SceneActorRef aa = new SceneActorRef(s);
scene.setSelected(aa.getSceneId() == null ? "" : aa.getSceneId());
sceneSelected();
actor.setSelected(aa.getActorId());
}
use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.
the class UIActors method read.
@Override
public void read(Json json, JsonValue jsonData) {
actors.clear();
JsonValue jsonValueActors = jsonData.get("actors");
SceneActorRef actorRef;
// GET ACTORS FROM HIS INIT SCENE.
for (int i = 0; i < jsonValueActors.size; i++) {
JsonValue jsonValueAct = jsonValueActors.get(i);
actorRef = new SceneActorRef(jsonValueAct.name);
Scene sourceScn = World.getInstance().getScene(actorRef.getSceneId());
BaseActor actor = sourceScn.getActor(actorRef.getActorId(), false);
sourceScn.removeActor(actor);
addActor((InteractiveActor) actor);
}
// to restore verb cb properly.
for (int i = 0; i < jsonValueActors.size; i++) {
JsonValue jsonValueAct = jsonValueActors.get(i);
actorRef = new SceneActorRef(jsonValueAct.name);
InteractiveActor actor = actors.get(i);
actor.read(json, jsonValueAct);
}
}
use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.
the class Inventory method write.
@Override
public void write(Json json) {
SceneActorRef actorRef;
json.writeValue("visible", visible);
json.writeObjectStart("items");
for (SpriteActor a : items) {
actorRef = new SceneActorRef(a.getInitScene(), a.getId());
json.writeValue(actorRef.toString(), a);
}
json.writeObjectEnd();
}
Aggregations