2023-04-28 17:35:52 +00:00
|
|
|
local lg = love.graphics
|
2023-08-26 21:05:48 +00:00
|
|
|
local AI = require 'ai'
|
2023-04-28 17:35:52 +00:00
|
|
|
local Cities = require 'cities'
|
|
|
|
local Lines = require 'lines'
|
2024-04-25 01:06:41 +00:00
|
|
|
local Nodes = require 'travelNodes'
|
2023-07-28 05:17:00 +00:00
|
|
|
local Camera = require 'camera'
|
2023-07-28 23:23:08 +00:00
|
|
|
local Territory = require 'territory'
|
2023-04-28 17:35:52 +00:00
|
|
|
|
2024-04-28 01:38:23 +00:00
|
|
|
--flat list of editable layers for convenience
|
|
|
|
local layers = {
|
2023-04-28 17:35:52 +00:00
|
|
|
coastlines = false,
|
|
|
|
coastlinesLow = false,
|
|
|
|
international = false,
|
2024-04-28 01:38:23 +00:00
|
|
|
africa = false,
|
|
|
|
europe = false,
|
|
|
|
northamerica = false,
|
|
|
|
russia = false,
|
|
|
|
southamerica = false,
|
|
|
|
southasia = false,
|
|
|
|
travelnodes = false,
|
|
|
|
sailable = false,
|
|
|
|
ainodes = false,
|
|
|
|
cities = false,
|
|
|
|
}
|
|
|
|
|
|
|
|
local map = {
|
|
|
|
layers = layers,
|
|
|
|
path = false,
|
|
|
|
loaded = false,
|
|
|
|
selected = false,
|
|
|
|
selectionLocked = false,
|
|
|
|
editLayer = false,
|
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
territory = {
|
2023-07-28 23:23:08 +00:00
|
|
|
africa = false,
|
|
|
|
europe = false,
|
|
|
|
northamerica = false,
|
|
|
|
russia = false,
|
|
|
|
southamerica = false,
|
|
|
|
southasia = false
|
2023-04-28 17:35:52 +00:00
|
|
|
},
|
2024-04-28 01:38:23 +00:00
|
|
|
|
|
|
|
background = false,
|
|
|
|
coastlines = false,
|
|
|
|
coastlinesLow = false,
|
|
|
|
international = false,
|
2023-04-28 17:35:52 +00:00
|
|
|
travelnodes = false,
|
|
|
|
sailable = false,
|
2024-04-21 16:07:56 +00:00
|
|
|
ainodes = false,
|
2023-04-28 17:35:52 +00:00
|
|
|
cities = false
|
|
|
|
}
|
|
|
|
|
2024-04-26 16:11:55 +00:00
|
|
|
function map.load( path )
|
2024-04-28 01:38:23 +00:00
|
|
|
map.background = lg.newImage( "data/graphics/blur.bmp" )
|
2023-04-28 17:35:52 +00:00
|
|
|
map.cities = Cities.load( "data/earth/cities.dat" )
|
|
|
|
map.coastlines = Lines.load( "data/earth/coastlines.dat" )
|
|
|
|
map.coastlinesLow = Lines.load( "data/earth/coastlines-low.dat" )
|
2023-08-28 23:12:43 +00:00
|
|
|
map.international = Lines.load( "data/earth/international.dat" )
|
|
|
|
map.sailable = Territory.load( "data/earth/sailable.bmp", "sailable" )
|
|
|
|
map.travelnodes = Nodes.load( "data/earth/travel_nodes.bmp", map.sailable.isSailable ) --travel node adjacency matrix depends on sailable bitmap
|
2023-08-26 21:05:48 +00:00
|
|
|
map.ainodes = AI.load( "data/earth/ai_markers.bmp" )
|
2023-07-28 23:23:08 +00:00
|
|
|
for k, v in pairs(map.territory) do
|
|
|
|
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
|
|
|
|
end
|
2024-04-21 16:07:56 +00:00
|
|
|
map.loaded = true
|
2024-04-26 16:11:55 +00:00
|
|
|
map.path = path
|
2024-04-28 01:38:23 +00:00
|
|
|
|
|
|
|
--update references
|
|
|
|
for k, v in pairs( layers ) do
|
|
|
|
layers[k] = map[k] or map.territory[k]
|
|
|
|
end
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function map.draw()
|
|
|
|
lg.clear( 0, 0, 0, 1 )
|
2024-04-21 16:07:56 +00:00
|
|
|
if not map.loaded then return end
|
2023-04-28 17:35:52 +00:00
|
|
|
|
2023-07-28 23:23:08 +00:00
|
|
|
do --territory
|
2023-09-04 01:15:01 +00:00
|
|
|
lg.setLineJoin( "none" )
|
2023-07-28 23:23:08 +00:00
|
|
|
lg.replaceTransform( Camera.tfTerritory )
|
|
|
|
lg.setBlendMode( "add" )
|
2024-04-28 01:38:23 +00:00
|
|
|
|
|
|
|
lg.setColor( 1, 1, 1, 0.2 )
|
|
|
|
lg.draw( map.background )
|
|
|
|
lg.setColor( 1, 1, 1, 0.5 )
|
2023-07-28 23:23:08 +00:00
|
|
|
for k, v in pairs(map.territory) do
|
2023-09-04 01:15:01 +00:00
|
|
|
if v.visible then
|
|
|
|
v:draw()
|
2024-04-21 14:10:53 +00:00
|
|
|
lg.setLineWidth( 1 / Camera.zoom )
|
2023-09-04 01:15:01 +00:00
|
|
|
v:drawBorder( "land" )
|
2024-04-21 14:10:53 +00:00
|
|
|
lg.setLineWidth( 3 / Camera.zoom )
|
2023-09-04 01:15:01 +00:00
|
|
|
v:drawBorder( "sea" )
|
|
|
|
end
|
2023-07-28 23:23:08 +00:00
|
|
|
end
|
2024-04-21 16:07:56 +00:00
|
|
|
if map.sailable.visible then
|
|
|
|
map.sailable:draw()
|
|
|
|
|
|
|
|
lg.setLineJoin( "none" )
|
|
|
|
lg.setLineWidth( 1 / Camera.zoom )
|
|
|
|
|
|
|
|
lg.setColor( 1, 1, 1, 0.5)
|
|
|
|
map.sailable:drawBorder( "sailable" )
|
|
|
|
|
|
|
|
lg.setLineWidth( 3 / Camera.zoom )
|
|
|
|
map.sailable:drawBorder( "placeable" )
|
|
|
|
end
|
2023-07-28 23:23:08 +00:00
|
|
|
lg.setBlendMode( "alpha" )
|
2024-04-21 16:07:56 +00:00
|
|
|
|
2023-09-04 00:49:02 +00:00
|
|
|
lg.setColor( 1, 1, 1, 1 )
|
|
|
|
end
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
do --all this stuff is drawn in world coordinates, ( -180, 180 ) x ( -100, 100 )
|
2024-04-21 16:07:56 +00:00
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
lg.replaceTransform( Camera.tf )
|
2024-04-28 01:38:23 +00:00
|
|
|
|
2024-04-25 01:06:41 +00:00
|
|
|
if map.selected then
|
2024-04-28 01:38:23 +00:00
|
|
|
if map.selected[1] then --lines
|
|
|
|
local p = map.selected
|
|
|
|
lg.setColor( 0.4, 0.5, 0.8, 0.5 )
|
|
|
|
lg.setLineWidth( 0.2 / Camera.zoom )
|
|
|
|
lg.rectangle( "fill", p.x, p.y, p.X - p.x, p.Y - p.y )
|
|
|
|
lg.setColor( 1.0, 0, 0, 1 )
|
|
|
|
lg.line( p )
|
|
|
|
else --points
|
|
|
|
lg.setColor( 1.0, 0.5, 0.5, 0.9 )
|
|
|
|
lg.setLineJoin( "miter" )
|
|
|
|
lg.setLineWidth( 1.0 / Camera.zoom )
|
|
|
|
lg.circle( "line", map.selected.x, map.selected.y, 0.2 + 1.0 / Camera.zoom )
|
|
|
|
end
|
2024-04-25 01:06:41 +00:00
|
|
|
end
|
2023-04-28 17:35:52 +00:00
|
|
|
|
2024-04-25 01:06:41 +00:00
|
|
|
if map.cities.visible then --points
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
lg.setColor( 1, 0, 0, 0.5 )
|
2024-04-25 01:06:41 +00:00
|
|
|
lg.setPointSize( 5.0 )
|
2023-07-28 05:17:00 +00:00
|
|
|
map.cities.draw()
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2024-04-25 01:06:41 +00:00
|
|
|
lg.setColor( 1, 1, 0.0, 0.5 )
|
2023-07-28 05:17:00 +00:00
|
|
|
map.cities.drawCapitals()
|
2024-04-28 01:38:23 +00:00
|
|
|
|
2024-04-25 01:06:41 +00:00
|
|
|
end
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2024-04-25 01:06:41 +00:00
|
|
|
if map.ainodes.visible then
|
|
|
|
lg.setPointSize( 5.0 )
|
|
|
|
map.ainodes:draw()
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
do --line stuff
|
|
|
|
lg.setColor(1, 1, 1, 0.2 )
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
lg.setLineJoin( "miter" )
|
|
|
|
lg.setLineWidth( 0.2 / Camera.zoom )
|
2023-04-28 17:35:52 +00:00
|
|
|
map.international:draw()
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
lg.setColor(1, 1, 1, 0.5 )
|
2023-04-28 17:35:52 +00:00
|
|
|
map.coastlines:draw()
|
|
|
|
map.coastlinesLow:draw()
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-07-28 05:17:00 +00:00
|
|
|
--International Date Line
|
|
|
|
lg.line( -180, -100, -180, 100 )
|
|
|
|
lg.line( 180, -100, 180, 100 )
|
|
|
|
lg.line( -180, 90, 180, 90 )
|
|
|
|
lg.line( -180, -90, 180, -90 )
|
|
|
|
lg.line( -180, 100, 180, 100 )
|
|
|
|
lg.line( -180, -100, 180, -100 )
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
2024-04-21 16:07:56 +00:00
|
|
|
|
2023-08-26 21:05:48 +00:00
|
|
|
do --travel nodes
|
|
|
|
lg.replaceTransform( Camera.tfNodes )
|
2024-04-21 16:07:56 +00:00
|
|
|
if map.travelnodes.visible then
|
|
|
|
map.travelnodes:draw()
|
|
|
|
end
|
2023-08-26 21:05:48 +00:00
|
|
|
end
|
2024-04-28 01:38:23 +00:00
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2024-04-28 01:38:23 +00:00
|
|
|
local function write( filename, string )
|
|
|
|
print( "Pretending to write", string:len(), "bytes to", filename )
|
2024-04-29 01:21:32 +00:00
|
|
|
--[[ os.rename( filename, filename..".bak" ) --just in case :^)
|
|
|
|
local file = assert( io.open( filename, "w+" ) )
|
|
|
|
assert( file:write( string ) )
|
|
|
|
file:close()]]
|
2024-04-26 16:42:52 +00:00
|
|
|
end
|
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
function map.save()
|
2024-04-29 01:21:32 +00:00
|
|
|
for k, layer in pairs( layers ) do
|
|
|
|
print( "SAVING:", k, tostring( layer.filename ) )
|
|
|
|
write( map.path..tostring( layer.filename ), assert( layer:save() ) )
|
2024-04-21 14:10:53 +00:00
|
|
|
end
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
2023-07-28 05:42:16 +00:00
|
|
|
function map.hover(x, y)
|
2023-07-28 23:23:08 +00:00
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
2024-04-28 01:38:23 +00:00
|
|
|
function map.undo()
|
|
|
|
print( "=== UNDO ===" )
|
|
|
|
end
|
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
return map
|