Install a hook from audio to animations if both are present.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 22 Apr 2015 21:32:18 +0000 (23:32 +0200)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 22 Apr 2015 21:32:18 +0000 (23:32 +0200)
src/yuu/ce.js
src/yuu/director.js

index 8cca5227ecc30428bca408dfec12cf36e8ebc3a4..d604e7065fb4ae3fab29be83565d036a4e889bdd 100644 (file)
     });
 
 
-    yuu.Animation = yT(yuu.C, {
+    var animationOps = [];
+
+    var Animation = yuu.Animation = yT(yuu.C, {
         constructor: function (timeline, params, completionHandler, delay) {
             this.timeline = yf.mapValues(yf.arrayify, timeline);
             this.params = params;
                 this.tweenAll(instr.tweenAll, instr);
             if (instr.event)
                 this.event(instr.event);
+            animationOps.forEach(function (f) {
+                if (instr[f.name])
+                    f.call(this, instr[f.name], instr);
+            }, this);
         },
 
         tick: function () {
         TAPS: ["tick", "tock"]
     });
 
+    Animation.registerOperation = function (f) {
+        animationOps.push(f);
+    };
+
     yuu.Tween = yT({
         /** Tween object properties over time
 
index a078ef5c6f8eea014bd7189fb0f3dc672af5be6f..7660b26a3ec3e95edacfa7213a394b06382fbb02 100644 (file)
         var director = yuu.director = new yuu.Director();
             /** The standard director */
 
+        if (yuu.audio) {
+            yuu.Animation.registerOperation(function playSound (sound) {
+                if (Array.isArray(sound))
+                    sound = yuu.random.choice(sound);
+                (new yuu.Instrument(sound)).play();
+            });
+        }
+
         yuu.registerInitHook(function () {
             return yuu.ready(director._scenes);
         });