2023-04-28 17:35:52 +00:00
|
|
|
local love = assert( love, "This tool requires LOVE: love2d.org" )
|
2024-04-21 16:07:56 +00:00
|
|
|
--assert( require('mobdebug') ).start() --remote debugger
|
2023-04-28 17:35:52 +00:00
|
|
|
local map = require 'map'
|
2024-04-21 14:10:53 +00:00
|
|
|
local button = require 'button'
|
2024-04-29 02:44:18 +00:00
|
|
|
require 'mainmenu'
|
2023-07-28 05:17:00 +00:00
|
|
|
local Camera = require 'camera'
|
2023-04-28 17:35:52 +00:00
|
|
|
|
|
|
|
function love.load()
|
2024-04-29 02:44:18 +00:00
|
|
|
love.filesystem.setIdentity( "dcearth", false )
|
2024-04-29 01:21:32 +00:00
|
|
|
love.keyboard.setKeyRepeat( true )
|
2024-04-29 02:44:18 +00:00
|
|
|
love.graphics.setNewFont( 14 )
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
2024-04-21 16:07:56 +00:00
|
|
|
function love.directorydropped( path )
|
2024-04-28 01:38:23 +00:00
|
|
|
if map.path then
|
|
|
|
assert( love.filesystem.unmount( map.path ) )
|
|
|
|
map.loaded = false
|
|
|
|
end
|
2024-04-21 16:07:56 +00:00
|
|
|
love.filesystem.mount( path, "" )
|
|
|
|
return map.load( path )
|
|
|
|
end
|
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
function love.update( dt )
|
2023-07-28 05:17:00 +00:00
|
|
|
local tx, ty = 0, 0
|
|
|
|
local moveCamera = false
|
2024-04-25 01:06:41 +00:00
|
|
|
if love.keyboard.isScancodeDown( "w" ) then moveCamera = true; ty = ty + 30 * dt end
|
|
|
|
if love.keyboard.isScancodeDown( "a" ) then moveCamera = true; tx = tx - 30 * dt end
|
|
|
|
if love.keyboard.isScancodeDown( "s" ) then moveCamera = true; ty = ty - 30 * dt end
|
|
|
|
if love.keyboard.isScancodeDown( "d" ) then moveCamera = true; tx = tx + 30 * dt end
|
|
|
|
if love.keyboard.isScancodeDown( "q" ) then Camera.Zoom( dt ) end
|
|
|
|
if love.keyboard.isScancodeDown( "e" ) then Camera.Zoom( -dt ) end
|
2023-07-28 05:17:00 +00:00
|
|
|
if moveCamera then Camera.Translate( tx, ty ) end
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
2024-04-21 16:07:56 +00:00
|
|
|
if not map.loaded then
|
2024-04-28 01:38:23 +00:00
|
|
|
local w, h = love.graphics.getDimensions()
|
2024-04-29 01:21:32 +00:00
|
|
|
return love.graphics.printf( "Drag and drop folder to begin.", w / 2 - 200, h / 2 - 128, 400, "center")
|
2024-04-21 16:07:56 +00:00
|
|
|
end
|
2024-04-25 01:06:41 +00:00
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
love.graphics.push( "all" )
|
|
|
|
map.draw()
|
|
|
|
love.graphics.pop()
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
--Status bar.
|
|
|
|
local x, y = love.mouse.getPosition()
|
|
|
|
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
2023-07-28 23:23:08 +00:00
|
|
|
local bx, by = Camera.GetBitmapCoordinate( x, y )
|
2024-04-28 01:38:23 +00:00
|
|
|
local h = love.graphics.getHeight() - 60
|
|
|
|
love.graphics.setColor( 0.1, 0.1, 0.5, 0.8 )
|
|
|
|
love.graphics.rectangle( "fill", 0, 0, 250, love.graphics.getHeight() )
|
2023-07-28 05:17:00 +00:00
|
|
|
love.graphics.setColor( 1, 1, 1, 1 )
|
2024-04-28 01:38:23 +00:00
|
|
|
love.graphics.print(([[
|
2024-04-29 01:21:32 +00:00
|
|
|
SCREEN %-12d %-12d
|
|
|
|
WORLD %-12.2f%-12.2f
|
2024-04-29 02:44:18 +00:00
|
|
|
BITMAP %-12d %-12d
|
2024-04-29 01:21:32 +00:00
|
|
|
%s]]):format(x, y, wx, wy, bx, by, map.editLayer and map.editLayer.filename or ""), 0, 0)
|
2024-04-28 01:38:23 +00:00
|
|
|
|
|
|
|
if map.selected then love.graphics.print( map.selected:formatDisplayInfo(), 0, 80 ) end
|
|
|
|
if map.selectionLocked then end
|
|
|
|
|
|
|
|
love.graphics.setColor( 1, 1, 1, 0.8 )
|
|
|
|
button:draw()
|
2023-07-28 05:17:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.resize(w, h)
|
|
|
|
Camera.Resize( w, h )
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.wheelmoved(x, y)
|
2024-04-29 01:21:32 +00:00
|
|
|
Camera.Zoom( (y > 0) and 0.1 or -0.1 )
|
2023-07-28 05:17:00 +00:00
|
|
|
end
|
|
|
|
|
2024-04-28 01:38:23 +00:00
|
|
|
function love.mousepressed( x, y, mouseButton, istouch, presses )
|
2023-07-28 05:17:00 +00:00
|
|
|
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
2024-04-29 01:21:32 +00:00
|
|
|
|
|
|
|
if button.selected and button.selected:contains( x, y ) then
|
|
|
|
print( ("MOUSE\tx %f\ty %f\twx %f\twy %f"):format(x, y, wx, wy) )
|
2024-04-29 02:44:18 +00:00
|
|
|
button.callback( button.selected )
|
2024-04-29 01:21:32 +00:00
|
|
|
return button.selected:callback()
|
|
|
|
end
|
2023-07-28 05:17:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.mousemoved( x, y, dx, dy, istouch )
|
2024-04-28 01:38:23 +00:00
|
|
|
if not map.loaded then return end
|
|
|
|
--mouse over menu
|
|
|
|
button.selectIn( x, y )
|
|
|
|
|
|
|
|
--mouse on map
|
|
|
|
if map.selectionLocked then return end
|
|
|
|
if map.editLayer and map.editLayer.selectNearest then
|
|
|
|
map.selected = map.editLayer:selectNearest( Camera.GetWorldCoordinate( x, y ) )
|
2024-04-25 01:06:41 +00:00
|
|
|
end
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
2024-04-28 01:38:23 +00:00
|
|
|
function love.keypressed(key, code, isRepeat)
|
|
|
|
|
2024-04-29 01:21:32 +00:00
|
|
|
if code == "left" then return button.selectPrev() end
|
|
|
|
if code == "right" then return button.selectNext() end
|
|
|
|
if code == "down" then return button.selectNextInGroup() end
|
|
|
|
if code == "up" then return button.selectPrevInGroup() end
|
2024-04-28 01:38:23 +00:00
|
|
|
if code == "return" then return button.selected:callback() end
|
|
|
|
|
|
|
|
if key == "c" then
|
|
|
|
map.selectionLocked = not( map.selectionLocked )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
2024-04-28 01:38:23 +00:00
|
|
|
|