2023-04-28 17:35:52 +00:00
|
|
|
--Load and save plaintext line mesh format for DEFCON coastlines etc.
|
|
|
|
local t = {}
|
|
|
|
local lfs = love.filesystem
|
|
|
|
local lg = love.graphics
|
|
|
|
|
|
|
|
function t.load( filename )
|
2023-07-28 05:42:16 +00:00
|
|
|
local polys = { visible = true }
|
2023-04-28 17:35:52 +00:00
|
|
|
local poly = {}
|
|
|
|
local n = 0
|
|
|
|
local k = 1
|
|
|
|
for line in assert( lfs.lines( filename ) ) do
|
|
|
|
if line == "b" then
|
|
|
|
k = 1
|
|
|
|
n = n + 1
|
|
|
|
poly = {}
|
|
|
|
polys[n] = poly
|
|
|
|
else
|
|
|
|
local _, _, x, y = line:find( "(%g+)%s+(%g+)" )
|
|
|
|
x, y = assert( tonumber( x ) ), assert( tonumber( y ) )
|
|
|
|
poly[k], poly[ k + 1 ] = x, y
|
|
|
|
k = k + 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print( "LOADED", filename, n )
|
|
|
|
return setmetatable( polys, {__index = t } )
|
|
|
|
end
|
|
|
|
|
|
|
|
function t.save( lines, filename )
|
|
|
|
|
|
|
|
|
2023-07-28 05:42:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function t.newPolygon( x, y )
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function t.addToCurrentPolygon( x, y )
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2023-07-28 23:23:08 +00:00
|
|
|
function t.deletePolygon( poly )
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function t.drawPolygonEditHandles( poly )
|
2023-07-28 05:42:16 +00:00
|
|
|
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function t.draw( lines )
|
2023-07-28 05:42:16 +00:00
|
|
|
if not lines.visible then return end
|
2023-04-28 17:35:52 +00:00
|
|
|
for _, poly in ipairs( lines ) do
|
|
|
|
lg.line( poly )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return t
|