Here are the examples of the java api com.bladecoder.engine.model.Verb taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
38 Examples
19
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void extractStrings(String sceneid, String actorid, Verb v) {
ArrayList<Action> actions = v.getActions();
for (int i = 0; i < actions.size(); i++) {
Action a = actions.get(i);
extractStrings(sceneid, actorid, v.getHashKey(), i, a);
}
}
19
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void putTranslationsInElement(Verb v, boolean worldScope) {
ArrayList<Action> actions = v.getActions();
for (Action a : actions) {
putTranslationsInElement(a, worldScope);
}
}
18
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void putTranslationsInElement(Scene scn) {
HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
for (Verb v : verbs.values()) putTranslationsInElement(v, false);
for (BaseActor a : scn.getActors().values()) {
putTranslationsInElement(a);
}
}
18
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private void getUsedKeys(Verb v, ArrayList<String> usedKeys) {
for (Action a : v.getActions()) {
if (a instanceof DisableActionAction)
a = ((DisableActionAction) a).getAction();
String[] fieldNames = ActionUtils.getFieldNames(a);
for (String name : fieldNames) {
if (name.toLowerCase().endsWith("text")) {
String value = null;
try {
value = ActionUtils.getStringValue(a, name);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
EditorLogger.error(e.getMessage());
}
if (value != null && !value.isEmpty() && value.charAt(0) == I18N.PREFIX) {
usedKeys.add(value.substring(1));
}
}
}
}
}
18
View Complete Implementation : CheckDesc.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void checkVerb(Verb v) {
if (v.getId().equals("leave"))
hasLeave = true;
else if (v.getId().equals("enter") || v.getId().equals("exit"))
hasEnterExit = true;
}
18
View Complete Implementation : CheckInteractionVerbs.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void checkVerb(Verb v) {
if (v.getId().equals("lookat"))
hasLookat = true;
else if (v.getId().equals("pickup"))
hasPickup = true;
else if (v.getId().equals("talkto"))
hasTalkto = true;
else if (v.getId().equals("leave"))
hasLeave = true;
else if (v.getId().equals("use"))
hasUse = true;
else if (v.getId().equals("enter") || v.getId().equals("exit"))
hasEnterExit = true;
}
18
View Complete Implementation : VerbList.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
protected EditModelDialog<VerbManager, Verb> getEditElementDialogInstance(Verb e) {
return new EditVerbDialog(skin, scopePanel.getScope(), parent, e);
}
18
View Complete Implementation : UndoDeleteAction.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public clreplaced UndoDeleteAction implements UndoOp {
private Verb v;
private Action a;
private int idx;
public UndoDeleteAction(Verb v, Action a, int idx) {
this.v = v;
this.a = a;
this.idx = idx;
}
@Override
public void undo() {
v.getActions().add(idx, a);
Ctx.project.setModified(this, Project.NOTIFY_ELEMENT_CREATED, null, a);
}
}
18
View Complete Implementation : UndoDeleteVerb.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public clreplaced UndoDeleteVerb implements UndoOp {
private VerbManager vm;
private Verb v;
public UndoDeleteVerb(VerbManager vm, Verb v) {
this.vm = vm;
}
@Override
public void undo() {
vm.addVerb(v);
Ctx.project.setModified(this, Project.NOTIFY_ELEMENT_CREATED, null, v);
}
}
17
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void extractStrings(Scene scn) {
HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
for (Verb v : verbs.values()) extractStrings(scn.getId(), null, v);
for (BaseActor a : scn.getActors().values()) {
extractStrings(scn.getId(), a);
}
}
17
View Complete Implementation : VerbList.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private void addActions() {
int pos = list.getSelectedIndex();
Verb v = null;
if (pos != -1) {
v = list.gereplacedems().get(pos);
actionList.setScope(scopePanel.getScope());
actionList.addElements(v, v.getActions());
} else {
actionList.addElements(null, null);
actionList.setScope(null);
}
}
17
View Complete Implementation : RunVerbAction.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
public void run(String currentTarget, ActionCallback cb) {
Verb v = getVerb();
v.run(currentTarget, cb);
}
17
View Complete Implementation : RunVerbAction.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
public ArrayList<Action> getActions() {
Verb v = getVerb();
if (v == null) {
if (actor != null)
EngineLogger.error(MessageFormat.format("Verb ''{0}'' not found for actor ''{1}({3})'' and target ''{2}''.", verb, actor, target, ((InteractiveActor) w.getCurrentScene().getActor(actor, true)).getState()));
else
EngineLogger.error(MessageFormat.format("Verb ''{0}'' not found.", verb));
return new ArrayList<Action>(0);
}
return v.getActions();
}
17
View Complete Implementation : DefaultSceneScreen.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
/**
* Calcs the rotation based in the actor screen position
*/
private float calcLeaveArrowRotation(InteractiveActor actor) {
Verb verb = actor.getVerb(Verb.LEAVE_VERB);
if (verb == null || verb.getIcon() == null) {
actor.getBBox().getBoundingRectangle().getCenter(unproject2Tmp);
if (unproject2Tmp.x < stage.getViewport().getWorldWidth() / 3f) {
// LEFT
return 180;
}
if (unproject2Tmp.x > stage.getViewport().getWorldWidth() / 3f * 2f) {
// RIGHT
return 0;
}
if (unproject2Tmp.y < stage.getViewport().getWorldHeight() / 5f) {
// DOWN
return -90;
}
// UP
return 90;
} else {
String dir = verb.getIcon();
if (dir.equals("left")) {
// LEFT
return 180;
}
if (dir.equals("right")) {
// RIGHT
return 0;
}
if (dir.equals("down")) {
// DOWN
return -90;
}
// UP
return 90;
}
}
16
View Complete Implementation : RunVerbAction.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private Verb getVerb() {
Verb v = null;
Scene s = w.getCurrentScene();
if (actor != null) {
InteractiveActor a = (InteractiveActor) s.getActor(actor, true);
v = a.getVerbManager().getVerb(verb, a.getState(), target);
}
if (v == null) {
v = s.getVerbManager().getVerb(verb, s.getState(), target);
}
if (v == null) {
v = w.getVerbManager().getVerb(verb, null, target);
}
if (v == null)
EngineLogger.error("Cannot find VERB: " + verb + " for ACTOR: " + actor);
return v;
}
16
View Complete Implementation : InventoryUI.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private void use(InteractiveActor targetActor, InteractiveActor invActor) {
// get best matched verb
Verb vtarget = targetActor.getVerb("use", invActor.getId());
Verb vinv = invActor.getVerb("use", targetActor.getId());
Verb bestMatch = vtarget;
if (bestMatch == null) {
bestMatch = vinv;
} else if (vtarget != null && vinv != null && targetActor.getId().equals(vinv.getTarget()) && !invActor.getId().equals(vtarget.getTarget())) {
// if the two actors have "use" verbs, we choose the one with the
// target matches the actor id.
bestMatch = vinv;
}
if (vinv == bestMatch) {
sceneScreen.runVerb(invActor, "use", targetActor.getId());
} else {
sceneScreen.runVerb(targetActor, "use", invActor.getId());
}
}
15
View Complete Implementation : VerbList.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
protected void copy() {
Verb e = list.getSelected();
if (e == null)
return;
clipboard = (Verb) ElementUtils.cloneElement(e);
toolbar.disablePaste(false);
// TRANSLATIONS
if (scopePanel.getScope().equals(ScopePanel.WORLD_SCOPE))
Ctx.project.getI18N().putTranslationsInElement(clipboard, true);
else
Ctx.project.getI18N().putTranslationsInElement(clipboard, false);
}
15
View Complete Implementation : ActionCallbackSerializer.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
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;
}
15
View Complete Implementation : ActionCallbackSerializer.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private static String find(ActionCallback cb, Scene s) {
if (s == null)
return null;
String id = s.getId();
for (Verb v : s.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;
}
15
View Complete Implementation : ActionCallbackSerializer.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
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;
}
14
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void putTranslationsInElement(BaseActor a) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
// 1. DESC attribute
ia.setDesc(getTranslation(ia.getDesc()));
// 2. ACTIONS
HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) putTranslationsInElement(v, false);
// 3. DIALOGS
if (a instanceof CharacterActor) {
HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
if (dialogs != null) {
for (Dialog d : dialogs.values()) putTranslationsInElement(d);
}
}
// 4. Text for TextRenderer
if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof TextRenderer) {
TextRenderer r = (TextRenderer) ((SpriteActor) a).getRenderer();
r.setText(getTranslation(r.getText()));
}
}
}
14
View Complete Implementation : VerbList.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
protected void delete() {
Verb v = removeSelected();
parent.getVerbs().remove(v.getHashKey());
// TRANSLATIONS
if (scopePanel.getScope().equals(ScopePanel.WORLD_SCOPE))
Ctx.project.getI18N().putTranslationsInElement(v, true);
else
Ctx.project.getI18N().putTranslationsInElement(v, false);
// UNDO
Ctx.project.getUndoStack().add(new UndoDeleteVerb(parent, v));
// Clear actions here because change event doesn't call when deleting
// the last element
if (list.getSelectedIndex() == -1)
addActions();
Ctx.project.setModified();
}
14
View Complete Implementation : ActionCallbackSerializer.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
/**
* 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(World w, Scene s, ActionCallback cb) {
String id = null;
if (cb == null)
return null;
// search in UIActors
id = find(cb, w.getUIActors());
if (id != null)
return id;
// search in inventory
id = find(cb, w.getInventory());
if (id != null)
return id;
// search in inkManager actions
id = find(cb, w.getInkManager().getVerbRunner());
if (id != null)
return id;
// search in scene verbs
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 : w.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;
}
14
View Complete Implementation : DefaultSceneScreen.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private void update(float delta) {
final World world = getWorld();
float deltaScaled = delta * speed;
if (!world.isDisposed()) {
world.update(deltaScaled);
// if the game ends returns
if (world.isDisposed())
return;
}
if (world.getreplacedetState() != replacedetState.LOADED) {
// TRY TO LOAD THE replacedETS FOR LOADING_WAIT_TIME_MS TO AVOID
// BLACK/LOADING SCREEN
long t0 = System.currentTimeMillis();
long t = t0;
while (EnginereplacedetManager.getInstance().isLoading() && t - t0 < LOADING_WAIT_TIME_MS) {
t = System.currentTimeMillis();
}
if (t - t0 >= LOADING_WAIT_TIME_MS) {
// Sets loading screen if resources are not loaded yet
ui.setCurrentScreen(Screens.LOADING_SCREEN);
} else {
updateUI();
world.resize(viewport.getWorldWidth(), viewport.getWorldHeight());
// update() to retrieve replacedets and exec init verb
world.update(0);
}
return;
}
stage.act(delta);
pointer.update(delta);
if (drawHotspots) {
Drawable hotspotDrawable = getUI().getSkin().getDrawable(Verb.LEAVE_VERB);
Drawable leaveDrawable = getUI().getSkin().getDrawable("hotspot");
if (hotspotDrawable != null && hotspotDrawable instanceof AnimationDrawable)
((AnimationDrawable) hotspotDrawable).act(delta);
if (leaveDrawable != null && leaveDrawable instanceof AnimationDrawable)
((AnimationDrawable) leaveDrawable).act(delta);
}
if (world.isPaused())
return;
recorder.update(deltaScaled);
testerBot.update(deltaScaled);
InteractiveActor actorUnderCursor = null;
if (uiEnabled && !world.hasDialogOptions()) {
if (inventoryUI.isVisible()) {
unproject2Tmp.set(Gdx.input.getX(), Gdx.input.getY());
inventoryUI.screenToLocalCoordinates(unproject2Tmp);
actorUnderCursor = inventoryUI.gereplacedemAt(unproject2Tmp.x, unproject2Tmp.y);
} else {
actorUnderCursor = getActorUnderCursor();
}
// UPDATE POINTER
if (!pie.isVisible() && actorUnderCursor != currentActor) {
currentActor = actorUnderCursor;
if (currentActor != null) {
if (showDesc)
pointer.setDesc(currentActor.getDesc());
Verb leaveVerb = currentActor.getVerb(Verb.LEAVE_VERB);
Drawable r = null;
if (leaveVerb != null) {
if ((r = getDrawable(leaveVerb.getIcon())) != null) {
pointer.setIcon(r);
} else {
pointer.setLeaveIcon(calcLeaveArrowRotation(currentActor));
}
} else {
Verb actionVerb = currentActor.getVerb(Verb.ACTION_VERB);
if (actionVerb != null && (r = getDrawable(actionVerb.getIcon())) != null) {
pointer.setIcon(r);
} else {
pointer.setHotspotIcon();
}
}
} else {
pointer.setDefaultIcon();
}
} else if (pie.isVisible()) {
currentActor = actorUnderCursor;
}
}
}
13
View Complete Implementation : ModelTools.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public static final void fixSaySubreplacedleActor() {
Map<String, Scene> scenes = Ctx.project.getWorld().getScenes();
for (Scene scn : scenes.values()) {
Map<String, BaseActor> actors = scn.getActors();
HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
if (act instanceof SayAction) {
try {
String stringValue = ActionUtils.getStringValue(act, "type");
if (stringValue.equals("SUBreplacedLE"))
ActionUtils.setParam(act, "actor", "$PLAYER");
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
EditorLogger.printStackTrace(e);
return;
}
}
}
}
for (BaseActor a : actors.values()) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
if (act instanceof SayAction) {
try {
String stringValue = ActionUtils.getStringValue(act, "type");
if (stringValue.equals("SUBreplacedLE"))
ActionUtils.setParam(act, "actor", "$PLAYER");
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
EditorLogger.printStackTrace(e);
return;
}
}
}
}
}
}
}
Ctx.project.setModified();
}
13
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void extractStrings(String sceneid, BaseActor a) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
// 1. DESC attribute
if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) != I18N.PREFIX) {
String key = genKey(sceneid, a.getId(), "desc");
String value = ia.getDesc();
ia.setDesc(key);
setTranslation(key, value);
}
// 2. ACTIONS
HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) extractStrings(sceneid, a.getId(), v);
// 3. DIALOGS
if (a instanceof CharacterActor) {
HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
if (dialogs != null)
for (Dialog d : dialogs.values()) extractStrings(sceneid, a.getId(), d);
}
// 4. Text for TextRenderer
if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof TextRenderer) {
TextRenderer r = (TextRenderer) ((SpriteActor) a).getRenderer();
String v = r.getText();
if (v != null && !v.isEmpty() && v.charAt(0) != I18N.PREFIX) {
String key = genKey(sceneid, a.getId(), "text");
r.setText(key, r.getText());
setTranslation(key, v);
}
}
}
}
13
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private void getUsedKeys(Scene s, ArrayList<String> usedKeys) {
for (Verb v : s.getVerbManager().getVerbs().values()) getUsedKeys(v, usedKeys);
for (BaseActor a : s.getActors().values()) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) == I18N.PREFIX)
usedKeys.add(ia.getDesc().substring(1));
for (Verb v : ia.getVerbManager().getVerbs().values()) getUsedKeys(v, usedKeys);
if (a instanceof CharacterActor) {
CharacterActor ca = (CharacterActor) a;
if (ca.getDialogs() != null) {
for (Dialog d : ca.getDialogs().values()) {
for (DialogOption o : d.getOptions()) {
if (o.getText() != null && !o.getText().isEmpty() && o.getText().charAt(0) == I18N.PREFIX)
usedKeys.add(o.getText().substring(1));
if (o.getResponseText() != null && !o.getResponseText().isEmpty() && o.getResponseText().charAt(0) == I18N.PREFIX)
usedKeys.add(o.getResponseText().substring(1));
}
}
}
}
if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof TextRenderer) {
TextRenderer r = (TextRenderer) ((SpriteActor) a).getRenderer();
String k = r.getText();
if (k != null && !k.isEmpty() && k.charAt(0) == I18N.PREFIX)
usedKeys.add(k.substring(1));
}
}
}
}
13
View Complete Implementation : WorldSerialization.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private void cacheSounds() {
for (Scene s : w.getScenes().values()) {
HashMap<String, Verb> verbs = s.getVerbManager().getVerbs();
// Search SoundAction and PlaySoundAction
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (int i = 0; i < actions.size(); i++) {
Action act = actions.get(i);
try {
if (act instanceof SoundAction) {
String actor = ActionUtils.getStringValue(act, "actor");
String play = ActionUtils.getStringValue(act, "play");
if (play != null) {
SoundDesc sd = w.getSounds().get(actor + "_" + play);
if (sd != null)
s.getSoundManager().addSoundToLoad(sd);
HashMap<String, String> params = new HashMap<>();
params.put("sound", sd.getId());
try {
Action a2 = ActionFactory.create(PlaySoundAction.clreplaced.getName(), params);
actions.set(i, a2);
a2.init(w);
} catch (ClreplacedNotFoundException | ReflectionException e) {
e.printStackTrace();
}
EngineLogger.debug("Converting SoundAction:" + s.getId() + "." + v.getId());
} else {
EngineLogger.debug("WARNING: Cannot convert SoundAction:" + s.getId() + "." + v.getId());
}
} else if (act instanceof PlaySoundAction) {
String sound = ActionUtils.getStringValue(act, "sound");
SoundDesc sd = w.getSounds().get(sound);
if (sd != null && sd.isPreload())
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();
for (Verb v : actorVerbs.values()) {
ArrayList<Action> actions = v.getActions();
for (int i = 0; i < actions.size(); i++) {
Action act = actions.get(i);
try {
if (act instanceof SoundAction) {
String actor = ActionUtils.getStringValue(act, "actor");
String play = ActionUtils.getStringValue(act, "play");
if (play != null) {
SoundDesc sd = w.getSounds().get(actor + "_" + play);
if (sd != null)
s.getSoundManager().addSoundToLoad(sd);
HashMap<String, String> params = new HashMap<>();
params.put("sound", sd.getId());
try {
Action a2 = ActionFactory.create(PlaySoundAction.clreplaced.getName(), params);
actions.set(i, a2);
a2.init(w);
} catch (ClreplacedNotFoundException | ReflectionException e) {
e.printStackTrace();
}
EngineLogger.debug("Converting SoundAction in:" + s.getId() + "." + a.getId() + "." + v.getId());
} else {
EngineLogger.debug("WARNING: Cannot convert SoundAction:" + s.getId() + "." + a.getId() + "." + v.getId());
}
} else if (act instanceof PlaySoundAction) {
String sound = ActionUtils.getStringValue(act, "sound");
SoundDesc sd = w.getSounds().get(sound);
if (sd != null && sd.isPreload())
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 = w.getSounds().get(sid);
if (sd == null)
sid = a.getId() + "_" + sid;
sd = w.getSounds().get(sid);
if (sd != null) {
if (sd.isPreload())
s.getSoundManager().addSoundToLoad(sd);
} else
EngineLogger.error(a.getId() + ": SOUND not found: " + ad.sound + " in animation: " + ad.id);
}
}
}
}
}
}
12
View Complete Implementation : CheckDesc.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
public void visit(BaseActor a) {
if (a instanceof InteractiveActor) {
ia = (InteractiveActor) a;
hasLeave = false;
hasEnterExit = false;
if (ia.getInteraction()) {
HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) checkVerb(v);
// TODO: check states and verbs for states.
if (hasLeave || hasEnterExit)
return;
if (ia.getDesc() == null || ia.getDesc().trim().isEmpty()) {
EditorLogger.error("CheckDesc: " + a.getScene().getId() + "." + a.getId());
}
}
}
}
12
View Complete Implementation : VerbList.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
protected void paste() {
Verb newElement = (Verb) ElementUtils.cloneElement(clipboard);
// Check for id duplicates
String[] keys = new String[parent.getVerbs().size()];
Verb[] values = parent.getVerbs().values().toArray(new Verb[0]);
for (int i = 0; i < keys.length; i++) {
keys[i] = values[i].getId();
}
newElement.setId(ElementUtils.getCheckedId(newElement.getId(), keys));
int pos = list.getSelectedIndex() + 1;
list.gereplacedems().insert(pos, newElement);
parent.addVerb(newElement);
if (scopePanel.getScope().equals(ScopePanel.WORLD_SCOPE))
Ctx.project.getI18N().extractStrings(null, null, newElement);
else if (scopePanel.getScope().equals(ScopePanel.SCENE_SCOPE))
Ctx.project.getI18N().extractStrings(Ctx.project.getSelectedScene().getId(), null, newElement);
else
Ctx.project.getI18N().extractStrings(Ctx.project.getSelectedScene().getId(), Ctx.project.getSelectedActor().getId(), newElement);
list.setSelectedIndex(pos);
list.invalidateHierarchy();
Ctx.project.setModified();
}
12
View Complete Implementation : ActionCallbackSerializer.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
/**
* Searches for the ActionCallback represented by the id string.
*
* @param id
*/
public static ActionCallback find(World w, Scene s, String id) {
if (id == null)
return null;
String[] split = id.split(SEPARATION_SYMBOL);
if (id.startsWith(INK_MANAGER_TAG)) {
if (split.length == 1)
return w.getInkManager().getVerbRunner();
int actionPos = Integer.parseInt(split[1]);
Action action = w.getInkManager().getVerbRunner().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 = w.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;
}
11
View Complete Implementation : ModelTools.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public static final void addCutMode() {
Map<String, Scene> scenes = Ctx.project.getWorld().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();
}
11
View Complete Implementation : I18NHandler.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
private void deleteUnusedKeys() {
ArrayList<String> usedKeys = new ArrayList<>();
// SCENES
for (Scene s : Ctx.project.getWorld().getScenes().values()) getUsedKeys(s, usedKeys);
Enumeration<String> keys = i18nChapter.propertyNames();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
// Doesn't remove ui and ink keys
if (!usedKeys.contains(key) && !key.startsWith("ui.") && !key.startsWith("ink.")) {
EditorLogger.debug("Removing translation key: " + key);
i18nChapter.removeProperty(key);
}
}
usedKeys.clear();
// WORLD VERBS
for (Verb v : Ctx.project.getWorld().getVerbManager().getVerbs().values()) getUsedKeys(v, usedKeys);
keys = i18nWorld.propertyNames();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
// Doesn't remove ui keys
if (!usedKeys.contains(key) && !key.startsWith("ui.")) {
EditorLogger.debug("Removing translation key: " + key);
i18nWorld.removeProperty(key);
}
}
}
10
View Complete Implementation : ModelTools.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public static final void checkI18NMissingKeys() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Map<String, Scene> scenes = Ctx.project.getWorld().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());
}
}
}
}
}
}
}
}
}
9
View Complete Implementation : ModelTools.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public static final void extractDialogs() {
Map<String, Scene> scenes = Ctx.project.getWorld().getScenes();
BufferedWriter writer = null;
try {
// create a temporary file
File dFile = new File(Ctx.project.getProjectPath() + "/" + "DIALOGS.md");
writer = new BufferedWriter(new FileWriter(dFile));
writer.write("# DIALOGS - " + (Ctx.project.getreplacedle() != null ? Ctx.project.getreplacedle().toUpperCase() : "") + "\n\n");
for (Scene scn : scenes.values()) {
Map<String, BaseActor> actors = scn.getActors();
writer.write("\n## SCENE: " + scn.getId() + "\n\n");
HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
// Process SayAction of TALK type
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
if (act instanceof SayAction) {
String type = ActionUtils.getStringValue(act, "type");
if ("TALK".equals(type)) {
String actor = ActionUtils.getStringValue(act, "actor").toUpperCase();
String rawText = ActionUtils.getStringValue(act, "text");
String text = Ctx.project.translate(rawText).replace("\\n\\n", "\n").replace("\\n", "\n");
writer.write(actor + ": " + text + "\n");
}
}
}
}
for (BaseActor a : actors.values()) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
verbs = ia.getVerbManager().getVerbs();
// Process SayAction of TALK type
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
if (act instanceof SayAction) {
String type = ActionUtils.getStringValue(act, "type");
if ("TALK".equals(type)) {
String actor = ActionUtils.getStringValue(act, "actor").toUpperCase();
String rawText = ActionUtils.getStringValue(act, "text");
String text = Ctx.project.translate(rawText).replace("\\n\\n", "\n").replace("\\n", "\n");
writer.write(actor + ": " + text + "\n");
}
}
}
}
}
if (a instanceof CharacterActor) {
CharacterActor ca = (CharacterActor) a;
HashMap<String, Dialog> dialogs = ca.getDialogs();
if (dialogs == null)
continue;
// Process SayAction of TALK type
for (Dialog d : dialogs.values()) {
ArrayList<DialogOption> options = d.getOptions();
if (options.size() > 0)
writer.write("\n**" + ca.getId().toUpperCase() + " - " + d.getId() + "**\n\n");
for (DialogOption o : options) {
String text = o.getText();
String response = o.getResponseText();
writer.write(scn.getPlayer().getId().toUpperCase() + ": " + Ctx.project.translate(text).replace("\\n\\n", "\n").replace("\\n", "\n") + "\n");
if (response != null)
writer.write(ca.getId().toUpperCase() + ": " + Ctx.project.translate(response).replace("\\n\\n", "\n").replace("\\n", "\n") + "\n\n");
}
}
}
}
}
} catch (Exception e) {
EditorLogger.printStackTrace(e);
} finally {
try {
// Close the writer regardless of what happens...
writer.close();
} catch (Exception e) {
}
}
}
8
View Complete Implementation : CheckInteractionVerbs.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
public void visit(BaseActor a) {
if (a instanceof InteractiveActor) {
ia = (InteractiveActor) a;
hasLookat = false;
hasPickup = false;
hasTalkto = false;
hasLeave = false;
hasEnterExit = false;
hasUse = false;
if (ia.getInteraction()) {
HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) checkVerb(v);
// TODO: check states and verbs for states.
if (hasLeave || hasEnterExit)
return;
// discard inventory actors
if (hasLookat) {
if (ia instanceof SpriteActor) {
SpriteActor sa = (SpriteActor) ia;
if (sa.getRenderer() instanceof AtlasRenderer) {
AtlasRenderer r = (AtlasRenderer) sa.getRenderer();
HashMap<String, AnimationDesc> animations = r.getAnimations();
if (animations.size() == 0) {
EditorLogger.error("CheckInteractionVerbs: Actor with no animations! - " + sa.getScene().getId() + "." + sa.getId());
}
if (animations.get(r.getInitAnimation()).source.contains("inventory")) {
if (!hasUse)
EditorLogger.msg("CheckInteractionVerbs: Inventory item should has default 'use' - " + sa.getScene().getId() + "." + sa.getId());
return;
}
}
}
}
// check for lookat and pickup/talk verbs
if (!hasLookat || (!hasPickup && !hasTalkto)) {
String msg = "CheckInteractionVerbs: " + a.getScene().getId() + "." + a.getId();
if (!hasLookat)
EditorLogger.error(msg);
else
EditorLogger.msg(msg);
}
}
}
}
7
View Complete Implementation : CheckCutmodeEnd.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
@Override
public void visit(Scene s, InteractiveActor a, Verb v) {
ArrayList<Action> actions = v.getActions();
if (actions.size() > 0) {
Action action = actions.get(actions.size() - 1);
if (action instanceof SetCutmodeAction) {
try {
String val = ActionUtils.getStringValue(action, "value");
if ("true".equals(val)) {
StringBuilder sb = new StringBuilder("CheckCutmodeEnd: Cutmode ends with value=true! - ");
if (s != null) {
sb.append(s.getId());
sb.append(".");
}
if (a != null) {
sb.append(a.getId());
sb.append(".");
}
sb.append(v.getId());
EditorLogger.error(sb.toString());
}
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
}
}
}
}
2
View Complete Implementation : ModelWalker.java
Copyright Apache License 2.0
Author : bladecoder
Copyright Apache License 2.0
Author : bladecoder
public void walk(World w) {
Map<String, Scene> scenes = Ctx.project.getWorld().getScenes();
for (StartVisitor sv : startVisitors) sv.start(w);
for (Scene scn : scenes.values()) {
for (SceneVisitor sv : sceneVisitors) sv.visit(scn);
Map<String, BaseActor> actors = scn.getActors();
// SCENE VERBS
HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
for (Verb v : verbs.values()) {
for (VerbVisitor vv : verbVisitors) vv.visit(scn, null, v);
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
for (ActionVisitor av : actionVisitors) av.visit(scn, null, v, act);
}
}
for (BaseActor a : actors.values()) {
for (ActorVisitor av : actorVisitors) av.visit(a);
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
// ACTOR VERBS
verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) {
for (VerbVisitor vv : verbVisitors) vv.visit(scn, ia, v);
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
for (ActionVisitor av : actionVisitors) av.visit(scn, ia, v, act);
}
}
}
// DIALOGS
if (a instanceof CharacterActor) {
HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
if (dialogs != null) {
for (Dialog d : dialogs.values()) {
for (DialogVisitor dv : dialogVisitors) dv.visit((CharacterActor) a, d);
ArrayList<DialogOption> options = d.getOptions();
for (DialogOption o : options) {
for (DialogOptionVisitor ov : optionVisitors) ov.visit((CharacterActor) a, d, o);
}
}
}
}
}
}
for (EndVisitor ev : endVisitors) ev.end(w);
}