Taking into account null rects and library width/height subtraction on sprite parsing.

This commit is contained in:
Nick Winter 2014-03-08 14:38:35 -08:00
parent 57f1588dea
commit be12d38e34

View file

@ -24,6 +24,11 @@ module.exports = class SpriteParser
@animationLongKeys[longKey] = shortKey
parse: (source) ->
# Grab the library properties' width/height so we can subtract half of each from frame bounds
properties = source.match(/.*lib\.properties = \{\n.*?width: (\d+),\n.*?height: (\d+)/im)
@width = parseInt(properties[1] ? "0", 10)
@height = parseInt(properties[2] ? "0", 10)
options = {loc: false, range: true}
ast = esprima.parse source, options
blocks = @findBlocks ast, source
@ -178,11 +183,18 @@ module.exports = class SpriteParser
else if arg.type is 'AssignmentExpression'
bounds = @grabFunctionArguments argSource.replace('rect=', ''), true
lastRect = bounds
else if arg.type is 'Literal' and arg.value is null
bounds = [0, 0, 1, 1] # Let's try this.
frameBounds.push bounds
else
console.log "Didn't have multiframe bounds for this movie clip!"
frameBounds = [nominalBounds]
# Subtract half of width/height parsed from lib.properties
for bounds in frameBounds
bounds[0] -= @width / 2
bounds[1] -= @height / 2
functionExpressions.push {name: name, bounds: nominalBounds, frameBounds: frameBounds, expression: node.parent.parent, kind: kind}
@walk ast, null, gatherFunctionExpressions
functionExpressions