From: Joe Wreschnig Date: Wed, 22 Apr 2015 21:32:18 +0000 (+0200) Subject: Install a hook from audio to animations if both are present. X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=f7850752cb4d643d906f4723008b507961b434ca;p=pwl6.git Install a hook from audio to animations if both are present. --- diff --git a/src/yuu/ce.js b/src/yuu/ce.js index 8cca522..d604e70 100644 --- a/src/yuu/ce.js +++ b/src/yuu/ce.js @@ -147,7 +147,9 @@ }); - 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; @@ -262,6 +264,10 @@ 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 () { @@ -293,6 +299,10 @@ TAPS: ["tick", "tock"] }); + Animation.registerOperation = function (f) { + animationOps.push(f); + }; + yuu.Tween = yT({ /** Tween object properties over time diff --git a/src/yuu/director.js b/src/yuu/director.js index a078ef5..7660b26 100644 --- a/src/yuu/director.js +++ b/src/yuu/director.js @@ -686,6 +686,14 @@ 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); });