From e9c7edb6be1527398c0ef638d720610968f9f493 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Mon, 15 Aug 2016 11:53:57 -0700 Subject: [PATCH] Fix populate i18n to also populate thang component configs --- app/models/CocoModel.coffee | 8 +++++++- app/views/editor/level/LevelEditView.coffee | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index 90310d5de..8441d2bc0 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -309,6 +309,8 @@ class CocoModel extends Backbone.Model sum = 0 data ?= $.extend true, {}, @attributes schema ?= @schema() or {} + if schema.oneOf # get populating the Programmable component config to work + schema = _.find(schema.oneOf, {type: 'object'}) addedI18N = false if schema.properties?.i18n and _.isPlainObject(data) and not data.i18n? data.i18n = {'-':{'-':'-'}} # mongoose doesn't work with empty objects @@ -318,7 +320,11 @@ class CocoModel extends Backbone.Model if _.isPlainObject data for key, value of data numChanged = 0 - numChanged = @populateI18N(value, childSchema, path+'/'+key) if childSchema = schema.properties?[key] + childSchema = schema.properties?[key] + if not childSchema and _.isObject(schema.additionalProperties) + childSchema = schema.additionalProperties + if childSchema + numChanged = @populateI18N(value, childSchema, path+'/'+key) if numChanged and not path # should only do this for the root object @set key, value sum += numChanged diff --git a/app/views/editor/level/LevelEditView.coffee b/app/views/editor/level/LevelEditView.coffee index 0f9b0d216..230d18a94 100644 --- a/app/views/editor/level/LevelEditView.coffee +++ b/app/views/editor/level/LevelEditView.coffee @@ -2,6 +2,7 @@ RootView = require 'views/core/RootView' template = require 'templates/editor/level/edit' Level = require 'models/Level' LevelSystem = require 'models/LevelSystem' +LevelComponent = require 'models/LevelComponent' World = require 'lib/world/world' DocumentFiles = require 'collections/DocumentFiles' LevelLoader = require 'lib/LevelLoader' @@ -217,6 +218,19 @@ module.exports = class LevelEditView extends RootView onPopulateI18N: -> @level.populateI18N() + + levelComponentMap = _(currentView.supermodel.getModels(LevelComponent)) + .map((c) -> [c.get('original'), c]) + .object() + .value() + + for thang, thangIndex in @level.get('thangs') + for thangComponent, thangComponentIndex in thang.components + component = levelComponentMap[thangComponent.original] + configSchema = component.get('configSchema') + path = "/thangs/#{thangIndex}/components/#{thangComponentIndex}/config" + @level.populateI18N(thangComponent.config, configSchema, path) + f = -> document.location.reload() setTimeout(f, 2000)