Reload map

Save cities.dat
Tweak travel node loading
This commit is contained in:
wan-may 2024-04-26 13:11:55 -03:00
parent 7c2c3867cf
commit 0fbbbe4409
4 changed files with 2768 additions and 11 deletions

View File

@ -61,6 +61,8 @@ function t.load( filename )
local n = 1
local idxPts = 1
local idxCaps = 1
points = {}
caps = {}
for line in assert( lfs.lines( filename ), "Error: could not open cities.dat" ) do
@ -96,12 +98,22 @@ function t.load( filename )
end
function t.save( cities, filename )
print( "=== SAVING CITIES ===" )
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 )
str[n] = ("%-41s%-41s%-14f%-14f%-19d %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 )
str = assert(table.concat( str, "\n" ))
local file = assert( io.open( filename, "w+" ) )
assert( file:write( str ) )
file:close()
--[[local tmpname = os.tmpname()
local tmpfile = assert( io.open( tmpname, "w+" ) )
assert( tmpfile:write( str ) )
tmpfile:close()
os.remove( filename ) --ooh this is probably pretty bad
os.rename( tmpname, filename )]]
print( "=== CITIES SAVED ===" )
end
return t

2745
data/cities.dat Normal file

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ function love.load()
end
function love.directorydropped( path )
if map.path then assert( love.filesystem.unmount( map.path ) ) end
love.filesystem.mount( path, "" )
return map.load( path )
end
@ -162,11 +163,9 @@ local layerVisibilityKeybinds = {
function love.keypressed(key)
ToggleVisibility( layerVisibilityKeybinds[key] )
if key == "l" then
-- To open a file or folder, "file://" must be prepended to the path.
love.system.openURL("file://"..love.filesystem.getSaveDirectory())
end
wasKeyPressed = true
if key == "l" then
return map.save()
end
end

View File

@ -25,7 +25,7 @@ local map = {
cities = false
}
function map.load( )
function map.load( path )
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" )
@ -37,6 +37,7 @@ function map.load( )
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
end
map.loaded = true
map.path = path
end
function map.draw()
@ -134,7 +135,7 @@ function map.draw()
end
function map.save()
map.cities.save()
map.cities:save( map.path.."/data/earth/cities.dat" )
map.coastlines.save()
map.coastlinesLow.save()
map.international.save()