Use new animation hooks (but still preload sounds).
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 22 Apr 2015 21:33:33 +0000 (23:33 +0200)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 22 Apr 2015 21:33:33 +0000 (23:33 +0200)
src/pwl6.js

index 4e87c1856ae62c47f0c4e446a7bbbb99edec0dc3..66b413960cff3f2337005178f1f5713a89e0c83d 100644 (file)
@@ -67,12 +67,7 @@ function load () {
     sounds = {
         tick: new yuu.Instrument("@tick"),
         tock: new yuu.Instrument("@tock"),
-        regear: new yuu.Instrument("@regear"),
-        winding: new yuu.Instrument("@winding"),
-        slam: new yuu.Instrument("@slam"),
         switch: new yuu.Instrument("@switch"),
-        clicking: new yuu.Instrument("@clicking"),
-        bookAppear: new yuu.Instrument("@book-appear"),
         switchBroke: new yuu.Instrument({
             sample: { "@switch": { duration: 0.27, offset: 0.1 } } }),
         switchOn: new yuu.Instrument({
@@ -99,6 +94,8 @@ function load () {
 
     return yuu.ready(
         [SIGILS, BOOK]
+        .concat(yf.map(yf.new_(yuu.Instrument), [
+            '@winding', '@regear', '@clicking', '@slam', '@book-appear']))
         .concat(yf.map(yf.getter.bind(sounds), Object.keys(sounds)))
     );
 }
@@ -255,7 +252,9 @@ var AnimationQueue = yT(yuu.C, {
 });
 
 var SLAMMER_ROTATE = {
-    0: { tween1: { yaw: "yaw" }, duration: 10 }
+    0: { tween1: { yaw: "yaw" },
+         playSound: "@clicking",
+         duration: 10 }
 };
 
 var ROTATE_ALL = {
@@ -272,7 +271,9 @@ var SLIDE_BLOCKS = {
 };
 
 var SLAMMER_SLAM = {
-    0:  { tween1: { y: -1.5 }, easing: "linear", duration: 6 },
+    0:  { tween1: { y: -1.5 }, easing: "linear",
+          playSound: "@slam",
+          duration: 6 },
     6:  { event: "slideBoardBlocks" },
     15: { event: "slam",
           tween1: { y: 0 }, easing: "linear", duration: 8 }
@@ -820,7 +821,6 @@ GridScene = yT(yuu.Scene, {
             var yaw0 = this.slammerRoot.transform.yaw;
             var yaw1 = orientation * Math.PI / 2;
 
-            sounds.clicking.play();
             this.entity0.attach(new yuu.Animation(
                 SLAMMER_ROTATE, {
                     $: this.slammerRoot.transform,
@@ -927,7 +927,6 @@ GridScene = yT(yuu.Scene, {
             }
             this._locks.increment("spin", "slam");
             circleScene.slam();
-            sounds.slam.play();
             handScene.slam(this.slammer.controller.orientation);
             this.entity0.attach(new yuu.Animation(
                 SLAMMER_SLAM, {
@@ -1153,7 +1152,9 @@ var FLASH = {
 };
 
 var MENU_SLAM = {
-    0:  { tween: { cursor: { y: "mid" } }, duration: 8 },
+    0:  { tween: { cursor: { y: "mid" } },
+          playSound: "@winding",
+          duration: 8 },
     8:  { tween: { cursor: { y: "line" },
                    select: { y: -1.0 }
                  }, duration: 12 },
@@ -1360,7 +1361,6 @@ MenuScene = yT(yuu.Scene, {
         handScene.menuChoice();
         circleScene.toBack();
         circleScene.slam();
-        sounds.winding.play();
         this.entity0.animationQueue.enqueue(
             MENU_SLAM, {
                 cursor: this.pointer.transform,
@@ -1513,11 +1513,13 @@ MenuScene = yT(yuu.Scene, {
 var BOOK_APPEAR = {
     0: { set1:   { y: 1.5, x: -1.5 },
          tween: { bgQuad: { alpha: 0.75 }, $: { y: 0, x: 0 }, },
+         playSound: "@book-appear",
          duration: 30 }
 };
 
 var BOOK_DISMISS = {
     0: { tween: { bgQuad: { alpha: 0 }, $: { y: 1.5, x: -1.5, } },
+         playSound: "@book-dismiss",
          duration: 30 }
 };
 
@@ -1530,7 +1532,9 @@ var BOOK_FORWARD = [
             tween: { page1: { x: -1/3 / 2, scaleX: 0 },
                      page2: { x: +1/3 / 2 },
                      page2Quad: { color: [1, 1, 1, 1] },
-                   }, duration: 15, easing: "linear" },
+                   }, duration: 15, easing: "linear",
+            playSound: ["@page-turn-1", "@page-turn-2", "@page-turn-3"]
+          },
       15: { set: { page1Quad: { z: 0, texBounds: [0.25, 0.5, 0.00, 1] },
                    page2Quad: { z: 0, texBounds: "page" } },
             tween: { page1: { x: -1/3, scaleX: -2/3 },
@@ -1540,7 +1544,9 @@ var BOOK_FORWARD = [
 
     { 0:  { tween: { page1: { x: -1/3 / 2 },
                      page2: { x: +1/3 / 2, scaleX: 0 }
-                   }, duration: 15, easing: "linear" },
+                   }, duration: 15, easing: "linear",
+            playSound: ["@page-turn-1", "@page-turn-2", "@page-turn-3"]
+          },
       15: { set:   { page1Quad: { z: 0, texBounds: [0.25, 0.5, 0.00, 1] },
                      page2Quad: { z: 1, texBounds: [1.00, 0.5, 0.75, 1] } },
             tween: { page1Quad: { color: [0.2, 0.2, 0.2, 1] },
@@ -1555,7 +1561,9 @@ var BOOK_FORWARD = [
 var BOOK_BACKWARD = [
     { 0:   { tween: { page1: { x: -1/3 / 2, scaleX: 0 },
                       page2: { x: +1/3 / 2 },
-                    }, duration: 15, easing: "linear" },
+                    }, duration: 15, easing: "linear",
+             playSound: ["@page-turn-1", "@page-turn-2", "@page-turn-3"]
+           },
       15: { set:   { page1Quad: { z: 1, texBounds: [0.50, 0.5, 0.75, 1] },
                      page2Quad: { z: 0 } },
             tween: { page2Quad: { color: [0.2, 0.2, 0.2, 1] },
@@ -1568,7 +1576,9 @@ var BOOK_BACKWARD = [
             tween: { page1Quad: { color: [1.0, 1.0, 1.0, 1] },
                      page1: { x: -1/3 / 2 },
                      page2: { x: +1/3 / 2, scaleX: 0 }
-                   }, duration: 15, easing: "linear" },
+                   }, duration: 15, easing: "linear",
+            playSound: ["@page-turn-1", "@page-turn-2", "@page-turn-3"]
+          },
     
       15: { set:   { page1Quad: { z: 0, texBounds: [0.25, 0.5, 0.00, 1] },
                      page2Quad: { z: 0, texBounds: "page" } },
@@ -1600,12 +1610,10 @@ BookScene = new yT(yuu.Scene, {
         this._locks = new FlagSet("turn");
         this.addEntities(bg, this.page1, this.page2);
 
-        this.dismissSound = new yuu.Instrument("@book-dismiss");
-        this.pageSounds = [new yuu.Instrument("@page-turn-1"),
-                           new yuu.Instrument("@page-turn-2"),
-                           new yuu.Instrument("@page-turn-3")];
-
-        this.ready = yuu.ready([this.dismissSound].concat(this.pageSounds));
+        this.ready = yuu.ready(yf.map(yf.new_(yuu.Instrument), [
+            "@page-turn-1", "@page-turn-2", "@page-turn-3",
+            "@book-dismiss"
+        ]));
     },
 
     help: yuu.cmd(function () {
@@ -1638,19 +1646,11 @@ BookScene = new yT(yuu.Scene, {
 
     _anim: function (anim) {
         this._locks.increment("turn");
-        // FIXME: Need hooks from animations to audio
         var completion = this._locks.decrementer("turn");
         switch (anim) {
         case BOOK_DISMISS:
-            this.dismissSound.play();
             completion = yuu.director.removeScene.bind(yuu.director, this);
             break;
-        case BOOK_APPEAR:
-            sounds.bookAppear.play();
-            break;
-        default:
-            yuu.random.choice(this.pageSounds).play();
-            break;
         }
 
         var device = yuu.director.preferredDevice();
@@ -1769,7 +1769,9 @@ var CIRCLE_TO_BACK = {
 };
 
 var CIRCLE_INNER_RATCHET = {
-    0:  { tween1: { rotation: "rotation1" }, duration: 15 },
+    0:  { tween1: { rotation: "rotation1" }, duration: 15,
+          playSound: "@regear"
+        },
     10: { tween1: { rotation: "rotation2" }, duration: 10 },
     20: { tween1: { rotation: "rotation1" }, duration: 20,
           easing: yuu.Tween.STEPPED(5) },
@@ -2130,7 +2132,6 @@ CircleScene = yT(yuu.Scene, {
                 rotation1: rot1,
                 rotation2: rot2
             }));
-        sounds.regear.play();
     },
 
     rotated: function () {