Thangs get inserted into hero levels without any Components for easy defaulting. Working on moving Hero Placeholder ThangType swapping from LevelLoader to Level, but it's not there yet.

This commit is contained in:
Nick Winter 2014-08-15 12:09:56 -07:00
parent 03e39c3f5c
commit 5f20e6f05e
3 changed files with 14 additions and 3 deletions
app
lib
models
views/editor/level/thangs

View file

@ -153,6 +153,7 @@ module.exports = class LevelLoader extends CocoClass
@worldNecessities = @worldNecessities.concat worldNecessities
populateHero: ->
return
return if @inLevelEditor
return unless @level.get('type') is 'hero' and hero = _.find @level.get('thangs'), id: 'Hero Placeholder'
heroConfig = @session.get('heroConfig')
@ -218,6 +219,7 @@ module.exports = class LevelLoader extends CocoClass
for thangTypeName in thangsToLoad
thangType = nameModelMap[thangTypeName]
console.log 'found ThangType', thangType, 'for', thangTypeName, 'of nameModelMap', nameModelMap unless thangType
continue if thangType.isFullyLoaded()
thangType.fetch()
thangType = @supermodel.loadModel(thangType, 'thang').model

View file

@ -46,6 +46,9 @@ module.exports = class Level extends CocoModel
for thangComponent in levelThang.components ? []
placeholders[thangComponent.original] = thangComponent
levelThang.components = []
heroThangType = session?.get('heroConfig')?.thangType
console.log "got thang type", heroThangType
levelThang.thangType = heroThangType if heroThangType
configs = {}
for thangComponent in levelThang.components

View file

@ -311,10 +311,14 @@ module.exports = class ThangsTabView extends CocoView
else
@addThangSprite = null
createEssentialComponents: ->
createEssentialComponents: (defaultComponents) ->
physicalConfig = {pos: {x: 10, y: 10, z: 1}}
if physicalOriginal = _.find(defaultComponents ? [], original: componentOriginals['physics.Physical'])
physicalConfig.pos.z = physicalOriginal.config.pos.z # Get the z right
console.log physicalOriginal, defaultComponents, componentOriginals['physics.Physical'], physicalConfig
[
{original: componentOriginals['existence.Exists'], majorVersion: 0, config: {}}
{original: componentOriginals['physics.Physical'], majorVersion: 0, config: {pos: {x: 10, y: 10, z: 1}, width: 2, height: 2, depth: 2, shape: 'box'}}
{original: componentOriginals['physics.Physical'], majorVersion: 0, config: physicalConfig}
]
createAddThang: ->
@ -424,9 +428,11 @@ module.exports = class ThangsTabView extends CocoView
if @cloneSourceThang
components = _.cloneDeep @thangsTreema.get "id=#{@cloneSourceThang.id}/components"
@selectAddThang null
else if @level.get('type') is 'hero'
components = [] # Load them all from default ThangType Components
else
components = _.cloneDeep thangType.get('components') ? []
components = @createEssentialComponents() unless components.length
components = @createEssentialComponents(thangType.get('components')) unless components.length
physical = _.find components, (c) -> c.config?.pos?
physical.config.pos = x: pos.x, y: pos.y, z: physical.config.pos.z if physical
thang = thangType: thangType.get('original'), id: thangID, components: components