This commit is contained in:
Scott Erickson 2014-08-29 17:12:44 -07:00
commit 3f6c9c4f02
5 changed files with 41 additions and 13 deletions

View file

@ -80,13 +80,14 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@age = 0
@stillLoading = true
if @thangType.isFullyLoaded()
@setupSprite()
@setUpSprite()
else
@thangType.setProjection null
@thangType.fetch() unless @thangType.loading
@listenToOnce(@thangType, 'sync', @setupSprite)
@listenToOnce(@thangType, 'sync', @setUpSprite)
@setUpPlaceholder()
setupSprite: ->
setUpSprite: ->
for trigger, sounds of @thangType.get('soundTriggers') or {} when trigger isnt 'say'
AudioPlayer.preloadSoundReference sound for sound in sounds
if @thangType.get('raster')
@ -97,7 +98,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
else
result = @buildSpriteSheet()
if _.isString result # async build
@listenToOnce @thangType, 'build-complete', @setupSprite
@listenToOnce @thangType, 'build-complete', @setUpSprite
@setUpPlaceholder()
else
@stillLoading = false
@actions = @thangType.getActions()
@ -106,6 +108,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@queueAction 'idle'
finishSetup: ->
@placeholder = null
@updateBaseScale()
@scaleFactorX = @thang.scaleFactorX if @thang?.scaleFactorX?
@scaleFactorX = @thang.scaleFactor if @thang?.scaleFactor?
@ -127,6 +130,28 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@imageObject.regY = -reg.y
@finishSetup()
setUpPlaceholder: ->
return if @placeholder or not @thang
shape = new createjs.Shape()
width = @thang.width * Camera.PPM
height = @thang.height * Camera.PPM * @options.camera.y2x
depth = @thang.depth * Camera.PPM * @options.camera.z2y * @options.camera.y2x
makeColor = (brightnessFactor) => (Math.round(c * brightnessFactor) for c in (healthColors[@thang.team] ? [180, 180, 180]))
topColor = "rgba(#{makeColor(0.85).join(', ')},1)"
mainColor = "rgba(#{makeColor(0.75).join(', ')},1)"
ellipse = @thang.shape in ['ellipsoid', 'disc']
fn = if ellipse then 'drawEllipse' else 'drawRect'
shape.graphics.beginFill(mainColor)[fn](-width / 2, -height / 2, width, height).endFill()
if ellipse
shape.graphics.moveTo(-width / 2, 0).beginFill(mainColor).lineTo(-width / 2, -depth).lineTo(width / 2, -depth).lineTo(width / 2, 0).lineTo(-width / 2, 0).endFill()
else
shape.graphics.moveTo(-width / 2, 0).beginFill(mainColor).lineTo(-width / 2, -depth).lineTo(width / 2, -depth).lineTo(width / 2, 0).lineTo(-width / 2, 0).endFill()
shape.graphics.beginFill(topColor)[fn](-width / 2, -height / 2 - depth, width, height).endFill()
shape.layerPriority = @thang?.layerPriority ? @thangType.get 'layerPriority'
@setImageObject shape
@updatePosition true
@placeholder = shape
toString: -> "<CocoSprite: #{@thang?.id}>"
buildSpriteSheet: ->
@ -311,15 +336,15 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
p1.z += bobOffset
x: p1.x, y: p1.y, z: if @thang.isLand then 0 else p1.z - @thang.depth / 2
updatePosition: (log) ->
return if @stillLoading
updatePosition: (whileLoading=false) ->
return if @stillLoading and not whileLoading
return unless @thang?.pos and @options.camera?
wop = @getWorldPosition()
[p0, p1] = [@lastPos, @thang.pos]
return if p0 and p0.x is p1.x and p0.y is p1.y and p0.z is p1.z and not @options.camera.tweeningZoomTo and not @thang.bobHeight
sup = @options.camera.worldToSurface wop
[@imageObject.x, @imageObject.y] = [sup.x, sup.y]
@lastPos = p1.copy?() or _.clone(p1)
@lastPos = p1.copy?() or _.clone(p1) unless whileLoading
@hasMoved = true
if @thangType.get('name') is 'Flag' and not @notOfThisWorld
# Let the pending flags know we're here (but not this call stack, they need to delete themselves, and we may be iterating sprites).

View file

@ -82,7 +82,7 @@ module.exports = class WizardSprite extends IndieSprite
shouldUpdate = not _.isEqual(newColorConfig, @options.colorConfig)
@options.colorConfig = $.extend(true, {}, newColorConfig)
if shouldUpdate
@setupSprite()
@setUpSprite()
@playAction(@currentAction) if @currentAction
onSpriteSelected: (e) ->
@ -205,8 +205,8 @@ module.exports = class WizardSprite extends IndieSprite
@faceTarget()
@update true
updatePosition: ->
return unless @options.camera
updatePosition: (whileLoading=false) ->
return if whileLoading or not @options.camera
@thang.pos = @getCurrentPosition()
@faceTarget()
sup = @options.camera.worldToSurface x: @thang.pos.x, y: @thang.pos.y, z: @thang.pos.z - @thang.depth / 2

View file

@ -41,6 +41,7 @@ module.exports = class AchievementEditView extends RootView
change: @pushChangesToPreview
@treema = @$el.find('#achievement-treema').treema(options)
@treema.build()
@pushChangesToPreview()
getRenderData: (context={}) ->
context = super(context)
@ -54,6 +55,7 @@ module.exports = class AchievementEditView extends RootView
@pushChangesToPreview()
pushChangesToPreview: =>
return unless @treema
@$el.find('#achievement-view').empty()
for key, value of @treema.data
@achievement.set key, value

View file

@ -14,7 +14,7 @@ module.exports = class ThangTypeColorsTabView extends CocoView
super options
@supermodel.loadModel @thangType, 'thang'
@colorConfig = {hue: 0, saturation: 0.5, lightness: 0.5}
@spriteBuilder = new SpriteBuilder(@thangType)
@spriteBuilder = new SpriteBuilder(@thangType) if @thangType.get('raw')
f = =>
@offset++
@updateMovieClip()
@ -54,7 +54,7 @@ module.exports = class ThangTypeColorsTabView extends CocoView
@updateMovieClip()
updateMovieClip: ->
return unless @currentColorGroupTreema
return unless @currentColorGroupTreema and @thangType.get('raw')
actionDict = @thangType.getActions()
animations = (a.animation for key, a of actionDict when a.animation)
index = @offset % animations.length
@ -74,6 +74,7 @@ module.exports = class ThangTypeColorsTabView extends CocoView
@stage.addChild @movieClip
updateContainer: ->
return unless @thangType.get('raw')
actionDict = @thangType.getActions()
idle = actionDict.idle
@stage.removeChild(@container) if @container

View file

@ -14,7 +14,7 @@ module.exports = class LevelGuideModal extends ModalView
constructor: (options) ->
@firstOnly = options.firstOnly
@docs = options?.docs
@docs = options?.docs ? {}
general = @docs.generalArticles or []
specific = @docs.specificArticles or []