Make it possible to resume the capture process

This commit is contained in:
David Vogel 2019-10-23 20:03:03 +02:00
parent 102f9f337c
commit 1a4700eba3
3 changed files with 49 additions and 22 deletions

View File

@ -3,8 +3,8 @@
-- This software is released under the MIT License. -- This software is released under the MIT License.
-- https://opensource.org/licenses/MIT -- https://opensource.org/licenses/MIT
local CAPTURE_PIXEL_SIZE = 2 -- in FullHD a ingame pixel is expected to be 2 real pixels local CAPTURE_PIXEL_SIZE = 2 -- in FullHD an ingame pixel is expected to be 2 real pixels
local CAPTURE_GRID_SIZE = 1080 / 4 -- in ingame pixels local CAPTURE_GRID_SIZE = 256 -- in ingame pixels. There will be 6 to 12 images overlapping
local CAPTURE_DELAY = 15 -- in frames local CAPTURE_DELAY = 15 -- in frames
local CAPTURE_FORCE_HP = 4 -- * 25HP local CAPTURE_FORCE_HP = 4 -- * 25HP
@ -40,32 +40,44 @@ function startCapturing()
function() function()
-- +x -- +x
for i = 1, i, 1 do for i = 1, i, 1 do
TriggerCapture(x * CAPTURE_PIXEL_SIZE, y * CAPTURE_PIXEL_SIZE) local rx, ry = x * CAPTURE_PIXEL_SIZE, y * CAPTURE_PIXEL_SIZE
x, y = x + CAPTURE_GRID_SIZE, y if not fileExists(string.format("mods/noita-mapcap/output/%d,%d.png", rx, ry)) then
GameSetCameraPos(x, y) GameSetCameraPos(x, y)
wait(CAPTURE_DELAY) wait(CAPTURE_DELAY)
TriggerCapture(rx, ry)
end
x, y = x + CAPTURE_GRID_SIZE, y
end end
-- +y -- +y
for i = 1, i, 1 do for i = 1, i, 1 do
TriggerCapture(x * CAPTURE_PIXEL_SIZE, y * CAPTURE_PIXEL_SIZE) local rx, ry = x * CAPTURE_PIXEL_SIZE, y * CAPTURE_PIXEL_SIZE
x, y = x, y + CAPTURE_GRID_SIZE if not fileExists(string.format("mods/noita-mapcap/output/%d,%d.png", rx, ry)) then
GameSetCameraPos(x, y) GameSetCameraPos(x, y)
wait(CAPTURE_DELAY) wait(CAPTURE_DELAY)
TriggerCapture(rx, ry)
end
x, y = x, y + CAPTURE_GRID_SIZE
end end
i = i + 1 i = i + 1
-- -x -- -x
for i = 1, i, 1 do for i = 1, i, 1 do
TriggerCapture(x * CAPTURE_PIXEL_SIZE, y * CAPTURE_PIXEL_SIZE) local rx, ry = x * CAPTURE_PIXEL_SIZE, y * CAPTURE_PIXEL_SIZE
x, y = x - CAPTURE_GRID_SIZE, y if not fileExists(string.format("mods/noita-mapcap/output/%d,%d.png", rx, ry)) then
GameSetCameraPos(x, y) GameSetCameraPos(x, y)
wait(CAPTURE_DELAY) wait(CAPTURE_DELAY)
TriggerCapture(rx, ry)
end
x, y = x - CAPTURE_GRID_SIZE, y
end end
-- -y -- -y
for i = 1, i, 1 do for i = 1, i, 1 do
TriggerCapture(x * CAPTURE_PIXEL_SIZE, y * CAPTURE_PIXEL_SIZE) local rx, ry = x * CAPTURE_PIXEL_SIZE, y * CAPTURE_PIXEL_SIZE
x, y = x, y - CAPTURE_GRID_SIZE if not fileExists(string.format("mods/noita-mapcap/output/%d,%d.png", rx, ry)) then
GameSetCameraPos(x, y) GameSetCameraPos(x, y)
wait(CAPTURE_DELAY) wait(CAPTURE_DELAY)
TriggerCapture(rx, ry)
end
x, y = x, y - CAPTURE_GRID_SIZE
end end
i = i + 1 i = i + 1
end end

View File

@ -14,15 +14,20 @@ async_loop(
GuiDestroy(modGUI) GuiDestroy(modGUI)
modGUI = nil modGUI = nil
end end
GuiTextCentered(modGUI, 0, 0, "Don't do anything while the capturing process is running!")
GuiTextCentered(modGUI, 0, 0, "Use ESC and close the game to stop the process.") GuiTextCentered(modGUI, 0, 0, "Use ESC and close the game to stop the process.")
--[[if GuiButton(gui, 0, 0, "DEBUG globals", 1) then GuiTextCentered(
local file = io.open("mods/noita-mapcap/output/globals.txt", "w") modGUI,
for i, v in pairs(_G) do 0,
file:write(i .. "\n") 0,
end 'You can resume capturing just by restarting noita and pressing "Start capturing map" again,'
file:close() )
end]] GuiTextCentered(modGUI, 0, 0, "the mod will skip already captured files.")
GuiTextCentered(
modGUI,
0,
0,
'If you want to start a new map, you have to delete all images from the "output" folder!'
)
GuiLayoutEnd(modGUI) GuiLayoutEnd(modGUI)
end end

View File

@ -87,3 +87,13 @@ function addPerkToPlayer(perkID)
--local effect = EntityLoad("data/entities/misc/effect_protection_all.xml", x, y) --local effect = EntityLoad("data/entities/misc/effect_protection_all.xml", x, y)
--EntityAddChild(playerEntity, effect) --EntityAddChild(playerEntity, effect)
end end
function fileExists(fileName)
local f = io.open(fileName, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end