mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Trying to get item ThangType nodes and inventory loading working.
This commit is contained in:
parent
d1e26b40c2
commit
706ab7a251
6 changed files with 30 additions and 15 deletions
|
@ -73,13 +73,13 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@opponentSessionResource = @supermodel.loadModel(opponentSession, 'opponent_session')
|
||||
@opponentSession = @opponentSessionResource.model
|
||||
@listenToOnce @opponentSession, 'sync', @onSessionLoaded
|
||||
|
||||
|
||||
onSessionLoaded: (session) ->
|
||||
session.url = -> '/db/level.session/' + @id
|
||||
if heroConfig = session.get('heroConfig')
|
||||
url = "/db/thang.type/#{heroConfig.thangType}/version?project=name,components"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
||||
|
||||
for itemThangType in _.values(heroConfig.inventory)
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
@ -148,21 +148,24 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@supermodel.loadModel wizard, 'thang'
|
||||
|
||||
@worldNecessities = @worldNecessities.concat worldNecessities
|
||||
|
||||
|
||||
loadItemThangsEquippedByLevelThang: (levelThang) ->
|
||||
return unless levelThang.components
|
||||
for component in levelThang.components
|
||||
if component.original is LevelComponent.EquipsID and inventory = component.config?.inventory
|
||||
for itemThangType in _.values(inventory)
|
||||
unless itemThangType
|
||||
console.warn "Empty item in inventory for", levelThang
|
||||
continue
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
||||
|
||||
onThangNamesLoaded: (thangNames) ->
|
||||
if @level.get('type') is 'hero'
|
||||
for thangType in thangNames.models
|
||||
@loadDefaultComponentsForThangType(thangType)
|
||||
@loadEquippedItemsInheritedFromThangType(thangType)
|
||||
|
||||
|
||||
loadDefaultComponentsForThangType: (thangType) ->
|
||||
return unless components = thangType.get('components')
|
||||
for component in components
|
||||
|
@ -183,10 +186,10 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
onWorldNecessityLoaded: (resource) ->
|
||||
index = @worldNecessities.indexOf(resource)
|
||||
if (@level.loading or (@level.get('type') is 'hero')) and resource.name is 'thang'
|
||||
if (@level?.loading or (@level?.get('type') is 'hero')) and resource.name is 'thang'
|
||||
@loadDefaultComponentsForThangType(resource.model)
|
||||
@loadEquippedItemsInheritedFromThangType(resource.model)
|
||||
|
||||
|
||||
return unless index >= 0
|
||||
@worldNecessities.splice(index, 1)
|
||||
@worldNecessities = (r for r in @worldNecessities when r?)
|
||||
|
|
|
@ -149,6 +149,7 @@ module.exports = class SpriteBoss extends CocoClass
|
|||
return false unless m.get('actions') or m.get('raster')
|
||||
return m.get('name') is thang.spriteName
|
||||
thangType ?= _.find @options.thangTypes, (m) -> return m.get('name') is thang.spriteName
|
||||
return console.error "Couldn't find ThangType for", thang unless thangType
|
||||
|
||||
options = @createSpriteOptions thang: thang
|
||||
options.resolutionFactor = if thangType.get('kind') is 'Floor' then 2 else SPRITE_RESOLUTION_FACTOR
|
||||
|
|
|
@ -143,6 +143,7 @@ module.exports = class World
|
|||
@aborted = true
|
||||
|
||||
loadFromLevel: (level, willSimulate=true) ->
|
||||
@level = level
|
||||
@loadSystemsFromLevel level
|
||||
@loadThangsFromLevel level, willSimulate
|
||||
@loadScriptsFromLevel level
|
||||
|
|
|
@ -22,9 +22,9 @@ module.exports = class Level extends CocoModel
|
|||
o.systems = @sortSystems o.systems, systemModels
|
||||
@fillInDefaultSystemConfiguration o.systems
|
||||
|
||||
o.thangTypes = (original: tt.get('original'), name: tt.get('name') for tt in supermodel.getModels ThangType)
|
||||
o.thangTypes = (original: tt.get('original'), name: tt.get('name'), components: tt.get('components') for tt in supermodel.getModels ThangType)
|
||||
o
|
||||
|
||||
|
||||
denormalize: (supermodel) ->
|
||||
o = $.extend true, {}, @attributes
|
||||
for levelThang in o.thangs
|
||||
|
@ -37,13 +37,13 @@ module.exports = class Level extends CocoModel
|
|||
configs = {}
|
||||
for thangComponent in levelThang.components
|
||||
configs[thangComponent.original] = thangComponent
|
||||
|
||||
|
||||
for defaultThangComponent in thangType.get('components')
|
||||
if levelThangComponent = configs[defaultThangComponent.original]
|
||||
# take the thang type default components and merge level-specific component config into it
|
||||
copy = $.extend true, {}, defaultThangComponent.config
|
||||
levelThangComponent.config = _.merge copy, levelThangComponent.config
|
||||
|
||||
|
||||
else
|
||||
# just add the component as is
|
||||
levelThang.components.push $.extend true, {}, defaultThangComponent
|
||||
|
|
|
@ -9,7 +9,7 @@ module.exports = class ThangComponentConfigView extends CocoView
|
|||
className: 'thang-component-config-view'
|
||||
template: template
|
||||
changed: false
|
||||
|
||||
|
||||
events:
|
||||
'click .treema-shortened': -> console.log 'clicked treema root'
|
||||
|
||||
|
@ -20,7 +20,7 @@ module.exports = class ThangComponentConfigView extends CocoView
|
|||
@world = options.world
|
||||
@level = options.level
|
||||
@callback = options.callback
|
||||
|
||||
|
||||
getRenderData: (context={}) ->
|
||||
context = super(context)
|
||||
context.component = @component.attributes
|
||||
|
@ -59,11 +59,12 @@ module.exports = class ThangComponentConfigView extends CocoView
|
|||
'seconds': nodes.SecondsNode
|
||||
'speed': nodes.SpeedNode
|
||||
'acceleration': nodes.AccelerationNode
|
||||
'item-thang-type': nodes.ItemThangTypeNode
|
||||
|
||||
@editThangTreema = @$el.find('.treema').treema treemaOptions
|
||||
@editThangTreema.build()
|
||||
@editThangTreema.open(2)
|
||||
if _.isEqual(@config, {}) and not @editThangTreema.canAddChild()
|
||||
if _.isEqual(@editThangTreema.data, {}) and not @editThangTreema.canAddChild()
|
||||
@$el.find('.panel-body').hide()
|
||||
|
||||
onConfigEdited: =>
|
||||
|
|
|
@ -200,7 +200,7 @@ module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.st
|
|||
constructor: (args...) ->
|
||||
super args...
|
||||
@thangType = _.find @settings.supermodel.getModels(ThangType), (m) => m.get('original') is @data if @data
|
||||
console.log 'ThangTypeNode found ThangType', @thangType, 'for data', @data
|
||||
#console.log 'ThangTypeNode found ThangType', @thangType, 'for data', @data
|
||||
|
||||
buildValueForDisplay: (valEl) ->
|
||||
@buildValueForDisplaySimply(valEl, @thangType?.get('name') or 'None')
|
||||
|
@ -219,3 +219,12 @@ module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.st
|
|||
@data = @thangType.get('original')
|
||||
else
|
||||
@data = null
|
||||
|
||||
module.exports.ItemThangTypeNode = class ThangTypeNode extends ThangTypeNode
|
||||
valueClass: 'treema-item-thang-type'
|
||||
buildValueForEditing: (valEl) ->
|
||||
super(valEl)
|
||||
thangTypeNames = (m.get('name') for m in @settings.supermodel.getModels ThangType when m.get('kind') is 'Item')
|
||||
input = valEl.find('input').autocomplete(source: thangTypeNames, minLength: 0, delay: 0, autoFocus: true)
|
||||
input.val(@thangType?.get('name') or 'None')
|
||||
valEl
|
||||
|
|
Loading…
Reference in a new issue