dfhack
dfhack copied to clipboard
[Developer Request] Publicize `necronomicon`'s internals
Make necronomicon's internal functions return strings rather than printing directly and make necronomicon a module or similar so one can call them rather than copying them. I think this would enable someone to make #5234 a thing.
Here is my rough mock up of the necronomicon notification, for the sake of getting someone started
local necro = require('necronomicon') -- maybe needs to be reqscript instead
[...]
{
name='necronomicon',
desc='Notifies you to books in your fort containing the secrets of life and death.',
default=true,
dwarf_fn=function ()
for _, vec in ipairs{df.global.world.items.other.BOOK, df.global.world.items.other.TOOL} do
for _, item in ipairs(vec) do
local _, interactions = necro.get_book_interactions(item)
if next(interactions) ~= nil then
return {{text='Necromancy Warning!', pen=COLOR_LIGHTRED}}
end
end
end
end,
on_click=function ()
local results = {}
for _, vec in ipairs{df.global.world.items.other.BOOK, df.global.world.items.other.TOOL} do
for _, item in ipairs(vec) do
local title, interactions = necro.get_book_interactions(item)
if next(interactions) ~= nil then
results.append({("\nBook: " .. dfhack.df2console(title)), necro.print_interactions(interactions)})
end
end
end
for _, item in ipairs(df.global.world.items.other.SLAB) do
if check_slab_secrets(item) then
local artifact = get_item_artifact(item)
local name = dfhack.translation.translateName(artifact.name)
results.append({("\nSlab: " .. dfhack.df2console(name))})
end
end
if results == {} then
results = {'No necromactic books, scrolls, or slabs were found'}
end
local msg = 'Some necromactic texts have been found in your fort:\n\n' .. results
dlg.showMessage("Necromancy Warning!", msg, COLOR_WHITE)
end
},