refactored sound system so that they can be specified in ACP, updated soundfile to work in FF, which fixes #1209
parent
175230e337
commit
553cabdcfa
Binary file not shown.
Binary file not shown.
@ -1,43 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
define(['buzz'], function(buzz) {
|
|
||||||
var Sound = {};
|
|
||||||
|
|
||||||
Sound.initialised = false;
|
|
||||||
Sound.loaded = {};
|
|
||||||
|
|
||||||
Sound.init = function(callback) {
|
|
||||||
var sounds = {
|
|
||||||
notification: RELATIVE_PATH + '/sound/notification.wav',
|
|
||||||
'chat-outgoing': RELATIVE_PATH + '/sound/chat-outgoing.wav',
|
|
||||||
'chat-incoming': RELATIVE_PATH + '/sound/chat-incoming.wav'
|
|
||||||
};
|
|
||||||
|
|
||||||
for(var name in sounds) {
|
|
||||||
if (sounds.hasOwnProperty(name)) {
|
|
||||||
var path = sounds[name];
|
|
||||||
|
|
||||||
Sound.loaded[name] = new buzz.sound(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initialised = true;
|
|
||||||
|
|
||||||
callback();
|
|
||||||
};
|
|
||||||
|
|
||||||
Sound.play = function(name) {
|
|
||||||
var ready = function() {
|
|
||||||
if (Sound.loaded[name]) {
|
|
||||||
Sound.loaded[name].play();
|
|
||||||
} else {
|
|
||||||
console.log('[sound] Not found:', name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!this.initialised) this.init(ready);
|
|
||||||
else ready();
|
|
||||||
};
|
|
||||||
|
|
||||||
return Sound;
|
|
||||||
});
|
|
@ -0,0 +1,74 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
define(['buzz'], function(buzz) {
|
||||||
|
var Sounds = {};
|
||||||
|
|
||||||
|
Sounds.initialised = false;
|
||||||
|
Sounds.loaded = {};
|
||||||
|
Sounds.mapping = {};
|
||||||
|
|
||||||
|
Sounds.init = function(callback) {
|
||||||
|
var ready = false,
|
||||||
|
onComplete = function() {
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
|
loadFiles(function() {
|
||||||
|
if (ready) {
|
||||||
|
onComplete();
|
||||||
|
} else {
|
||||||
|
ready = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
loadMapping(function() {
|
||||||
|
if (ready) {
|
||||||
|
onComplete();
|
||||||
|
} else {
|
||||||
|
ready = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var loadFiles = function(callback) {
|
||||||
|
socket.emit('modules.sounds.getSounds', function(err, sounds) {
|
||||||
|
if (err) {
|
||||||
|
return console.log('[sounds] Could not initialise!');
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var name in sounds) {
|
||||||
|
if (sounds.hasOwnProperty(name)) {
|
||||||
|
var path = sounds[name];
|
||||||
|
|
||||||
|
Sounds.loaded[name] = new buzz.sound(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initialised = true;
|
||||||
|
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var loadMapping = function(callback) {
|
||||||
|
socket.emit('modules.sounds.getMapping', function(err, mapping) {
|
||||||
|
Sounds.mapping = mapping;
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Sounds.play = function(name) {
|
||||||
|
var ready = function() {
|
||||||
|
if (Sounds.mapping[name] && Sounds.loaded[Sounds.mapping[name]]) {
|
||||||
|
Sounds.loaded[Sounds.mapping[name]].play();
|
||||||
|
} else {
|
||||||
|
console.log('[sounds] Not found:', name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!this.initialised) this.init(ready);
|
||||||
|
else ready();
|
||||||
|
};
|
||||||
|
|
||||||
|
return Sounds;
|
||||||
|
});
|
Loading…
Reference in New Issue