diff --git a/assets/js/controllers/tasksCtrl.coffee b/assets/js/controllers/tasksCtrl.coffee new file mode 100644 index 0000000000..7fd39f9634 --- /dev/null +++ b/assets/js/controllers/tasksCtrl.coffee @@ -0,0 +1,140 @@ +"use strict" +habitrpg.controller "TasksCtrl", ($scope, $rootScope, $location, filterFilter, User, Algos, Helpers, Notification) -> + + $scope.taskLists = [ + {header: 'Habits', type: 'habit', inputValue:'_newHabit', placeHolder: 'New Habit', list: User.user.habits, main:true, editable:true} + {header: 'Dailies', type: 'daily', inputValue:'_newDaily', placeHolder: 'New Daily', list: User.user.dailys, main:true, editable:true} + {header: 'Todos', type: 'todo', inputValue:'_newTodo', placeHolder: 'New Todo', list: User.user.todos, main:true, editable:true} + {header: 'Reward', type: 'reward', inputValue:'_newReward', placeHolder: 'New Reward', list: User.user.rewards, main:true, editable:true} + ] + + $scope.score = (task, direction) -> + + #save current stats to compute the difference after scoring. + statsDiff = {} + oldStats = _.clone(User.user.stats) + Algos.score User.user, task, direction + + #compute the stats change. + _.each oldStats, (value, key) -> + newValue = User.user.stats[key] + statsDiff[key] = newValue - value if newValue isnt value + + + #notify user if there are changes in stats. + if Object.keys(statsDiff).length > 0 + Notification.push + type: "stats" + stats: statsDiff + + if task.type is "reward" and _.isEmpty(statsDiff) + Notification.push + type: "text" + text: "Not enough GP." + + User.log + op: "score" + data: task + dir: direction + + + $scope.notDue = (task) -> + if task.type is "daily" + not window.habitrpgShared.helpers.shouldDo(moment(), task.repeat) + else + false + + $scope.getClass = (value) -> + out = "" + if value < -20 + out += " color-worst" + else if value < -10 + out += " color-worse" + else if value < -1 + out += " color-bad" + else if value < 1 + out += " color-neutral" + else if value < 5 + out += " color-good" + else if value < 10 + out += " color-better" + else + out += " color-best" + out + + $scope.addTask = -> + return unless $scope.newTask.length + defaults = + text: $scope.newTask + type: $scope.taskType() + value: (if $scope.taskType() is "reward" then 20 else 0) + + extra = {} + switch $scope.taskType() + when "habit" + extra = + up: true + down: true + when "daily", "todo" + extra = completed: false + newTask = _.defaults(extra, defaults) + newTask.id = Helpers.uuid() + User.user[newTask.type + "s"].unshift newTask + $scope.showedTasks.unshift newTask + User.log + op: "addTask" + data: newTask + + $scope.newTask = "" + + + #Add the new task to the actions log + $scope.clearDoneTodos = -> + + + #We can't alter $scope.user.tasks here. We have to invoke API call. + #To be implemented + $scope.selectTask = (task) -> + $rootScope.selectedTask = task + $location.path "/tasks/" + task.id + + $scope.changeCheck = (task) -> + + # This is calculated post-change, so task.completed=true if they just checked it + if task.completed + $scope.score task, "up" + else + $scope.score task, "down" + + $(".taskWell").css "height", $(window).height() - 61 + + # TODO this should be somewhere else, but fits the html location better here + $rootScope.revive = -> + window.habitrpgShared.algos.revive User.user + User.log op: "revive" + + counter = 0 + + ### + ------------------------ + Items + ------------------------ + ### + $scope.$watch "user.items", -> + $scope.itemStore = window.habitrpgShared.items.updateStore($scope.user) + + $scope.buy = (type) -> + hasEnough = window.habitrpgShared.items.buyItem($scope.user, type) + if hasEnough + User.log + op: "buy" + type: type + + Notification.push + type: "text" + text: "Item bought!" + + else + Notification.push + type: "text" + text: "Not enough GP." diff --git a/assets/js/controllers/tasksCtrl.js b/assets/js/controllers/tasksCtrl.js deleted file mode 100644 index 3db9a77af5..0000000000 --- a/assets/js/controllers/tasksCtrl.js +++ /dev/null @@ -1,188 +0,0 @@ -'use strict'; - -habitrpg.controller('TasksCtrl', - ['$scope', '$rootScope', '$location', 'filterFilter', 'User', 'Algos', 'Helpers', 'Notification', - function($scope, $rootScope, $location, filterFilter, User, Algos, Helpers, Notification) { - - $scope.user = User.user; - - $scope.taskTypeTitleSingular = function () { -// show title according to the location, singular form - return $rootScope.taskContext.type.charAt(0).toUpperCase() + $rootScope.taskContext.type.slice(1); - }; - - $scope.taskType = function () { - return $location.path().split('/')[1] - }; - - $scope.tasks = function () { - //return task array based on our location i.e. /habit will return user.habits[] - return User.user[$scope.taskType() + 's']; - }; - - $scope.showedTasks = [] - - $scope.taskFilter = function (task) { - return ($location.path() == '/todo') ? !task.completed : - ($location.path() == '/todo/completed') ? task.completed : - true; - }; - - $scope.score = function (task, direction) { - //save current stats to compute the difference after scoring. - var statsDiff = {}; - var oldStats = _.clone(User.user.stats); - - Algos.score(User.user, task, direction); - - //compute the stats change. - _.each(oldStats, function (value, key) { - var newValue = User.user.stats[key]; - if (newValue !== value) { - statsDiff[key] = newValue - value; - } - }); - //notify user if there are changes in stats. - if (Object.keys(statsDiff).length > 0) { - Notification.push({type: 'stats', stats: statsDiff}); - } - - if (task.type == 'reward' && _.isEmpty(statsDiff)) { - Notification.push({type: 'text', text: 'Not enough GP.'}); - } - - User.log({op: 'score', data: task, dir: direction}); - }; - - $scope.notDue = function(task) { - if (task.type == 'daily') { - return !window.habitrpgShared.helpers.shouldDo(moment(), task.repeat); - } else { - return false - } - } - - $scope.getClass = function(value) { - - var out = '' - if (value < -20) - out += ' color-worst' - else if (value < -10) - out += ' color-worse' - else if (value < -1) - out += ' color-bad' - else if (value < 1) - out += ' color-neutral' - else if (value < 5) - out += ' color-good' - else if (value < 10) - out += ' color-better' - else - out += ' color-best' - return out - } - - $scope.addTask = function () { - if (!$scope.newTask.length) { - return; - } - - var defaults = { - text: $scope.newTask, - type: $scope.taskType(), - value: $scope.taskType() == 'reward' ? 20 : 0 - }, - extra = {}; - - switch ($scope.taskType()) { - case 'habit': - extra = {up: true, down: true}; - break; - case 'daily': - case 'todo': - extra = {completed: false}; - break; - } - - - var newTask = _.defaults(extra, defaults); - newTask.id = Helpers.uuid(); - User.user[newTask.type + 's'].unshift(newTask) - $scope.showedTasks.unshift(newTask) - User.log({op: 'addTask', data: newTask}); - $scope.newTask = ''; - //Add the new task to the actions log - - }; - - $scope.clearDoneTodos = function () { - //We can't alter $scope.user.tasks here. We have to invoke API call. - //To be implemented - }; - - $scope.selectTask = function (task) { - $rootScope.selectedTask = task; - $location.path('/tasks/' + task.id) - } - - $scope.changeCheck = function (task) { - // This is calculated post-change, so task.completed=true if they just checked it - if (task.completed) { - $scope.score(task, 'up') - } else { - $scope.score(task, 'down') - } - } - - $('.taskWell').css('height', $(window).height() - 61) - - // TODO this should be somewhere else, but fits the html location better here - $rootScope.revive = function() { - window.habitrpgShared.algos.revive(User.user); - User.log({op:'revive'}); - } - - var counter = 0; - - - /** - * ------------------------ - * Items - * ------------------------ - */ - - $scope.$watch('user.items', function(){ - $scope.itemStore = window.habitrpgShared.items.updateStore($scope.user); - }); - - $scope.buy = function(type) { - var hasEnough = window.habitrpgShared.items.buyItem($scope.user, type); - if (hasEnough) { - User.log({op:'buy', type:type}); - Notification.push({type:'text', text:"Item bought!"}) - } else { - Notification.push({type:'text', text:"Not enough GP."}) - } - } - - /* - $scope.loadMore = function() { - - var length = $scope.showedTasks.length - if (typeof $scope.tasks() != 'undefined') { - for (var i = length; i < length+7; i++) { - if (typeof $scope.tasks()[i] != 'undefined') { - $scope.showedTasks.push($scope.tasks()[i]); - } - } - } - - - }; - - $scope.loadMore() - - */ - - } -]); diff --git a/views/header/header.jade b/views/header/header.jade index d6846e4e03..b4f3cdd58f 100644 --- a/views/header/header.jade +++ b/views/header/header.jade @@ -6,8 +6,10 @@ header.site-header(ng-class='{hidden: user.preferences.hideHeader}', role='banner', data-partysize='{{party.members.length>1 ? truarr(party.members.length) : 0}}') // avatar .herobox-wrap.main-herobox(ng-controller='UserAvatarCtrl') + include ./avatar //app:avatar:avatar(profile='{{user}}', main='true') + // stat bars .hero-stats .meter.health(title='Health') diff --git a/views/index.jade b/views/index.jade index df43cd7fc4..ea1137539e 100644 --- a/views/index.jade +++ b/views/index.jade @@ -5,8 +5,8 @@ block content include ./modals/login include ./header/header - span(ng-class='{hidden: _gamePane}') - | app:filters:filters + span(ng-hide='_gamePane') + app:filters:filters br #notification-area @@ -14,11 +14,11 @@ block content app:alerts:flash //if they hide the header, we still need user-menu visible app:settings:menu(ng-show='_user.preferences.hideHeader') - .exp-chart(ng-class='{hidden: _page.charts.exp}') + .exp-chart(ng-show='_page.charts.exp') #main.grid - div(ng-class='{hidden: _gamePane}') - app:tasks:task-lists(habits='{{_habitList}}', dailys='{{_dailyList}}', todos='{{_todoList}}', rewards='{{_rewardList}}', main='true', editable='true') - div(ng-class='{hidden: _gamePane}') + div(ng-hide='_gamePane') + include ./tasks/task-list + div(ng-show='_gamePane') app:game-pane:main app:footer:footer diff --git a/views/modals/achievements.jade b/views/modals/achievements.jade new file mode 100644 index 0000000000..7b6d81360e --- /dev/null +++ b/views/modals/achievements.jade @@ -0,0 +1,11 @@ + +// Streak Achievement +div(modal='modals.streakAchievement', header='Achievement!') + .modal-header + h3 Achievement! + .modal-body + .achievement.achievement-thermometer + | You have stacked your "Streaker" Achievement! Every 21 days of streak, you gain 1 achievement point here. + .modal-footer + button.btn.btn-default.cancel(ng-click='modals.modals.streakAchievement = false') Cancel + diff --git a/views/tasks/task-list.html b/views/tasks/task-list.html new file mode 100644 index 0000000000..a571201970 --- /dev/null +++ b/views/tasks/task-list.html @@ -0,0 +1,86 @@ + + + + + +
-
You have stacked your "Streaker" Achievement! Every 21 days of streak, you gain 1 achievement point here. - - <@footer> - - @footer> -