no onChangeState fn, let scripts attach themselves

develop
myk002 2022-12-06 14:42:27 -08:00 committed by Myk Taylor
parent 854642734c
commit a872cdbcd4
No known key found for this signature in database
2 changed files with 8 additions and 10 deletions

@ -2,9 +2,11 @@ script-manager
==============
.. dfhack-tool::
:summary: Manages startup tasks for scripts.
:summary: Triggers startup tasks for scripts.
:tags: dev
:no-command:
This plugin connects ``onStateChange()`` hooks for scripts so they can load
saved state and handles enabled state tracking and reporting.
This plugin loads all scripts that are declared as modules so that they can
put state change hooks in place for loading persistent data. It also scans for
global ``isEnabled()`` functions and gathers them for script enabled state
tracking and reporting for the `enable` command.

@ -26,7 +26,8 @@ end
local enabled_map = {}
local function process_global(env_name, env, global_name, target)
local function process_script(env_name, env)
local global_name = 'isEnabled'
local fn = env[global_name]
if not fn then return end
if type(fn) ~= 'function' then
@ -35,12 +36,7 @@ local function process_global(env_name, env, global_name, target)
' value is not a function'):format(global_name, env_name))
return
end
target[env_name] = fn
end
local function process_script(env_name, env)
process_global(env_name, env, 'onStateChange', dfhack.onStateChange)
process_global(env_name, env, 'isEnabled', enabled_map)
enabled_map[env_name] = fn
end
function init()