diff --git a/ci/test.lua b/ci/test.lua index 9a7c0d3452..e57facf14b 100644 --- a/ci/test.lua +++ b/ci/test.lua @@ -458,9 +458,7 @@ local function load_tests(file, tests) local targets = type(env.config.target) == 'table' and env.config.target or {env.config.target} for _,target in ipairs(targets) do if target == 'core' then goto continue end - if type(target) ~= 'string' or not helpdb.is_entry(target) or - helpdb.get_entry_tags(target).unavailable - then + if type(target) ~= 'string' or helpdb.has_tag(target, 'unavailable') then dfhack.printerr('Skipping tests for unavailable target: ' .. target) return true end diff --git a/docs/changelog.txt b/docs/changelog.txt index 493ff8a309..48906b5fdf 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -63,6 +63,7 @@ Template for new versions: - `tiletypes`: make aquifers functional when adding the ``aquifer`` property - `seedwatch`: do not include unplantable tree seeds in its status report - ``Buildings::containsTile``: fix result for buildings that are solid and have no extent structures +- Mortal mode: prevent keybindings that run armok tools from being recognized when in mortal mode ## Misc Improvements - `blueprint`: capture track carving designations in addition to already-carved tracks diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 00c8944e6f..2202f6d71b 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -3950,6 +3950,10 @@ Each entry has several properties associated with it: Returns the set of tag names for the given entry. +* ``helpdb.has_tag(entry, tag)`` + + Returns whether the given entry exists and has the specified tag. + * ``helpdb.is_tag(str)``, ``helpdb.is_tag(list)`` Returns whether the given string (or list of strings) is a (are all) valid tag diff --git a/library/Core.cpp b/library/Core.cpp index 3b7168c840..4e17d93986 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2460,6 +2460,23 @@ bool Core::doSdlInputEvent(SDL_Event* ev) return false; } +static bool should_hide_from_mortals(const std::string &command) { + auto &out = Core::getInstance().getConsole(); + + bool is_mortal = false; + Lua::CallLuaModuleFunction(out, "dfhack", "getHideArmokTools", {}, 1, + [&](lua_State* L) { is_mortal = lua_toboolean(L, -1); }); + + if (!is_mortal) + return false; + + bool is_armok = false; + Lua::CallLuaModuleFunction(out, "helpdb", "has_tag", std::make_tuple(command, "armok"), 1, + [&](lua_State* L) { is_armok = lua_toboolean(L, -1); }); + + return is_armok; +} + bool Core::SelectHotkey(int sym, int modifiers) { // Find the topmost viewscreen @@ -2504,6 +2521,11 @@ bool Core::SelectHotkey(int sym, int modifiers) binding.command[0].c_str()); continue; } + if (should_hide_from_mortals(binding.command[0])) { + DEBUG(keybinding).print("skipping keybinding due to mortal mode (command: '%s')\n", + binding.command[0].c_str()); + continue; + } cmd = binding.cmdline; DEBUG(keybinding).print("matched hotkey\n"); diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index fbb90ccf12..0c1bc7dc15 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -963,7 +963,7 @@ local warned_scripts = {} function dfhack.run_script(name,...) if not warned_scripts[name] then local helpdb = require('helpdb') - if helpdb.is_entry(name) and helpdb.get_entry_tags(name).unavailable then + if helpdb.has_tag(name, 'unavailable') then warned_scripts[name] = true dfhack.printerr(('UNTESTED WARNING: the "%s" script has not been validated to work well with this version of DF.'):format(name)) dfhack.printerr('It may not work as expected, or it may corrupt your game.') diff --git a/library/lua/helpdb.lua b/library/lua/helpdb.lua index 281582ec25..216f6c582c 100644 --- a/library/lua/helpdb.lua +++ b/library/lua/helpdb.lua @@ -526,6 +526,11 @@ function get_entry_tags(entry) return get_db_property(entry, 'tags') end +-- returns whether the given entry exists and has the specified tag +function has_tag(entry, tag) + return is_entry(entry) and get_entry_tags(entry)[tag] +end + -- returns whether the given string (or list of strings) matches a tag name function is_tag(str) ensure_db() diff --git a/plugins/lua/hotkeys.lua b/plugins/lua/hotkeys.lua index e19bd055f9..23ff25bdbb 100644 --- a/plugins/lua/hotkeys.lua +++ b/plugins/lua/hotkeys.lua @@ -16,9 +16,7 @@ end function should_hide_armok(cmdline) local command = get_command(cmdline) - return dfhack.getHideArmokTools() and - helpdb.is_entry(command) and - helpdb.get_entry_tags(command).armok + return dfhack.getHideArmokTools() and helpdb.has_tag(command, 'armok') end -- ----------------- --