Search in sources :

Example 1 with AnimationDesc

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);
        }
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Example 2 with AnimationDesc

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);
                    }
                }
            }
        }
    }
}
Also used : SoundAction(com.bladecoder.engine.actions.SoundAction) PlaySoundAction(com.bladecoder.engine.actions.PlaySoundAction) Action(com.bladecoder.engine.actions.Action) SoundAction(com.bladecoder.engine.actions.SoundAction) PlaySoundAction(com.bladecoder.engine.actions.PlaySoundAction) PlaySoundAction(com.bladecoder.engine.actions.PlaySoundAction) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Example 3 with AnimationDesc

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();
}
Also used : AtlasAnimationDesc(com.bladecoder.engine.anim.AtlasAnimationDesc) SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) ImageRenderer(com.bladecoder.engine.model.ImageRenderer) AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc) AtlasAnimationDesc(com.bladecoder.engine.anim.AtlasAnimationDesc) SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 4 with AnimationDesc

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);
}
Also used : AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Example 5 with AnimationDesc

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();
}
Also used : AnimationDesc(com.bladecoder.engine.anim.AnimationDesc) UndoDeleteAnimation(com.bladecoder.engineeditor.undo.UndoDeleteAnimation) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Aggregations

AnimationDesc (com.bladecoder.engine.anim.AnimationDesc)13 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)3 Vector2 (com.badlogic.gdx.math.Vector2)2 AtlasAnimationDesc (com.bladecoder.engine.anim.AtlasAnimationDesc)2 SpineAnimationDesc (com.bladecoder.engine.anim.SpineAnimationDesc)2 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)2 SpriteActor (com.bladecoder.engine.model.SpriteActor)2 SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)2 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)1 Action (com.bladecoder.engine.actions.Action)1 PlaySoundAction (com.bladecoder.engine.actions.PlaySoundAction)1 SoundAction (com.bladecoder.engine.actions.SoundAction)1 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)1 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)1 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)1 Verb (com.bladecoder.engine.model.Verb)1 UndoDeleteAnimation (com.bladecoder.engineeditor.undo.UndoDeleteAnimation)1 ArrayList (java.util.ArrayList)1