apiv2 handle notifications circular-dependency. migration

fixes. Rest=>Sleep fixes
This commit is contained in:
Tyler Renelle 2013-12-14 21:58:53 -07:00
parent ae4ca337c8
commit bc0034f022
8 changed files with 20 additions and 18 deletions

View file

@ -13,7 +13,7 @@ users = mongo.db('localhost:27017/habitrpg?auto_reconnect').collection('users')
users.count query, (err, count) ->
console.log {count}
return console.error(err) if err
users.findEach query, {batchSize:10}, (err, user) ->
users.findEach query, {batchSize:500}, (err, user) ->
unless user then err = 'Blank user';count--
return console.log(err) if err
@ -64,19 +64,21 @@ users.count query, (err, count) ->
costume: {}
_.each {head: "showHelm", weapon: "showWeapon", shield: "showShield", armor: "showArmor"}, (show, type) ->
user.items[type] = if Math.abs(user.items[type]) > 10 then 0 else ~~user.items[type]
_.times user.items[type], (i) ->
user.items[type] = unless 0 < ~~user.items[type] < 8 then 0 else ~~user.items[type]
_.times user.items[type]+1, (i) -> #+1 since 0 is significant
item =
if type is 'weapon'
if i > 8 then 'weapon_warrior_6'
else if i is 8 then "weapon_special_1"
else if i is 7 then "weapon_special_0"
else "weapon_warrior_#{i}"
else
if i > 7 then "#{type}_warrior_5"
else if i is 7 then "#{type}_special_1"
else if i is 6 then "#{type}_special_0"
else if i is 0 then "#{type}_base_0"
else "#{type}_warrior_#{i}"
gear.owned[item] = true
gear.owned[item] = true unless item is "#{type}_base_0"
gear.equipped[type] = item
# # TODO how to handle combo of wearing / hiding?

View file

@ -5,16 +5,19 @@ habitrpg.controller('NotificationCtrl',
$rootScope.$watch('user.stats.hp', function(after, before) {
if (after == before) return;
if (User.user.stats.lvl == 0) return;
Notification.hp(after - before, 'hp');
});
$rootScope.$watch('user.stats.exp', function(after, before) {
if (after == before) return;
if (User.user.stats.lvl == 0) return;
Notification.exp(after - before);
});
$rootScope.$watch('user.stats.gp', function(after, before) {
if (after == before) return;
if (User.user.stats.lvl == 0) return;
var money = after - before;
Notification.gp(money);

View file

@ -2,7 +2,7 @@
Set up "+1 Exp", "Level Up", etc notifications
*/
angular.module("notificationServices", [])
.factory("Notification", ['User', function(User) {
.factory("Notification", [function() {
function growl(html, type) {
$.bootstrapGrowl(html, {
ele: '#notification-area',
@ -45,16 +45,13 @@ angular.module("notificationServices", [])
coins: coins,
hp: function(val) {
// don't show notifications if user dead
if (User.user.stats.lvl == 0) return;
growl("<i class='icon-heart'></i> " + sign(val) + " " + round(val) + " HP", 'hp');
},
exp: function(val) {
if (User.user.stats.lvl == 0) return;
if (val < -50) return; // don't show when they level up (resetting their exp)
growl("<i class='icon-star'></i> " + sign(val) + " " + round(val) + " XP", 'xp');
},
gp: function(val) {
if (User.user.stats.lvl == 0) return;
growl(sign(val) + " " + coins(val), 'gp');
},
text: function(val){

View file

@ -5,8 +5,8 @@
*/
angular.module('userServices', []).
factory('User', ['$rootScope', '$http', '$location', '$window', 'API_URL', 'STORAGE_USER_ID', 'STORAGE_SETTINGS_ID',
function($rootScope, $http, $location, $window, API_URL, STORAGE_USER_ID, STORAGE_SETTINGS_ID) {
factory('User', ['$rootScope', '$http', '$location', '$window', 'API_URL', 'STORAGE_USER_ID', 'STORAGE_SETTINGS_ID', 'Notification',
function($rootScope, $http, $location, $window, API_URL, STORAGE_USER_ID, STORAGE_SETTINGS_ID, Notification) {
var authenticated = false,
defaultSettings = {
auth: { apiId: '', apiToken: ''},
@ -75,8 +75,7 @@ angular.module('userServices', []).
_.each(user.ops, function(op,k){
user.ops[k] = _.partialRight(op, function(err, req){
if (err) {
//Notification.text(err.code ? err.message : err); // FIXME Circular dependency found: Notification <- User
alert(err.code ? err.message : err);
Notification.text(err.code ? err.message : err);
// In the case of 200s, they're friendly alert messages like "You're pet has hatched!" - still send the op
if ((err.code && err.code >= 400) || !err.code) return;
}

View file

@ -73,6 +73,7 @@
"bower_components/angular-loading-bar/build/loading-bar.js",
"js/static.js",
"js/services/userServices.js",
"js/services/notificationServices.js",
"js/controllers/authCtrl.js"
],
"css": [

View file

@ -13,10 +13,10 @@
.popover-content
| Welcome to the Tavern! Stay a while and meet the locals. If you need to rest (going on vacation? sudden illness?), I'll set you up at the inn - Dailies won't hurt you while you're resting.
div
button.btn.btn-large.btn-success(ng-class='{active: user.flags.rest}', ng-click='User.user.ops.sleep({})')
span(ng-show='user.flags.rest') Check Out of Inn
span(ng-hide='user.flags.rest') Rest in the Inn
.alert.alert-info(ng-show='user.flags.rest')
button.btn.btn-large.btn-success(ng-class='{active: user.preferences.sleep}', ng-click='User.user.ops.sleep({})')
span(ng-show='user.preferences.sleep') Check Out of Inn
span(ng-hide='user.preferences.sleep') Rest in the Inn
.alert.alert-info(ng-show='user.preferences.sleep')
| Whilst resting, your dailies are saved and aren't affected by day turn-over. Whether you check out tomorrow or in a week's time, you'll continue in the same state as when you checked in.
// Resources

View file

@ -37,7 +37,7 @@ figure.herobox(ng-click='spell ? castEnd(profile, "user", $event) : clickMember(
span(ng-if='profile.items.currentMount', class='Mount_Head_{{profile.items.currentMount}}')
// Resting
span(ng-class='{zzz:profile.flags.rest}')
span(ng-class='{zzz:profile.preferences.sleep}')
// FIXME handle @minimal, this might have to be a directive
span.current-pet(class='Pet-{{profile.items.currentPet}}', ng-show='profile.items.currentPet && !minimal')
.avatar-level(ng-class='userLevelStyle(profile,"label")')

View file

@ -44,7 +44,7 @@
span(class='hair_beard_{{user.preferences.hair.beard}}_{{user.preferences.hair.color}}')
span(class='hair_mustache_{{user.preferences.hair.mustache}}_{{user.preferences.hair.color}}')
span(class='head_rogue_5')
span(class='shield_rogue_5')
span(class='shield_rogue_6')
span(class='weapon_rogue_6')
.span3(ng-click='selectedClass = "healer"')
h5 Healer