use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.
the class ActionCallbackSerialization method find.
private static String find(ActionCallback cb, InteractiveActor a) {
if (a == null)
return null;
String id = a.getId();
for (Verb v : a.getVerbManager().getVerbs().values()) {
String result = find(cb, v);
if (result != null) {
StringBuilder stringBuilder = new StringBuilder(id);
stringBuilder.append(SEPARATION_SYMBOL).append(result);
return stringBuilder.toString();
}
}
return null;
}
use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.
the class ActionCallbackSerialization method find.
/**
* Generates a String for serialization that allows locate the
* ActionCallback
*
* @param cb
* The ActionCallback to serialize
* @return The generated location string
*/
public static String find(ActionCallback cb) {
String id = null;
if (cb == null)
return null;
// search in UIActors
id = find(cb, World.getInstance().getUIActors());
if (id != null)
return id;
// search in inventory
id = find(cb, World.getInstance().getInventory());
if (id != null)
return id;
// search in inkManager actions
id = find(cb, World.getInstance().getInkManager());
if (id != null)
return id;
// search in scene verbs
Scene s = World.getInstance().getCurrentScene();
id = find(cb, s);
if (id != null)
return id;
// search in player
id = find(cb, s.getPlayer());
if (id != null)
return id;
// search in actors
for (BaseActor a : s.getActors().values()) {
if (!(a instanceof InteractiveActor))
continue;
id = find(cb, (InteractiveActor) a);
if (id != null)
return id;
}
// search in worldVerbs
for (Verb v : World.getInstance().getVerbManager().getVerbs().values()) {
id = find(cb, v);
if (id != null) {
StringBuilder stringBuilder = new StringBuilder(DEFAULT_VERB_TAG);
stringBuilder.append(SEPARATION_SYMBOL).append(id);
return stringBuilder.toString();
}
}
return null;
}
use of com.bladecoder.engine.model.Verb 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;
}
use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.
the class RunVerbAction method run.
@Override
public void run(String currentTarget, ActionCallback cb) {
Verb v = getVerb();
v.run(currentTarget, cb);
}
use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.
the class ModelTools method addCutMode.
public static final void addCutMode() {
Map<String, Scene> scenes = World.getInstance().getScenes();
for (Scene scn : scenes.values()) {
Map<String, BaseActor> actors = scn.getActors();
for (BaseActor a : actors.values()) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
// Don't process verbs for inventory
if (v.getState() != null && v.getState().equalsIgnoreCase("INVENTORY"))
continue;
if (actions.size() == 1) {
Action act = actions.get(0);
if (act instanceof LookAtAction || act instanceof SayAction) {
actions.clear();
SetCutmodeAction cma1 = new SetCutmodeAction();
SetCutmodeAction cma2 = new SetCutmodeAction();
try {
ActionUtils.setParam(cma1, "value", "true");
ActionUtils.setParam(cma2, "value", "false");
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
EditorLogger.printStackTrace(e);
}
actions.add(cma1);
actions.add(act);
actions.add(cma2);
}
}
}
}
}
}
Ctx.project.setModified();
}
Aggregations