mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 10:06:08 -05:00
Replayed useful changes from last few InventoryModal commits after big merge.
This commit is contained in:
parent
f21f54cd19
commit
fbbcf2a925
1 changed files with 41 additions and 109 deletions
|
@ -7,6 +7,7 @@ ItemView = require './ItemView'
|
||||||
SpriteBuilder = require 'lib/sprites/SpriteBuilder'
|
SpriteBuilder = require 'lib/sprites/SpriteBuilder'
|
||||||
ItemDetailsView = require 'views/play/modal/ItemDetailsView'
|
ItemDetailsView = require 'views/play/modal/ItemDetailsView'
|
||||||
Purchase = require 'models/Purchase'
|
Purchase = require 'models/Purchase'
|
||||||
|
LevelOptions = require 'lib/LevelOptions'
|
||||||
|
|
||||||
hasGoneFullScreenOnce = false
|
hasGoneFullScreenOnce = false
|
||||||
|
|
||||||
|
@ -40,9 +41,6 @@ module.exports = class InventoryModal extends ModalView
|
||||||
initialize: (options) ->
|
initialize: (options) ->
|
||||||
super(arguments...)
|
super(arguments...)
|
||||||
@items = new CocoCollection([], {model: ThangType})
|
@items = new CocoCollection([], {model: ThangType})
|
||||||
@equipment = options.equipment or @options.session?.get('heroConfig')?.inventory or me.get('heroConfig')?.inventory or {}
|
|
||||||
@equipment = $.extend true, {}, @equipment
|
|
||||||
@requireLevelEquipment()
|
|
||||||
# TODO: switch to item store loading system?
|
# TODO: switch to item store loading system?
|
||||||
@items.url = '/db/thang.type?view=items'
|
@items.url = '/db/thang.type?view=items'
|
||||||
@items.setProjection [
|
@items.setProjection [
|
||||||
|
@ -56,10 +54,13 @@ module.exports = class InventoryModal extends ModalView
|
||||||
'heroClass',
|
'heroClass',
|
||||||
'i18n'
|
'i18n'
|
||||||
]
|
]
|
||||||
@listenToOnce @items, 'sync', @onItemsLoaded
|
|
||||||
@supermodel.loadCollection(@items, 'items')
|
@supermodel.loadCollection(@items, 'items')
|
||||||
|
@equipment = {} # Assign for real when we have loaded the session and items.
|
||||||
|
|
||||||
onItemsLoaded: ->
|
onItemsLoaded: ->
|
||||||
|
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
|
||||||
@requireLevelEquipment()
|
@requireLevelEquipment()
|
||||||
@itemGroups = {}
|
@itemGroups = {}
|
||||||
@itemGroups.availableItems = new Backbone.Collection()
|
@itemGroups.availableItems = new Backbone.Collection()
|
||||||
|
@ -80,20 +81,21 @@ module.exports = class InventoryModal extends ModalView
|
||||||
item.classes.push 'equipped' if item.get('original') in equipped
|
item.classes.push 'equipped' if item.get('original') in equipped
|
||||||
|
|
||||||
# sort into one of the four groups
|
# sort into one of the four groups
|
||||||
locked = @allowedItems and not (item.get('original') in @allowedItems)
|
locked = not (item.get('original') in me.items())
|
||||||
|
|
||||||
if locked and item.get('slug') isnt 'simple-boots'
|
if locked and item.get('slug') isnt 'simple-boots'
|
||||||
@itemGroups.lockedItems.add(item)
|
@itemGroups.lockedItems.add(item)
|
||||||
item.classes.push 'locked'
|
item.classes.push 'locked'
|
||||||
item.classes.push 'silhouette' if item.isSilhouettedItem()
|
item.classes.push 'silhouette' if item.isSilhouettedItem()
|
||||||
else if item.get('slug') in _.values(restrictedGearByLevel[@options.levelID] ? {})
|
else if item.get('slug') in _.values(LevelOptions[@options.levelID]?.restrictedGear ? {})
|
||||||
@itemGroups.restrictedItems.add(item)
|
@itemGroups.restrictedItems.add(item)
|
||||||
item.classes.push 'restricted'
|
item.classes.push 'restricted'
|
||||||
else
|
else
|
||||||
@itemGroups.availableItems.add(item)
|
@itemGroups.availableItems.add(item)
|
||||||
|
|
||||||
onLoaded: ->
|
onLoaded: ->
|
||||||
item.notInLevel = true for item in @items.models
|
# Both items and session have been loaded.
|
||||||
|
@onItemsLoaded()
|
||||||
super()
|
super()
|
||||||
|
|
||||||
getRenderData: (context={}) ->
|
getRenderData: (context={}) ->
|
||||||
|
@ -110,7 +112,9 @@ module.exports = class InventoryModal extends ModalView
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
super()
|
super()
|
||||||
|
@$el.find('#play-level-button').css('visibility', 'hidden')
|
||||||
return unless @supermodel.finished()
|
return unless @supermodel.finished()
|
||||||
|
@$el.find('#play-level-button').css('visibility', 'visible')
|
||||||
|
|
||||||
@setUpDraggableEventsForAvailableEquipment()
|
@setUpDraggableEventsForAvailableEquipment()
|
||||||
@setUpDraggableEventsForEquippedArea()
|
@setUpDraggableEventsForEquippedArea()
|
||||||
|
@ -338,8 +342,8 @@ module.exports = class InventoryModal extends ModalView
|
||||||
|
|
||||||
requireLevelEquipment: ->
|
requireLevelEquipment: ->
|
||||||
# This is temporary, until we have a more general way of awarding items and configuring required/restricted items per level.
|
# This is temporary, until we have a more general way of awarding items and configuring required/restricted items per level.
|
||||||
return unless necessaryGear = requiredGearByLevel[@options.levelID]
|
requiredGear = LevelOptions[@options.levelID]?.requiredGear ? {}
|
||||||
restrictedGear = restrictedGearByLevel[@options.levelID] ? {}
|
restrictedGear = LevelOptions[@options.levelID]?.restrictedGear ? {}
|
||||||
if @inserted
|
if @inserted
|
||||||
if @supermodel.finished()
|
if @supermodel.finished()
|
||||||
equipment = @getCurrentEquipmentConfig() # Make sure @equipment is updated
|
equipment = @getCurrentEquipmentConfig() # Make sure @equipment is updated
|
||||||
|
@ -354,10 +358,15 @@ module.exports = class InventoryModal extends ModalView
|
||||||
if equipped and equipped is gear[restrictedGear[slot]]
|
if equipped and equipped is gear[restrictedGear[slot]]
|
||||||
console.log 'Unequipping restricted item', restrictedGear[slot], 'for', slot, 'before level', @options.levelID
|
console.log 'Unequipping restricted item', restrictedGear[slot], 'for', slot, 'before level', @options.levelID
|
||||||
@unequipItemFromSlot @$el.find(".item-slot[data-slot='#{slot}']")
|
@unequipItemFromSlot @$el.find(".item-slot[data-slot='#{slot}']")
|
||||||
for slot, item of necessaryGear
|
for slot, item of requiredGear
|
||||||
continue if item is 'leather-tunic' and inWorldMap and @options.levelID is 'the-raised-sword' # Don't tell them they need it until they need it in the level
|
#continue if item is 'leather-tunic' and inWorldMap and @options.levelID is 'the-raised-sword' # Don't tell them they need it until they need it in the level # ... when we make it so that you can buy it
|
||||||
equipped = equipment[slot]
|
equipped = equipment[slot]
|
||||||
continue if equipped and not ((item is 'builders-hammer' and equipped is gear['simple-sword']) or (item is 'leather-boots' and equipped is gear['simple-boots']))
|
continue if equipped and not (
|
||||||
|
(item is 'builders-hammer' and equipped in [gear['simple-sword'], gear['long-sword']]) or
|
||||||
|
(item in ['simple-sword', 'long-sword'] and equipped is gear['builders-hammer']) or
|
||||||
|
(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}
|
itemModel = @items.findWhere {slug: item}
|
||||||
continue unless itemModel
|
continue unless itemModel
|
||||||
availableSlotSelector = "#unequipped .item[data-item-id='#{itemModel.id}']"
|
availableSlotSelector = "#unequipped .item[data-item-id='#{itemModel.id}']"
|
||||||
|
@ -368,18 +377,9 @@ module.exports = class InventoryModal extends ModalView
|
||||||
@remainingRequiredEquipment.push slot: slot, item: gear[item]
|
@remainingRequiredEquipment.push slot: slot, item: gear[item]
|
||||||
if hadRequired and not @remainingRequiredEquipment.length
|
if hadRequired and not @remainingRequiredEquipment.length
|
||||||
@endHighlight()
|
@endHighlight()
|
||||||
@highlightElement (if inWorldMap then '#play-level-button' else '.overlaid-close-button'), duration: 5000
|
@highlightElement '#play-level-button', duration: 5000
|
||||||
$('#play-level-button').prop('disabled', @remainingRequiredEquipment.length > 0)
|
$('#play-level-button').prop('disabled', @remainingRequiredEquipment.length > 0)
|
||||||
|
|
||||||
# Restrict available items to those that would be available by this level.
|
|
||||||
@allowedItems = []
|
|
||||||
for level, items of requiredGearByLevel
|
|
||||||
for slot, item of items
|
|
||||||
@allowedItems.push gear[item] unless gear[item] in @allowedItems
|
|
||||||
break if level is @options.levelID
|
|
||||||
for item in me.items() when not (item in @allowedItems)
|
|
||||||
@allowedItems.push item
|
|
||||||
|
|
||||||
setHero: (@selectedHero) ->
|
setHero: (@selectedHero) ->
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
|
@ -448,71 +448,3 @@ gear =
|
||||||
'bronze-shield': '544c310ae0017993fce214bf'
|
'bronze-shield': '544c310ae0017993fce214bf'
|
||||||
'wooden-glasses': '53e2167653457600003e3eb3'
|
'wooden-glasses': '53e2167653457600003e3eb3'
|
||||||
'basic-flags': '545bacb41e649a4495f887da'
|
'basic-flags': '545bacb41e649a4495f887da'
|
||||||
|
|
||||||
requiredGearByLevel =
|
|
||||||
'dungeons-of-kithgard': {feet: 'simple-boots'}
|
|
||||||
'gems-in-the-deep': {feet: 'simple-boots'}
|
|
||||||
'shadow-guard': {feet: 'simple-boots'}
|
|
||||||
'kounter-kithwise': {feet: 'simple-boots'}
|
|
||||||
'crawlways-of-kithgard': {feet: 'simple-boots'}
|
|
||||||
'forgetful-gemsmith': {feet: 'simple-boots'}
|
|
||||||
'true-names': {feet: 'simple-boots', 'right-hand': 'simple-sword', waist: 'leather-belt'}
|
|
||||||
'favorable-odds': {feet: 'simple-boots', 'right-hand': 'simple-sword'}
|
|
||||||
'the-raised-sword': {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic'}
|
|
||||||
'the-first-kithmaze': {feet: 'simple-boots', 'programming-book': 'programmaticon-i'}
|
|
||||||
'haunted-kithmaze': {feet: 'simple-boots', 'programming-book': 'programmaticon-i'}
|
|
||||||
'descending-further': {feet: 'simple-boots', 'programming-book': 'programmaticon-i'}
|
|
||||||
'the-second-kithmaze': {feet: 'simple-boots', 'programming-book': 'programmaticon-i'}
|
|
||||||
'dread-door': {'right-hand': 'simple-sword', 'programming-book': 'programmaticon-i'}
|
|
||||||
'known-enemy': {'right-hand': 'simple-sword', 'programming-book': 'programmaticon-i', torso: 'leather-tunic'}
|
|
||||||
'master-of-names': {feet: 'simple-boots', 'right-hand': 'simple-sword', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses', torso: 'leather-tunic'}
|
|
||||||
'lowly-kithmen': {feet: 'simple-boots', 'right-hand': 'simple-sword', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses', torso: 'leather-tunic'}
|
|
||||||
'closing-the-distance': {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic', eyes: 'crude-glasses'}
|
|
||||||
'tactical-strike': {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic', eyes: 'crude-glasses'}
|
|
||||||
'the-final-kithmaze': {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses'}
|
|
||||||
'the-gauntlet': {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses'}
|
|
||||||
'kithgard-gates': {feet: 'simple-boots', 'right-hand': 'builders-hammer', torso: 'leather-tunic'}
|
|
||||||
'defense-of-plainswood': {feet: 'simple-boots', 'right-hand': 'builders-hammer'}
|
|
||||||
'winding-trail': {feet: 'leather-boots', 'right-hand': 'builders-hammer'}
|
|
||||||
'thornbush-farm': {feet: 'leather-boots', 'right-hand': 'builders-hammer', eyes: 'crude-glasses'}
|
|
||||||
'a-fiery-trap': {feet: 'leather-boots', torso: 'leather-tunic', waist: 'leather-belt', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses', 'right-hand': 'simple-sword', 'left-hand': 'wooden-shield'}
|
|
||||||
'ogre-encampment': {torso: 'leather-tunic', waist: 'leather-belt', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses', 'right-hand': 'simple-sword', 'left-hand': 'wooden-shield'}
|
|
||||||
'woodland-cleaver': {torso: 'leather-tunic', waist: 'leather-belt', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses', 'right-hand': 'long-sword', 'left-hand': 'wooden-shield', wrists: 'sundial-wristwatch', feet: 'leather-boots'}
|
|
||||||
'shield-rush': {torso: 'leather-tunic', waist: 'leather-belt', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses', 'right-hand': 'long-sword', 'left-hand': 'bronze-shield', wrists: 'sundial-wristwatch'}
|
|
||||||
'peasant-protection': {torso: 'leather-tunic', waist: 'leather-belt', 'programming-book': 'programmaticon-i', eyes: 'wooden-glasses', 'right-hand': 'long-sword', 'left-hand': 'bronze-shield', wrists: 'sundial-wristwatch'}
|
|
||||||
'munchkin-swarm': {torso: 'leather-tunic', waist: 'leather-belt', 'programming-book': 'programmaticon-i', eyes: 'wooden-glasses', 'right-hand': 'long-sword', 'left-hand': 'bronze-shield', wrists: 'sundial-wristwatch'}
|
|
||||||
'coinucopia': {'programming-book': 'programmaticon-i', feet: 'leather-boots', flag: 'basic-flags'}
|
|
||||||
'copper-meadows': {'programming-book': 'programmaticon-i', feet: 'leather-boots', flag: 'basic-flags', eyes: 'wooden-glasses'}
|
|
||||||
'drop-the-flag': {'programming-book': 'programmaticon-i', feet: 'leather-boots', flag: 'basic-flags', eyes: 'wooden-glasses', 'right-hand': 'builders-hammer'}
|
|
||||||
'rich-forager': {'programming-book': 'programmaticon-i', feet: 'leather-boots', flag: 'basic-flags', eyes: 'wooden-glasses', torso: 'leather-tunic', 'right-hand': 'longsword', 'left-hand': 'bronze-shield'}
|
|
||||||
'deadly-pursuit': {'programming-book': 'programmaticon-i', feet: 'leather-boots', flag: 'basic-flags', eyes: 'wooden-glasses', 'right-hand': 'builders-hammer'}
|
|
||||||
'multiplayer-treasure-grove': {'programming-book': 'programmaticon-i', feet: 'leather-boots', flag: 'basic-flags', eyes: 'wooden-glasses', torso: 'leather-tunic'}
|
|
||||||
|
|
||||||
restrictedGearByLevel =
|
|
||||||
'dungeons-of-kithgard': {feet: 'leather-boots'}
|
|
||||||
'gems-in-the-deep': {feet: 'leather-boots'}
|
|
||||||
'shadow-guard': {feet: 'leather-boots', 'right-hand': 'simple-sword'}
|
|
||||||
'kounter-kithwise': {feet: 'leather-boots', 'right-hand': 'simple-sword', 'programming-book': 'programmaticon-i'}
|
|
||||||
'crawlways-of-kithgard': {feet: 'leather-boots', 'right-hand': 'simple-sword', 'programming-book': 'programmaticon-i'}
|
|
||||||
'forgetful-gemsmith': {feet: 'leather-boots', 'programming-book': 'programmaticon-i'}
|
|
||||||
'true-names': {feet: 'leather-boots', 'programming-book': 'programmaticon-i'}
|
|
||||||
'favorable-odds': {feet: 'leather-boots', 'programming-book': 'programmaticon-i'}
|
|
||||||
'the-raised-sword': {feet: 'leather-boots', 'programming-book': 'programmaticon-i'}
|
|
||||||
'the-first-kithmaze': {feet: 'leather-boots'}
|
|
||||||
'haunted-kithmaze': {feet: 'leather-boots'}
|
|
||||||
'descending-further': {feet: 'leather-boots'}
|
|
||||||
'the-second-kithmaze': {feet: 'leather-boots'}
|
|
||||||
'the-final-kithmaze': {feet: 'leather-boots'}
|
|
||||||
'the-gauntlet': {feet: 'leather-boots'}
|
|
||||||
'kithgard-gates': {'right-hand': 'simple-sword'}
|
|
||||||
'defense-of-plainswood': {'right-hand': 'simple-sword'}
|
|
||||||
'winding-trail': {feet: 'simple-boots', 'right-hand': 'simple-sword'}
|
|
||||||
'thornbush-farm': {feet: 'simple-boots', 'right-hand': 'simple-sword'}
|
|
||||||
'a-fiery-trap': {feet: 'simple-boots', 'right-hand': 'builders-hammer'}
|
|
||||||
'ogre-encampment': {feet: 'simple-boots', 'right-hand': 'builders-hammer'}
|
|
||||||
'woodland-cleaver': {feet: 'simple-boots', 'right-hand': 'simple-sword'}
|
|
||||||
'shield-rush': {'left-hand': 'wooden-shield'}
|
|
||||||
'peasant-protection': {eyes: 'crude-glasses'}
|
|
||||||
'drop-the-flag': {'right-hand': 'longsword'}
|
|
||||||
'rich-forager': {'right-hand': 'builders-hammer'}
|
|
||||||
'deadly-pursuit': {'right-hand': 'longsword'}
|
|
||||||
|
|
Loading…
Reference in a new issue