use of com.bladecoder.engine.actions.Action in project bladecoder-adventure-engine by bladecoder.
the class ActionDetector method detect.
public static void detect() {
actions = new HashMap<String, Class<?>>();
final TypeReporter reporter = new TypeReporter() {
@SuppressWarnings("unchecked")
@Override
public Class<? extends Annotation>[] annotations() {
return new Class[] { ActionDescription.class };
}
@SuppressWarnings("unchecked")
@Override
public void reportTypeAnnotation(Class<? extends Annotation> annotation, String className) {
Class<Action> c = null;
try {
c = ClassReflection.forName(className);
} catch (ReflectionException e) {
EditorLogger.printStackTrace(e);
}
String name = ActionUtils.getName(c);
if (!c.isAssignableFrom(EndAction.class) && !c.isAssignableFrom(DisableActionAction.class))
actions.put(name, c);
}
};
final AnnotationDetector cf = new AnnotationDetector(reporter);
try {
cf.detect();
} catch (IOException e) {
EditorLogger.printStackTrace(e);
}
}
use of com.bladecoder.engine.actions.Action in project bladecoder-adventure-engine by bladecoder.
the class ElementUtils method cloneElement.
public static Object cloneElement(Object e) {
Json json = new Json();
if (e instanceof Action) {
StringWriter buffer = new StringWriter();
json.setWriter(buffer);
ActionUtils.writeJson((Action) e, json);
String str = buffer.toString();
EditorLogger.debug(str);
JsonValue root = new JsonReader().parse(str);
return ActionUtils.readJson(json, root);
} else {
SerializationHelper.getInstance().setMode(Mode.MODEL);
String str = json.toJson(e, (Class<?>) null);
return json.fromJson(e.getClass(), str);
}
}
use of com.bladecoder.engine.actions.Action 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);
}
}
}
use of com.bladecoder.engine.actions.Action in project bladecoder-adventure-engine by bladecoder.
the class InkManager method cancel.
@Override
public void cancel() {
ArrayList<Action> actions = getActions();
for (Action c : actions) {
if (c instanceof VerbRunner)
((VerbRunner) c).cancel();
}
ip = actions.size();
}
use of com.bladecoder.engine.actions.Action in project bladecoder-adventure-engine by bladecoder.
the class ActionCallbackSerialization method find.
private static String find(ActionCallback cb, Verb v) {
String id = v.getHashKey();
if (cb == v)
return id;
int pos = 0;
for (Action a : v.getActions()) {
if (cb == a) {
StringBuilder stringBuilder = new StringBuilder(id);
stringBuilder.append(SEPARATION_SYMBOL).append(pos);
return stringBuilder.toString();
}
pos++;
}
return null;
}
Aggregations