Browse Source

Use a refcount for disable sound.

pull/217/head
Simon Eisenmann 11 years ago
parent
commit
8d28b9a597
  1. 16
      static/js/services/playsound.js

16
static/js/services/playsound.js

@ -162,7 +162,7 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) {
}; };
Sound.prototype.shouldPlaySound = function(id) { Sound.prototype.shouldPlaySound = function(id) {
if (disabled[id]) { if (disabled.hasOwnProperty(id) && disabled[id] >= 1) {
return false; return false;
} }
var data = appData.get(); var data = appData.get();
@ -204,11 +204,19 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) {
return s.play(id, time); return s.play(id, time);
}, },
disable: function(id, status) { disable: function(id, status) {
// Use disable disable play back of a certain sound id. // Disable play back of a certain sound id. Pass status as false to re-enable.
// Pass status as false to reenable. if (!disabled.hasOwnProperty(id)) {
disabled[id] = 0;
}
if (status !== false) { if (status !== false) {
disabled[id] = true; // Increment for disable.
disabled[id]++;
} else { } else {
// Decrement for eenable.
disabled[id]--;
}
if (disabled[id] === 0) {
// Cleanup when 0.
delete disabled[id]; delete disabled[id];
} }
} }

Loading…
Cancel
Save