2022-07-27 16:17:26 +00:00
|
|
|
-- Copyright (c) 2022 David Vogel
|
|
|
|
--
|
|
|
|
-- This software is released under the MIT License.
|
|
|
|
-- https://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
-- Allows Noita mods to reload themselves every now and then.
|
|
|
|
-- This helps dramatically with development, as we don't have to restart Noita for every change.
|
|
|
|
|
|
|
|
local LiveReload = {}
|
|
|
|
|
|
|
|
---Reloads the mod's init file in the given interval in frames.
|
|
|
|
---For reloading to work correctly, the mod has to be structured in a special way.
|
2022-07-29 22:32:11 +00:00
|
|
|
---Like the usage of require, namespaces, correct error handling, ...
|
2022-07-27 16:17:26 +00:00
|
|
|
---
|
|
|
|
---Just put this into your `OnWorldPreUpdate` or `OnWorldPostUpdate` callback:
|
|
|
|
---
|
2022-07-27 16:19:18 +00:00
|
|
|
--- LiveReload:Reload("mods/your-mod/", 60) -- The trailing path separator is needed!
|
2022-07-27 16:17:26 +00:00
|
|
|
---@param modPath string
|
|
|
|
---@param interval integer
|
|
|
|
function LiveReload:Reload(modPath, interval)
|
2022-07-27 16:19:18 +00:00
|
|
|
interval = interval or 60
|
2022-07-27 16:17:26 +00:00
|
|
|
self.Counter = (self.Counter or 0) + 1
|
|
|
|
if self.Counter < interval then return end
|
|
|
|
self.Counter = nil
|
|
|
|
|
2022-07-29 22:32:11 +00:00
|
|
|
dofile(modPath .. "init.lua")
|
2022-07-27 16:17:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return LiveReload
|