dcearth/lines.lua

57 lines
1019 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 = { visible = true }
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.newPolygon( x, y )
end
function t.addToCurrentPolygon( x, y )
end
function t.deletePolygon( poly )
end
function t.drawPolygonEditHandles( poly )
end
function t.draw( lines )
if not lines.visible then return end
for _, poly in ipairs( lines ) do
lg.line( poly )
end
end
return t