mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -05:00
Add system names into delta messages
This commit is contained in:
parent
b20f8fd260
commit
75b759b1dc
3 changed files with 15 additions and 2 deletions
10
app/lib/SystemNameLoader.coffee
Normal file
10
app/lib/SystemNameLoader.coffee
Normal file
|
@ -0,0 +1,10 @@
|
|||
CocoClass = require 'lib/CocoClass'
|
||||
|
||||
namesCache = {}
|
||||
|
||||
class SystemNameLoader extends CocoClass
|
||||
getName: (id) -> namesCache[id]?.name
|
||||
|
||||
setName: (system) -> namesCache[system.get('original')] = {name:system.get('name')}
|
||||
|
||||
module.exports = new SystemNameLoader()
|
|
@ -1,3 +1,4 @@
|
|||
SystemNameLoader = require 'lib/SystemNameLoader'
|
||||
###
|
||||
Good-to-knows:
|
||||
dataPath: an array of keys that walks you up a JSON object that's being patched
|
||||
|
@ -73,7 +74,7 @@ expandFlattenedDelta = (delta, left, schema) ->
|
|||
humanKey = null
|
||||
childData = if i is delta.dataPath.length-1 and delta.action is 'added' then o[0] else childLeft
|
||||
humanKey ?= childData.name or childData.id if childData
|
||||
humanKey ?= "#{childSchema.title} ##{key+1}" if childSchema.title and _.isNumber(key)
|
||||
humanKey ?= SystemNameLoader.getName(childData?.original)
|
||||
humanKey ?= "#{childSchema.title}" if childSchema.title
|
||||
humanKey ?= _.string.titleize key
|
||||
humanPath.push humanKey
|
||||
|
@ -155,4 +156,4 @@ prunePath = (delta, path) ->
|
|||
else
|
||||
prunePath delta[path[0]], path.slice(1)
|
||||
keys = (k for k in _.keys(delta[path[0]]) when k isnt '_t')
|
||||
delete delta[path[0]] if keys.length is 0
|
||||
delete delta[path[0]] if keys.length is 0
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
CocoModel = require('./CocoModel')
|
||||
SystemNameLoader = require('lib/SystemNameLoader')
|
||||
|
||||
module.exports = class LevelSystem extends CocoModel
|
||||
@className: "LevelSystem"
|
||||
|
@ -16,6 +17,7 @@ module.exports = class LevelSystem extends CocoModel
|
|||
onLoaded: ->
|
||||
super()
|
||||
@set 'js', @compile(@get 'code') unless @get 'js'
|
||||
SystemNameLoader.setName @
|
||||
|
||||
compile: (code) ->
|
||||
if @get('language') and @get('language') isnt 'coffeescript'
|
||||
|
|
Loading…
Reference in a new issue