diff --git a/app/lib/surface/CocoSprite.coffee b/app/lib/surface/CocoSprite.coffee index 23e16cec8..478a71b0c 100644 --- a/app/lib/surface/CocoSprite.coffee +++ b/app/lib/surface/CocoSprite.coffee @@ -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: -> "" 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). diff --git a/app/lib/surface/WizardSprite.coffee b/app/lib/surface/WizardSprite.coffee index c577dae28..d5bdfede2 100644 --- a/app/lib/surface/WizardSprite.coffee +++ b/app/lib/surface/WizardSprite.coffee @@ -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 diff --git a/app/views/editor/achievement/AchievementEditView.coffee b/app/views/editor/achievement/AchievementEditView.coffee index 524c14e2e..0825c9de6 100644 --- a/app/views/editor/achievement/AchievementEditView.coffee +++ b/app/views/editor/achievement/AchievementEditView.coffee @@ -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 diff --git a/app/views/editor/thang/ThangTypeColorsTabView.coffee b/app/views/editor/thang/ThangTypeColorsTabView.coffee index cdc624587..8f5884eda 100644 --- a/app/views/editor/thang/ThangTypeColorsTabView.coffee +++ b/app/views/editor/thang/ThangTypeColorsTabView.coffee @@ -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 diff --git a/app/views/play/level/modal/LevelGuideModal.coffee b/app/views/play/level/modal/LevelGuideModal.coffee index 4f454b380..0d54a71a7 100644 --- a/app/views/play/level/modal/LevelGuideModal.coffee +++ b/app/views/play/level/modal/LevelGuideModal.coffee @@ -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 []