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.
-- https://opensource.org/licenses/MIT
local CAPTURE_PIXEL_SIZE = 2 -- in FullHD a ingame pixel is expected to be 2 real pixels
local CAPTURE_GRID_SIZE = 1080 / 4 -- in ingame pixels
local CAPTURE_PIXEL_SIZE = 2 -- in FullHD an ingame pixel is expected to be 2 real 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_FORCE_HP = 4 -- * 25HP
@ -40,32 +40,44 @@ function startCapturing()
function()
-- +x
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
if not fileExists(string.format("mods/noita-mapcap/output/%d,%d.png", rx, ry)) then
GameSetCameraPos(x, y)
wait(CAPTURE_DELAY)
TriggerCapture(rx, ry)
end
x, y = x + CAPTURE_GRID_SIZE, y
GameSetCameraPos(x, y)
wait(CAPTURE_DELAY)
end
-- +y
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
if not fileExists(string.format("mods/noita-mapcap/output/%d,%d.png", rx, ry)) then
GameSetCameraPos(x, y)
wait(CAPTURE_DELAY)
TriggerCapture(rx, ry)
end
x, y = x, y + CAPTURE_GRID_SIZE
GameSetCameraPos(x, y)
wait(CAPTURE_DELAY)
end
i = i + 1
-- -x
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
if not fileExists(string.format("mods/noita-mapcap/output/%d,%d.png", rx, ry)) then
GameSetCameraPos(x, y)
wait(CAPTURE_DELAY)
TriggerCapture(rx, ry)
end
x, y = x - CAPTURE_GRID_SIZE, y
GameSetCameraPos(x, y)
wait(CAPTURE_DELAY)
end
-- -y
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
if not fileExists(string.format("mods/noita-mapcap/output/%d,%d.png", rx, ry)) then
GameSetCameraPos(x, y)
wait(CAPTURE_DELAY)
TriggerCapture(rx, ry)
end
x, y = x, y - CAPTURE_GRID_SIZE
GameSetCameraPos(x, y)
wait(CAPTURE_DELAY)
end
i = i + 1
end

View File

@ -14,15 +14,20 @@ async_loop(
GuiDestroy(modGUI)
modGUI = nil
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.")
--[[if GuiButton(gui, 0, 0, "DEBUG globals", 1) then
local file = io.open("mods/noita-mapcap/output/globals.txt", "w")
for i, v in pairs(_G) do
file:write(i .. "\n")
end
file:close()
end]]
GuiTextCentered(
modGUI,
0,
0,
'You can resume capturing just by restarting noita and pressing "Start capturing map" again,'
)
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)
end

View File

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