2014-11-06 19:23:23 -05:00
ModalView = require ' views/kinds/ModalView '
template = require ' templates/game-menu/inventory-modal '
2014-08-08 14:36:41 -04:00
{ me } = require ' lib/auth '
ThangType = require ' models/ThangType '
2014-08-13 20:21:37 -04:00
CocoCollection = require ' collections/CocoCollection '
ItemView = require ' ./ItemView '
2014-09-21 02:06:28 -04:00
SpriteBuilder = require ' lib/sprites/SpriteBuilder '
2014-11-10 18:24:05 -05:00
ItemDetailsView = require ' views/play/modal/ItemDetailsView '
Purchase = require ' models/Purchase '
2014-11-10 19:09:41 -05:00
LevelOptions = require ' lib/LevelOptions '
2014-08-13 20:21:37 -04:00
2014-11-06 19:23:23 -05:00
hasGoneFullScreenOnce = false
module.exports = class InventoryModal extends ModalView
id: ' inventory-modal '
className: ' modal fade play-modal '
2014-08-08 14:36:41 -04:00
template: template
2014-10-21 16:57:49 -04:00
slots: [ ' head ' , ' eyes ' , ' neck ' , ' torso ' , ' wrists ' , ' gloves ' , ' left-ring ' , ' right-ring ' , ' right-hand ' , ' left-hand ' , ' waist ' , ' feet ' , ' programming-book ' , ' pet ' , ' minion ' , ' flag ' ] #, 'misc-0', 'misc-1'] # TODO: bring in misc slot(s) again when we have space
2014-11-10 18:24:05 -05:00
closesOnClickOutside: false # because draggable somehow triggers hide when you don't drag onto a draggable
2014-08-14 18:09:10 -04:00
2014-08-13 20:21:37 -04:00
events:
' click .item-slot ' : ' onItemSlotClick '
2014-11-18 16:02:01 -05:00
' click # unequipped .item ' : ' onUnequippedItemClick '
' doubletap # unequipped .item ' : ' onUnequippedItemDoubleClick '
' doubletap .item-slot .item ' : ' onEquippedItemDoubleClick '
' click button.equip-item ' : ' onClickEquipItemButton '
2014-11-06 19:23:23 -05:00
' shown.bs.modal ' : ' onShown '
' click # choose-hero-button ' : ' onClickChooseHero '
' click # play-level-button ' : ' onClickPlayLevel '
2014-11-10 18:24:05 -05:00
' click .unlock-button ' : ' onUnlockButtonClicked '
' click # equip-item-viewed ' : ' onClickEquipItemViewed '
' click # unequip-item-viewed ' : ' onClickUnequipItemViewed '
' click # close-modal ' : ' hide '
2014-09-21 02:06:28 -04:00
2014-08-13 20:21:37 -04:00
shortcuts:
' esc ' : ' clearSelection '
2014-11-06 19:23:23 -05:00
' enter ' : ' onClickPlayLevel '
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
#- Setup
2014-08-14 18:09:10 -04:00
2014-08-13 20:21:37 -04:00
initialize: (options) ->
super ( arguments . . . )
2014-08-14 18:09:10 -04:00
@items = new CocoCollection ( [ ] , { model: ThangType } )
2014-11-10 18:24:05 -05:00
# TODO: switch to item store loading system?
@items.url = ' /db/thang.type?view=items '
@ items . setProjection [
2014-11-11 01:07:55 -05:00
' name '
' slug '
' components '
' original '
' rasterIcon '
' gems '
' tier '
' description '
' heroClass '
2014-11-10 18:24:05 -05:00
' i18n '
]
2014-08-13 20:21:37 -04:00
@ supermodel . loadCollection ( @ items , ' items ' )
2014-11-10 19:09:41 -05:00
@equipment = { } # Assign for real when we have loaded the session and items.
2014-09-21 02:06:28 -04:00
2014-11-10 18:24:05 -05:00
onItemsLoaded: ->
2014-11-10 19:09:41 -05:00
item.notInLevel = true for item in @ items . models
@equipment = @ options . equipment or @ options . session ? . get ( ' heroConfig ' ) ? . inventory or me . get ( ' heroConfig ' ) ? . inventory or { }
@equipment = $ . extend true , { } , @ equipment
2014-11-10 18:24:05 -05:00
@ requireLevelEquipment ( )
@itemGroups = { }
@itemGroups.availableItems = new Backbone . Collection ( )
@itemGroups.restrictedItems = new Backbone . Collection ( )
@itemGroups.lockedItems = new Backbone . Collection ( )
2014-11-17 11:25:27 -05:00
itemGroup.comparator = ( (m) -> m . get ( ' gems ' ) ? m . get ( ' tier ' ) ) for itemGroup in _ . values @ itemGroups
2014-11-10 18:24:05 -05:00
equipped = _ . values ( @ equipment )
@ sortItem ( item , equipped ) for item in @ items . models
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
sortItem: (item, equipped) ->
equipped ? = _ . values ( @ equipment )
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
# general starting classes
item.classes = _ . clone ( item . getAllowedSlots ( ) )
for heroClass in item . getAllowedHeroClasses ( )
item . classes . push heroClass
item . classes . push ' equipped ' if item . get ( ' original ' ) in equipped
# sort into one of the four groups
2014-11-10 19:09:41 -05:00
locked = not ( item . get ( ' original ' ) in me . items ( ) )
2014-11-20 23:06:59 -05:00
locked = false if me . get ( ' slug ' ) is ' nick '
2014-11-10 18:24:05 -05:00
2014-11-19 16:23:55 -05:00
if not item . getFrontFacingStats ( ) . props . length and not _ . size ( item . getFrontFacingStats ( ) . stats ) and not locked # Temp: while there are placeholder items
2014-11-18 22:37:08 -05:00
null # Don't put into a collection
else if locked and item . get ( ' slug ' ) isnt ' simple-boots '
2014-11-10 18:24:05 -05:00
@ itemGroups . lockedItems . add ( item )
item . classes . push ' locked '
item . classes . push ' silhouette ' if item . isSilhouettedItem ( )
2014-11-17 11:25:27 -05:00
item . classes . push ' hidden ' unless item . get ( ' gems ' )
2014-11-10 19:09:41 -05:00
else if item . get ( ' slug ' ) in _ . values ( LevelOptions [ @ options . levelID ] ? . restrictedGear ? { } )
2014-11-10 18:24:05 -05:00
@ itemGroups . restrictedItems . add ( item )
item . classes . push ' restricted '
else
@ itemGroups . availableItems . add ( item )
2014-11-10 19:09:41 -05:00
2014-08-13 20:21:37 -04:00
onLoaded: ->
2014-11-10 19:09:41 -05:00
# Both items and session have been loaded.
@ onItemsLoaded ( )
2014-08-13 20:21:37 -04:00
super ( )
2014-08-08 14:36:41 -04:00
getRenderData: (context={}) ->
context = super ( context )
2014-08-13 20:21:37 -04:00
context.equipped = _ . values ( @ equipment )
2014-08-14 18:09:10 -04:00
context.items = @ items . models
2014-11-10 18:24:05 -05:00
context.itemGroups = @ itemGroups
2014-08-13 20:21:37 -04:00
context.slots = @ slots
2014-11-10 18:24:05 -05:00
context.selectedHero = @ selectedHero
2014-08-13 20:21:37 -04:00
context.equipment = _ . clone @ equipment
2014-11-10 18:24:05 -05:00
context . equipment [ slot ] = @ items . findWhere { original: itemOriginal } for slot , itemOriginal of context . equipment
context.gems = me . gems ( )
2014-08-08 14:36:41 -04:00
context
afterRender: ->
super ( )
2014-11-10 19:09:41 -05:00
@ $el . find ( ' # play-level-button ' ) . css ( ' visibility ' , ' hidden ' )
2014-08-13 20:21:37 -04:00
return unless @ supermodel . finished ( )
2014-11-10 19:09:41 -05:00
@ $el . find ( ' # play-level-button ' ) . css ( ' visibility ' , ' visible ' )
2014-11-10 18:24:05 -05:00
@ setUpDraggableEventsForAvailableEquipment ( )
@ setUpDraggableEventsForEquippedArea ( )
@ delegateEvents ( )
@itemDetailsView = new ItemDetailsView ( )
@ insertSubView ( @ itemDetailsView )
@ requireLevelEquipment ( )
2014-11-12 21:01:35 -05:00
@ $el . find ( ' .nano ' ) . nanoScroller ( { alwaysVisible: true } )
2014-11-18 16:20:51 -05:00
@ onSelectionChanged ( )
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
afterInsert: ->
super ( )
@canvasWidth = @ $el . find ( ' canvas ' ) . innerWidth ( )
@canvasHeight = @ $el . find ( ' canvas ' ) . innerHeight ( )
@inserted = true
@ requireLevelEquipment ( )
#- Draggable logic
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
setUpDraggableEventsForAvailableEquipment: ->
2014-11-18 16:02:01 -05:00
for availableItemEl in @ $el . find ( ' # unequipped .item ' )
2014-11-10 18:24:05 -05:00
availableItemEl = $ ( availableItemEl )
continue if availableItemEl . hasClass ( ' locked ' ) or availableItemEl . hasClass ( ' restricted ' )
dragHelper = availableItemEl . clone ( ) . addClass ( ' draggable-item ' )
do (dragHelper, availableItemEl) =>
availableItemEl . draggable
2014-09-21 02:06:28 -04:00
revert: ' invalid '
appendTo: @ $el
cursorAt: { left: 35.5 , top: 35.5 }
helper: -> dragHelper
revertDuration: 200
2014-09-21 23:19:27 -04:00
distance: 10
2014-09-21 02:06:28 -04:00
scroll: false
2014-11-10 18:24:05 -05:00
zIndex: 1100
availableItemEl . on ' dragstart ' , => @ selectUnequippedItem ( availableItemEl )
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
setUpDraggableEventsForEquippedArea: ->
2014-09-21 02:06:28 -04:00
for itemSlot in @ $el . find ' .item-slot '
slot = $ ( itemSlot ) . data ' slot '
2014-10-09 18:54:18 -04:00
do (slot, itemSlot) =>
2014-09-21 02:06:28 -04:00
$ ( itemSlot ) . droppable
2014-11-10 18:24:05 -05:00
drop: (e, ui) => @ equipSelectedItem ( )
2014-09-21 02:06:28 -04:00
accept: (el) -> $ ( el ) . parent ( ) . hasClass slot
activeClass: ' droppable '
hoverClass: ' droppable-hover '
2014-09-21 14:24:37 -04:00
tolerance: ' touch '
2014-10-09 18:54:18 -04:00
@ makeEquippedSlotDraggable $ ( itemSlot )
2014-08-14 18:09:10 -04:00
2014-11-10 18:24:05 -05:00
@ $el . find ( ' # equipped ' ) . droppable
drop: (e, ui) => @ equipSelectedItem ( )
2014-10-27 14:17:34 -04:00
accept: (el) -> true
activeClass: ' droppable '
hoverClass: ' droppable-hover '
tolerance: ' pointer '
2014-11-10 19:09:41 -05:00
2014-10-09 18:54:18 -04:00
makeEquippedSlotDraggable: (slot) ->
2014-11-10 21:13:04 -05:00
unequip = =>
@ unequipItemFromSlot slot
@ requireLevelEquipment ( )
2014-10-09 18:54:18 -04:00
shouldStayEquippedWhenDropped = (isValidDrop) ->
pos = $ ( @ ) . position ( )
revert = Math . abs ( pos . left ) < $ ( @ ) . outerWidth ( ) and Math . abs ( pos . top ) < $ ( @ ) . outerHeight ( )
unequip ( ) if not revert
revert
# TODO: figure out how to make this actually above the available items list (the .ui-draggable-helper img is still inside .item-view and so underlaps...)
$ ( slot ) . find ( ' img ' ) . draggable
revert: shouldStayEquippedWhenDropped
appendTo: @ $el
cursorAt: { left: 35.5 , top: 35.5 }
revertDuration: 200
distance: 10
scroll: false
2014-11-10 18:24:05 -05:00
zIndex: 100
slot . on ' dragstart ' , => @ selectItemSlot ( slot )
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
#- Select/equip event handlers
2014-08-13 20:21:37 -04:00
onItemSlotClick: (e) ->
2014-11-05 17:17:11 -05:00
return if @ remainingRequiredEquipment ? . length # Don't let them select a slot if we need them to first equip some require gear.
2014-11-10 18:24:05 -05:00
@ selectItemSlot ( $ ( e . target ) . closest ( ' .item-slot ' ) )
onUnequippedItemClick: (e) ->
return if @ justDoubleClicked
2014-11-18 16:02:01 -05:00
itemEl = $ ( e . target ) . closest ( ' .item ' )
2014-11-10 18:24:05 -05:00
@ selectUnequippedItem ( itemEl )
onUnequippedItemDoubleClick: (e) ->
2014-11-18 16:02:01 -05:00
itemEl = $ ( e . target ) . closest ( ' .item ' )
return if itemEl . hasClass ( ' locked ' ) or itemEl . hasClass ( ' restricted ' )
2014-11-10 18:24:05 -05:00
@ equipSelectedItem ( )
@justDoubleClicked = true
_ . defer => @justDoubleClicked = false
onEquippedItemDoubleClick: -> @ unequipSelectedItem ( )
onClickEquipItemViewed: -> @ equipSelectedItem ( )
onClickUnequipItemViewed: -> @ unequipSelectedItem ( )
2014-11-10 19:09:41 -05:00
2014-11-18 16:02:01 -05:00
onClickEquipItemButton: (e) ->
itemEl = $ ( e . target ) . closest ( ' .item ' )
@ selectUnequippedItem ( itemEl )
@ equipSelectedItem ( )
2014-11-10 18:24:05 -05:00
onUnlockButtonClicked: (e) ->
button = $ ( e . target ) . closest ( ' button ' )
if button . hasClass ( ' confirm ' )
item = @ items . get ( $ ( e . target ) . data ( ' item-id ' ) )
purchase = Purchase . makeFor ( item )
purchase . save ( )
#- set local changes to mimic what should happen on the server...
purchased = me . get ( ' purchased ' ) ? { }
purchased . items ? = [ ]
purchased . items . push ( item . get ( ' original ' ) )
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
me . set ( ' purchased ' , purchased )
me . set ( ' spent ' , ( me . get ( ' spent ' ) ? 0 ) + item . get ( ' gems ' ) )
#- ...then rerender key bits
@ requireLevelEquipment ( )
@ itemGroups . lockedItems . remove ( item )
@ sortItem ( item )
@ renderSelectors ( " # unequipped " , " # gems-count " )
@ delegateEvents ( )
@ setUpDraggableEventsForAvailableEquipment ( )
@ itemDetailsView . setItem ( item )
2014-11-21 19:23:26 -05:00
Backbone . Mediator . publish ' store:item-purchased ' , item: item , itemSlug: item . get ( ' slug ' )
2014-09-21 12:53:58 -04:00
else
2014-11-10 18:24:05 -05:00
button . addClass ( ' confirm ' ) . text ( $ . i18n . t ( ' play.confirm ' ) )
@ $el . one ' click ' , (e) ->
button . removeClass ( ' confirm ' ) . text ( $ . i18n . t ( ' play.unlock ' ) ) if e . target isnt button [ 0 ]
#- Select/equip higher-level, all encompassing methods the callbacks all use
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
selectItemSlot: (slotEl) ->
@ clearSelection ( )
slotEl . addClass ( ' selected ' )
2014-11-18 16:02:01 -05:00
selectedSlotItemID = slotEl . find ( ' .item ' ) . data ( ' item-id ' )
2014-11-10 18:24:05 -05:00
item = @ items . get ( selectedSlotItemID )
if item then @ showItemDetails ( item , ' unequip ' )
2014-08-13 20:21:37 -04:00
@ onSelectionChanged ( )
2014-08-14 18:09:10 -04:00
2014-11-10 18:24:05 -05:00
selectUnequippedItem: (itemEl) ->
@ clearSelection ( )
itemEl . addClass ( ' active ' )
showExtra = if itemEl . hasClass ( ' restricted ' ) then ' restricted ' else if not itemEl . hasClass ( ' locked ' ) then ' equip ' else ' '
@ showItemDetails ( @ items . get ( itemEl . data ( ' item-id ' ) ) , showExtra )
2014-08-13 20:21:37 -04:00
@ onSelectionChanged ( )
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
equipSelectedItem: ->
selectedItemEl = @ getSelectedUnequippedItem ( )
selectedItem = @ items . get ( selectedItemEl . data ( ' item-id ' ) )
return unless selectedItem
allowedSlots = selectedItem . getAllowedSlots ( )
slotEl = @ $el . find ( " .item-slot[data-slot= ' #{ allowedSlots [ 0 ] } ' ] " )
selectedItemEl . effect ( ' transfer ' , to: slotEl , duration: 500 , easing: ' easeOutCubic ' )
unequipped = @ unequipItemFromSlot ( slotEl )
selectedItemEl . addClass ( ' equipped ' )
2014-11-18 16:02:01 -05:00
slotEl . append ( selectedItemEl . find ( ' img ' ) . clone ( ) . addClass ( ' item ' ) . data ( ' item-id ' , selectedItem . id ) )
2014-11-10 18:24:05 -05:00
@ clearSelection ( )
@ showItemDetails ( selectedItem , ' unequip ' )
slotEl . addClass ( ' selected ' )
selectedItem . classes . push ' equipped '
@ makeEquippedSlotDraggable slotEl
@ requireLevelEquipment ( )
2014-08-13 20:21:37 -04:00
@ onSelectionChanged ( )
2014-08-14 18:09:10 -04:00
2014-11-10 18:24:05 -05:00
unequipSelectedItem: ->
slotEl = @ getSelectedSlot ( )
@ clearSelection ( )
itemEl = @ unequipItemFromSlot ( slotEl )
return unless itemEl
itemEl . addClass ( ' active ' )
slotEl . effect ( ' transfer ' , to: itemEl , duration: 500 , easing: ' easeOutCubic ' )
selectedSlotItemID = itemEl . data ( ' item-id ' )
item = @ items . get ( selectedSlotItemID )
item.classes = _ . without item . classes , ' equipped '
@ showItemDetails ( item , ' equip ' )
@ requireLevelEquipment ( )
2014-08-14 16:41:32 -04:00
@ onSelectionChanged ( )
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
#- Select/equip helpers
clearSelection: ->
@ deselectAllSlots ( )
@ deselectAllUnequippedItems ( )
@ hideItemDetails ( )
2014-08-14 18:09:10 -04:00
2014-11-10 18:24:05 -05:00
unequipItemFromSlot: (slotEl) ->
2014-11-18 16:02:01 -05:00
itemEl = slotEl . find ( ' .item ' )
2014-11-10 18:24:05 -05:00
itemIDToUnequip = itemEl . data ( ' item-id ' )
return unless itemIDToUnequip
itemEl . remove ( )
2014-11-18 16:02:01 -05:00
@ $el . find ( " # unequipped .item[data-item-id= #{ itemIDToUnequip } ] " ) . removeClass ( ' equipped ' )
2014-08-14 18:09:10 -04:00
2014-11-10 18:24:05 -05:00
deselectAllSlots: ->
2014-09-21 02:06:28 -04:00
@ $el . find ( ' # equipped .item-slot.selected ' ) . removeClass ( ' selected ' )
2014-08-14 18:09:10 -04:00
2014-11-10 18:24:05 -05:00
deselectAllUnequippedItems: ->
2014-11-18 16:02:01 -05:00
@ $el . find ( ' # unequipped .item ' ) . removeClass ( ' active ' )
2014-08-14 18:09:10 -04:00
2014-08-14 16:41:32 -04:00
getSlot: (name) ->
@ $el . find ( " .item-slot[data-slot= #{ name } ] " )
2014-08-14 18:09:10 -04:00
2014-11-10 18:24:05 -05:00
getSelectedSlot: ->
@ $el . find ( ' # equipped .item-slot.selected ' )
2014-08-14 18:09:10 -04:00
2014-11-10 18:24:05 -05:00
getSelectedUnequippedItem: ->
2014-11-18 16:02:01 -05:00
@ $el . find ( ' # unequipped .item.active ' )
2014-08-14 18:09:10 -04:00
2014-08-13 20:21:37 -04:00
onSelectionChanged: ->
2014-11-18 16:20:51 -05:00
heroClass = @ selectedHero ? . get ( ' heroClass ' )
itemsCanBeEquipped = @ $el . find ( ' # unequipped .item.available:not(.equipped) ' ) . filter ( ' . ' + heroClass ) . length
toShow = @ $el . find ( ' # double-click-hint, # available-description ' )
if itemsCanBeEquipped then toShow . removeClass ( ' secret ' ) else toShow . addClass ( ' secret ' )
2014-08-13 20:21:37 -04:00
@ delegateEvents ( )
2014-08-14 18:09:10 -04:00
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
showItemDetails: (item, showExtra) ->
@ itemDetailsView . setItem ( item )
@ $el . find ( ' # item-details-extra > * ' ) . addClass ( ' secret ' )
@ $el . find ( " # #{ showExtra } -item-viewed " ) . removeClass ( ' secret ' )
2014-11-10 19:09:41 -05:00
2014-11-10 18:24:05 -05:00
hideItemDetails: ->
@ itemDetailsView . setItem ( null )
@ $el . find ( ' # item-details-extra > * ' ) . addClass ( ' secret ' )
2014-08-13 20:21:37 -04:00
getCurrentEquipmentConfig: ->
config = { }
for slot in @ $el . find ( ' .item-slot ' )
slotName = $ ( slot ) . data ( ' slot ' )
2014-11-18 16:02:01 -05:00
slotItemID = $ ( slot ) . find ( ' .item ' ) . data ( ' item-id ' )
2014-08-13 20:21:37 -04:00
continue unless slotItemID
item = _ . find @ items . models , { id : slotItemID }
config [ slotName ] = item . get ( ' original ' )
2014-08-14 18:09:10 -04:00
config
2014-10-09 18:54:18 -04:00
requireLevelEquipment: ->
2014-11-05 23:56:17 -05:00
# This is temporary, until we have a more general way of awarding items and configuring required/restricted items per level.
2014-11-10 19:09:41 -05:00
requiredGear = LevelOptions [ @ options . levelID ] ? . requiredGear ? { }
restrictedGear = LevelOptions [ @ options . levelID ] ? . restrictedGear ? { }
2014-10-09 22:59:57 -04:00
if @ inserted
if @ supermodel . finished ( )
equipment = @ getCurrentEquipmentConfig ( ) # Make sure @equipment is updated
else
equipment = @ equipment
hadRequired = @ remainingRequiredEquipment ? . length
@remainingRequiredEquipment = [ ]
@ $el . find ( ' .should-equip ' ) . removeClass ( ' should-equip ' )
inWorldMap = $ ( ' # world-map-view ' ) . length
2014-11-11 19:36:44 -05:00
if heroClass = @ selectedHero ? . get ( ' heroClass ' )
for slot , item of _ . clone equipment
itemModel = @ items . findWhere original: item
unless itemModel and heroClass in itemModel . classes
console . log ' Unequipping ' , itemModel . get ( ' heroClass ' ) , ' item ' , itemModel . get ( ' name ' ) , ' from slot due to class restrictions. '
@ unequipItemFromSlot @ $el . find ( " .item-slot[data-slot= ' #{ slot } ' ] " )
2014-11-21 15:20:24 -05:00
delete equipment [ slot ]
2014-11-05 23:56:17 -05:00
for slot , item of restrictedGear
equipped = equipment [ slot ]
if equipped and equipped is gear [ restrictedGear [ slot ] ]
console . log ' Unequipping restricted item ' , restrictedGear [ slot ] , ' for ' , slot , ' before level ' , @ options . levelID
@ unequipItemFromSlot @ $el . find ( " .item-slot[data-slot= ' #{ slot } ' ] " )
2014-11-21 15:20:24 -05:00
delete equipment [ slot ]
2014-11-11 19:36:44 -05:00
if heroClass is ' Warrior '
# After they switch to a ranger or wizard, we stop being so finicky about gear.
for slot , item of requiredGear
2014-11-21 19:23:26 -05:00
continue if item is ' tarnished-bronze-breastplate ' and inWorldMap and @ options . levelID is ' the-raised-sword ' # Don't tell them they need it until they need it in the level
2014-11-11 19:36:44 -05:00
equipped = equipment [ slot ]
continue if equipped and not (
2014-11-17 12:20:44 -05:00
( item is ' crude-builders-hammer ' and equipped in [ gear [ ' simple-sword ' ] , gear [ ' long-sword ' ] , gear [ ' sharpened-sword ' ] , gear [ ' roughedge ' ] ] ) or
( item in [ ' simple-sword ' , ' long-sword ' , ' roughedge ' , ' sharpened-sword ' ] and equipped is gear [ ' crude-builders-hammer ' ] ) or
2014-11-11 19:36:44 -05:00
( item is ' leather-boots ' and equipped is gear [ ' simple-boots ' ] ) or
( item is ' simple-boots ' and equipped is gear [ ' leather-boots ' ] )
)
itemModel = @ items . findWhere { slug: item }
continue unless itemModel
availableSlotSelector = " # unequipped .item[data-item-id= ' #{ itemModel . id } ' ] "
@ highlightElement availableSlotSelector , delay: 500 , sides: [ ' right ' ] , rotation: Math . PI / 2
@ $el . find ( availableSlotSelector ) . addClass ' should-equip '
@ $el . find ( " # equipped div[data-slot= ' #{ slot } ' ] " ) . addClass ' should-equip '
@ remainingRequiredEquipment . push slot: slot , item: gear [ item ]
2014-10-09 22:59:57 -04:00
if hadRequired and not @ remainingRequiredEquipment . length
@ endHighlight ( )
2014-11-10 19:09:41 -05:00
@ highlightElement ' # play-level-button ' , duration: 5000
2014-10-09 22:59:57 -04:00
$ ( ' # play-level-button ' ) . prop ( ' disabled ' , @ remainingRequiredEquipment . length > 0 )
2014-09-22 23:44:45 -04:00
2014-11-10 18:24:05 -05:00
setHero: (@selectedHero) ->
2014-11-11 19:36:44 -05:00
if @ selectedHero . loading
@ listenToOnce @ selectedHero , ' sync ' , => @ setHero ? @ selectedHero
return
2014-11-10 21:13:04 -05:00
@ $el . removeClass ( ' Warrior Ranger Wizard ' ) . addClass ( @ selectedHero . get ( ' heroClass ' ) )
2014-11-11 19:36:44 -05:00
@ requireLevelEquipment ( )
2014-11-10 18:24:05 -05:00
@ render ( )
2014-09-21 02:06:28 -04:00
onShown: ->
# Called when we switch tabs to this within the modal
2014-10-09 18:54:18 -04:00
@ requireLevelEquipment ( )
2014-09-21 02:06:28 -04:00
2014-08-14 18:09:10 -04:00
onHidden: ->
2014-09-21 02:06:28 -04:00
# Called when the modal itself is dismissed
2014-10-09 18:54:18 -04:00
@ endHighlight ( )
2014-11-09 19:19:18 -05:00
super ( )
2014-11-05 23:56:17 -05:00
2014-11-06 19:23:23 -05:00
onClickChooseHero: ->
@ hide ( )
@ trigger ' choose-hero-click '
onClickPlayLevel: (e) ->
return if @ $el . find ( ' # play-level-button ' ) . prop ' disabled '
@ showLoading ( )
ua = navigator . userAgent . toLowerCase ( )
unless hasGoneFullScreenOnce or ( /safari/ . test ( ua ) and not /chrome/ . test ( ua ) ) or $ ( window ) . height ( ) >= 658 # Min vertical resolution needed at 1366px wide
@ toggleFullscreen ( )
hasGoneFullScreenOnce = true
@ updateConfig =>
2014-11-13 13:49:37 -05:00
@ trigger ? ' play-click '
2014-11-20 23:31:17 -05:00
window . tracker ? . trackEvent ' Play Level Modal ' , Action: ' Play ' , [ ' Google Analytics ' ]
2014-11-10 19:09:41 -05:00
2014-11-06 19:23:23 -05:00
updateConfig: (callback, skipSessionSave) ->
sessionHeroConfig = @ options . session . get ( ' heroConfig ' ) ? { }
lastHeroConfig = me . get ( ' heroConfig ' ) ? { }
inventory = @ getCurrentEquipmentConfig ( )
patchSession = patchMe = false
patchSession || = not _ . isEqual inventory , sessionHeroConfig . inventory
sessionHeroConfig.inventory = inventory
2014-11-11 19:36:44 -05:00
if hero = @ selectedHero . get ( ' original ' )
patchSession || = not _ . isEqual hero , sessionHeroConfig . thangType
sessionHeroConfig.thangType = hero
patchMe || = not _ . isEqual inventory , lastHeroConfig . inventory
2014-11-06 19:23:23 -05:00
lastHeroConfig.inventory = inventory
if patchMe
console . log ' setting me.heroConfig to ' , JSON . stringify ( lastHeroConfig )
me . set ' heroConfig ' , lastHeroConfig
me . patch ( )
if patchSession
console . log ' setting session.heroConfig to ' , JSON . stringify ( sessionHeroConfig )
@ options . session . set ' heroConfig ' , sessionHeroConfig
@ options . session . patch success: callback unless skipSessionSave
else
callback ? ( )
2014-11-05 23:56:17 -05:00
2014-11-10 18:24:05 -05:00
destroy: ->
@ stage ? . removeAllChildren ( )
super ( )
2014-11-05 23:56:17 -05:00
gear =
' simple-boots ' : ' 53e237bf53457600003e3f05 '
' simple-sword ' : ' 53e218d853457600003e3ebe '
2014-11-21 19:23:26 -05:00
' tarnished-bronze-breastplate ' : ' 53e22eac53457600003e3efc '
2014-11-05 23:56:17 -05:00
' leather-boots ' : ' 53e2384453457600003e3f07 '
' leather-belt ' : ' 5437002a7beba4a82024a97d '
' programmaticon-i ' : ' 53e4108204c00d4607a89f78 '
' crude-glasses ' : ' 53e238df53457600003e3f0b '
2014-11-17 12:20:44 -05:00
' crude-builders-hammer ' : ' 53f4e6e3d822c23505b74f42 '
2014-11-08 22:33:00 -05:00
' long-sword ' : ' 544d7d1f8494308424f564a3 '
' sundial-wristwatch ' : ' 53e2396a53457600003e3f0f '
' bronze-shield ' : ' 544c310ae0017993fce214bf '
' wooden-glasses ' : ' 53e2167653457600003e3eb3 '
' basic-flags ' : ' 545bacb41e649a4495f887da '
2014-11-14 14:03:01 -05:00
' roughedge ' : ' 544d7d918494308424f564a7 '
' sharpened-sword ' : ' 544d7deb8494308424f564ab '