begin "select pet" functionality

This commit is contained in:
Tyler Renelle 2013-02-11 00:13:44 -05:00
parent 29898b49aa
commit 5d343f3c5f
3 changed files with 73 additions and 16 deletions

View file

@ -22,4 +22,7 @@ module.exports.viewHelpers = (view) ->
view.fn "tokens", (gp) ->
return gp/0.25
view.fn "mod", (a, b) ->
parseInt(a) % parseInt(b) == 0

View file

@ -37,6 +37,26 @@ items = module.exports.items =
potion: {type: 'potion', text: "Potion", notes: "Recover 15 HP", value: 25, classes: 'potion'}
reroll: {type: 'reroll', text: "Re-Roll", classes: 'reroll', notes: "Resets your tasks. When you're struggling and everything's red, use for a clean slate.", value:0 }
pets: [
{index: 0, name: 'bearcub', icon: 'Pet-BearCub-Base.png'}
{index: 1, name: 'cactus', icon: 'Pet-Cactus-Base.png'}
{index: 2, name: 'dragon', icon: 'Pet-Dragon-Base.png'}
{index: 3, name: 'flyingpig', icon: 'Pet-FlyingPig-Base.png'}
{index: 4, name: 'fox', icon: 'Pet-Fox-Base.png'}
{index: 5, name: 'lioncub', icon: 'Pet-LionCub-Base.png'}
{index: 6, name: 'pandacub', icon: 'Pet-PandaCub-Base.png'}
{index: 7, name: 'tigercub', icon: 'Pet-TigerCub-Base.png'}
{index: 8, name: 'wolfDesert', icon: 'Pet-Wolf-Desert.png'}
{index: 9, name: 'wolfGolden', icon: 'Pet-Wolf-Golden.png'}
{index: 10, name: 'wolfRed', icon: 'Pet-Wolf-Red.png'}
{index: 11, name: 'wolfShade', icon: 'Pet-Wolf-Shade.png'}
{index: 12, name: 'wolfSkeleton', icon: 'Pet-Wolf-Skeleton.png'}
{index: 13, name: 'wolfVeteran', icon: 'Pet-Wolf-Veteran.png'}
{index: 14, name: 'wolfWhite', icon: 'Pet-Wolf-White.png'}
{index: 15, name: 'wolfZombie', icon: 'Pet-Wolf-Zombie.png'}
{index: 16, name: 'wolfBorder', icon: 'wolf_border.png'}
]
# 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
@ -121,6 +141,23 @@ module.exports.app = (appExports, model) ->
hp = 50 if hp > 50
user.set 'stats.hp', hp
appExports.selectPet = (e, el) ->
name = $(el).attr('data-pet')
pet = _.find items.pets, (p) -> p.name == name
debugger
if user.get "items.pets.#{name}"
user.set 'items.pet', pet
else
tokens = user.get('balance')*4
if tokens < 2
alert "Not enough tokens"
return
r = confirm("Buy this pet with 2 of your #{tokens} tokens?");
if r
user.set "items.pets.#{name}",true
user.set 'items.pet', pet
user.set 'balance', (tokens - 2) / 4
user.on 'set', 'flags.itemsEnabled', (captures, args) ->
return unless captures == true
html = """
@ -151,6 +188,7 @@ module.exports.updateStore = updateStore = (model) ->
model.set '_view.items.potion', items.potion
model.set '_view.items.reroll', items.reroll
model.set '_view.items.pets', items.pets

View file

@ -374,30 +374,42 @@ do a find for the string after "→"
</div>
<div class="tab-pane" id="pets-tab">
{#with _view.items.pets as :pets}
<div class="row-fluid">
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-BearCub-Base.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Cactus-Base.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Dragon-Base.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-FlyingPig-Base.png'/></div>
{#with :pets[0]}<app:pet />{/}
{#with :pets[1]}<app:pet />{/}
{#with :pets[2]}<app:pet />{/}
{#with :pets[3]}<app:pet />{/}
</div>
<div class="row-fluid">
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-LionCub-Base.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-PandaCub-Base.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-TigerCub-Base.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Wolf-Desert.png'/></div>
{#with :pets[4]}<app:pet />{/}
{#with :pets[5]}<app:pet />{/}
{#with :pets[6]}<app:pet />{/}
{#with :pets[7]}<app:pet />{/}
</div>
<div class="row-fluid">
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Wolf-Golden.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Wolf-Red.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Wolf-Shade.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Wolf-Skeleton.png'/></div>
{#with :pets[8]}<app:pet />{/}
{#with :pets[9]}<app:pet />{/}
{#with :pets[10]}<app:pet />{/}
{#with :pets[11]}<app:pet />{/}
</div>
<div class="row-fluid">
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Wolf-Veteran.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Wolf-White.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/Pet-Wolf-Zombie.png'/></div>
<div class="span3"><img src='img/BrowserQuest/habitrpg_mods/wolf_border.png'/></div>
{#with :pets[12]}<app:pet />{/}
{#with :pets[13]}<app:pet />{/}
{#with :pets[14]}<app:pet />{/}
{#with :pets[15]}<app:pet />{/}
</div>
<div class="row-fluid">
{#with :pets[16]}<app:pet />{/}
</div>
{/}
</div>
<div class="tab-pane" id="mounts-tab">...</div>
</div>
@ -455,6 +467,9 @@ do a find for the string after "→"
</div>
</div>
</footer>
<pet:>
<div class="span3"><img x-bind="click:selectPet" data-pet='{.name}' src='img/BrowserQuest/habitrpg_mods/{.icon}'/></div>
<!-- $modal-template -->
@ -602,6 +617,7 @@ do a find for the string after "→"
<!-- $avatar-template -->
<avatar:>
<div class="avatar {{#if @main}}main-avatar{{/}} {{#if @party}}party-avatar{{/}}" data-toggle='{{#if @main}}modal{{/}}' data-target='{{#if @main}}#customizations-modal{{/}}'>
{#if _user.items.pet}<img src='img/BrowserQuest/habitrpg_mods/{_user.items.pet.icon}' />{/}
<div class='character-sprites'>
{#with @profile.preferences as :p}
<span class='{:p.gender}_skin_{:p.skin}'></span>