mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Added i18n population action to the level editor.
This commit is contained in:
parent
9c8841e838
commit
c85971e5e6
5 changed files with 28 additions and 1 deletions
|
@ -68,7 +68,7 @@ expandFlattenedDelta = (delta, left, schema) ->
|
||||||
parentLeft = left
|
parentLeft = left
|
||||||
parentSchema = schema
|
parentSchema = schema
|
||||||
for key, i in delta.dataPath
|
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 {}
|
childSchema = parentSchema?.items or parentSchema?.properties?[key] or {}
|
||||||
childLeft = parentLeft?[key]
|
childLeft = parentLeft?[key]
|
||||||
humanKey = null
|
humanKey = null
|
||||||
|
|
|
@ -133,6 +133,7 @@ class CocoModel extends Backbone.Model
|
||||||
schema ?= @schema()
|
schema ?= @schema()
|
||||||
models = []
|
models = []
|
||||||
|
|
||||||
|
# TODO: Better schema/json walking
|
||||||
if $.isArray(data) and schema.items?
|
if $.isArray(data) and schema.items?
|
||||||
for subData, i in data
|
for subData, i in data
|
||||||
models = models.concat(@getReferencedModels(subData, schema.items, path+i+'/', shouldLoadProjection))
|
models = models.concat(@getReferencedModels(subData, schema.items, path+i+'/', shouldLoadProjection))
|
||||||
|
@ -227,4 +228,26 @@ class CocoModel extends Backbone.Model
|
||||||
watching: ->
|
watching: ->
|
||||||
return me.id in (@get('watchers') or [])
|
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
|
module.exports = CocoModel
|
||||||
|
|
|
@ -68,6 +68,8 @@ block header
|
||||||
a(data-i18n="common.fork")#fork-level-start-button Fork
|
a(data-i18n="common.fork")#fork-level-start-button Fork
|
||||||
li(class=anonymous ? "disabled": "")
|
li(class=anonymous ? "disabled": "")
|
||||||
a(data-toggle="coco-modal", data-target="modal/revert", data-i18n="editor.revert")#revert-button Revert
|
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.divider
|
||||||
li.dropdown-header Info
|
li.dropdown-header Info
|
||||||
li#level-history-button
|
li#level-history-button
|
||||||
|
|
|
@ -233,6 +233,7 @@ class InternationalizationNode extends TreemaNode.nodeMap.object
|
||||||
type: "object"
|
type: "object"
|
||||||
properties: {}
|
properties: {}
|
||||||
}
|
}
|
||||||
|
return i18nChildSchema unless @parent
|
||||||
unless @schema.props?
|
unless @schema.props?
|
||||||
console.warn "i18n props array is empty! Filling with all parent properties by default"
|
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")
|
@schema.props = (prop for prop,_ of @parent.schema.properties when prop isnt "i18n")
|
||||||
|
|
|
@ -31,6 +31,7 @@ module.exports = class EditorLevelView extends View
|
||||||
'click #patches-tab': -> @patchesView.load()
|
'click #patches-tab': -> @patchesView.load()
|
||||||
'click #level-patch-button': 'startPatchingLevel'
|
'click #level-patch-button': 'startPatchingLevel'
|
||||||
'click #level-watch-button': 'toggleWatchLevel'
|
'click #level-watch-button': 'toggleWatchLevel'
|
||||||
|
'click #pop-level-i18n-button': -> @level.populateI18N()
|
||||||
|
|
||||||
constructor: (options, @levelID) ->
|
constructor: (options, @levelID) ->
|
||||||
super options
|
super options
|
||||||
|
|
Loading…
Reference in a new issue