2022-07-18 20:53:34 +00:00
|
|
|
-- Copyright (c) 2022 David Vogel
|
2022-07-23 15:36:21 +00:00
|
|
|
--
|
2022-07-18 20:53:34 +00:00
|
|
|
-- This software is released under the MIT License.
|
|
|
|
-- https://opensource.org/licenses/MIT
|
|
|
|
|
2022-07-23 15:36:21 +00:00
|
|
|
-----------------------
|
|
|
|
-- Load global stuff --
|
|
|
|
-----------------------
|
2019-10-18 14:14:06 +00:00
|
|
|
|
2022-07-23 15:36:21 +00:00
|
|
|
-- Emulate and override some functions and tables to make everything conform more to standard lua.
|
|
|
|
-- This will make `require` work, even in sandboxes with restricted Noita API.
|
2022-07-23 18:43:04 +00:00
|
|
|
local libPath = "mods/noita-mapcap/files/libraries/"
|
|
|
|
dofile(libPath .. "noita-api/compatibility.lua")(libPath)
|
2022-07-22 19:31:40 +00:00
|
|
|
|
2022-07-27 23:48:49 +00:00
|
|
|
-- TODO: Replace Noita's coroutine lib with something better
|
2022-07-23 15:36:21 +00:00
|
|
|
if not async then
|
2022-07-23 18:43:04 +00:00
|
|
|
require("coroutines") -- Loads Noita's coroutines library from `data/scripts/lib/coroutines.lua`.
|
2022-07-23 15:36:21 +00:00
|
|
|
end
|
|
|
|
|
2022-07-23 20:36:14 +00:00
|
|
|
--------------------------
|
|
|
|
-- Load library modules --
|
|
|
|
--------------------------
|
|
|
|
|
2022-07-24 20:05:34 +00:00
|
|
|
local CameraAPI = require("noita-api.camera")
|
2022-07-27 16:17:26 +00:00
|
|
|
local Coords = require("coordinates")
|
2022-07-24 20:05:34 +00:00
|
|
|
local DebugAPI = require("noita-api.debug")
|
2022-07-29 22:32:11 +00:00
|
|
|
local LiveReload = require("noita-api.live-reload")
|
2022-07-24 20:05:34 +00:00
|
|
|
local Vec2 = require("noita-api.vec2")
|
2022-07-23 20:36:14 +00:00
|
|
|
|
2022-07-26 22:06:09 +00:00
|
|
|
-----------------------
|
|
|
|
-- Global namespaces --
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
Capture = Capture or {}
|
2022-07-27 23:48:49 +00:00
|
|
|
Check = Check or {}
|
2022-07-26 22:06:09 +00:00
|
|
|
Config = Config or {}
|
2022-07-27 23:48:49 +00:00
|
|
|
Message = Message or {}
|
|
|
|
Modification = Modification or {}
|
2022-07-26 22:06:09 +00:00
|
|
|
UI = UI or {}
|
|
|
|
|
2022-07-23 18:43:04 +00:00
|
|
|
-------------------------------
|
|
|
|
-- Load and run script files --
|
|
|
|
-------------------------------
|
|
|
|
|
2022-07-23 15:36:21 +00:00
|
|
|
dofile("mods/noita-mapcap/files/capture.lua")
|
2022-07-26 22:06:09 +00:00
|
|
|
dofile("mods/noita-mapcap/files/config.lua")
|
2022-07-27 23:48:49 +00:00
|
|
|
dofile("mods/noita-mapcap/files/check.lua")
|
|
|
|
dofile("mods/noita-mapcap/files/message.lua")
|
|
|
|
dofile("mods/noita-mapcap/files/modification.lua")
|
2022-07-23 15:36:21 +00:00
|
|
|
dofile("mods/noita-mapcap/files/ui.lua")
|
|
|
|
|
|
|
|
--------------------
|
|
|
|
-- Hook callbacks --
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
---Called in order upon loading a new(?) game.
|
|
|
|
function OnModPreInit()
|
2022-07-29 14:57:28 +00:00
|
|
|
if ModSettingGet("noita-mapcap.seed") ~= "" then
|
|
|
|
SetWorldSeed(tonumber(ModSettingGet("noita-mapcap.seed")) or 0)
|
|
|
|
end
|
|
|
|
|
2022-07-29 13:29:15 +00:00
|
|
|
-- Read Noita's config to be used in checks later on.
|
|
|
|
Check.StartupConfig = Modification.GetConfig()
|
|
|
|
|
2022-07-28 22:26:57 +00:00
|
|
|
-- Set magic numbers and other stuff based on mod settings.
|
2022-07-29 09:29:14 +00:00
|
|
|
local config, magic, memory, patches = Modification.RequiredChanges()
|
2022-07-27 23:48:49 +00:00
|
|
|
Modification.SetMagicNumbers(magic)
|
2022-07-28 22:26:57 +00:00
|
|
|
Modification.SetMemoryOptions(memory)
|
2022-07-29 09:29:14 +00:00
|
|
|
Modification.PatchFiles(patches)
|
2022-07-27 23:48:49 +00:00
|
|
|
|
2022-07-27 16:17:26 +00:00
|
|
|
-- Override virtual resolution and some other stuff.
|
2022-07-27 23:48:49 +00:00
|
|
|
--ModMagicNumbersFileAdd("mods/noita-mapcap/files/magic-numbers/1024.xml")
|
|
|
|
ModMagicNumbersFileAdd("mods/noita-mapcap/files/magic-numbers/fast-cam.xml")
|
2022-07-27 16:17:26 +00:00
|
|
|
--ModMagicNumbersFileAdd("mods/noita-mapcap/files/magic-numbers/no-ui.xml")
|
|
|
|
--ModMagicNumbersFileAdd("mods/noita-mapcap/files/magic-numbers/offset.xml")
|
|
|
|
|
|
|
|
-- Remove hover animation of newly created perks.
|
|
|
|
ModLuaFileAppend("data/scripts/perks/perk.lua", "mods/noita-mapcap/files/overrides/perks/perk.lua")
|
2022-07-23 15:36:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---Called in order upon loading a new(?) game.
|
|
|
|
function OnModInit()
|
|
|
|
end
|
|
|
|
|
|
|
|
---Called in order upon loading a new(?) game.
|
|
|
|
function OnModPostInit()
|
|
|
|
end
|
|
|
|
|
|
|
|
---Called when player entity has been created.
|
|
|
|
---Ensures chunks around the player have been loaded & created.
|
|
|
|
---@param playerEntityID integer
|
|
|
|
function OnPlayerSpawned(playerEntityID)
|
2022-07-28 22:25:19 +00:00
|
|
|
-- Set camera free based on mod settings.
|
|
|
|
-- We need to do this here, otherwise it will bug up or delete the player entity.
|
|
|
|
Modification.SetCameraFree()
|
2019-10-18 14:14:06 +00:00
|
|
|
end
|
|
|
|
|
2022-07-23 15:36:21 +00:00
|
|
|
---Called when the player dies.
|
|
|
|
---@param playerEntityID integer
|
|
|
|
function OnPlayerDied(playerEntityID)
|
|
|
|
end
|
|
|
|
|
|
|
|
---Called once the game world is initialized.
|
|
|
|
---Doesn't ensure any chunks around the player.
|
|
|
|
function OnWorldInitialized()
|
|
|
|
end
|
|
|
|
|
|
|
|
---Called *every* time the game is about to start updating the world.
|
2022-07-19 16:28:30 +00:00
|
|
|
function OnWorldPreUpdate()
|
2022-07-29 09:29:14 +00:00
|
|
|
Message:CatchException("OnWorldPreUpdate", function()
|
2022-07-28 22:25:19 +00:00
|
|
|
|
2022-07-27 23:48:49 +00:00
|
|
|
-- Coroutines aren't run every frame in this lua sandbox, do it manually here.
|
|
|
|
wake_up_waiting_threads(1)
|
|
|
|
|
|
|
|
end)
|
2022-07-23 15:36:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---Called *every* time the game has finished updating the world.
|
|
|
|
function OnWorldPostUpdate()
|
2022-07-29 09:29:14 +00:00
|
|
|
Message:CatchException("OnWorldPostUpdate", function()
|
2022-07-28 08:32:23 +00:00
|
|
|
-- Reload mod every 60 frames.
|
|
|
|
-- This allows live updates to the mod while Noita is running.
|
2022-07-29 22:32:11 +00:00
|
|
|
-- !!! DISABLE THE FOLLOWING LINE BEFORE COMMITTING !!!
|
2022-07-28 08:32:23 +00:00
|
|
|
--LiveReload:Reload("mods/noita-mapcap/", 60)
|
2022-07-27 23:48:49 +00:00
|
|
|
|
2022-07-28 20:34:56 +00:00
|
|
|
-- Run checks every 60 frames.
|
|
|
|
Check:Regular(60)
|
2022-07-27 23:48:49 +00:00
|
|
|
|
|
|
|
-- Draw UI after coroutines have been resumed.
|
|
|
|
UI:Draw()
|
|
|
|
|
|
|
|
end)
|
2022-07-23 15:36:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---Called when the biome config is loaded.
|
|
|
|
function OnBiomeConfigLoaded()
|
|
|
|
end
|
|
|
|
|
|
|
|
---The last point where the Mod API is available.
|
|
|
|
---After this materials.xml will be loaded.
|
|
|
|
function OnMagicNumbersAndWorldSeedInitialized()
|
2022-07-23 20:36:14 +00:00
|
|
|
-- Get resolutions for correct coordinate transformations.
|
|
|
|
-- This needs to be done once all magic numbers are set.
|
|
|
|
Coords:ReadResolutions()
|
2022-07-27 23:48:49 +00:00
|
|
|
|
|
|
|
Check:Startup()
|
2022-07-23 15:36:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---Called when the game is paused or unpaused.
|
|
|
|
---@param isPaused boolean
|
|
|
|
---@param isInventoryPause boolean
|
|
|
|
function OnPausedChanged(isPaused, isInventoryPause)
|
2022-08-27 12:07:37 +00:00
|
|
|
Message:CatchException("OnPausedChanged", function()
|
|
|
|
-- Set some stuff based on mod settings.
|
|
|
|
-- Normally this would be in `OnModSettingsChanged`, but that doesn't seem to be called.
|
|
|
|
local config, magic, memory, patches = Modification.RequiredChanges()
|
|
|
|
Modification.SetMemoryOptions(memory)
|
|
|
|
|
|
|
|
end)
|
2022-07-23 15:36:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---Will be called when the game is unpaused, if player changed any mod settings while the game was paused.
|
|
|
|
function OnModSettingsChanged()
|
|
|
|
end
|
|
|
|
|
|
|
|
---Will be called when the game is paused, either by the pause menu or some inventory menus.
|
|
|
|
---Please be careful with this, as not everything will behave well when called while the game is paused.
|
|
|
|
function OnPausePreUpdate()
|
2019-10-18 14:14:06 +00:00
|
|
|
end
|