mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-16 00:19:50 -05:00
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
|
||||
containers = _.filter blocks, {kind: 'Container'}
|
||||
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)
|
||||
@animationName = mainClip.name
|
||||
for container, index in containers
|
||||
|
@ -69,17 +62,24 @@ module.exports = class SpriteParser
|
|||
break
|
||||
continue unless container.bounds and instructions.length
|
||||
@addContainer {c: instructions, b: container.bounds}, container.name
|
||||
|
||||
childrenMovieClips = []
|
||||
|
||||
for movieClip, index in movieClips
|
||||
if index is 0
|
||||
for bounds in movieClip.frameBounds
|
||||
bounds[0] -= @width / 2
|
||||
bounds[1] -= @height / 2
|
||||
movieClip.bounds[0] -= @width / 2
|
||||
movieClip.bounds[1] -= @height / 2
|
||||
lastBounds = null
|
||||
# fill in bounds which are null...
|
||||
for bounds, boundsIndex in movieClip.frameBounds
|
||||
if not bounds
|
||||
movieClip.frameBounds[boundsIndex] = _.clone(lastBounds)
|
||||
else
|
||||
lastBounds = bounds
|
||||
|
||||
localGraphics = @getGraphicsFromBlock(movieClip, source)
|
||||
[shapeKeys, localShapes] = @getShapesFromBlock movieClip, source
|
||||
localContainers = @getContainersFromMovieClip movieClip, source, true
|
||||
localAnimations = @getAnimationsFromMovieClip movieClip, source, true
|
||||
for animation in localAnimations
|
||||
childrenMovieClips.push(animation.gn)
|
||||
localTweens = @getTweensFromMovieClip movieClip, source, localShapes, localContainers, localAnimations
|
||||
@addAnimation {
|
||||
shapes: localShapes
|
||||
|
@ -90,6 +90,14 @@ module.exports = class SpriteParser
|
|||
bounds: movieClip.bounds
|
||||
frameBounds: movieClip.frameBounds
|
||||
}, 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()
|
||||
return movieClips[0]?.name
|
||||
|
|
Loading…
Reference in a new issue