changed saving. fixed polygon loading (it was dropping the first line)
This commit is contained in:
parent
0fbbbe4409
commit
a2eeafcdb3
15
cities.lua
15
cities.lua
|
@ -101,19 +101,10 @@ function t.save( cities, filename )
|
||||||
print( "=== SAVING CITIES ===" )
|
print( "=== SAVING CITIES ===" )
|
||||||
local str = {}
|
local str = {}
|
||||||
for n, city in ipairs( cities ) do
|
for n, city in ipairs( cities ) do
|
||||||
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 )
|
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
|
||||||
str = assert(table.concat( str, "\n" ))
|
return 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
|
end
|
||||||
|
|
||||||
return t
|
return t
|
|
@ -6,7 +6,7 @@ local lg = love.graphics
|
||||||
function t.load( filename )
|
function t.load( filename )
|
||||||
local polys = { visible = true }
|
local polys = { visible = true }
|
||||||
local poly = {}
|
local poly = {}
|
||||||
local n = 0
|
local n = 1
|
||||||
local k = 1
|
local k = 1
|
||||||
for line in assert( lfs.lines( filename ) ) do
|
for line in assert( lfs.lines( filename ) ) do
|
||||||
if line:find "b" then
|
if line:find "b" then
|
||||||
|
|
9
map.lua
9
map.lua
|
@ -134,8 +134,15 @@ function map.draw()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function write( filename, string )
|
||||||
|
os.rename( filename, filename..".bak" ) --just in case :^)
|
||||||
|
local file = assert( io.open( filename, "w+" ) )
|
||||||
|
assert( file:write( string ) )
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
|
||||||
function map.save()
|
function map.save()
|
||||||
map.cities:save( map.path.."/data/earth/cities.dat" )
|
write( map.path.."/data/earth/cities.dat", map.cities:save())
|
||||||
map.coastlines.save()
|
map.coastlines.save()
|
||||||
map.coastlinesLow.save()
|
map.coastlinesLow.save()
|
||||||
map.international.save()
|
map.international.save()
|
||||||
|
|
Loading…
Reference in New Issue