From 48373de4043cc0a93427b1904844711fa6116dc5 Mon Sep 17 00:00:00 2001 From: c3r341 <99835108+c3r341@users.noreply.github.com> Date: Mon, 7 Oct 2024 01:44:22 -0400 Subject: [PATCH 1/4] Update necronomicon.lua --- necronomicon.lua | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/necronomicon.lua b/necronomicon.lua index fcffb0fdb..91159a48d 100644 --- a/necronomicon.lua +++ b/necronomicon.lua @@ -79,11 +79,37 @@ function necronomicon(include_slabs) end end +function necronomicon_world(include_slabs) + if include_slabs then + print("Slabs:") + print() + for _,rec in ipairs(df.global.world.artifacts.all) do + if df.item_slabst:is_instance(rec.item) and check_slab_secrets(rec.item) then + print(dfhack.TranslateName(rec.name)) + end + end + print() + end + print("Books and Scrolls:") + print() + for _,rec in ipairs(df.global.world.artifacts.all) do + if df.item_bookst:is_instance(rec.item) or df.item_toolst:is_instance(rec.item) then + local title, interactions = get_book_interactions(rec.item) + + if next(interactions) then + print(" " .. dfhack.df2console(title)) + print_interactions(interactions) + print() + end + end + end +end local help = false -local include_slabs = false +local include_slabs, scan_world = false, false local args = argparse.processArgsGetopt({...}, { {"s", "include-slabs", handler=function() include_slabs = true end}, + {"w", "world", handler=function() scan_world = true end}, {"h", "help", handler=function() help = true end} }) @@ -91,8 +117,12 @@ local cmd = args[1] if help or cmd == "help" then print(dfhack.script_help()) -elseif cmd == nil or cmd == "" then - necronomicon(include_slabs) +elseif not cmd then + if scan_world then + necronomicon_world(include_slabs) + else + necronomicon(include_slabs) + end else print(('necronomicon: Invalid argument: "%s"'):format(cmd)) end From 22b1fa59cabdff2cefcb068a20bcfc8bf70d8f1f Mon Sep 17 00:00:00 2001 From: c3r341 <99835108+c3r341@users.noreply.github.com> Date: Mon, 7 Oct 2024 01:47:47 -0400 Subject: [PATCH 2/4] Update necronomicon.rst --- docs/necronomicon.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/necronomicon.rst b/docs/necronomicon.rst index 5028304ee..199d04d79 100644 --- a/docs/necronomicon.rst +++ b/docs/necronomicon.rst @@ -23,3 +23,7 @@ Options ``-s``, ``--include-slabs`` Also list slabs that contain the secrets of life and death. Note that dwarves cannot read the secrets from a slab in fort mode. + +``-w``, ``-world`` + Lists ALL secret containing books and scrolls across the entire world, + not just your fortress. From ad2ccfae8c974f64909fa15e8f05e888ab75deeb Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 28 Nov 2024 11:16:58 -0800 Subject: [PATCH 3/4] update docs, fix review comments --- changelog.txt | 1 + docs/necronomicon.rst | 14 +++++++------- necronomicon.lua | 12 +++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/changelog.txt b/changelog.txt index 25e1688ee..7c9a075dd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -50,6 +50,7 @@ Template for new versions: - `idle-crafting`: also support making shell crafts for workshops with linked input stockpiles - `gui/gm-editor`: automatic display of semantic values for language_name fields - `fix/stuck-worship`: reduced console output by default. Added ``--verbose`` and ``--quiet`` options. +- `necronomicon`: new ``--world`` option to list all secret-containing items in the entire world ## Removed - `modtools/force`: merged into `force` diff --git a/docs/necronomicon.rst b/docs/necronomicon.rst index 199d04d79..274501327 100644 --- a/docs/necronomicon.rst +++ b/docs/necronomicon.rst @@ -5,10 +5,10 @@ necronomicon :summary: Find books that contain the secrets of life and death. :tags: fort inspection items -Lists all books in the fortress that contain the secrets to life and death. -To find the books in fortress mode, go to the Written content submenu in -Objects (O). Slabs are not shown by default since dwarves cannot read secrets -from a slab in fort mode. +Lists all books in the fortress (or world) that contain the secrets to life and +death. To zoom to the books in fortress mode, go to the ``Artifacts`` tab in +`gui/sitemap` and click on their names. Slabs are not listed by default since +dwarves cannot read secrets from a slab in fort mode. Usage ----- @@ -24,6 +24,6 @@ Options Also list slabs that contain the secrets of life and death. Note that dwarves cannot read the secrets from a slab in fort mode. -``-w``, ``-world`` - Lists ALL secret containing books and scrolls across the entire world, - not just your fortress. +``-w``, ``--world`` + Lists ALL secret-containing items across the entire world, not just your + fortress. diff --git a/necronomicon.lua b/necronomicon.lua index 91159a48d..ca760ff4f 100644 --- a/necronomicon.lua +++ b/necronomicon.lua @@ -9,14 +9,16 @@ function get_book_interactions(item) improvement._type == df.itemimprovement_writingst then for _, content_id in ipairs(improvement.contents) do local written_content = df.written_content.find(content_id) - title = written_content.title + if not written_content then goto continue end + title = written_content.title for _, ref in ipairs (written_content.refs) do if ref._type == df.general_ref_interactionst then local interaction = df.interaction.find(ref.interaction_id) table.insert(book_interactions, interaction) end end + ::continue:: end end end @@ -85,23 +87,23 @@ function necronomicon_world(include_slabs) print() for _,rec in ipairs(df.global.world.artifacts.all) do if df.item_slabst:is_instance(rec.item) and check_slab_secrets(rec.item) then - print(dfhack.TranslateName(rec.name)) + print(dfhack.df2console(dfhack.TranslateName(rec.name))) end end - print() + print() end print("Books and Scrolls:") print() for _,rec in ipairs(df.global.world.artifacts.all) do if df.item_bookst:is_instance(rec.item) or df.item_toolst:is_instance(rec.item) then local title, interactions = get_book_interactions(rec.item) - + if next(interactions) then print(" " .. dfhack.df2console(title)) print_interactions(interactions) print() end - end + end end end From d92a90ed261ef78d7bfbc0adfe2f1d24f88d3d0d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:18:49 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- necronomicon.lua | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/necronomicon.lua b/necronomicon.lua index ca760ff4f..47d7c374a 100644 --- a/necronomicon.lua +++ b/necronomicon.lua @@ -82,29 +82,29 @@ function necronomicon(include_slabs) end function necronomicon_world(include_slabs) - if include_slabs then - print("Slabs:") - print() - for _,rec in ipairs(df.global.world.artifacts.all) do - if df.item_slabst:is_instance(rec.item) and check_slab_secrets(rec.item) then - print(dfhack.df2console(dfhack.TranslateName(rec.name))) - end - end - print() - end - print("Books and Scrolls:") + if include_slabs then + print("Slabs:") + print() + for _,rec in ipairs(df.global.world.artifacts.all) do + if df.item_slabst:is_instance(rec.item) and check_slab_secrets(rec.item) then + print(dfhack.df2console(dfhack.TranslateName(rec.name))) + end + end + print() + end + print("Books and Scrolls:") print() for _,rec in ipairs(df.global.world.artifacts.all) do - if df.item_bookst:is_instance(rec.item) or df.item_toolst:is_instance(rec.item) then - local title, interactions = get_book_interactions(rec.item) + if df.item_bookst:is_instance(rec.item) or df.item_toolst:is_instance(rec.item) then + local title, interactions = get_book_interactions(rec.item) - if next(interactions) then - print(" " .. dfhack.df2console(title)) - print_interactions(interactions) - print() - end - end - end + if next(interactions) then + print(" " .. dfhack.df2console(title)) + print_interactions(interactions) + print() + end + end + end end local help = false