diff --git a/cities.lua b/cities.lua index 6776081..aa467b0 100644 --- a/cities.lua +++ b/cities.lua @@ -101,19 +101,10 @@ function t.save( cities, filename ) print( "=== SAVING CITIES ===" ) local str = {} 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 - 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 ===" ) + return assert(table.concat( str, "\n" )) end return t \ No newline at end of file diff --git a/lines.lua b/lines.lua index a80bdf1..904aa44 100644 --- a/lines.lua +++ b/lines.lua @@ -6,7 +6,7 @@ local lg = love.graphics function t.load( filename ) local polys = { visible = true } local poly = {} - local n = 0 + local n = 1 local k = 1 for line in assert( lfs.lines( filename ) ) do if line:find "b" then diff --git a/map.lua b/map.lua index 612ca35..1a1fd33 100644 --- a/map.lua +++ b/map.lua @@ -134,8 +134,15 @@ function map.draw() 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() - map.cities:save( map.path.."/data/earth/cities.dat" ) + write( map.path.."/data/earth/cities.dat", map.cities:save()) map.coastlines.save() map.coastlinesLow.save() map.international.save()