Search in sources :

Example 1 with SceneActorRef

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);
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef) Color(com.badlogic.gdx.graphics.Color) Field(java.lang.reflect.Field) Vector2(com.badlogic.gdx.math.Vector2) ActorAnimationRef(com.bladecoder.engine.actions.ActorAnimationRef)

Example 2 with SceneActorRef

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();
}
Also used : Field(java.lang.reflect.Field) ActionProperty(com.bladecoder.engine.actions.ActionProperty) SceneActorRef(com.bladecoder.engine.actions.SceneActorRef) Vector2(com.badlogic.gdx.math.Vector2) Color(com.badlogic.gdx.graphics.Color) ActorAnimationRef(com.bladecoder.engine.actions.ActorAnimationRef)

Example 3 with SceneActorRef

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());
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef)

Example 4 with SceneActorRef

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);
    }
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 5 with SceneActorRef

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();
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef)

Aggregations

SceneActorRef (com.bladecoder.engine.actions.SceneActorRef)9 Vector2 (com.badlogic.gdx.math.Vector2)3 JsonValue (com.badlogic.gdx.utils.JsonValue)3 Color (com.badlogic.gdx.graphics.Color)2 ActorAnimationRef (com.bladecoder.engine.actions.ActorAnimationRef)2 Field (java.lang.reflect.Field)2 ActionProperty (com.bladecoder.engine.actions.ActionProperty)1 PolygonalNavGraph (com.bladecoder.engine.polygonalpathfinder.PolygonalNavGraph)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1