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'
|
2023-04-28 17:35:52 +00:00
|
|
|
local SAVEDIRECTORY = "out/"
|
2023-07-28 05:17:00 +00:00
|
|
|
local Camera = require 'camera'
|
|
|
|
local wasKeyPressed
|
2023-04-28 17:35:52 +00:00
|
|
|
|
|
|
|
function love.load()
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
local lfs = assert( love.filesystem )
|
|
|
|
lfs.setIdentity( "dcearth", false )
|
|
|
|
assert( lfs.createDirectory( SAVEDIRECTORY.."data/earth" ))
|
|
|
|
assert( lfs.createDirectory( SAVEDIRECTORY.."data/graphics" ))
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
|
|
|
|
love.graphics.setNewFont( 12, "mono" )
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
2024-04-21 16:07:56 +00:00
|
|
|
function love.directorydropped( path )
|
|
|
|
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
|
|
|
|
if love.keyboard.isScancodeDown( "w" ) then moveCamera = true; ty = ty + 1 end
|
|
|
|
if love.keyboard.isScancodeDown( "a" ) then moveCamera = true; tx = tx - 1 end
|
|
|
|
if love.keyboard.isScancodeDown( "s" ) then moveCamera = true; ty = ty - 1 end
|
|
|
|
if love.keyboard.isScancodeDown( "d" ) then moveCamera = true; tx = tx + 1 end
|
2023-07-28 23:23:08 +00:00
|
|
|
if love.keyboard.isScancodeDown( "q" ) then Camera.Zoom( true ) end
|
|
|
|
if love.keyboard.isScancodeDown( "e" ) then Camera.Zoom( false ) 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
|
|
|
|
|
2024-04-21 14:10:53 +00:00
|
|
|
local toolButtons = {
|
|
|
|
"Brush",
|
|
|
|
"Move Nodes",
|
|
|
|
"Add Nodes",
|
|
|
|
"Edit Node",
|
|
|
|
"Draw Polygon",
|
|
|
|
"Erase Polygon"
|
|
|
|
}
|
|
|
|
|
|
|
|
local layerButtons = {
|
|
|
|
"Africa",
|
|
|
|
"Europe",
|
|
|
|
"North America",
|
|
|
|
"South America",
|
|
|
|
"Asia",
|
|
|
|
"Russia",
|
|
|
|
"Travel Nodes",
|
|
|
|
"AI Markers",
|
|
|
|
"Cities",
|
|
|
|
"Coastlines",
|
|
|
|
"Coastlines Low",
|
|
|
|
"Sailable"
|
|
|
|
}
|
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
function love.draw()
|
2024-04-21 16:07:56 +00:00
|
|
|
if not map.loaded then
|
|
|
|
return love.graphics.print( "Drag and drop folder to begin.")
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
2024-04-21 14:10:53 +00:00
|
|
|
--Layer buttons.
|
|
|
|
do
|
|
|
|
love.graphics.setColor( 1, 1, 1, 1 )
|
|
|
|
local h = love.graphics.getHeight() - 60
|
|
|
|
for x = 0, 300, 30 do
|
|
|
|
love.graphics.rectangle( "line", x, h, 30, 30 )
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
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 )
|
2023-07-28 05:17:00 +00:00
|
|
|
local h = love.graphics.getHeight() - 30
|
|
|
|
love.graphics.setColor( 0.2, 0.1, 0.1, 0.5 )
|
|
|
|
love.graphics.rectangle( "fill", 0, h, love.graphics.getWidth() / 2, 30 )
|
|
|
|
love.graphics.setColor( 1, 1, 1, 1 )
|
|
|
|
love.graphics.rectangle( "line", 0, h, love.graphics.getWidth() / 2, 30 )
|
|
|
|
love.graphics.print(("SCREEN\t%d\t%d\nWORLD \t%5.2f\t%5.2f"):format(x, y, wx, wy), 0, h)
|
2023-07-28 23:23:08 +00:00
|
|
|
love.graphics.print(("BITMAP\t%5.2f\t%5.2f"):format(bx, by), 200, h )
|
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
--Edit box.
|
|
|
|
love.graphics.rectangle( "line", love.graphics.getWidth() / 2, h, love.graphics.getWidth() / 2, 30 )
|
2024-04-21 16:07:56 +00:00
|
|
|
if map.loaded and map.cities.selected then
|
2023-09-04 00:49:02 +00:00
|
|
|
local c = map.cities.selected
|
2023-07-28 05:42:16 +00:00
|
|
|
love.graphics.setColor( 0.2, 0.1, 0.1, 0.5 )
|
|
|
|
love.graphics.rectangle( "fill", 0, 0, 150 ,100 )
|
|
|
|
love.graphics.setColor( 1, 1, 1, 1 )
|
|
|
|
love.graphics.rectangle( "line", 0, 0, 150 ,100 )
|
|
|
|
love.graphics.setColor( 1.2, 1.1, 1.1, 1.5 )
|
2023-07-28 05:17:00 +00:00
|
|
|
love.graphics.print( ("NAME: %s\nX: %3.2f\nY: %3.2f\nPOP: %d\nCAPITAL: %s\nCOUNTRY: %s"):format(c.name, c.x, c.y, c.pop, tostring(c.capital), c.country), 0, 0 )
|
2024-04-21 16:07:56 +00:00
|
|
|
elseif map.loaded and map.travelnodes.selected then
|
2023-09-04 00:49:02 +00:00
|
|
|
local c = map.travelnodes.selected
|
|
|
|
love.graphics.setColor( 0.2, 0.1, 0.1, 0.5 )
|
|
|
|
love.graphics.rectangle( "fill", 0, 0, 150 ,100 )
|
|
|
|
love.graphics.setColor( 1, 1, 1, 1 )
|
|
|
|
love.graphics.rectangle( "line", 0, 0, 150 ,100 )
|
|
|
|
love.graphics.setColor( 1.2, 1.1, 1.1, 1.5 )
|
|
|
|
love.graphics.print( ("Node: %d\nX: %3.2f\nY: %3.2f\n"):format(c.number, c.x, c.y) )
|
2024-04-21 16:07:56 +00:00
|
|
|
elseif map.loaded and map.ainodes.selectedNode then
|
2023-09-04 00:49:02 +00:00
|
|
|
local c = map.ainodes.selected
|
|
|
|
love.graphics.setColor( 0.2, 0.1, 0.1, 0.5 )
|
|
|
|
love.graphics.rectangle( "fill", 0, 0, 150 ,100 )
|
|
|
|
love.graphics.setColor( 1, 1, 1, 1 )
|
|
|
|
love.graphics.rectangle( "line", 0, 0, 150 ,100 )
|
|
|
|
love.graphics.setColor( 1.2, 1.1, 1.1, 1.5 )
|
|
|
|
love.graphics.print( ("Node: %d\nX: %3.2f\nY: %3.2f\noffensive: %s"):format(c.number, c.x, c.y, c.attack) )
|
2023-07-28 05:17:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.resize(w, h)
|
|
|
|
Camera.Resize( w, h )
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.wheelmoved(x, y)
|
|
|
|
Camera.Zoom( (y > 0) and true or false )
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.mousepressed( x, y, button, istouch, presses )
|
|
|
|
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
2024-04-21 16:07:56 +00:00
|
|
|
if map.loaded then
|
|
|
|
if button == 1 then
|
|
|
|
map.cities.lockSelection()
|
|
|
|
else
|
|
|
|
map.cities.unlockSelection()
|
|
|
|
end
|
2023-07-28 05:42:16 +00:00
|
|
|
end
|
2023-07-28 05:17:00 +00:00
|
|
|
print( ("MOUSE\tx %f\ty %f\twx %f\twy %f"):format(x, y, wx, wy) )
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.mousemoved( x, y, dx, dy, istouch )
|
2024-04-21 16:07:56 +00:00
|
|
|
if map.loaded and map.cities.visible then map.cities.selectNearestCity( Camera.GetWorldCoordinate( x, y ) ) end
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
2023-07-28 23:23:08 +00:00
|
|
|
local function ToggleVisibility( layer )
|
|
|
|
if not layer then return end
|
|
|
|
local ml
|
|
|
|
if map[layer] then ml = map[layer] end
|
|
|
|
if map.territory[layer] then ml = map.territory[layer] end
|
|
|
|
assert( ml )
|
|
|
|
ml.visible = not( ml.visible )
|
|
|
|
print( layer, ml.visible )
|
|
|
|
end
|
|
|
|
|
|
|
|
local layerVisibilityKeybinds = {
|
|
|
|
["1"] = "africa",
|
|
|
|
["2"] = "europe",
|
|
|
|
["3"] = "northamerica",
|
|
|
|
["4"] = "southamerica",
|
|
|
|
["5"] = "southasia",
|
|
|
|
["6"] = "russia",
|
|
|
|
["7"] = "sailable",
|
|
|
|
["8"] = "coastlines",
|
|
|
|
["9"] = "coastlinesLow",
|
|
|
|
["0"] = "international",
|
2024-04-21 16:07:56 +00:00
|
|
|
["-"] = "cities",
|
|
|
|
["="] = "travelnodes",
|
|
|
|
["backspace"] = "ainodes",
|
2023-07-28 23:23:08 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
function love.keypressed(key)
|
2023-07-28 23:23:08 +00:00
|
|
|
ToggleVisibility( layerVisibilityKeybinds[key] )
|
|
|
|
|
|
|
|
if key == "l" then
|
|
|
|
-- To open a file or folder, "file://" must be prepended to the path.
|
|
|
|
love.system.openURL("file://"..love.filesystem.getSaveDirectory())
|
|
|
|
end
|
|
|
|
|
|
|
|
wasKeyPressed = true
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|