use of com.bladecoder.engine.actions.SoundAction 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);
}
}
}
}
}
}
Aggregations