mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Fixed camera zoom killing coordinate hover unnecessarily.
This commit is contained in:
parent
46c4601ac6
commit
df51e28a1d
3 changed files with 18 additions and 5 deletions
|
@ -283,8 +283,9 @@ module.exports = class Camera extends CocoClass
|
||||||
target = @boundTarget @target, @zoom
|
target = @boundTarget @target, @zoom
|
||||||
return if not force and _.isEqual target, @currentTarget
|
return if not force and _.isEqual target, @currentTarget
|
||||||
@currentTarget = target
|
@currentTarget = target
|
||||||
@updateViewports target
|
viewportDifference = @updateViewports target
|
||||||
Backbone.Mediator.publish 'camera:zoom-updated', camera: @, zoom: @zoom, surfaceViewport: @surfaceViewport
|
if viewportDifference > 0.1 # Roughly 0.1 pixel difference in what we can see
|
||||||
|
Backbone.Mediator.publish 'camera:zoom-updated', camera: @, zoom: @zoom, surfaceViewport: @surfaceViewport
|
||||||
|
|
||||||
boundTarget: (pos, zoom) ->
|
boundTarget: (pos, zoom) ->
|
||||||
# Given an {x, y} in Surface coordinates, return one that will keep our viewport on the Surface.
|
# Given an {x, y} in Surface coordinates, return one that will keep our viewport on the Surface.
|
||||||
|
@ -303,6 +304,11 @@ module.exports = class Camera extends CocoClass
|
||||||
sv = width: @canvasWidth / @zoom, height: @canvasHeight / @zoom, cx: target.x, cy: target.y
|
sv = width: @canvasWidth / @zoom, height: @canvasHeight / @zoom, cx: target.x, cy: target.y
|
||||||
sv.x = sv.cx - sv.width / 2
|
sv.x = sv.cx - sv.width / 2
|
||||||
sv.y = sv.cy - sv.height / 2
|
sv.y = sv.cy - sv.height / 2
|
||||||
|
if @surfaceViewport
|
||||||
|
# Calculate how different this viewport is. (If it's basically not different, we can avoid visualizing the update.)
|
||||||
|
viewportDifference = Math.abs(@surfaceViewport.x - sv.x) + 1.01 * Math.abs(@surfaceViewport.y - sv.y) + 1.02 * Math.abs(@surfaceViewport.width - sv.width)
|
||||||
|
else
|
||||||
|
viewportDifference = 9001
|
||||||
@surfaceViewport = sv
|
@surfaceViewport = sv
|
||||||
|
|
||||||
wv = @surfaceToWorld sv # get x and y
|
wv = @surfaceToWorld sv # get x and y
|
||||||
|
@ -312,6 +318,8 @@ module.exports = class Camera extends CocoClass
|
||||||
wv.cy = wv.y + wv.height / 2
|
wv.cy = wv.y + wv.height / 2
|
||||||
@worldViewport = wv
|
@worldViewport = wv
|
||||||
|
|
||||||
|
viewportDifference
|
||||||
|
|
||||||
lock: ->
|
lock: ->
|
||||||
@target = @currentTarget
|
@target = @currentTarget
|
||||||
@locked = true
|
@locked = true
|
||||||
|
|
|
@ -16,6 +16,7 @@ module.exports = class CoordinateDisplay extends createjs.Container
|
||||||
console.error @toString(), 'needs a camera.' unless @camera
|
console.error @toString(), 'needs a camera.' unless @camera
|
||||||
console.error @toString(), 'needs a layer.' unless @layer
|
console.error @toString(), 'needs a layer.' unless @layer
|
||||||
@build()
|
@build()
|
||||||
|
@performShow = @show
|
||||||
@show = _.debounce @show, 125
|
@show = _.debounce @show, 125
|
||||||
Backbone.Mediator.subscribe(channel, @[func], @) for channel, func of @subscriptions
|
Backbone.Mediator.subscribe(channel, @[func], @) for channel, func of @subscriptions
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ module.exports = class CoordinateDisplay extends createjs.Container
|
||||||
wop.y = Math.round(wop.y)
|
wop.y = Math.round(wop.y)
|
||||||
return if wop.x is @lastPos?.x and wop.y is @lastPos?.y
|
return if wop.x is @lastPos?.x and wop.y is @lastPos?.y
|
||||||
@lastPos = wop
|
@lastPos = wop
|
||||||
|
@lastScreenPos = x: e.x, y: e.y
|
||||||
@hide()
|
@hide()
|
||||||
@show() # debounced
|
@show() # debounced
|
||||||
|
|
||||||
|
@ -58,8 +60,11 @@ module.exports = class CoordinateDisplay extends createjs.Container
|
||||||
Backbone.Mediator.publish 'surface:coordinate-selected', wop
|
Backbone.Mediator.publish 'surface:coordinate-selected', wop
|
||||||
|
|
||||||
onZoomUpdated: (e) ->
|
onZoomUpdated: (e) ->
|
||||||
@hide()
|
return unless @lastPos
|
||||||
@show()
|
wop = @camera.screenToWorld @lastScreenPos
|
||||||
|
@lastPos.x = Math.round wop.x
|
||||||
|
@lastPos.y = Math.round wop.y
|
||||||
|
@performShow() if @label.parent
|
||||||
|
|
||||||
onFlagColorSelected: (e) ->
|
onFlagColorSelected: (e) ->
|
||||||
@placingFlag = Boolean e.color
|
@placingFlag = Boolean e.color
|
||||||
|
|
|
@ -10,7 +10,7 @@ hipchat = require '../hipchat'
|
||||||
deltasLib = require '../../app/lib/deltas'
|
deltasLib = require '../../app/lib/deltas'
|
||||||
|
|
||||||
PROJECT = {original: 1, name: 1, version: 1, description: 1, slug: 1, kind: 1, created: 1, permissions: 1}
|
PROJECT = {original: 1, name: 1, version: 1, description: 1, slug: 1, kind: 1, created: 1, permissions: 1}
|
||||||
FETCH_LIMIT = 500
|
FETCH_LIMIT = 1000 # So many ThangTypes
|
||||||
|
|
||||||
module.exports = class Handler
|
module.exports = class Handler
|
||||||
# subclasses should override these properties
|
# subclasses should override these properties
|
||||||
|
|
Loading…
Reference in a new issue