mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Finish hooking up prerendered spritesheets with LayerAdapter
This commit is contained in:
parent
1085731fdd
commit
305cffb5ea
5 changed files with 63 additions and 13 deletions
|
@ -18,12 +18,12 @@ class SpriteExporter extends CocoClass
|
|||
@colorConfig = options.colorConfig or {}
|
||||
@resolutionFactor = options.resolutionFactor or 1
|
||||
@actionNames = options.actionNames or (action.name for action in @thangType.getDefaultActions())
|
||||
@spriteType = options.spriteType or @thangType.get('spriteType')
|
||||
@spriteType = options.spriteType or @thangType.get('spriteType') or 'segmented'
|
||||
super()
|
||||
|
||||
build: (renderType) ->
|
||||
spriteSheetBuilder = new createjs.SpriteSheetBuilder()
|
||||
if (renderType or @thangType.get('spriteType') or 'segmented') is 'segmented'
|
||||
if @spriteType is 'segmented'
|
||||
@renderSegmentedThangType(spriteSheetBuilder)
|
||||
else
|
||||
@renderSingularThangType(spriteSheetBuilder)
|
||||
|
@ -65,7 +65,7 @@ class SpriteExporter extends CocoClass
|
|||
frames = (framesMap[parseInt(frame)] for frame in action.frames.split(','))
|
||||
else
|
||||
frames = _.sortBy(_.values(framesMap))
|
||||
next = @nextForAction(action)
|
||||
next = @thangType.nextForAction(action)
|
||||
spriteSheetBuilder.addAnimation(action.name, frames, next)
|
||||
|
||||
containerActions = []
|
||||
|
|
|
@ -352,6 +352,7 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
#- Rendering containers for segmented thang types
|
||||
|
||||
renderSegmentedThangType: (thangType, colorConfig, actionNames, spriteSheetBuilder) ->
|
||||
prerenderedSpriteSheet = thangType.getPrerenderedSpriteSheet(colorConfig, 'segmented')
|
||||
containersToRender = thangType.getContainersForActions(actionNames)
|
||||
spriteBuilder = new SpriteBuilder(thangType, {colorConfig: colorConfig})
|
||||
for containerGlobalName in containersToRender
|
||||
|
@ -360,6 +361,11 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
container = new createjs.Sprite(@spriteSheet)
|
||||
container.gotoAndStop(containerKey)
|
||||
frame = spriteSheetBuilder.addFrame(container)
|
||||
else if prerenderedSpriteSheet
|
||||
container = new createjs.Sprite(prerenderedSpriteSheet.spriteSheet)
|
||||
container.gotoAndStop(containerGlobalName)
|
||||
scale = @resolutionFactor / (prerenderedSpriteSheet.get('resolutionFactor') or 1)
|
||||
frame = spriteSheetBuilder.addFrame(container, null, scale)
|
||||
else
|
||||
container = spriteBuilder.buildContainerFromStore(containerGlobalName)
|
||||
frame = spriteSheetBuilder.addFrame(container, null, @resolutionFactor * (thangType.get('scale') or 1))
|
||||
|
@ -368,6 +374,15 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
#- Rendering sprite sheets for singular thang types
|
||||
|
||||
renderSingularThangType: (thangType, colorConfig, actionNames, spriteSheetBuilder) ->
|
||||
prerenderedSpriteSheet = thangType.getPrerenderedSpriteSheet(colorConfig, 'singular')
|
||||
prerenderedFramesMap = {}
|
||||
if prerenderedSpriteSheet
|
||||
scale = @resolutionFactor / (prerenderedSpriteSheet.get('resolutionFactor') or 1)
|
||||
for frame, i in prerenderedSpriteSheet.spriteSheet._frames
|
||||
sprite = new createjs.Sprite(prerenderedSpriteSheet.spriteSheet)
|
||||
sprite.gotoAndStop(i)
|
||||
prerenderedFramesMap[i] = spriteSheetBuilder.addFrame(sprite, null, scale)
|
||||
|
||||
actionObjects = _.values(thangType.getActions())
|
||||
animationActions = []
|
||||
for a in actionObjects
|
||||
|
@ -393,10 +408,20 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
for key, index in actionKeys
|
||||
action = actions[index]
|
||||
frames = (framesMap[f] for f in @spriteSheet.getAnimation(key).frames)
|
||||
next = @nextForAction(action)
|
||||
next = thangType.nextForAction(action)
|
||||
spriteSheetBuilder.addAnimation(key, frames, next)
|
||||
continue
|
||||
|
||||
if prerenderedSpriteSheet
|
||||
for action in actions
|
||||
name = @renderGroupingKey(thangType, action.name, colorConfig)
|
||||
prerenderedFrames = prerenderedSpriteSheet.get('animations')?[action.name]?.frames
|
||||
continue if not prerenderedFrames
|
||||
frames = (prerenderedFramesMap[frame] for frame in prerenderedFrames)
|
||||
next = thangType.nextForAction(action)
|
||||
spriteSheetBuilder.addAnimation(name, frames, next)
|
||||
continue
|
||||
|
||||
mc = spriteBuilder.buildMovieClip(animationName, null, null, null, {'temp':0})
|
||||
|
||||
if renderAll
|
||||
|
@ -418,7 +443,7 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
frames = (framesMap[parseInt(frame)] for frame in action.frames.split(','))
|
||||
else
|
||||
frames = _.sortBy(_.values(framesMap))
|
||||
next = @nextForAction(action)
|
||||
next = thangType.nextForAction(action)
|
||||
spriteSheetBuilder.addAnimation(name, frames, next)
|
||||
|
||||
containerActions = []
|
||||
|
@ -429,6 +454,14 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
|
||||
containerGroups = _.groupBy containerActions, (action) -> action.container
|
||||
for containerName, actions of containerGroups
|
||||
if prerenderedSpriteSheet
|
||||
for action in actions
|
||||
name = @renderGroupingKey(thangType, action.name, colorConfig)
|
||||
prerenderedFrames = prerenderedSpriteSheet.get('animations')?[action.name]?.frames
|
||||
continue if not prerenderedFrames
|
||||
frame = prerenderedFramesMap[prerenderedFrames[0]]
|
||||
spriteSheetBuilder.addAnimation(name, [frame], false)
|
||||
continue
|
||||
container = spriteBuilder.buildContainerFromStore(containerName)
|
||||
scale = actions[0].scale or thangType.get('scale') or 1
|
||||
frame = spriteSheetBuilder.addFrame(container, null, scale * @resolutionFactor)
|
||||
|
@ -436,12 +469,6 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
name = @renderGroupingKey(thangType, action.name, colorConfig)
|
||||
spriteSheetBuilder.addAnimation(name, [frame], false)
|
||||
|
||||
nextForAction: (action) ->
|
||||
next = true
|
||||
next = action.goesTo if action.goesTo
|
||||
next = false if action.loops is false
|
||||
return next
|
||||
|
||||
#- Rendering frames for raster thang types
|
||||
|
||||
renderRasterThangType: (thangType, spriteSheetBuilder) ->
|
||||
|
|
|
@ -511,6 +511,12 @@ module.exports = class ThangType extends CocoModel
|
|||
containersToRender[container.gn] = true for container in animationContainers
|
||||
return _.keys(containersToRender)
|
||||
|
||||
nextForAction: (action) ->
|
||||
next = true
|
||||
next = action.goesTo if action.goesTo
|
||||
next = false if action.loops is false
|
||||
return next
|
||||
|
||||
initPrerenderedSpriteSheets: ->
|
||||
return if @prerenderedSpriteSheets or not data = @get('prerenderedSpriteSheetData')
|
||||
# creates a collection of prerendered sprite sheets
|
||||
|
|
|
@ -18,6 +18,18 @@ block modal-body-content
|
|||
label.col-sm-3.control-label Resolution Factor
|
||||
.col-sm-9
|
||||
input#resolution-input.form-control(value=3)
|
||||
|
||||
.form-group
|
||||
label.col-sm-3.control-label Sprite Type
|
||||
.col-sm-9
|
||||
- var spriteType = view.thangType.get('spriteType') || 'segmented'
|
||||
label.radio-inline
|
||||
input(type="radio" name="sprite-type" value="segmented" checked=spriteType==='segmented')
|
||||
| Segmented
|
||||
label.radio-inline
|
||||
input(type="radio" name="sprite-type" value="singular" checked=spriteType!=='segmented')
|
||||
| Singular
|
||||
|
||||
.form-group
|
||||
label.col-sm-3.control-label Actions
|
||||
.col-sm-9
|
||||
|
@ -31,4 +43,6 @@ block modal-body-content
|
|||
|
||||
block modal-footer-content
|
||||
button.btn.btn-default(data-dismiss="modal") Cancel
|
||||
button#save-btn.btn.btn-primary Save
|
||||
button#save-btn.btn.btn-primary Save
|
||||
.progress.progress-striped.active.hide
|
||||
.progress-bar(style="width: 100%")
|
|
@ -27,9 +27,12 @@ module.exports = class ExportThangTypeModal extends ModalView
|
|||
getActionNames: -> _.map @$('input[name="action"]:checked'), (el) -> $(el).val()
|
||||
getResolutionFactor: -> parseInt(@$('#resolution-input').val()) or SPRITE_RESOLUTION_FACTOR
|
||||
getFilename: -> 'spritesheet-'+_.string.slugify(moment().format())+'.png'
|
||||
getSpriteType: -> @thangType.get('spriteType') or 'segmented'
|
||||
getSpriteType: -> @$('input[name="sprite-type"]:checked').val()
|
||||
|
||||
onClickSaveButton: ->
|
||||
@$('.modal-footer button').addClass('hide')
|
||||
@$('.modal-footer .progress').removeClass('hide')
|
||||
@$('input, select').attr('disabled', true)
|
||||
options = {
|
||||
resolutionFactor: @getResolutionFactor()
|
||||
actionNames: @getActionNames()
|
||||
|
|
Loading…
Reference in a new issue