Added i18n population action to the level editor.

This commit is contained in:
Scott Erickson 2014-04-22 17:56:41 -07:00
parent 9c8841e838
commit c85971e5e6
5 changed files with 28 additions and 1 deletions

View file

@ -68,7 +68,7 @@ expandFlattenedDelta = (delta, left, schema) ->
parentLeft = left
parentSchema = schema
for key, i in delta.dataPath
# TODO: A more comprehensive way of getting child schemas
# TODO: Better schema/json walking
childSchema = parentSchema?.items or parentSchema?.properties?[key] or {}
childLeft = parentLeft?[key]
humanKey = null

View file

@ -133,6 +133,7 @@ class CocoModel extends Backbone.Model
schema ?= @schema()
models = []
# TODO: Better schema/json walking
if $.isArray(data) and schema.items?
for subData, i in data
models = models.concat(@getReferencedModels(subData, schema.items, path+i+'/', shouldLoadProjection))
@ -226,5 +227,27 @@ class CocoModel extends Backbone.Model
watching: ->
return me.id in (@get('watchers') or [])
populateI18N: (data, schema, path='') ->
# TODO: Better schema/json walking
sum = 0
data ?= $.extend true, {}, @attributes
schema ?= @schema() or {}
if schema.properties?.i18n and _.isPlainObject(data) and not data.i18n?
data.i18n = {}
sum += 1
if _.isPlainObject data
for key, value of data
numChanged = 0
numChanged = @populateI18N(value, childSchema, path+'/'+key) if childSchema = schema.properties?[key]
if numChanged and not path # should only do this for the root object
@set key, value
sum += numChanged
if schema.items and _.isArray data
sum += @populateI18N(value, schema.items, path+'/'+index) for value, index in data
sum
module.exports = CocoModel

View file

@ -68,6 +68,8 @@ block header
a(data-i18n="common.fork")#fork-level-start-button Fork
li(class=anonymous ? "disabled": "")
a(data-toggle="coco-modal", data-target="modal/revert", data-i18n="editor.revert")#revert-button Revert
li(class=anonymous ? "disabled": "")
a(data-i18n="editor.pop_i18n")#pop-level-i18n-button Populate i18n
li.divider
li.dropdown-header Info
li#level-history-button

View file

@ -233,6 +233,7 @@ class InternationalizationNode extends TreemaNode.nodeMap.object
type: "object"
properties: {}
}
return i18nChildSchema unless @parent
unless @schema.props?
console.warn "i18n props array is empty! Filling with all parent properties by default"
@schema.props = (prop for prop,_ of @parent.schema.properties when prop isnt "i18n")

View file

@ -31,6 +31,7 @@ module.exports = class EditorLevelView extends View
'click #patches-tab': -> @patchesView.load()
'click #level-patch-button': 'startPatchingLevel'
'click #level-watch-button': 'toggleWatchLevel'
'click #pop-level-i18n-button': -> @level.populateI18N()
constructor: (options, @levelID) ->
super options