More fixes for empty string array serialization.

This commit is contained in:
Nick Winter 2014-03-06 16:32:13 -08:00
parent 2fb1c184f9
commit b6335a30ae
2 changed files with 16 additions and 12 deletions

View file

@ -389,31 +389,30 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@addMark('bounds').toggle true if @thang?.drawsBounds
@addMark('shadow').toggle true unless @thangType.get('shadow') is 0
mark.update() for name, mark of @marks
# @thang.effectNames = ['berserk', 'confuse', 'control', 'curse', 'fear', 'poison', 'paralyze', 'regen', 'sleep', 'slow', 'speed']
#@thang.effectNames = ['berserk', 'confuse', 'control', 'curse', 'fear', 'poison', 'paralyze', 'regen', 'sleep', 'slow', 'speed']
@updateEffectMarks() if @thang?.effectNames?.length
updateEffectMarks: ->
@thang.effectNames = (e for e in @thang.effectNames when e) # hack because empty strings appear in the array
return if _.isEqual @thang.effectNames, @previousEffectNames
for effect in @thang.effectNames
mark = @addMark effect, @options.floatingLayer, effect
mark.statusEffect = true
mark.toggle 'on'
mark.show()
if @previousEffectNames
for effect in @previousEffectNames
mark = @marks[effect]
mark.toggle 'off'
if @thang.effectNames.length > 1 and not @effectInterval
@rotateEffect()
@effectInterval = setInterval @rotateEffect, 1500
else if @effectInterval and @thang.effectNames.length <= 1
@clearInterval @effectInterval
@effectInterval = null
@previousEffectNames = @thang.effectNames
rotateEffect: =>
@ -450,7 +449,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@labels[name]
addMark: (name, layer, thangType=null) ->
console.log 'what are my effects?', @thang.effectNames unless name
@marks[name] ?= new Mark name: name, sprite: @, camera: @options.camera, layer: layer ? @options.groundLayer, thangType: thangType
@marks[name]

View file

@ -50,9 +50,12 @@ module.exports = class ThangState
value = @thang.world.getThangByID @specialKeysToValues[specialKey]
else if type is 'array'
specialKey = storage[@frameIndex]
value = @specialKeysToValues[specialKey]
# Remove leading and trailing Group Separators and split by any Record Separators to restore the array of strings
value = value.substring(1, value.length - 1).split('\x1E') if value
valueString = @specialKeysToValues[specialKey]
if valueString and valueString.length > 1
# Trim leading Group Separator and trailing Record Separator, split by Record Separators, restore string array.
value = valueString.substring(1, valueString.length - 1).split '\x1E'
else
value = []
else
value = storage[@frameIndex]
value
@ -135,7 +138,10 @@ module.exports = class ThangState
storage[frameIndex] = specialKey
else if type is 'array'
# We make sure the array keys won't collide with any string keys by using some unprintable characters.
value = '\x1D' + value.join('\x1E') + '\x1D' # Group Separator, Record Separator(s), Group Separator
stringPieces = ['\x1D'] # Group Separator
for element in value
stringPieces.push element, '\x1E' # Record Separator(s)
value = stringPieces.join('')
specialKey = specialValuesToKeys[value]
unless specialKey
specialKey = specialKeysToValues.length