use of com.bladecoder.engine.model.SoundDesc in project bladecoder-adventure-engine by bladecoder.
the class EditSoundDialog method inputsToModel.
@Override
protected void inputsToModel(boolean create) {
if (create) {
e = new SoundDesc();
// UNDO OP
Ctx.project.getUndoStack().add(new UndoCreateSound(e));
} else {
HashMap<String, SoundDesc> sounds = parent.getSounds();
sounds.remove(e.getId());
}
String checkedId = parent.getSounds() == null ? id.getText() : ElementUtils.getCheckedId(id.getText(), parent.getSounds().keySet().toArray(new String[parent.getSounds().size()]));
e.setId(checkedId);
e.setFilename(filename.getText());
e.setLoop(Boolean.parseBoolean(loop.getText()));
e.setVolume(Float.parseFloat(volume.getText()));
e.setPan(Float.parseFloat(pan.getText()));
e.setPitch(Float.parseFloat(pitch.getText()));
e.setPreload(Boolean.parseBoolean(preload.getText()));
parent.getSounds().put(e.getId(), e);
Ctx.project.setModified();
}
use of com.bladecoder.engine.model.SoundDesc in project bladecoder-adventure-engine by bladecoder.
the class WorldSerialization method cacheSounds.
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) {
if (actor.equals("$PLAYER"))
actor = s.getPlayer().getId();
SoundDesc sd = w.getSounds().get(actor + "_" + play);
if (sd == null) {
EngineLogger.error("Reference to sound not found: " + s.getId() + "." + actor + "." + play);
continue;
}
s.getSoundManager().addSoundToLoad(sd);
HashMap<String, String> params = new HashMap<>();
params.put("sound", sd.getId());
try {
Action a2 = ActionFactory.create(PlaySoundAction.class.getName(), params);
actions.set(i, a2);
a2.init(w);
} catch (ClassNotFoundException | 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) {
if ("$PLAYER".equals(actor))
actor = s.getPlayer().getId();
SoundDesc sd = w.getSounds().get(actor + "_" + play);
if (sd == null) {
EngineLogger.error("Reference to sound not found: " + s.getId() + "." + actor + "." + play);
continue;
}
s.getSoundManager().addSoundToLoad(sd);
HashMap<String, String> params = new HashMap<>();
params.put("sound", sd.getId());
try {
Action a2 = ActionFactory.create(PlaySoundAction.class.getName(), params);
actions.set(i, a2);
a2.init(w);
} catch (ClassNotFoundException | 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);
}
}
}
}
}
}
Aggregations