From 8d28b9a597ba329673231d478de857cf7b6434c5 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Thu, 9 Jul 2015 10:06:41 +0200 Subject: [PATCH] Use a refcount for disable sound. --- static/js/services/playsound.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/static/js/services/playsound.js b/static/js/services/playsound.js index d1677be8..e2a021b6 100644 --- a/static/js/services/playsound.js +++ b/static/js/services/playsound.js @@ -162,7 +162,7 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) { }; Sound.prototype.shouldPlaySound = function(id) { - if (disabled[id]) { + if (disabled.hasOwnProperty(id) && disabled[id] >= 1) { return false; } var data = appData.get(); @@ -204,11 +204,19 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) { return s.play(id, time); }, disable: function(id, status) { - // Use disable disable play back of a certain sound id. - // Pass status as false to reenable. + // Disable play back of a certain sound id. Pass status as false to re-enable. + if (!disabled.hasOwnProperty(id)) { + disabled[id] = 0; + } if (status !== false) { - disabled[id] = true; + // Increment for disable. + disabled[id]++; } else { + // Decrement for eenable. + disabled[id]--; + } + if (disabled[id] === 0) { + // Cleanup when 0. delete disabled[id]; } }