From 589268dc4f4a8aa54656c7a49d8fa547ab6737ee Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Mon, 15 Sep 2014 13:15:18 -0700 Subject: [PATCH] Fixes for initializing Hero Placeholder Components. --- app/models/Level.coffee | 24 +++++++++++++++++------- app/models/LevelComponent.coffee | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/models/Level.coffee b/app/models/Level.coffee index ddad95999..ec7afa810 100644 --- a/app/models/Level.coffee +++ b/app/models/Level.coffee @@ -54,9 +54,15 @@ module.exports = class Level extends CocoModel denormalizeThang: (levelThang, supermodel, session) -> levelThang.components ?= [] + isHero = levelThang.id is 'Hero Placeholder' + # Empty out placeholder Components and store their values if we're the hero placeholder. - placeholders = {} - if levelThang.id is 'Hero Placeholder' + if isHero + placeholders = {} + placeholdersUsed = {} + placeholderThangType = supermodel.getModelByOriginal(ThangType, levelThang.thangType) + for defaultPlaceholderComponent in placeholderThangType.get('components') + placeholders[defaultPlaceholderComponent.original] = defaultPlaceholderComponent for thangComponent in levelThang.components placeholders[thangComponent.original] = thangComponent levelThang.components = [] # We have stored the placeholder values, so we can inherit everything else. @@ -80,7 +86,8 @@ module.exports = class Level extends CocoModel levelThangComponent = $.extend true, {}, defaultThangComponent levelThang.components.push levelThangComponent - if placeholderComponent = placeholders[defaultThangComponent.original] + if isHero and placeholderComponent = placeholders[defaultThangComponent.original] + placeholdersUsed[placeholderComponent.original] = true placeholderConfig = placeholderComponent.config ? {} if placeholderConfig.pos # Pull in Physical pos x and y levelThangComponent.config.pos ?= {} @@ -93,10 +100,13 @@ module.exports = class Level extends CocoModel copy = $.extend true, {}, placeholderConfig levelThangComponent.config = _.merge copy, levelThangComponent.config - if levelThang.id is 'Hero Placeholder' and equips = _.find levelThang.components, {original: LevelComponent.EquipsID} - inventory = session?.get('heroConfig')?.inventory - equips.config ?= {} - equips.config.inventory = $.extend true, {}, inventory if inventory + if isHero + if equips = _.find levelThang.components, {original: LevelComponent.EquipsID} + inventory = session?.get('heroConfig')?.inventory + equips.config ?= {} + equips.config.inventory = $.extend true, {}, inventory if inventory + for original, placeholderComponent of placeholders when not placeholdersUsed[original] + levelThang.components.push placeholderComponent sortSystems: (levelSystems, systemModels) -> diff --git a/app/models/LevelComponent.coffee b/app/models/LevelComponent.coffee index 6c0dbbc65..d8a9bc4f1 100644 --- a/app/models/LevelComponent.coffee +++ b/app/models/LevelComponent.coffee @@ -11,6 +11,7 @@ module.exports = class LevelComponent extends CocoModel @ExistsID: '524b4150ff92f1f4f8000024' @LandID: '524b7aff7fc0f6d519000006' @CollidesID: '524b7b857fc0f6d519000012' + @PlansID: '524b7b517fc0f6d51900000d' urlRoot: '/db/level.component' set: (key, val, options) ->