dcearth/lines.lua

40 lines
788 B
Lua

--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 )
local polys = {}
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 )
end
function t.draw( lines )
for _, poly in ipairs( lines ) do
lg.line( poly )
end
end
return t