parent
7c2c3867cf
commit
0fbbbe4409
18
cities.lua
18
cities.lua
|
@ -61,6 +61,8 @@ function t.load( filename )
|
||||||
local n = 1
|
local n = 1
|
||||||
local idxPts = 1
|
local idxPts = 1
|
||||||
local idxCaps = 1
|
local idxCaps = 1
|
||||||
|
points = {}
|
||||||
|
caps = {}
|
||||||
|
|
||||||
for line in assert( lfs.lines( filename ), "Error: could not open cities.dat" ) do
|
for line in assert( lfs.lines( filename ), "Error: could not open cities.dat" ) do
|
||||||
|
|
||||||
|
@ -96,12 +98,22 @@ function t.load( filename )
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.save( cities, filename )
|
function t.save( cities, filename )
|
||||||
|
print( "=== SAVING CITIES ===" )
|
||||||
local str = {}
|
local str = {}
|
||||||
for n, city in ipairs( cities ) do
|
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
|
end
|
||||||
assert( lfs.write( filename, table.concat( str, "\n" ) ) )
|
str = assert(table.concat( str, "\n" ))
|
||||||
print( "Saved", filename )
|
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
|
end
|
||||||
|
|
||||||
return t
|
return t
|
File diff suppressed because it is too large
Load Diff
7
main.lua
7
main.lua
|
@ -18,6 +18,7 @@ function love.load()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.directorydropped( path )
|
function love.directorydropped( path )
|
||||||
|
if map.path then assert( love.filesystem.unmount( map.path ) ) end
|
||||||
love.filesystem.mount( path, "" )
|
love.filesystem.mount( path, "" )
|
||||||
return map.load( path )
|
return map.load( path )
|
||||||
end
|
end
|
||||||
|
@ -162,11 +163,9 @@ local layerVisibilityKeybinds = {
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
ToggleVisibility( layerVisibilityKeybinds[key] )
|
ToggleVisibility( layerVisibilityKeybinds[key] )
|
||||||
|
wasKeyPressed = true
|
||||||
|
|
||||||
if key == "l" then
|
if key == "l" then
|
||||||
-- To open a file or folder, "file://" must be prepended to the path.
|
return map.save()
|
||||||
love.system.openURL("file://"..love.filesystem.getSaveDirectory())
|
|
||||||
end
|
end
|
||||||
|
|
||||||
wasKeyPressed = true
|
|
||||||
end
|
end
|
||||||
|
|
5
map.lua
5
map.lua
|
@ -25,7 +25,7 @@ local map = {
|
||||||
cities = false
|
cities = false
|
||||||
}
|
}
|
||||||
|
|
||||||
function map.load( )
|
function map.load( path )
|
||||||
map.cities = Cities.load( "data/earth/cities.dat" )
|
map.cities = Cities.load( "data/earth/cities.dat" )
|
||||||
map.coastlines = Lines.load( "data/earth/coastlines.dat" )
|
map.coastlines = Lines.load( "data/earth/coastlines.dat" )
|
||||||
map.coastlinesLow = Lines.load( "data/earth/coastlines-low.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 )
|
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
|
||||||
end
|
end
|
||||||
map.loaded = true
|
map.loaded = true
|
||||||
|
map.path = path
|
||||||
end
|
end
|
||||||
|
|
||||||
function map.draw()
|
function map.draw()
|
||||||
|
@ -134,7 +135,7 @@ function map.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function map.save()
|
function map.save()
|
||||||
map.cities.save()
|
map.cities:save( map.path.."/data/earth/cities.dat" )
|
||||||
map.coastlines.save()
|
map.coastlines.save()
|
||||||
map.coastlinesLow.save()
|
map.coastlinesLow.save()
|
||||||
map.international.save()
|
map.international.save()
|
||||||
|
|
Loading…
Reference in New Issue