fix bug music not playing if music menu not open + integrate daily/todo/reward sounds

This commit is contained in:
Adrien Lemaire 2014-08-09 17:29:56 +09:00
parent dcbd460331
commit a5f1e30880
4 changed files with 21 additions and 10 deletions

View file

@ -50,9 +50,8 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
}
$rootScope.playSound = function(id){
if (!User.user.preferences.sound) return;
var select = document.getElementById('audioTheme');
var theme = select.options[select.selectedIndex].value;
if (!user.preferences.sound) return;
var theme = user.preferences.soundTheme;
var file = 'audio/' + theme + '/' + id;
document.getElementById('oggSource').src = file + '.ogg';
document.getElementById('mp3Source').src = file + '.mp3';

View file

@ -6,8 +6,20 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
$scope.user = User.user;
$scope.score = function(task, direction) {
if (direction === 'down') $rootScope.playSound('Minus_Habit');
if (direction === 'up') $rootScope.playSound('Plus_Habit');
switch (task.type) {
case 'reward':
$rootScope.playSound('Reward');
break;
case 'daily':
$rootScope.playSound('Daily');
break;
case 'todo':
$rootScope.playSound('ToDo');
break;
default:
if (direction === 'down') $rootScope.playSound('Minus_Habit');
else if (direction === 'up') $rootScope.playSound('Plus_Habit');
}
User.user.ops.score({params:{id: task.id, direction:direction}})
};

View file

@ -35,8 +35,3 @@ html(ng-app="habitrpg", ng-controller="RootCtrl", ng-class='{"applying-action":a
#main(ui-view)
include ./shared/footer
// Load audio last
audio#sound(autoplay)
source#oggSource(type="audio/ogg")
source#mp3Source(type="audio/mp3")

View file

@ -78,3 +78,8 @@ footer.footer(ng-controller='FooterCtrl')
a.btn.btn-default(ng-click='addOneLevel()') +1 Level
div(ng-init='deferredScripts()')
// Load audio last
audio#sound(autoplay)
source#oggSource(type="audio/ogg")
source#mp3Source(type="audio/mp3")