diff --git a/app/lib/surface/CocoSprite.coffee b/app/lib/surface/CocoSprite.coffee index 57146866a..279ef087b 100644 --- a/app/lib/surface/CocoSprite.coffee +++ b/app/lib/surface/CocoSprite.coffee @@ -82,6 +82,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass @imageObject?.off 'animationend', @playNextAction @playNextAction = null @displayObject?.off() + clearInterval @effectInterval if @effectInterval super() toString: -> "" @@ -375,18 +376,55 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass scale *= @options.resolutionFactor if prop is 'registration' pos.x *= scale pos.y *= scale + if @thang + scaleFactor = @thang.scaleFactor ? 1 + pos.x *= @thang.scaleFactorX ? scaleFactor + pos.y *= @thang.scaleFactorY ? scaleFactor pos updateMarks: -> return unless @options.camera - @addMark 'repair', null, @options.markThangTypes.repair if @thang?.errorsOut + @addMark 'repair', null, 'repair' if @thang?.errorsOut @marks.repair?.toggle @thang?.errorsOut @addMark('bounds').toggle true if @thang?.drawsBounds @addMark('shadow').toggle true unless @thangType.get('shadow') is 0 mark.update() for name, mark of @marks +# @thang.effectNames = ['berserk', 'confused', 'controlled', 'cursed', 'fear', 'poison', 'paralyzed', 'regeneration', 'sleep', 'slowed', 'speed'] + @updateEffectMarks() if @thang?.effectNames?.length + + updateEffectMarks: -> + return if _.isEqual @thang.effectNames, @previousEffectNames + for effect in @thang.effectNames + mark = @addMark effect, @options.floatingLayer, effect + mark.statusEffect = true + mark.toggle 'on' + mark.show() + + if @previousEffectNames + for effect in @previousEffectNames + mark = @marks[effect] + mark.toggle 'off' + + if @thang.effectNames.length > 1 and not @effectInterval + @rotateEffect() + @effectInterval = setInterval @rotateEffect, 1500 + + else if @effectInterval and @thang.effectNames.length <= 1 + @clearInterval @effectInterval + @effectInterval = null + + @previousEffectNames = @thang.effectNames + + rotateEffect: => + effects = (m.name for m in _.values(@marks) when m.on and m.statusEffect and m.mark) + effects.sort() + @effectIndex ?= 0 + @effectIndex = (@effectIndex + 1) % effects.length + @marks[effect].hide() for effect in effects + @marks[effects[@effectIndex]].show() setHighlight: (to, delay) -> - @addMark 'highlight', @options.floatingLayer, @options.markThangTypes.highlight if to + @addMark 'highlight', @options.floatingLayer, 'highlight' if to @marks.highlight?.highlightDelay = delay @marks.highlight?.toggle to and not @dimmed diff --git a/app/lib/surface/Mark.coffee b/app/lib/surface/Mark.coffee index c012b537c..5a2e7689f 100644 --- a/app/lib/surface/Mark.coffee +++ b/app/lib/surface/Mark.coffee @@ -1,5 +1,7 @@ CocoClass = require 'lib/CocoClass' Camera = require './Camera' +ThangType = require 'models/ThangType' +markThangTypes = {} module.exports = class Mark extends CocoClass subscriptions: {} @@ -20,6 +22,7 @@ module.exports = class Mark extends CocoClass destroy: -> @mark?.parent?.removeChild @mark @markSprite?.destroy() + @thangType?.off 'sync', @onLoadedThangType, @ @sprite = null super() @@ -27,7 +30,9 @@ module.exports = class Mark extends CocoClass toggle: (to) -> return @ if to is @on + return @toggleTo = to unless @mark @on = to + delete @toggleTo if @on @layer.addChild @mark @layer.updateLayerOrder() @@ -52,7 +57,7 @@ module.exports = class Mark extends CocoClass else if @name is 'debug' then @buildDebug() else if @thangType then @buildSprite() else console.error "Don't know how to build mark for", @name - @mark.mouseEnabled = false + @mark?.mouseEnabled = false @ buildBounds: -> @@ -126,15 +131,34 @@ module.exports = class Mark extends CocoClass @mark.graphics.endFill() buildSprite: -> - #console.log "building", @name, "with thangtype", @thangType + if _.isString @thangType + thangType = markThangTypes[@thangType] + return @loadThangType() if not thangType + @thangType = thangType + + return @thangType.once 'sync', @onLoadedThangType, @ if not @thangType.loaded CocoSprite = require './CocoSprite' markSprite = new CocoSprite @thangType, @thangType.spriteOptions markSprite.queueAction 'idle' @mark = markSprite.displayObject @markSprite = markSprite + loadThangType: -> + name = @thangType + @thangType = new ThangType() + @thangType.url = -> "/db/thang.type/#{name}" + @thangType.once 'sync', @onLoadedThangType, @ + @thangType.fetch() + markThangTypes[name] = @thangType + window.mtt = markThangTypes + + onLoadedThangType: -> + @build() + @toggle(@toggleTo) if @toggleTo? + update: (pos=null) -> - return false unless @on + return false unless @on and @mark + @mark.alpha = if @hidden then 0 else 1 @updatePosition pos @updateRotation() @updateScale() @@ -156,10 +180,11 @@ module.exports = class Mark extends CocoClass pos ?= @sprite?.displayObject @mark.x = pos.x @mark.y = pos.y - if @name is 'highlight' + if @statusEffect or @name is 'highlight' offset = @sprite.getOffset 'aboveHead' @mark.x += offset.x @mark.y += offset.y + @mark.y -= 3 if @statusEffect updateRotation: -> if @name is 'debug' or (@name is 'shadow' and @sprite.thang?.shape in ["rectangle", "box"]) @@ -187,3 +212,5 @@ module.exports = class Mark extends CocoClass stop: -> @markSprite?.stop() play: -> @markSprite?.play() + hide: -> @hidden = true + show: -> @hidden = false diff --git a/app/lib/surface/SpriteBoss.coffee b/app/lib/surface/SpriteBoss.coffee index 130d017b7..f84d52a28 100644 --- a/app/lib/surface/SpriteBoss.coffee +++ b/app/lib/surface/SpriteBoss.coffee @@ -48,10 +48,6 @@ module.exports = class SpriteBoss extends CocoClass thangTypeFor: (type) -> _.find @options.thangTypes, (m) -> m.get('original') is type or m.get('name') is type - markThangTypes: -> - highlight: @thangTypeFor "Highlight" - repair: @thangTypeFor "Repair" - createLayers: -> @spriteLayers = {} for [name, priority] in [ @@ -87,11 +83,11 @@ module.exports = class SpriteBoss extends CocoClass sprite createMarks: -> - @targetMark = new Mark name: 'target', camera: @camera, layer: @spriteLayers["Ground"], thangType: @thangTypeFor("Target") - @selectionMark = new Mark name: 'selection', camera: @camera, layer: @spriteLayers["Ground"], thangType: @thangTypeFor("Selection") + @targetMark = new Mark name: 'target', camera: @camera, layer: @spriteLayers["Ground"], thangType: 'target' + @selectionMark = new Mark name: 'selection', camera: @camera, layer: @spriteLayers["Ground"], thangType: 'selection' createSpriteOptions: (options) -> - _.extend options, camera: @camera, resolutionFactor: 4, groundLayer: @spriteLayers["Ground"], textLayer: @surfaceTextLayer, floatingLayer: @spriteLayers["Floating"], markThangTypes: @markThangTypes(), spriteSheetCache: @spriteSheetCache, showInvisible: @options.showInvisible + _.extend options, camera: @camera, resolutionFactor: 4, groundLayer: @spriteLayers["Ground"], textLayer: @surfaceTextLayer, floatingLayer: @spriteLayers["Floating"], spriteSheetCache: @spriteSheetCache, showInvisible: @options.showInvisible createIndieSprites: (indieSprites, withWizards) -> unless @indieSprites diff --git a/app/models/Level.coffee b/app/models/Level.coffee index fca1f8249..176b09aa6 100644 --- a/app/models/Level.coffee +++ b/app/models/Level.coffee @@ -115,15 +115,5 @@ module.exports = class Level extends CocoModel model = CocoModel.getOrMakeModelFromLink link, shouldLoadProjection models.push model if model else if path is '/' - # We also we need to make sure we grab the Wizard ThangType and the Marks. Hackitrooooid! - for [type, original] in [ - ["Highlight", "529f8fdbdacd325127000003"] - ["Selection", "52aa5f7520fccb0000000002"] - ["Target", "52b32ad97385ec3d03000001"] - ["Repair", "52bcc4591f766a891c000003"] - ] - link = "/db/thang_type/#{original}/version" - model = CocoModel.getOrMakeModelFromLink link, shouldLoadProjection - models.push model if model models.push ThangType.loadUniversalWizard() models