Add test files;
|
@ -0,0 +1,5 @@
|
|||
--Load and save the bmp formats used by DEFCON.
|
||||
local bmp = {}
|
||||
|
||||
|
||||
return bmp
|
|
@ -0,0 +1,61 @@
|
|||
--Load and save the fixed width plaintext data used by DEFCON.
|
||||
local t = {}
|
||||
local io = io
|
||||
local table = table
|
||||
local tonumber = tonumber
|
||||
local lfs = love.filesystem
|
||||
local lg = love.graphics
|
||||
local cities
|
||||
local points = {}
|
||||
local caps = {}
|
||||
|
||||
function t.draw()
|
||||
lg.points( points )
|
||||
end
|
||||
|
||||
function t.drawCapitals()
|
||||
lg.points( caps )
|
||||
end
|
||||
|
||||
function t.load( filename )
|
||||
|
||||
cities = {}
|
||||
local n = 0
|
||||
local idxPts = 1
|
||||
local idxCaps = 1
|
||||
|
||||
for line in assert( io.lines( filename ), "Error: could not open cities.dat" ) do
|
||||
n = n + 1
|
||||
local _, _, x, y, pop, capital = line:sub( 83 ):find( "(%g+)%s+(%g+)%s+(%g+)%s+(%g+)" )
|
||||
x, y, pop, capital = tonumber( x ), tonumber( y ), tonumber( pop ), ( tonumber( capital ) > 0)
|
||||
local city = {
|
||||
name = line:sub( 1, 39 ):gsub("%s+$",""),
|
||||
country = line:sub( 42, 82 ):gsub("%s+$",""),
|
||||
x = x, y = y, pop = pop, capital = capital
|
||||
}
|
||||
cities[n] = city
|
||||
|
||||
points[idxPts], points[idxPts + 1] = x, y
|
||||
idxPts = idxPts + 2
|
||||
|
||||
if capital then
|
||||
caps[idxCaps], caps[idxCaps + 1] = x, y
|
||||
idxCaps = idxCaps + 2
|
||||
end
|
||||
end
|
||||
|
||||
print( "LOADED", filename, n )
|
||||
|
||||
return setmetatable( cities, {__index = t } )
|
||||
end
|
||||
|
||||
function t.save( cities, filename )
|
||||
local str = {}
|
||||
for n, city in ipairs( cities ) do
|
||||
str[n] = ("%-40s%-40s%f %f %d %d"):format( city.name, city.country, city.x, city.y, city.pop, city.capital and 1 or 0 )
|
||||
end
|
||||
assert( lfs.write( filename, table.concat( str, "\n" ) ) )
|
||||
print( "Saved", filename )
|
||||
end
|
||||
|
||||
return t
|
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 71 KiB |
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 71 KiB |
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 156 KiB |
After Width: | Height: | Size: 426 KiB |
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 428 KiB |
|
@ -0,0 +1,40 @@
|
|||
--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
|
|
@ -0,0 +1,29 @@
|
|||
local love = assert( love, "This tool requires LOVE: love2d.org" )
|
||||
local map = require 'map'
|
||||
local SAVEDIRECTORY = "out/"
|
||||
|
||||
function love.load()
|
||||
local lfs = assert( love.filesystem )
|
||||
lfs.setIdentity( "dcearth", false )
|
||||
assert( lfs.createDirectory( SAVEDIRECTORY.."data/earth" ))
|
||||
assert( lfs.createDirectory( SAVEDIRECTORY.."data/graphics" ))
|
||||
map.load()
|
||||
end
|
||||
|
||||
local canvas = love.graphics.newCanvas()
|
||||
function love.update( dt )
|
||||
love.graphics.setCanvas( canvas )
|
||||
map.draw()
|
||||
love.graphics.setCanvas()
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
love.graphics.draw( canvas )
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
if key == "s" then
|
||||
-- To open a file or folder, "file://" must be prepended to the path.
|
||||
love.system.openURL("file://"..love.filesystem.getSaveDirectory())
|
||||
end
|
||||
end
|
|
@ -0,0 +1,76 @@
|
|||
local lg = love.graphics
|
||||
local Cities = require 'cities'
|
||||
local Lines = require 'lines'
|
||||
local Bitmap = require 'bmp'
|
||||
|
||||
local map = {
|
||||
coastlines = false,
|
||||
coastlinesLow = false,
|
||||
international = false,
|
||||
territory = {
|
||||
af = false,
|
||||
eu = false,
|
||||
na = false,
|
||||
ru = false,
|
||||
sa = false,
|
||||
as = false
|
||||
},
|
||||
travelnodes = false,
|
||||
sailable = false,
|
||||
aimarkers = false,
|
||||
cities = false
|
||||
}
|
||||
|
||||
function map.load()
|
||||
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" )
|
||||
map.international = Lines.load( "data/earth/international.dat" )
|
||||
end
|
||||
|
||||
function map.draw()
|
||||
lg.clear( 0, 0, 0, 1 )
|
||||
|
||||
do --all this stuff is drawn in world coordinates, ( -180, 180 ) x ( -100, 100 )
|
||||
lg.push( "transform" )
|
||||
lg.scale( lg.getCanvas():getDimensions() )
|
||||
lg.scale( 1 / 360, - 1 / 200 )
|
||||
lg.translate( 180, -100 )
|
||||
|
||||
|
||||
|
||||
do --points
|
||||
lg.setColor( 1, 0, 0, 0.5 )
|
||||
lg.setPointSize( 2 )
|
||||
map.cities:draw()
|
||||
|
||||
lg.setColor( 1, 0, 0, 1.0 )
|
||||
lg.setPointSize( 4 )
|
||||
map.cities:drawCapitals()
|
||||
end
|
||||
|
||||
do --line stuff
|
||||
lg.setColor(1, 1, 1, 0.2 )
|
||||
lg.setLineWidth( 0.2 )
|
||||
map.international:draw()
|
||||
|
||||
lg.setColor(1, 1, 1, 1 )
|
||||
lg.setLineWidth( 0.3 )
|
||||
map.coastlines:draw()
|
||||
map.coastlinesLow:draw()
|
||||
end
|
||||
|
||||
lg.pop( )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function map.save()
|
||||
|
||||
end
|
||||
|
||||
function map.setVisible()
|
||||
|
||||
end
|
||||
|
||||
return map
|