From 462ee0cba7f89d1148f885f1725c23c59cd8cab4 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 20 Jul 2023 17:43:57 -0700 Subject: [PATCH 1/2] generalize mod directory scanning --- library/lua/script-manager.lua | 50 ++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/library/lua/script-manager.lua b/library/lua/script-manager.lua index 450012357..91b4985ac 100644 --- a/library/lua/script-manager.lua +++ b/library/lua/script-manager.lua @@ -74,7 +74,7 @@ function list() end --------------------- --- mod script paths +-- mod paths -- this perhaps could/should be queried from the Steam API -- are there any installation configurations where this will be wrong, though? @@ -98,8 +98,8 @@ local function get_mod_id_and_version(path) end if not version then -- note this doesn't include the closing brace since some people put - -- non-number characters in here, and DF only reads the digits as the - -- numeric version + -- non-number characters in here, and DF only reads the leading digits + -- as the numeric version _,_,version = line:find('^%[NUMERIC_VERSION:(%d+)') end -- note that we do *not* want to break out of this loop early since @@ -108,37 +108,31 @@ local function get_mod_id_and_version(path) return id, version end -local function add_script_path(mod_script_paths, path) +local function add_mod_paths(mod_paths, id, base_path, subdir) + local sep = base_path:endswith('/') and '' or '/' + local path = ('%s%s%s'):format(base_path, sep, subdir) if dfhack.filesystem.isdir(path) then - print('indexing mod scripts: ' .. path) - table.insert(mod_script_paths, path) + print('indexing mod path: ' .. path) + table.insert(mod_paths, {id=id, path=path}) end end -local function add_script_paths(mod_script_paths, base_path, include_modactive) - if not base_path:endswith('/') then - base_path = base_path .. '/' - end - if include_modactive then - add_script_path(mod_script_paths, base_path..'scripts_modactive') - end - add_script_path(mod_script_paths, base_path..'scripts_modinstalled') -end - -function get_mod_script_paths() +function get_mod_paths(installed_subdir, active_subdir) -- ordered map of mod id -> {handled=bool, versions=map of version -> path} local mods = utils.OrderedTable() - local mod_script_paths = {} + local mod_paths = {} -- if a world is loaded, process active mods first, and lock to active version - if dfhack.isWorldLoaded() then + if active_subdir and dfhack.isWorldLoaded() then for _,path in ipairs(df.global.world.object_loader.object_load_order_src_dir) do path = tostring(path.value) + -- skip vanilla "mods" if not path:startswith(INSTALLED_MODS_PATH) then goto continue end local id = get_mod_id_and_version(path) if not id then goto continue end mods[id] = {handled=true} - add_script_paths(mod_script_paths, path, true) + add_mod_paths(mod_paths, id, path, active_subdir) + add_mod_paths(mod_paths, id, path, installed_subdir) ::continue:: end end @@ -159,8 +153,8 @@ function get_mod_script_paths() ::skip_path_root:: end - -- add script paths from most recent version of all not-yet-handled mods - for _,v in pairs(mods) do + -- add paths from most recent version of all not-yet-handled mods + for id,v in pairs(mods) do if v.handled then goto continue end local max_version, path for version,mod_path in pairs(v.versions) do @@ -169,11 +163,19 @@ function get_mod_script_paths() max_version = version end end - add_script_paths(mod_script_paths, path) + add_mod_paths(mod_paths, id, path, installed_subdir) ::continue:: end - return mod_script_paths + return mod_paths +end + +function get_mod_script_paths() + local paths = {} + for _,v in ipairs(get_mod_paths('scripts_modinstalled', 'scripts_modactive')) do + table.insert(paths, v.path) + end + return paths end return _ENV From e67df53c482555a9318dbd28eec0f34a78c4de4c Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 20 Jul 2023 17:44:09 -0700 Subject: [PATCH 2/2] document new blueprints dir in mods --- docs/guides/modding-guide.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/guides/modding-guide.rst b/docs/guides/modding-guide.rst index 38117503c..297e8482a 100644 --- a/docs/guides/modding-guide.rst +++ b/docs/guides/modding-guide.rst @@ -45,6 +45,7 @@ this:: info.txt graphics/... objects/... + blueprints/... scripts_modactive/example-mod.lua scripts_modactive/internal/example-mod/... scripts_modinstalled/... @@ -58,6 +59,9 @@ Let's go through that line by line. - Modifications to the game raws (potentially with custom raw tokens) go in the :file:`graphics/` and :file:`objects/` folders. You can read more about the files that go in these directories on the :wiki:`Modding` wiki page. +- Any `quickfort` blueprints included with your mod go in the + :file:`blueprints` folder. Note that your mod can *just* be blueprints and + nothing else if you like. - A control script in :file:`scripts_modactive/` directory that handles system-level event hooks (e.g. reloading state when a world is loaded), registering `overlays `, and