use of com.bladecoder.engine.actions.ActionCallback in project bladecoder-adventure-engine by bladecoder.
the class ActionCallbackSerialization method find.
/**
* Searches for the ActionCallback represented by the id string.
*
* @param id
*/
public static ActionCallback find(String id) {
if (id == null)
return null;
Scene s = World.getInstance().getCurrentScene();
String[] split = id.split(SEPARATION_SYMBOL);
if (id.startsWith(INK_MANAGER_TAG)) {
if (split.length == 1)
return World.getInstance().getInkManager();
int actionPos = Integer.parseInt(split[1]);
Action action = World.getInstance().getInkManager().getActions().get(actionPos);
if (action instanceof ActionCallback)
return (ActionCallback) action;
}
if (split.length < 2)
return null;
String actorId;
String verbId;
int actionPos = -1;
if (id.startsWith(UIACTORS_TAG) || id.startsWith(INVENTORY_TAG)) {
actorId = split[1];
verbId = split[2];
if (split.length > 3)
actionPos = Integer.parseInt(split[3]);
} else {
actorId = split[0];
verbId = split[1];
if (split.length > 2)
actionPos = Integer.parseInt(split[2]);
}
Verb v = null;
if (actorId.equals(DEFAULT_VERB_TAG)) {
v = World.getInstance().getVerbManager().getVerb(verbId, null, null);
} else {
InteractiveActor a;
if (actorId.equals(s.getId())) {
v = s.getVerbManager().getVerbs().get(verbId);
} else {
a = (InteractiveActor) s.getActor(actorId, true);
if (a == null) {
EngineLogger.error("ActionCallbackSerialization - Actor not found: " + actorId + " cb: " + id);
return null;
}
v = a.getVerbManager().getVerbs().get(verbId);
}
}
if (v == null) {
EngineLogger.error("ActionCallbackSerialization - Verb not found: " + verbId + " cb: " + id);
return null;
}
if (actionPos == -1)
return v;
Action action = v.getActions().get(actionPos);
if (action instanceof ActionCallback)
return (ActionCallback) action;
EngineLogger.error("ActionCallbackSerialization - CB not found: " + id);
return null;
}
Aggregations