|
|
@ -5,6 +5,8 @@ local json = require('json')
|
|
|
|
local utils = require('utils')
|
|
|
|
local utils = require('utils')
|
|
|
|
local widgets = require('gui.widgets')
|
|
|
|
local widgets = require('gui.widgets')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local scriptmanager = require('plugins.script-manager')
|
|
|
|
|
|
|
|
|
|
|
|
local OVERLAY_CONFIG_FILE = 'dfhack-config/overlay.json'
|
|
|
|
local OVERLAY_CONFIG_FILE = 'dfhack-config/overlay.json'
|
|
|
|
local OVERLAY_WIDGETS_VAR = 'OVERLAY_WIDGETS'
|
|
|
|
local OVERLAY_WIDGETS_VAR = 'OVERLAY_WIDGETS'
|
|
|
|
|
|
|
|
|
|
|
@ -250,11 +252,9 @@ local function load_widget(name, widget_class)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function load_widgets(env_prefix, provider, env_fn)
|
|
|
|
local function load_widgets(env_name, env)
|
|
|
|
local env_name = env_prefix .. provider
|
|
|
|
local overlay_widgets = env[OVERLAY_WIDGETS_VAR]
|
|
|
|
local ok, provider_env = pcall(env_fn, env_name)
|
|
|
|
if not overlay_widgets then return end
|
|
|
|
if not ok or not provider_env[OVERLAY_WIDGETS_VAR] then return end
|
|
|
|
|
|
|
|
local overlay_widgets = provider_env[OVERLAY_WIDGETS_VAR]
|
|
|
|
|
|
|
|
if type(overlay_widgets) ~= 'table' then
|
|
|
|
if type(overlay_widgets) ~= 'table' then
|
|
|
|
dfhack.printerr(
|
|
|
|
dfhack.printerr(
|
|
|
|
('error loading overlay widgets from "%s": %s map is malformed')
|
|
|
|
('error loading overlay widgets from "%s": %s map is malformed')
|
|
|
@ -262,7 +262,7 @@ local function load_widgets(env_prefix, provider, env_fn)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for widget_name,widget_class in pairs(overlay_widgets) do
|
|
|
|
for widget_name,widget_class in pairs(overlay_widgets) do
|
|
|
|
local name = provider .. '.' .. widget_name
|
|
|
|
local name = env_name .. '.' .. widget_name
|
|
|
|
if not safecall(load_widget, name, widget_class) then
|
|
|
|
if not safecall(load_widget, name, widget_class) then
|
|
|
|
dfhack.printerr(('error loading overlay widget "%s"'):format(name))
|
|
|
|
dfhack.printerr(('error loading overlay widget "%s"'):format(name))
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -274,23 +274,13 @@ function reload()
|
|
|
|
reset()
|
|
|
|
reset()
|
|
|
|
|
|
|
|
|
|
|
|
for _,plugin in ipairs(dfhack.internal.listPlugins()) do
|
|
|
|
for _,plugin in ipairs(dfhack.internal.listPlugins()) do
|
|
|
|
load_widgets('plugins.', plugin, require)
|
|
|
|
local env_name = 'plugins.' .. plugin
|
|
|
|
end
|
|
|
|
local ok, plugin_env = pcall(require, env_name)
|
|
|
|
for _,script_path in ipairs(dfhack.internal.getScriptPaths()) do
|
|
|
|
if ok then
|
|
|
|
local files = dfhack.filesystem.listdir_recursive(
|
|
|
|
load_widgets(plugin, plugin_env)
|
|
|
|
script_path, nil, false)
|
|
|
|
|
|
|
|
if not files then goto skip_path end
|
|
|
|
|
|
|
|
for _,f in ipairs(files) do
|
|
|
|
|
|
|
|
if not f.isdir and
|
|
|
|
|
|
|
|
f.path:endswith('.lua') and
|
|
|
|
|
|
|
|
not f.path:startswith('test/') and
|
|
|
|
|
|
|
|
not f.path:startswith('internal/') then
|
|
|
|
|
|
|
|
local script_name = f.path:sub(1, #f.path - 4) -- remove '.lua'
|
|
|
|
|
|
|
|
load_widgets('', script_name, reqscript)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
::skip_path::
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
scriptmanager.foreach_module_script(load_widgets)
|
|
|
|
|
|
|
|
|
|
|
|
for name in pairs(widget_db) do
|
|
|
|
for name in pairs(widget_db) do
|
|
|
|
table.insert(widget_index, name)
|
|
|
|
table.insert(widget_index, name)
|
|
|
|