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 = {}
|
2024-04-26 16:42:52 +00:00
|
|
|
local n = 1
|
2023-04-28 17:35:52 +00:00
|
|
|
local k = 1
|
|
|
|
for line in assert( lfs.lines( filename ) ) do
|
2024-04-21 16:07:56 +00:00
|
|
|
if line:find "b" then
|
2023-04-28 17:35:52 +00:00
|
|
|
k = 1
|
2024-04-21 16:07:56 +00:00
|
|
|
if #poly > 2 then n = n + 1 end
|
2023-04-28 17:35:52 +00:00
|
|
|
poly = {}
|
|
|
|
polys[n] = poly
|
|
|
|
else
|
|
|
|
local _, _, x, y = line:find( "(%g+)%s+(%g+)" )
|
2024-04-21 16:07:56 +00:00
|
|
|
x, y = tonumber( x ), tonumber( y )
|
|
|
|
if x and y then
|
|
|
|
poly[k], poly[ k + 1 ] = x, y
|
|
|
|
k = k + 2
|
|
|
|
else
|
|
|
|
print( "LINES: malformed line:", filename, line )
|
|
|
|
end
|
2023-04-28 17:35:52 +00:00
|
|
|
end
|
|
|
|
end
|
2024-04-21 16:07:56 +00:00
|
|
|
|
|
|
|
if not polys[n] or (#(polys[n]) < 3) then
|
|
|
|
polys[n] = nil
|
|
|
|
n = n - 1
|
|
|
|
end
|
2023-04-28 17:35:52 +00:00
|
|
|
|
|
|
|
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
|