move tnl to a view function instead of model function, beging adding

party stats visuals (hp & exp presently)
This commit is contained in:
Tyler Renelle 2013-03-15 12:00:47 -04:00
parent 565c9004ca
commit d2837afbd4
5 changed files with 23 additions and 20 deletions

View file

@ -4,16 +4,6 @@ moment = require 'moment'
restoreRefs = module.exports.restoreRefs = (model) ->
# tnl function
model.fn '_tnl', '_user.stats.lvl', (lvl) ->
# see https://github.com/lefnire/habitrpg/issues/4
# also update in scoring.coffee. TODO create a function accessible in both locations
#TODO find a method of calling algos.tnl()
if lvl==100
0
else
Math.round(((Math.pow(lvl,2)*0.25)+(10 * lvl) + 139.75)/10)*10
#refLists
_.each ['habit', 'daily', 'todo', 'reward'], (type) ->
model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids"

View file

@ -1,6 +1,7 @@
character = require './character'
browser = require './browser'
items = require './items'
algos = require './algos'
moment = require 'moment'
_ = require 'underscore'
@ -21,6 +22,9 @@ module.exports.username = username = (auth) ->
module.exports.view = (view) ->
view.fn "username", (auth) -> username(auth)
view.fn "tnl", (level) -> algos.tnl(level)
module.exports.app = (appExports, model) ->
user = model.at '_user'

View file

@ -1,4 +1,5 @@
moment = require 'moment'
algos = require './algos'
module.exports.app = (appExports, model) ->
user = model.at('_user')
@ -14,7 +15,7 @@ module.exports.app = (appExports, model) ->
window.location.reload()
appExports.cheat = ->
user.incr 'stats.exp', model.get '_tnl'
user.incr 'stats.exp', algos.tnl(user.get('stats.lvl'))
user.incr 'stats.gp', 1000
appExports.reset = ->

View file

@ -136,7 +136,7 @@ updateStats = (model, newStats, batch) ->
obj.stats.hp = newStats.hp
if newStats.exp?
tnl = model.get '_tnl'
tnl = algos.tnl(obj.stats.lvl)
#silent = false
# if we're at level 100, turn xp to gold
if obj.stats.lvl >= 100

View file

@ -8,13 +8,21 @@
</figure>
<!-- party -->
{#each _partyMembers as :member}
{#unless equal(:member.id, _userId)}
<figure class="party-avatar-wrap" rel="tooltip" title="{username(:member.auth)}" data-placement="bottom">
<app:avatar:avatar profile={:member} party="true" />
{{#each _partyMembers as :member}}
{{#unless equal(:member.id, _userId)}}
<figure class="party-avatar-wrap" rel="tooltip" title="{{username(:member.auth)}}" data-placement="bottom">
<app:avatar:avatar profile={{:member}} party="true" />
<div>
<div class="progress progress-danger" style="height:5px; margin:5px">
<div class="bar" style="height: 5px; width: {percent(:member.stats.hp, 50)}%;"></div>
</div>
<div class="progress progress-warning" style="height:5px; margin:5px">
<div class="bar" style="height: 5px; width: {percent(:member.stats.exp, tnl(:member.stats.lvl))}%;"></div>
</div>
</div>
</figure>
{/}
{/}
{{/}}
{{/}}
<!-- progress bars -->
<div class="progress-bars">
@ -24,12 +32,12 @@
</div>
<div class="progress progress-warning" rel=tooltip data-placement=bottom title="Experience">
<div class="bar" style="width: {percent(_user.stats.exp,_tnl)}%;"></div>
<div class="bar" style="width: {percent(_user.stats.exp,tnl(_user.stats.lvl))}%;"></div>
<span class="progress-text">
{#if _user.history.exp}
<a x-bind=click:toggleChart data-toggle-id="exp-chart" data-history-path="_user.history.exp" rel=tooltip title="Progress"><i class=icon-signal></i></a>&nbsp;
{/}
<i class=icon-star></i> {floor(_user.stats.exp)} / {_tnl}
<i class=icon-star></i> {floor(_user.stats.exp)} / {tnl(_user.stats.lvl)}
</span>
</div>
<div id="exp-chart" style="display:none;"></div>