v3 client: misc fixes

This commit is contained in:
Matteo Pagliazzi
2016-05-16 12:54:43 +02:00
parent 4d08fde068
commit ab27ef47fe
5 changed files with 35 additions and 24 deletions

View File

@@ -289,7 +289,7 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
}
});
} else if (spell.target == 'tasks') {
var tasks = User.user.habits.concat(User.user.dailys).concat(User.user.rewards);
var tasks = User.user.habits.concat(User.user.dailys).concat(User.user.rewards).concat(User.user.todos);
// exclude challenge tasks
tasks = tasks.filter(function (t) {
if (!t.challenge) return true;

View File

@@ -176,6 +176,7 @@ habitrpg.controller('SettingsCtrl',
$scope.reset = function(){
User.reset({});
User.sync();
$rootScope.$state.go('tasks');
}

View File

@@ -81,8 +81,7 @@ angular.module('habitrpg')
clearCards: clearCards,
}
//@TOOD: Port when User service is updated
function clearCards() {
User.user.ops.update && User.set({'flags.cardReceived':false});
User.user._wrapped && User.set({'flags.cardReceived':false});
}
}]);

View File

@@ -264,8 +264,8 @@ function($rootScope, User, $timeout, $state, Analytics) {
}
//Init and show the welcome tour (only after user is pulled from server & wrapped).
var watcher = $rootScope.$watch('User.user.ops.update', function(updateFn){
if (!updateFn) return; // only run after user has been wrapped
var watcher = $rootScope.$watch('User.user._wrapped', function(wrapped){
if (!wrapped) return; // only run after user has been wrapped
watcher(); // deregister watcher
if (window.env.IS_MOBILE) return; // Don't show tour immediately on mobile devices
if (User.user.flags.welcomed == false) {

View File

@@ -61,21 +61,13 @@ angular.module('habitrpg')
// replicated. We need to wrap each op to provide a callback to send that operation
$window.habitrpgShared.wrap(user);
_.each(user.ops, function(op,k){
user.ops[k] = function(req,cb){
if (cb) return op(req,cb);
op(req,function(err,response) {
for(var updatedItem in req.body) {
var itemUpdateResponse = userNotifications[updatedItem];
if(itemUpdateResponse) Notification.text(itemUpdateResponse);
user.ops[k] = function(req){
try {
op(req);
} catch (err) {
Notification.text(err.message);
return;
}
if (err) {
var message = err.code ? err.message : err;
Notification.text(message);
// In the case of 200s, they're friendly alert messages like "Your pet has hatched!" - still send the op
if ((err.code && err.code >= 400) || !err.code) return;
}
userServices.log({op:k, params: req.params, query:req.query, body:req.body});
});
}
});
}
@@ -106,13 +98,27 @@ angular.module('habitrpg')
function callOpsFunctionAndRequest (opName, endPoint, method, paramString, opData) {
if (!opData) opData = {};
var clientResponse;
try {
$window.habitrpgShared.ops[opName](user, opData);
var args = [user];
if (opName === 'rebirth' || opName === 'reroll' || opName === 'reset') {
args.push(user.habits.concat(user.dailys).concat(user.rewards).concat(user.todos));
}
args.push(opData);
clientResponse = $window.habitrpgShared.ops[opName].apply(null, args);
} catch (err) {
Notification.text(err.message);
return;
}
var clientMessage = clientResponse[1];
if (clientMessage) {
Notification.text(clientMessage);
}
var url = '/api/v3/user/' + endPoint;
if (paramString) {
url += '/' + paramString
@@ -130,7 +136,7 @@ angular.module('habitrpg')
body: body,
})
.then(function (response) {
if (response.data.message) Notification.text(response.data.message);
if (response.data.message && response.data.message !== clientMessage) Notification.text(response.data.message);
save();
})
}
@@ -182,7 +188,12 @@ angular.module('habitrpg')
},
score: function (data) {
try {
$window.habitrpgShared.ops.scoreTask({user: user, task: data.params.task, direction: data.params.direction}, data.params);
} catch (err) {
Notification.text(err.message);
return;
}
save();
Tasks.scoreTask(data.params.task._id, data.params.direction).then(function (res) {
var tmp = res.data.data._tmp || {}; // used to notify drops, critical hits and other bonuses