Add LuaNXML library

- Change VSCode lua addon to not ignore submodules
- Add function to read resolutions from Noita config file
This commit is contained in:
David Vogel 2022-07-23 22:36:14 +02:00
parent afaedf9159
commit f2e582622e
6 changed files with 40 additions and 1 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "files/libraries/luanxml"]
path = files/libraries/luanxml
url = https://github.com/zatherz/luanxml

View File

@ -35,5 +35,6 @@
"Lua.runtime.version": "LuaJIT", "Lua.runtime.version": "LuaJIT",
"Lua.format.defaultConfig": { "Lua.format.defaultConfig": {
"max_line_length": "512" "max_line_length": "512"
} },
"Lua.workspace.ignoreSubmodules": false
} }

View File

@ -112,6 +112,10 @@ The rectangles for the different capture modes are defined in `.../Noita/mods/no
As the resulting stitched image is really big, you can read [this comment](https://github.com/Dadido3/noita-mapcap/issues/7#issuecomment-723591552) that addresses how you can view, convert or even self-host your images. As the resulting stitched image is really big, you can read [this comment](https://github.com/Dadido3/noita-mapcap/issues/7#issuecomment-723591552) that addresses how you can view, convert or even self-host your images.
## Acknowledgements
This addon uses the [LuaNXML](https://github.com/zatherz/luanxml) library by [Zatherz](https://github.com/zatherz).
## License ## License
[MIT](LICENSE) [MIT](LICENSE)

View File

@ -10,6 +10,8 @@
-------------------------- --------------------------
local CameraAPI = require("noita-api.camera") local CameraAPI = require("noita-api.camera")
local NXML = require("luanxml.nxml")
local Utils = require("noita-api.utils")
local Vec2 = require("noita-api.vec2") local Vec2 = require("noita-api.vec2")
---------- ----------
@ -26,6 +28,24 @@ local Coords = {
VirtualResolution = Vec2(0, 0), VirtualResolution = Vec2(0, 0),
} }
---Reads and updates the internal, window and virtual resolutions from Noita's config files and API.
---@return any error
function Coords:ReadResolutions()
local filename = Utils.GetSpecialDirectory("save-shared") .. "config.xml"
local f, err = io.open(filename, "r")
if not f then return err end
local xml = NXML.parse(f:read("*a"))
self.WindowResolution = Vec2(tonumber(xml.attr["window_w"]), tonumber(xml.attr["window_h"]))
self.InternalResolution = Vec2(tonumber(xml.attr["internal_size_w"]), tonumber(xml.attr["internal_size_h"]))
self.VirtualResolution = Vec2(tonumber(MagicNumbersGetValue("VIRTUAL_RESOLUTION_X")), tonumber(MagicNumbersGetValue("VIRTUAL_RESOLUTION_Y")))
f:close()
return nil
end
---Returns the size of the internal rectangle in window/screen coordinates. ---Returns the size of the internal rectangle in window/screen coordinates.
---The internal rect is always uniformly scaled to fit inside the window rectangle. ---The internal rect is always uniformly scaled to fit inside the window rectangle.
---@return Vec2 ---@return Vec2

@ -0,0 +1 @@
Subproject commit 03d28907ccced296e5b2f8b16303a312ab4eaa3b

View File

@ -16,6 +16,12 @@ if not async then
require("coroutines") -- Loads Noita's coroutines library from `data/scripts/lib/coroutines.lua`. require("coroutines") -- Loads Noita's coroutines library from `data/scripts/lib/coroutines.lua`.
end end
--------------------------
-- Load library modules --
--------------------------
local Coords = require("coordinates")
------------------------------- -------------------------------
-- Load and run script files -- -- Load and run script files --
------------------------------- -------------------------------
@ -23,6 +29,7 @@ end
dofile("mods/noita-mapcap/files/external.lua") dofile("mods/noita-mapcap/files/external.lua")
dofile("mods/noita-mapcap/files/capture.lua") dofile("mods/noita-mapcap/files/capture.lua")
dofile("mods/noita-mapcap/files/ui.lua") dofile("mods/noita-mapcap/files/ui.lua")
--dofile("mods/noita-mapcap/files/blablabla.lua")
-------------------- --------------------
-- Hook callbacks -- -- Hook callbacks --
@ -78,6 +85,9 @@ end
---The last point where the Mod API is available. ---The last point where the Mod API is available.
---After this materials.xml will be loaded. ---After this materials.xml will be loaded.
function OnMagicNumbersAndWorldSeedInitialized() function OnMagicNumbersAndWorldSeedInitialized()
-- Get resolutions for correct coordinate transformations.
-- This needs to be done once all magic numbers are set.
Coords:ReadResolutions()
end end
---Called when the game is paused or unpaused. ---Called when the game is paused or unpaused.