Replace hardcoded capture areas

We now retrieve the correct biome size and offsets from the game itself.
This commit is contained in:
David Vogel 2024-04-29 09:52:07 +02:00
parent 1936dc100c
commit 44ed26952c
2 changed files with 53 additions and 26 deletions

View File

@ -770,8 +770,9 @@ function Capture:StartCapturing()
self:StartCapturingAreaScan(topLeft, bottomRight, captureGridSize, outputPixelScale, captureDelay) self:StartCapturingAreaScan(topLeft, bottomRight, captureGridSize, outputPixelScale, captureDelay)
else else
local predefinedArea = Config.CaptureArea[area] local predefinedAreaFunction = Config.CaptureArea[area]
if predefinedArea then if predefinedAreaFunction then
local predefinedArea = predefinedAreaFunction()
self:StartCapturingAreaScan(predefinedArea.TopLeft, predefinedArea.BottomRight, captureGridSize, outputPixelScale, captureDelay) self:StartCapturingAreaScan(predefinedArea.TopLeft, predefinedArea.BottomRight, captureGridSize, outputPixelScale, captureDelay)
else else
Message:ShowRuntimeError("PredefinedArea", string.format("Unknown predefined capturing area %q", tostring(area))) Message:ShowRuntimeError("PredefinedArea", string.format("Unknown predefined capturing area %q", tostring(area)))

View File

@ -3,6 +3,7 @@
-- 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 NXML = require("luanxml.nxml")
local Vec2 = require("noita-api.vec2") local Vec2 = require("noita-api.vec2")
-- List of components that will be disabled on every encountered entity. -- List of components that will be disabled on every encountered entity.
@ -27,40 +28,65 @@ Config.ComponentsToDisable = {
--"AudioComponent", --"AudioComponent",
} }
local CHUNK_SIZE = 512
---Returns the rectangle of the base area as two vectors.
---@return Vec2 TopLeft Top left corner in world coordinates.
---@return Vec2 BottomRight Bottom right corner in world coordinates. This pixel is not included in the final rectangle.
local function getBaseArea()
local xml = NXML.parse(ModTextFileGetContent("data/biome/_biomes_all.xml"))
local width, height = BiomeMapGetSize()
local offsetX, offsetY = math.floor(width/2), xml.attr.biome_offset_y -- TODO: This may not be right. Check what Noita is really doing when we have a biome map with an odd width.
return Vec2(-offsetX, -offsetY)*CHUNK_SIZE, Vec2(-offsetX+width, -offsetY+height)*CHUNK_SIZE
--return Vec2(-17920, -7168), Vec2(17920, 17408) -- Coordinates for a "New Game" without mods or anything.
end
---A list of capture areas.
---This contains functions that determine the capture area based on the biome size and other parameters.
---The returned vectors are the top left corner, and the bottom right corner of the capture area in world coordinates.
---The bottom right corner pixel is not included in the rectangle.
---@type table<string, fun():Vec2, Vec2>
Config.CaptureArea = { Config.CaptureArea = {
-- Base layout: Every part outside this is based on a similar layout, but uses different materials/seeds. -- Base layout: Every part outside this is based on a similar layout, but uses different materials/seeds.
["1x1"] = { ["1x1"] = getBaseArea,
TopLeft = Vec2(-17920, -7168), -- in world coordinates.
BottomRight = Vec2(17920, 17408), -- in world coordinates. This pixel is not included in the rectangle.
},
-- Main world: The main world with 3 parts: sky, normal and hell. -- Main world: The main world with 3 parts: sky, normal and hell.
["1x3"] = { ["1x3"] = function()
TopLeft = Vec2(-17920, -31744), -- in world coordinates. local width, height = BiomeMapGetSize()
BottomRight = Vec2(17920, 41984), -- in world coordinates. This pixel is not included in the rectangle. local topLeft, bottomRight = getBaseArea()
}, return topLeft + Vec2(0, -height)*CHUNK_SIZE, bottomRight + Vec2(0, height)*CHUNK_SIZE
--return Vec2(-17920, -31744), Vec2(17920, 41984) -- Coordinates for a "New Game" without mods or anything.
end,
-- -1 parallel world: The parallel world with 3 parts: sky, normal and hell. -- -1 parallel world: The parallel world with 3 parts: sky, normal and hell.
["1x3 -1"] = { ["1x3 -1"] = function()
TopLeft = Vec2(-17920, -31744) + Vec2(-35840, 0), -- in world coordinates. local width, height = BiomeMapGetSize()
BottomRight = Vec2(17920, 41984) + Vec2(-35840, 0), -- in world coordinates. This pixel is not included in the rectangle. local topLeft, bottomRight = getBaseArea()
}, return topLeft + Vec2(-width, -height)*CHUNK_SIZE, bottomRight + Vec2(-width, height)*CHUNK_SIZE
--return Vec2(-17920, -31744) + Vec2(-35840, 0), Vec2(17920, 41984) + Vec2(-35840, 0) -- Coordinates for a "New Game" without mods or anything.
end,
-- +1 parallel world: The parallel world with 3 parts: sky, normal and hell. -- +1 parallel world: The parallel world with 3 parts: sky, normal and hell.
["1x3 +1"] = { ["1x3 +1"] = function()
TopLeft = Vec2(-17920, -31744) + Vec2(35840, 0), -- in world coordinates. local width, height = BiomeMapGetSize()
BottomRight = Vec2(17920, 41984) + Vec2(35840, 0), -- in world coordinates. This pixel is not included in the rectangle. local topLeft, bottomRight = getBaseArea()
}, return topLeft + Vec2(width, -height)*CHUNK_SIZE, bottomRight + Vec2(width, height)*CHUNK_SIZE
--return Vec2(-17920, -31744) + Vec2(35840, 0), Vec2(17920, 41984) + Vec2(35840, 0) -- Coordinates for a "New Game" without mods or anything.
end,
-- Extended: Main world + a fraction of the parallel worlds to the left and right. -- Extended: Main world + a fraction of the parallel worlds to the left and right.
["1.5x3"] = { ["1.5x3"] = function()
TopLeft = Vec2(-25600, -31744), -- in world coordinates. local width, height = BiomeMapGetSize()
BottomRight = Vec2(25600, 41984), -- in world coordinates. This pixel is not included in the rectangle. local topLeft, bottomRight = getBaseArea()
}, return topLeft + Vec2(-math.floor(0.25*width), -height)*CHUNK_SIZE, bottomRight + Vec2(math.floor(0.25*width), height)*CHUNK_SIZE
--return Vec2(-25600, -31744), Vec2(25600, 41984) -- Coordinates for a "New Game" without mods or anything. These coordinates may not exactly be 1.5 of the base width for historic reasons.
end,
-- Extended: Main world + each parallel world to the left and right. -- Extended: Main world + each parallel world to the left and right.
["3x3"] = { ["3x3"] = function()
TopLeft = Vec2(-53760, -31744), -- in world coordinates. local width, height = BiomeMapGetSize()
BottomRight = Vec2(53760, 41984), -- in world coordinates. This pixel is not included in the rectangle. local topLeft, bottomRight = getBaseArea()
}, return topLeft + Vec2(-width, -height)*CHUNK_SIZE, bottomRight + Vec2(width, height)*CHUNK_SIZE
--return Vec2(-53760, -31744), Vec2(53760, 41984) -- Coordinates for a "New Game" without mods or anything.
end,
} }