mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Tweaked the level serialization, leaving in walkDefaults for now because there may still be some components that don't have defaults properly set up. Added a warn log for when this happens so it can be fixed.
This commit is contained in:
parent
74ca7fe0cc
commit
5fd154ca8b
1 changed files with 20 additions and 0 deletions
|
@ -140,12 +140,32 @@ module.exports = class Level extends CocoModel
|
||||||
continue unless lc = _.find levelComponents, {original: component.original}
|
continue unless lc = _.find levelComponents, {original: component.original}
|
||||||
component.config ?= {}
|
component.config ?= {}
|
||||||
TreemaNode.utils.populateDefaults(component.config, lc.configSchema)
|
TreemaNode.utils.populateDefaults(component.config, lc.configSchema)
|
||||||
|
@lastType = 'component'
|
||||||
|
@lastOriginal = component.original
|
||||||
|
@walkDefaults component.config, lc.configSchema.properties
|
||||||
|
|
||||||
fillInDefaultSystemConfiguration: (levelSystems) ->
|
fillInDefaultSystemConfiguration: (levelSystems) ->
|
||||||
for system in levelSystems ? []
|
for system in levelSystems ? []
|
||||||
system.config ?= {}
|
system.config ?= {}
|
||||||
TreemaNode.utils.populateDefaults(system.config, system.model.configSchema)
|
TreemaNode.utils.populateDefaults(system.config, system.model.configSchema)
|
||||||
|
@lastType = 'system'
|
||||||
|
@lastOriginal = system.model.name
|
||||||
|
@walkDefaults system.config, system.model.configSchema.properties
|
||||||
|
|
||||||
|
walkDefaults: (config, properties) ->
|
||||||
|
# This function is redundant, but is the old implementation.
|
||||||
|
# Remove it and calls to it once we stop seeing these warnings.
|
||||||
|
return unless properties
|
||||||
|
for prop, schema of properties
|
||||||
|
if schema.default? and config[prop] is undefined
|
||||||
|
console.warn 'Setting default of', config, 'for', prop, 'to', schema.default, 'but this method is deprecated... check your config schema!', @lastType, @lastOriginal
|
||||||
|
config[prop] = schema.default
|
||||||
|
if schema.type is 'object' and config[prop]
|
||||||
|
@walkDefaults config[prop], schema.properties
|
||||||
|
else if schema.type is 'array' and config[prop]
|
||||||
|
for item in config[prop] or []
|
||||||
|
@walkDefaults item, schema.items
|
||||||
|
|
||||||
dimensions: ->
|
dimensions: ->
|
||||||
width = 0
|
width = 0
|
||||||
height = 0
|
height = 0
|
||||||
|
|
Loading…
Reference in a new issue