use of com.bladecoder.engine.actions.Action in project bladecoder-adventure-engine by bladecoder.
the class Verb method write.
@Override
public void write(Json json) {
if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
json.writeValue("id", id);
if (target != null)
json.writeValue("target", target);
if (state != null)
json.writeValue("state", state);
if (icon != null)
json.writeValue("icon", icon);
json.writeArrayStart("actions");
for (Action a : actions) {
ActionUtils.writeJson(a, json);
}
json.writeArrayEnd();
} else {
json.writeValue("ip", ip);
json.writeValue("cb", ActionCallbackSerialization.find(cb));
if (currentTarget != null)
json.writeValue("currentTarget", currentTarget);
json.writeArrayStart("actions");
for (Action a : actions) {
if (a instanceof Serializable) {
json.writeObjectStart();
((Serializable) a).write(json);
json.writeObjectEnd();
}
}
json.writeArrayEnd();
}
}
use of com.bladecoder.engine.actions.Action in project bladecoder-adventure-engine by bladecoder.
the class World method cacheSounds.
private void cacheSounds() {
for (Scene s : scenes.values()) {
HashMap<String, Verb> verbs = s.getVerbManager().getVerbs();
// Search SoundAction and PlaySoundAction
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
try {
if (act instanceof SoundAction) {
String actor = ActionUtils.getStringValue(act, "actor");
String play = ActionUtils.getStringValue(act, "play");
if (play != null) {
SoundDesc sd = World.getInstance().getSounds().get(actor + "_" + play);
if (sd != null)
s.getSoundManager().addSoundToLoad(sd);
}
} else if (act instanceof PlaySoundAction) {
String sound = ActionUtils.getStringValue(act, "sound");
SoundDesc sd = World.getInstance().getSounds().get(sound);
if (sd != null)
s.getSoundManager().addSoundToLoad(sd);
}
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
}
}
}
for (BaseActor a : s.getActors().values()) {
if (a instanceof InteractiveActor) {
HashMap<String, Verb> actorVerbs = ((InteractiveActor) a).getVerbManager().getVerbs();
// Process SayAction of TALK type
for (Verb v : actorVerbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
try {
if (act instanceof SoundAction) {
String actor = ActionUtils.getStringValue(act, "actor");
String play = ActionUtils.getStringValue(act, "play");
if (play != null) {
SoundDesc sd = World.getInstance().getSounds().get(actor + "_" + play);
if (sd != null)
s.getSoundManager().addSoundToLoad(sd);
}
} else if (act instanceof PlaySoundAction) {
String sound = ActionUtils.getStringValue(act, "sound");
SoundDesc sd = World.getInstance().getSounds().get(sound);
if (sd != null)
s.getSoundManager().addSoundToLoad(sd);
}
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
}
}
}
}
if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof AnimationRenderer) {
HashMap<String, AnimationDesc> anims = ((AnimationRenderer) ((SpriteActor) a).getRenderer()).getAnimations();
for (AnimationDesc ad : anims.values()) {
if (ad.sound != null) {
String sid = ad.sound;
SoundDesc sd = World.getInstance().getSounds().get(sid);
if (sd == null)
sid = a.getId() + "_" + sid;
sd = World.getInstance().getSounds().get(sid);
if (sd != null)
s.getSoundManager().addSoundToLoad(sd);
else
EngineLogger.error(a.getId() + ": SOUND not found: " + ad.sound + " in animation: " + ad.id);
}
}
}
}
}
}
use of com.bladecoder.engine.actions.Action 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();
}
use of com.bladecoder.engine.actions.Action in project bladecoder-adventure-engine by bladecoder.
the class ModelTools method checkI18NMissingKeys.
public static final void checkI18NMissingKeys() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Map<String, Scene> scenes = World.getInstance().getScenes();
for (Scene scn : scenes.values()) {
Map<String, BaseActor> actors = scn.getActors();
// SCENE VERBS
HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
String[] params = ActionUtils.getFieldNames(act);
for (String p : params) {
String val = ActionUtils.getStringValue(act, p);
if (val != null && !val.isEmpty() && val.charAt(0) == I18N.PREFIX) {
String trans = Ctx.project.translate(val);
if (trans == val) {
EditorLogger.error("Key not found: " + val);
}
}
}
}
}
for (BaseActor a : actors.values()) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
// DESC
if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) == I18N.PREFIX) {
String trans = Ctx.project.translate(ia.getDesc());
if (trans == ia.getDesc()) {
EditorLogger.error("Key not found: " + ia.getDesc());
}
}
// ACTOR VERBS
verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
String[] params = ActionUtils.getFieldNames(act);
for (String p : params) {
String val = ActionUtils.getStringValue(act, p);
if (val != null && !val.isEmpty() && val.charAt(0) == I18N.PREFIX) {
String trans = Ctx.project.translate(val);
if (trans == val) {
EditorLogger.error("Key not found: " + val);
}
}
}
}
}
}
// DIALOGS
if (a instanceof CharacterActor) {
HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
if (dialogs != null) {
for (Dialog d : dialogs.values()) {
ArrayList<DialogOption> options = d.getOptions();
for (DialogOption o : options) {
if (o.getText() != null && !o.getText().isEmpty() && o.getText().charAt(0) == I18N.PREFIX) {
String trans = Ctx.project.translate(o.getText());
if (trans == o.getText()) {
EditorLogger.error("Key not found: " + o.getText());
}
}
if (o.getResponseText() != null && !o.getResponseText().isEmpty() && o.getResponseText().charAt(0) == I18N.PREFIX) {
String trans = Ctx.project.translate(o.getResponseText());
if (trans == o.getResponseText()) {
EditorLogger.error("Key not found: " + o.getResponseText());
}
}
}
}
}
}
}
}
}
use of com.bladecoder.engine.actions.Action in project bladecoder-adventure-engine by bladecoder.
the class ActionList method toggleEnabled.
private void toggleEnabled() {
if (list.getSelection().size() <= 0)
return;
Array<Action> sel = new Array<Action>();
for (Action a : list.getSelection().toArray()) {
// CONTROL ACTIONS CAN'T BE DISABLED
if (a == null || isControlAction(a))
continue;
Array<Action> items = list.getItems();
int pos = items.indexOf(a, true);
if (a instanceof DisableActionAction) {
Action a2 = ((DisableActionAction) a).getAction();
parent.getActions().set(pos, a2);
items.set(pos, a2);
sel.add(a2);
} else {
DisableActionAction a2 = new DisableActionAction();
a2.setAction(a);
parent.getActions().set(pos, a2);
items.set(pos, a2);
sel.add(a2);
}
}
Ctx.project.setModified();
list.getSelection().clear();
list.getSelection().addAll(sel);
}
Aggregations