use of com.bladecoder.engine.anim.AnimationDesc in project bladecoder-adventure-engine by bladecoder.
the class SpriteActor method outAnim.
/**
* Actions to do when setting an animation: - play animation sound - add 'in'
* distance
*
* @param repeatType
*/
protected void outAnim(Type repeatType) {
AnimationDesc fa = ((AnimationRenderer) renderer).getCurrentAnimation();
if (fa != null) {
if (fa.sound != null && repeatType != Tween.Type.REVERSE) {
// Backwards compatibility
String sid = fa.sound;
if (World.getInstance().getSounds().get(sid) == null)
sid = id + "_" + fa.sound;
if (scene != null)
scene.getSoundManager().playSound(sid);
else
// The actor is in the
World.getInstance().getCurrentScene().getSoundManager().playSound(sid);
// inventory
}
Vector2 inD = fa.inD;
if (inD != null) {
float s = EngineAssetManager.getInstance().getScale();
setPosition(getX() + inD.x * s, getY() + inD.y * s);
}
}
}
use of com.bladecoder.engine.anim.AnimationDesc 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.anim.AnimationDesc in project bladecoder-adventure-engine by bladecoder.
the class EditAnimationDialog method inputsToModel.
@Override
protected void inputsToModel(boolean create) {
String sourceStr = source.getText();
AnimationRenderer renderer = (AnimationRenderer) parent.getRenderer();
if (create) {
if (renderer instanceof SpineRenderer) {
e = new SpineAnimationDesc();
if (spineAtlasExists(sourceStr)) {
((SpineAnimationDesc) e).atlas = null;
setVisible(atlas, false);
} else {
if (!atlas.isVisible()) {
setVisible(atlas, true);
}
((SpineAnimationDesc) e).atlas = atlas.getText();
}
} else if (renderer instanceof AtlasRenderer) {
e = new AtlasAnimationDesc();
} else {
e = new AnimationDesc();
}
} else {
HashMap<String, AnimationDesc> animations = renderer.getAnimations();
animations.remove(e.id);
if (e.id.equals(renderer.getInitAnimation()))
renderer.setInitAnimation(null);
}
e.id = id.getText();
e.sound = sound.getText();
e.source = sourceStr;
e.count = Integer.parseInt(count.getText());
e.preload = Boolean.parseBoolean(preload.getText());
e.disposeWhenPlayed = Boolean.parseBoolean(dispose.getText());
e.animationType = Type.valueOf(repeat.getText());
e.inD = Param.parseVector2(in.getText());
e.outD = Param.parseVector2(out.getText());
e.duration = Float.parseFloat(speed.getText());
((AnimationRenderer) parent.getRenderer()).addAnimation(e);
if (renderer instanceof ImageRenderer && Boolean.parseBoolean(localizable.getText()) && e.source != null && e.source.length() > 0) {
e.source = I18N.PREFIX + e.source;
}
if (renderer.getInitAnimation() == null)
renderer.setInitAnimation(e.id);
// TODO UNDO OP
// UndoOp undoOp = new UndoAddElement(doc, e);
// Ctx.project.getUndoStack().add(undoOp);
Ctx.project.setModified();
}
use of com.bladecoder.engine.anim.AnimationDesc in project bladecoder-adventure-engine by bladecoder.
the class SpriteList method copy.
@Override
protected void copy() {
AnimationDesc e = list.getSelected();
if (e == null)
return;
clipboard = (AnimationDesc) ElementUtils.cloneElement(e);
toolbar.disablePaste(false);
}
use of com.bladecoder.engine.anim.AnimationDesc in project bladecoder-adventure-engine by bladecoder.
the class SpriteList method delete.
@Override
protected void delete() {
AnimationDesc d = removeSelected();
AnimationRenderer renderer = (AnimationRenderer) parent.getRenderer();
renderer.getAnimations().remove(d.id);
// UNDO
Ctx.project.getUndoStack().add(new UndoDeleteAnimation(parent, d));
// init_animation
if (renderer.getInitAnimation().equals(d.id)) {
HashMap<String, AnimationDesc> animations = renderer.getAnimations();
String newValue = null;
if (animations.size() > 0)
newValue = animations.keySet().iterator().next();
renderer.setInitAnimation(newValue);
Ctx.project.setModified(this, "init_animation", d.id, newValue);
}
Ctx.project.setModified();
}
Aggregations