From 42b18d001bca119b44328fe70c52e2c60135307d Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 11 Mar 2023 12:51:46 -0800 Subject: [PATCH] refresh overlay and helpdb on new world to pick up mod content --- library/lua/helpdb.lua | 10 ++++++++++ plugins/lua/overlay.lua | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/library/lua/helpdb.lua b/library/lua/helpdb.lua index df5482aec..a7ac6226f 100644 --- a/library/lua/helpdb.lua +++ b/library/lua/helpdb.lua @@ -12,6 +12,8 @@ local TAG_DEFINITIONS = 'hack/docs/docs/Tags.txt' local SCRIPT_DOC_BEGIN = '[====[' local SCRIPT_DOC_END = ']====]' +local GLOBAL_KEY = 'HELPDB' + -- enums local ENTRY_TYPES = { BUILTIN='builtin', @@ -423,6 +425,14 @@ function refresh() ensure_db() end +dfhack.onStateChange[GLOBAL_KEY] = function(sc) + if sc ~= SC_WORLD_LOADED then + return + end + -- pick up widgets from active mods + refresh() +end + local function parse_blocks(text) local blocks = {} for line in text:gmatch('[^\n]*') do diff --git a/plugins/lua/overlay.lua b/plugins/lua/overlay.lua index 3d476bf0d..ff8bf7c98 100644 --- a/plugins/lua/overlay.lua +++ b/plugins/lua/overlay.lua @@ -8,6 +8,7 @@ local widgets = require('gui.widgets') local OVERLAY_CONFIG_FILE = 'dfhack-config/overlay.json' local OVERLAY_WIDGETS_VAR = 'OVERLAY_WIDGETS' +local GLOBAL_KEY = 'OVERLAY' local DEFAULT_X_POS, DEFAULT_Y_POS = -2, -2 @@ -311,6 +312,14 @@ function reload() reposition_widgets() end +dfhack.onStateChange[GLOBAL_KEY] = function(sc) + if sc ~= SC_WORLD_LOADED then + return + end + -- pick up widgets from active mods + reload() +end + local function dump_widget_config(name, widget) local pos = overlay_config[name].pos print(('widget %s is positioned at x=%d, y=%d'):format(name, pos.x, pos.y))