Tweaked SpriteParser to be smarter about finding root MovieClips and shifting their bounds.
This commit is contained in:
parent
87c34e81c6
commit
e870de6146
1 changed files with 22 additions and 14 deletions
|
@ -37,14 +37,7 @@ module.exports = class SpriteParser
|
||||||
blocks = @findBlocks ast, source
|
blocks = @findBlocks ast, source
|
||||||
containers = _.filter blocks, {kind: 'Container'}
|
containers = _.filter blocks, {kind: 'Container'}
|
||||||
movieClips = _.filter blocks, {kind: 'MovieClip'}
|
movieClips = _.filter blocks, {kind: 'MovieClip'}
|
||||||
if movieClips.length
|
|
||||||
# First movie clip is root, so do it last
|
|
||||||
movieClips = movieClips[1 ... movieClips.length].concat([movieClips[0]])
|
|
||||||
|
|
||||||
# first container isn't necessarily root... actually the last one is root in blue-cart
|
|
||||||
# else if containers.length
|
|
||||||
# # First container is root, so do it last
|
|
||||||
# containers = containers[1 ... containers.length].concat([containers[0]])
|
|
||||||
mainClip = _.last(movieClips) ? _.last(containers)
|
mainClip = _.last(movieClips) ? _.last(containers)
|
||||||
@animationName = mainClip.name
|
@animationName = mainClip.name
|
||||||
for container, index in containers
|
for container, index in containers
|
||||||
|
@ -69,17 +62,24 @@ module.exports = class SpriteParser
|
||||||
break
|
break
|
||||||
continue unless container.bounds and instructions.length
|
continue unless container.bounds and instructions.length
|
||||||
@addContainer {c: instructions, b: container.bounds}, container.name
|
@addContainer {c: instructions, b: container.bounds}, container.name
|
||||||
|
|
||||||
|
childrenMovieClips = []
|
||||||
|
|
||||||
for movieClip, index in movieClips
|
for movieClip, index in movieClips
|
||||||
if index is 0
|
lastBounds = null
|
||||||
for bounds in movieClip.frameBounds
|
# fill in bounds which are null...
|
||||||
bounds[0] -= @width / 2
|
for bounds, boundsIndex in movieClip.frameBounds
|
||||||
bounds[1] -= @height / 2
|
if not bounds
|
||||||
movieClip.bounds[0] -= @width / 2
|
movieClip.frameBounds[boundsIndex] = _.clone(lastBounds)
|
||||||
movieClip.bounds[1] -= @height / 2
|
else
|
||||||
|
lastBounds = bounds
|
||||||
|
|
||||||
localGraphics = @getGraphicsFromBlock(movieClip, source)
|
localGraphics = @getGraphicsFromBlock(movieClip, source)
|
||||||
[shapeKeys, localShapes] = @getShapesFromBlock movieClip, source
|
[shapeKeys, localShapes] = @getShapesFromBlock movieClip, source
|
||||||
localContainers = @getContainersFromMovieClip movieClip, source, true
|
localContainers = @getContainersFromMovieClip movieClip, source, true
|
||||||
localAnimations = @getAnimationsFromMovieClip movieClip, source, true
|
localAnimations = @getAnimationsFromMovieClip movieClip, source, true
|
||||||
|
for animation in localAnimations
|
||||||
|
childrenMovieClips.push(animation.gn)
|
||||||
localTweens = @getTweensFromMovieClip movieClip, source, localShapes, localContainers, localAnimations
|
localTweens = @getTweensFromMovieClip movieClip, source, localShapes, localContainers, localAnimations
|
||||||
@addAnimation {
|
@addAnimation {
|
||||||
shapes: localShapes
|
shapes: localShapes
|
||||||
|
@ -90,6 +90,14 @@ module.exports = class SpriteParser
|
||||||
bounds: movieClip.bounds
|
bounds: movieClip.bounds
|
||||||
frameBounds: movieClip.frameBounds
|
frameBounds: movieClip.frameBounds
|
||||||
}, movieClip.name
|
}, movieClip.name
|
||||||
|
|
||||||
|
for movieClip in movieClips
|
||||||
|
if movieClip.name not in childrenMovieClips
|
||||||
|
for bounds in movieClip.frameBounds
|
||||||
|
bounds[0] -= @width / 2
|
||||||
|
bounds[1] -= @height / 2
|
||||||
|
movieClip.bounds[0] -= @width / 2
|
||||||
|
movieClip.bounds[1] -= @height / 2
|
||||||
|
|
||||||
@saveToModel()
|
@saveToModel()
|
||||||
return movieClips[0]?.name
|
return movieClips[0]?.name
|
||||||
|
|
Reference in a new issue