mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-06-21 10:08:11 +02:00
🎨 some side work for the telnet version
This commit is contained in:
parent
e79d91186b
commit
309a237bda
@ -78,7 +78,7 @@ module.exports = class BrailleBuffer
|
|||||||
frame: ->
|
frame: ->
|
||||||
output = []
|
output = []
|
||||||
currentColor = null
|
currentColor = null
|
||||||
delimeter = "\n"
|
delimeter = "\r\n"
|
||||||
|
|
||||||
for idx in [0...@pixelBuffer.length]
|
for idx in [0...@pixelBuffer.length]
|
||||||
output.push delimeter if idx and (idx % (@width/2)) is 0
|
output.push delimeter if idx and (idx % (@width/2)) is 0
|
||||||
|
@ -62,7 +62,7 @@ module.exports = class Mapscii
|
|||||||
|
|
||||||
_initKeyboard: ->
|
_initKeyboard: ->
|
||||||
keypress config.input
|
keypress config.input
|
||||||
config.input.setRawMode true
|
config.input.setRawMode true if config.input.setRawMode
|
||||||
config.input.resume()
|
config.input.resume()
|
||||||
|
|
||||||
config.input.on 'keypress', (ch, key) => @_onKey key
|
config.input.on 'keypress', (ch, key) => @_onKey key
|
||||||
@ -108,7 +108,8 @@ module.exports = class Mapscii
|
|||||||
|
|
||||||
z = utils.baseZoom @zoom
|
z = utils.baseZoom @zoom
|
||||||
center = utils.ll2tile @center.lon, @center.lat, z
|
center = utils.ll2tile @center.lon, @center.lat, z
|
||||||
@mousePosition = utils.tile2ll center.x+(dx/size), center.y+(dy/size), z
|
|
||||||
|
@mousePosition = utils.normalize utils.tile2ll center.x+(dx/size), center.y+(dy/size), z
|
||||||
|
|
||||||
_onClick: (event) ->
|
_onClick: (event) ->
|
||||||
@_updateMousePosition event
|
@_updateMousePosition event
|
||||||
@ -153,14 +154,18 @@ module.exports = class Mapscii
|
|||||||
@notify @_getFooter()
|
@notify @_getFooter()
|
||||||
|
|
||||||
_onKey: (key) ->
|
_onKey: (key) ->
|
||||||
|
if config.keyCallback and not config.keyCallback key
|
||||||
|
return
|
||||||
|
|
||||||
# check if the pressed key is configured
|
# check if the pressed key is configured
|
||||||
draw = switch key?.name
|
draw = switch key?.name
|
||||||
when "q"
|
when "q", "esc", "c"
|
||||||
|
if config.endCallback
|
||||||
|
config.endCallback()
|
||||||
|
null
|
||||||
|
else
|
||||||
process.exit 0
|
process.exit 0
|
||||||
|
|
||||||
when "w" then @zoomy = 1
|
|
||||||
when "s" then @zoomy = -1
|
|
||||||
|
|
||||||
when "a" then @zoomBy config.zoomStep
|
when "a" then @zoomBy config.zoomStep
|
||||||
when "z" then @zoomBy -config.zoomStep
|
when "z" then @zoomBy -config.zoomStep
|
||||||
|
|
||||||
@ -174,9 +179,9 @@ module.exports = class Mapscii
|
|||||||
|
|
||||||
if draw isnt null
|
if draw isnt null
|
||||||
@_draw()
|
@_draw()
|
||||||
else
|
#else
|
||||||
# display debug info for unhandled keys
|
# display debug info for unhandled keys
|
||||||
@notify JSON.stringify key
|
#@notify JSON.stringify key
|
||||||
|
|
||||||
_draw: ->
|
_draw: ->
|
||||||
@renderer
|
@renderer
|
||||||
@ -218,11 +223,4 @@ module.exports = class Mapscii
|
|||||||
@setCenter @center.lat+lat, @center.lon+lon
|
@setCenter @center.lat+lat, @center.lon+lon
|
||||||
|
|
||||||
setCenter: (lat, lon) ->
|
setCenter: (lat, lon) ->
|
||||||
lon += 360 if lon < -180
|
@center = utils.normalize lon: lon, lat: lat
|
||||||
lon -= 360 if lon > 180
|
|
||||||
|
|
||||||
lat = 85.0511 if lat > 85.0511
|
|
||||||
lat = -85.0511 if lat < -85.0511
|
|
||||||
|
|
||||||
@center.lat = lat
|
|
||||||
@center.lon = lon
|
|
@ -55,5 +55,13 @@ utils =
|
|||||||
digits: (number, digits) ->
|
digits: (number, digits) ->
|
||||||
Math.floor(number*Math.pow(10, digits))/Math.pow(10, digits)
|
Math.floor(number*Math.pow(10, digits))/Math.pow(10, digits)
|
||||||
|
|
||||||
|
normalize: (ll) ->
|
||||||
|
ll.lon += 360 if ll.lon < -180
|
||||||
|
ll.lon -= 360 if ll.lon > 180
|
||||||
|
|
||||||
|
ll.lat = 85.0511 if ll.lat > 85.0511
|
||||||
|
ll.lat = -85.0511 if ll.lat < -85.0511
|
||||||
|
|
||||||
|
ll
|
||||||
|
|
||||||
module.exports = utils
|
module.exports = utils
|
||||||
|
Loading…
x
Reference in New Issue
Block a user