use of com.bladecoder.engine.actions.ActorAnimationRef 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.ActorAnimationRef 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.ActorAnimationRef in project bladecoder-adventure-engine by bladecoder.
the class ActorAnimationInputPanel method setText.
public void setText(String s) {
ActorAnimationRef aa = new ActorAnimationRef(s);
actor.setSelected(aa.getActorId() == null ? "" : aa.getActorId());
actorSelected();
animation.setSelected(aa.getAnimationId());
}
use of com.bladecoder.engine.actions.ActorAnimationRef in project bladecoder-adventure-engine by bladecoder.
the class ActorAnimationInputPanel method validateField.
@Override
public boolean validateField() {
ActorAnimationRef a = new ActorAnimationRef(getText());
if (isMandatory()) {
if (a.getActorId() == null || a.getActorId().trim().isEmpty() || a.getAnimationId() == null || a.getAnimationId().trim().isEmpty()) {
setError(true);
return false;
}
}
setError(false);
return true;
}
Aggregations