Merge branch 'inventory' of github.com:switz/habitrpg into switz-inventory

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
This commit is contained in:
Tyler Renelle 2013-03-09 11:04:54 -05:00
commit 8ecf3eacc0
7 changed files with 39 additions and 5 deletions

View file

@ -8,6 +8,16 @@ module.exports.daysBetween = (yesterday, now, dayStart) ->
module.exports.dayMapping = dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'}
# http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object
# obj: object
# returns random property (the value)
module.exports.randomProp = (obj) ->
result = undefined
count = 0
for key, val of obj
result = val if Math.random() < (1 / ++count)
result
module.exports.viewHelpers = (view) ->
view.fn "percent", (x, y) ->

View file

@ -50,6 +50,11 @@ items = module.exports.items =
{text: 'Bear Cub', name: 'BearCub', value: 3}
]
meats: [
{index: 0, name: 'Red Meat', text: 'Turns your animal into a mean red meat eater.'}
{index: 1, name: 'Blue Meat', text: 'Turns your animal into Neo.' }
]
# add "type" to each item, so we can reference that as "weapon" or "armor" in the html
_.each ['weapon', 'armor', 'head', 'shield'], (key) ->
_.each items[key], (item) -> item.type = key

View file

@ -1,3 +1,6 @@
{ randomProp } = require './helpers'
{ pets } = require('./items').items
###
app exports
###
@ -5,7 +8,12 @@ module.exports.app = (appExports, model) ->
user = model.at '_user'
user.on 'set', 'flags.dropsEnabled', (captures, args) ->
console.log 'hi!'
return unless captures == true
egg = randomProp pets
user.push 'items.eggs', egg.name
user.set 'items.egg', egg
# do drops enabled stuff
$('#dropsEnabled-modal').show()

View file

@ -159,7 +159,7 @@ updateStats = (model, newStats, batch) ->
obj.stats.exp = newStats.exp
#if silent
#console.log("pushing silent :" + obj.stats.exp)
#user.pass(true).set('stats.exp', obj.stats.exp)
#user.pass(true).set('stats.exp', obj.stats.exp)
# Set flags when they unlock features
if !obj.flags.customizationsNotification and (obj.stats.exp > 10 or obj.stats.lvl > 1)

View file

@ -181,6 +181,11 @@
<inventory:>
<div class='row-fluid'>
<div class='span6 well'>
testing
{#if not(_user.items.meats)}
<p>You don't have any meat yet.</p>
{/if}
{#each _user.items.meats as :meat}
{:meat}
{/each}
</div>
</div>

View file

@ -3,6 +3,7 @@
<app:avatar:modals />
<app:settings:modals />
<app:party:modals />
<app:pets:modals />
<!-- Game Over Modal -->
<div style="{#unless equal(_user.stats.lvl,0)}display:none;{/}">

View file

@ -1,5 +1,10 @@
<modal:>
<modals:>
<app:modals:modal modalId='dropsEnabled-modal' header="Drops Enabled!">
<app:userTokens/>
<p>Highly discouraged because red tasks provide good incentive to improve (<a target="_blank" href="https://github.com/lefnire/habitrpg#all-my-tasks-are-red-im-dying-too-fast">read more</a>). However, this becomes necessary after long bouts of bad habits.</p>
<p>You've unlocked the drop system.</p>
<p>Here's your first egg! {_user.items.egg.name}</p>
<p>Feed it some meat to get it to hatch.</p>
<@footer>
<button data-dismiss="modal" class="btn btn-success">Ok</button>
</@footer>
</app:modals:modal>