clean branch from develop to add audio

This commit is contained in:
Adrien Lemaire 2014-08-08 23:03:52 +09:00
parent b19649ce37
commit 3d2d8fbfef
27 changed files with 58 additions and 6 deletions

View file

@ -31,7 +31,7 @@
"bootstrap-growl": "git://github.com/ifightcrime/bootstrap-growl.git#master",
"bootstrap-tour": "~0.8.1",
"habitrpg-shared": "git://github.com/HabitRPG/habitrpg-shared.git#develop",
"BrowserQuest": "git://github.com/mozilla/BrowserQuest.git",
"BrowserQuest": "git://github.com/browserquest/BrowserQuest.git",
"github-buttons": "git://github.com/mdo/github-buttons.git",
"marked": "~0.2.9",
"Angular-At-Directive": "git://github.com/snicker/Angular-At-Directive#master",

View file

@ -0,0 +1,9 @@
//Add defaults to show gears in all users
db.users.update(
{},
{$set:{
'preferences.soundTheme': 'danielTheBard',
'preferences.sound': 1
}},
{multi:true}
)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -4,13 +4,14 @@ habitrpg.controller('NotificationCtrl',
['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification',
function ($scope, $rootScope, Shared, Content, User, Guide, Notification) {
$rootScope.$watch('user.stats.hp', function(after, before) {
$rootScope.$watch('user.stats.hp', function (after, before) {
if (after <= 0){
$rootScope.openModal('death', {keyboard:false, backdrop:'static'});
}
if (after == before) return;
if (User.user.stats.lvl == 0) return;
Notification.hp(after - before, 'hp');
if (after < 0) $rootScope.playSound('Minus_Habit');
});
$rootScope.$watch('user.stats.exp', function(after, before) {
@ -19,6 +20,10 @@ habitrpg.controller('NotificationCtrl',
Notification.exp(after - before);
});
$rootScope.$watch('user.achievements', function(){
$rootScope.playSound('Achievement_Unlocked');
}, true);
$rootScope.$watch('user.stats.gp', function(after, before) {
if (after == before) return;
if (User.user.stats.lvl == 0) return;
@ -53,6 +58,7 @@ habitrpg.controller('NotificationCtrl',
$rootScope.$watch('user._tmp.drop', function(after, before){
// won't work when getting the same item twice?
if (after == before || !after) return;
$rootScope.playSound('Achievement_Unlocked');
if (after.type !== 'gear') {
var type = (after.type == 'Food') ? 'food' :
(after.type == 'HatchingPotion') ? 'hatchingPotions' : // can we use camelcase and remove this line?
@ -85,6 +91,7 @@ habitrpg.controller('NotificationCtrl',
if(before == undefined || after == before || after < before) return;
if (User.user.achievements.streak > 1) {
Notification.streak(User.user.achievements.streak);
$rootScope.playSound('Achievement_Unlocked');
}
else {
$rootScope.openModal('achievements/streak');

View file

@ -49,6 +49,16 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
return style;
}
$rootScope.playSound = function(id){
if (!User.user.preferences.sound) return;
var select = document.getElementById('audioTheme');
var theme = select.options[select.selectedIndex].value;
var file = 'audio/' + theme + '/' + id;
document.getElementById('oggSource').src = file + '.ogg';
document.getElementById('mp3Source').src = file + '.mp3';
document.getElementById('sound').load();
}
// count pets, mounts collected totals, etc
$rootScope.countExists = function(items) {return _.reduce(items,function(m,v){return m+(v?1:0)},0)}

View file

@ -142,5 +142,10 @@ habitrpg.controller('SettingsCtrl',
window.location.href = '/api/v2/coupons?limit='+codes.count+'&_id='+User.user._id+'&apiToken='+User.user.apiToken;
})
}
// Audio list of themes
$scope.soundThemes = {
'danielTheBard': 'Daniel the Bard'
};
}
]);

View file

@ -1,11 +1,13 @@
"use strict";
habitrpg.controller("TasksCtrl", ['$scope', '$location', 'User','Notification', '$http', 'API_URL', '$timeout', 'Shared',
function($scope, $location, User, Notification, $http, API_URL, $timeout, Shared) {
habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','Notification', '$http', 'API_URL', '$timeout', 'Shared',
function($scope, $rootScope, $location, User, Notification, $http, API_URL, $timeout, Shared) {
$scope.obj = User.user; // used for task-lists
$scope.user = User.user;
$scope.score = function(task, direction) {
if (direction === 'down') $rootScope.playSound('Minus_Habit');
if (direction === 'up') $rootScope.playSound('Plus_Habit');
User.user.ops.score({params:{id: task.id, direction:direction}})
};

View file

@ -255,6 +255,8 @@ var UserSchema = new Schema({
skin: {type:String, 'default':'915533'},
shirt: {type: String, 'default': 'blue'},
timezoneOffset: Number,
sound: Boolean,
soundTheme: {type:String, 'default':'danielTheBard'},
language: String,
automaticAllocation: Boolean,
allocationMode: {type:String, enum: ['flat','classbased','taskbased'], 'default': 'flat'},

View file

@ -34,4 +34,9 @@ html(ng-app="habitrpg", ng-controller="RootCtrl", ng-class='{"applying-action":a
.col-md-12.exp-chart(ng-show='charts.exp')
#main(ui-view)
include ./shared/footer
include ./shared/footer
// Load audio last
audio#sound(autoplay)
source#oggSource(type="audio/ogg")
source#mp3Source(type="audio/mp3")

View file

@ -139,6 +139,18 @@ nav.toolbar(ng-controller='AuthCtrl', ng-class='{active: isToolbarHidden}')
li.toolbar-sync
a(ng-click='User.sync()', popover=env.t('sync'),popover-placement='bottom',popover-trigger='mouseenter')
span.glyphicon.glyphicon-refresh
li.toolbar-audio
a(ng-if='user.preferences.sound', ng-click='set("preferences.sound",false)')
i.icon-volume-up(tooltip='Turn Sound Off')
a(ng-if='!user.preferences.sound', ng-click='set("preferences.sound",true)')
i.icon-volume-off(tooltip='Turn Sound On')
select#audioTheme(
style='width:140px',
ng-controller='SettingsCtrl',
ng-model='user.preferences.soundTheme',
ng-options='k as v for (k , v) in soundThemes',
ng-change='set("preferences.soundTheme", user.preferences.soundTheme)'
)
li.toolbar-settings
a(ng-click='expandMenu("settings")')
span.glyphicon.glyphicon-cog
@ -181,4 +193,4 @@ nav.toolbar(ng-controller='AuthCtrl', ng-class='{active: isToolbarHidden}')
span {{Shared.silver(user.stats.gp)}}
ul.toolbar-bailey(ng-class='{inactive: !_expandedMenu}')
li.toolbar-bailey-container(ng-if='user.flags.newStuff')
.npc_bailey.npc_bailey_head(popover=env.t('psst'), popover-trigger='mouseenter', popover-placement='right', ng-click='openModal("newStuff")')
.npc_bailey.npc_bailey_head(popover=env.t('psst'), popover-trigger='mouseenter', popover-placement='right', ng-click='openModal("newStuff")')