From 03f1a96112a9236f4b9f0daf9020ea43a8e6b974 Mon Sep 17 00:00:00 2001 From: wan-may Date: Fri, 24 May 2024 23:43:39 -0300 Subject: [PATCH] fix a couple of travel node saving bugs --- bmp.lua | 29 ++++++++++++++++------------- button.lua | 22 ---------------------- lines.lua | 4 ++-- main.lua | 8 ++++---- map.lua | 7 +++---- territory.lua | 8 +++----- 6 files changed, 28 insertions(+), 50 deletions(-) diff --git a/bmp.lua b/bmp.lua index 64d35b0..1332c1a 100644 --- a/bmp.lua +++ b/bmp.lua @@ -10,7 +10,7 @@ local bit = require 'bit' local function getHeader( filename ) local offset = love.data.unpack( " button.y end -local function debugLoop() - local i = 0 - local j = 0 - local a = t - repeat - i = i + 1 - --print( "BUTTON", i, tostring( a ) ) - a = a.next - until a == t or i > 100 - a = t - repeat - j = j + 1 - --print( "BUTTON", i, tostring( a ) ) - a = a.prev - until a == t or j > 100 - print( i, j, "BUTTONS" ) -end -local k = 1 function t.new( b ) b = setmetatable( b or {}, t ) b.next = t t.prev.next = b b.prev = t.prev t.prev = b - --nonsense - k = k + 1 - print( "ADD BUTTON", k, tostring( b ) ) - debugLoop() return b end diff --git a/lines.lua b/lines.lua index 1eddb14..551d25c 100644 --- a/lines.lua +++ b/lines.lua @@ -87,9 +87,9 @@ function t.selectNearest( lines, wx, wy ) end function t.save( lines ) - local str = {} + local str = { "b" } for i, poly in ipairs( lines ) do - str[i] = table.concat( poly, " " ) + str[i + 1] = table.concat( poly, " " ) end str = table.concat( str, "\nb\n" ):gsub("(%S+) (%S+) ", "%1 %2\n") return str diff --git a/main.lua b/main.lua index 2e83b2e..97ba21d 100644 --- a/main.lua +++ b/main.lua @@ -23,10 +23,10 @@ end function love.update( dt ) local tx, ty = 0, 0 local moveCamera = false - if love.keyboard.isScancodeDown( "w" ) then moveCamera = true; ty = ty + 30 * dt end - if love.keyboard.isScancodeDown( "a" ) then moveCamera = true; tx = tx - 30 * dt end - if love.keyboard.isScancodeDown( "s" ) then moveCamera = true; ty = ty - 30 * dt end - if love.keyboard.isScancodeDown( "d" ) then moveCamera = true; tx = tx + 30 * dt end + if love.keyboard.isScancodeDown( "w" ) then moveCamera = true; ty = ty + dt * 150 / Camera.zoom end + if love.keyboard.isScancodeDown( "a" ) then moveCamera = true; tx = tx - dt * 150 / Camera.zoom end + if love.keyboard.isScancodeDown( "s" ) then moveCamera = true; ty = ty - dt * 150 / Camera.zoom end + if love.keyboard.isScancodeDown( "d" ) then moveCamera = true; tx = tx + dt * 150 / Camera.zoom end if love.keyboard.isScancodeDown( "q" ) then Camera.Zoom( dt * 400 ) end if love.keyboard.isScancodeDown( "e" ) then Camera.Zoom( -dt* 400 ) end if moveCamera then Camera.Translate( tx, ty ) end diff --git a/map.lua b/map.lua index 155a82c..a6cdfb5 100644 --- a/map.lua +++ b/map.lua @@ -179,16 +179,15 @@ function map.draw() end local function write( filename, string ) - print( "Pretending to write", string:len(), "bytes to", filename ) - --[[ os.rename( filename, filename..".bak" ) --just in case :^) + print( "Writing", string:len(), "bytes to", filename ) + os.rename( filename, filename..".bak" ) --just in case :^) local file = assert( io.open( filename, "w+" ) ) assert( file:write( string ) ) - file:close()]] + file:close() end function map.save() for k, layer in pairs( layers ) do - print( "SAVING:", k, tostring( layer.filename ) ) write( map.path..tostring( layer.filename ), assert( layer:save() ) ) end end diff --git a/territory.lua b/territory.lua index 55765c9..faa9cbd 100644 --- a/territory.lua +++ b/territory.lua @@ -57,10 +57,6 @@ function t.getPixel( territory, x, y ) return territory.imgd:getPixel( imgx, imgy ) end -function t.toggleVisibility( territory ) - -end - --[[ 0 20 -- once sailable.bmp is brighter than this, the area is traversable by ships @@ -147,7 +143,9 @@ function t.computeBorder( territory, threshold, key ) end function t.save( territory ) - return bmp.save( territory.imgd, "512rgb24" ) + local fmt = (territory.name == "sailable") and "512r4" or "512rgb24" + print( "saving bitmap: ", territory.name, fmt ) + return bmp.save( territory.imgd, fmt ) end return t \ No newline at end of file