Refactored buildRadius() to work with any range radius

This commit is contained in:
Shrihari 2014-03-18 17:39:16 +05:30
parent 005a91cec2
commit b283757315
2 changed files with 43 additions and 50 deletions

View file

@ -22,6 +22,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
healthBar: null
marks: null
labels: null
ranges: null
rangeValues: null
options:
resolutionFactor: 4
@ -62,6 +64,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@actionQueue = []
@marks = {}
@labels = {}
@ranges = []
@rangeValues = []
@handledAoEs = {}
@age = 0
@displayObject = new createjs.Container()
@ -413,14 +417,22 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
createMarks: ->
if @thang
allProps = []
allProps = ['visualRange', 'attackRange', 'voiceRange']
allProps = allProps.concat (@thang.hudProperties ? [])
allProps = allProps.concat (@thang.programmableProperties ? [])
allProps = allProps.concat (@thang.moreProgrammableProperties ? [])
@addMark('voiceradius') if 'voiceRange' in allProps
@addMark('visualradius') if 'visualRange' in allProps
@addMark('attackradius') if 'attackRange' in allProps
for property in allProps
if m = property.match(".*Range$")
if @thang[m[0]]? and @thang[m[0]] < 9001
@ranges.push([ m[0], @thang[m[0]] ])
@ranges = @ranges.sort((a, b) ->
return a[1] < b[1]
)
for range in @ranges
@addMark(range[0])
@addMark('bounds').toggle true if @thang?.drawsBounds
@addMark('shadow').toggle true unless @thangType.get('shadow') is 0
@ -431,13 +443,17 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@marks.repair?.toggle @thang?.errorsOut
if @selected
@marks.voiceradius?.toggle true
@marks.visualradius?.toggle true
@marks.attackradius?.toggle true
else
@marks.voiceradius?.toggle false
@marks.visualradius?.toggle false
@marks.attackradius?.toggle false
for range in @ranges
@marks[range[0]].toggle true
# @marks.voiceradius?.toggle true
# @marks.visualradius?.toggle true
# @marks.attackradius?.toggle true
else
for range in @ranges
@marks[range[0]].toggle false
# @marks.voiceradius?.toggle false
# @marks.visualradius?.toggle false
# @marks.attackradius?.toggle false
mark.update() for name, mark of @marks
#@thang.effectNames = ['berserk', 'confuse', 'control', 'curse', 'fear', 'poison', 'paralyze', 'regen', 'sleep', 'slow', 'haste']

View file

@ -55,9 +55,7 @@ module.exports = class Mark extends CocoClass
if @name is 'bounds' then @buildBounds()
else if @name is 'shadow' then @buildShadow()
else if @name is 'debug' then @buildDebug()
else if @name is 'voiceradius' then @buildRadius('voice')
else if @name is 'visualradius' then @buildRadius('visual')
else if @name is 'attackradius' then @buildRadius('attack')
else if @name.match(".*Range$") then @buildRadius(@name)
else if @thangType then @buildSprite()
else console.error "Don't know how to build mark for", @name
@mark?.mouseEnabled = false
@ -118,50 +116,29 @@ module.exports = class Mark extends CocoClass
#@mark.cache 0, 0, diameter, diameter # not actually faster than simple ellipse draw
buildRadius: (type) ->
return if type is 'voice' and @sprite.thang.voiceRange > 9000
return if type is 'visual' and @sprite.thang.visualRange > 9000
return if type is 'attack' and @sprite.thang.attackRange > 9000
alpha = 1
colors =
voice: "rgba(0, 145, 0, alpha)"
visual: "rgba(0, 0, 145, alpha)"
attack: "rgba(145, 0, 0, alpha)"
color = colors[type]
voiceRange: "rgba(0, 145, 0, #{alpha})"
visualRange: "rgba(0, 0, 145, #{alpha})"
attackRange: "rgba(145, 0, 0, #{alpha})"
@mark = new createjs.Shape()
@mark.graphics.beginFill color.replace('alpha', 0.4)
@mark.graphics.beginFill colors[type]
if type is 'voice'
r = @sprite.thang.voiceRange
ranges = [
r,
if 'visualradius' of @sprite.marks and @sprite.thang.visualRange < 9001 then @sprite.thang.visualRange else 0,
if 'attackradius' of @sprite.marks and @sprite.thang.attackRange < 9001 then @sprite.thang.attackRange else 0
]
else if type is 'visual'
r = @sprite.thang.visualRange
ranges = [
r,
if 'attackradius' of @sprite.marks and @sprite.thang.attackRange < 9001 then @sprite.thang.attackRange else 0,
if 'voiceradius' of @sprite.marks and @sprite.thang.voiceRange < 9001 then @sprite.thang.voiceRange else 0,
]
else if type is 'attack'
r = @sprite.thang.attackRange
ranges = [
r,
if 'voiceradius' of @sprite.marks and @sprite.thang.voiceRange < 9001 then @sprite.thang.voiceRange else 0,
if 'visualradius' of @sprite.marks and @sprite.thang.visualRange < 9001 then @sprite.thang.visualRange else 0
]
r = @sprite.thang[type]
rangeNames = @sprite.ranges.map((value, index) ->
value[0]
)
i = rangeNames.indexOf(type)
console.log(i, @sprite.ranges)
# Draw the outer circle
@mark.graphics.drawCircle 0, 0, r * Camera.PPM
# Cut out the inner circle
if Math.max(ranges['1'], ranges['2']) < r
@mark.graphics.arc 0, 0, Math.max(ranges['1'], ranges['2']) * Camera.PPM, Math.PI*2, 0, true
else if Math.min(ranges['1'], ranges['2']) < r
@mark.graphics.arc 0, 0, Math.min(ranges['1'], ranges['2']) * Camera.PPM, Math.PI*2, 0, true
# Cut out the hollow part if necessary
if i+1 < @sprite.ranges.length
@mark.graphics.arc 0, 0, @sprite.ranges[i+1][1], Math.PI*2, 0, true
# Add perspective
@mark.scaleY *= @camera.y2x