Skip to content

Commit 021a9cf

Browse files
committed
internal/notify/notifications.lua apply GitHub and Discord feedback
1 parent 3019f02 commit 021a9cf

2 files changed

Lines changed: 39 additions & 53 deletions

File tree

‎changelog.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Template for new versions:
2929
## New Tools
3030

3131
## New Features
32-
- `gui/notify`: new notification type: missing nemesis records; displays a warning message and some recommended steps to test for game corruption.
32+
- `gui/notify`: new notification type: missing nemesis records; displays a warning message about game corruption.
3333

3434
## Fixes
3535

‎internal/notify/notifications.lua‎

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -334,76 +334,62 @@ local function save_popup()
334334
end
335335
end
336336

337-
local function get_citizens_with_missing_nemesis_records()
338-
local citizens = {}
339-
for _, unit in ipairs(dfhack.units.getCitizens(true)) do
340-
if dfhack.units.getGeneralRef(unit, df.general_ref_type.IS_NEMESIS) then
341-
local nid = dfhack.units.getGeneralRef(unit, df.general_ref_type.IS_NEMESIS).nemesis_id
342-
if df.nemesis_record.find(nid) == nil then
343-
table.insert(citizens, ' ' .. dfhack.units.getReadableName(unit))
337+
local function get_units_with_missing_nemesis_records()
338+
local namelist = {}
339+
for _, unit in ipairs(df.global.world.units.active) do
340+
local ref = dfhack.units.getGeneralRef(unit, df.general_ref_type.IS_NEMESIS)
341+
if ref then
342+
local nrec = ref:getNemesis()
343+
if nrec == nil then
344+
table.insert(namelist, dfhack.units.getReadableName(unit))
344345
end
345346
end
346347
end
347-
if #citizens == 0 then return end
348-
table.insert(citizens, 1, '\n' .. 'These citizens are missing nemesis records:')
349-
table.insert(citizens, '\n')
350-
return table.concat(citizens, '\n')
348+
return namelist
351349
end
352350

353351
-- the order of this list controls the order the notifications will appear in the overlay
354352
NOTIFICATIONS_BY_IDX = {
355353
{
356354
name='missing_nemesis',
357-
desc='Reports missing nemesis records, indicating possible game corruption.',
355+
desc='Reports missing nemesis records, indicating savegame corruption.',
358356
default=true,
359357
fn = function()
360358
local count = df.global.nemesis_next_id - #df.global.world.nemesis.all
361359
if count == 0 then return end
362-
return string.format('missing %d nemesis record%s', count, (count == 1 and '' or 's'))
360+
return { {
361+
pen = COLOR_LIGHTRED,
362+
text = ('missing %d nemesis record%s'):format(count, count == 1 and '' or 's'),
363+
} }
363364
end,
364365
on_click=function()
365-
local message = {}
366-
table.insert(message, -- indentation MATTERS here!
367-
(([[THE GAME MAY BE CORRUPT! Or it may be fine.
368-
This notification is experimental.
369-
370-
Nemesis records are missing from the world.
371-
Missing nemesis records have been known to
372-
cause crashes during game save or quit.
373-
374-
]] ):gsub(string.rep(' ',24), '')) )
375-
local redtext = get_citizens_with_missing_nemesis_records()
376-
if redtext ~= nil and redtext ~= '' then
377-
for _, line in ipairs(redtext:split('\n')) do
378-
table.insert(message, { pen = COLOR_LIGHTRED, text = line })
366+
local message = {
367+
{ pen = COLOR_RED, text = 'This save game may be corrupt.' }, NEWLINE,
368+
NEWLINE,
369+
{ pen = COLOR_WHITE, text = 'This save game contains units which are missing' }, NEWLINE,
370+
{ pen = COLOR_WHITE, text = 'their assigned nemesis records.' }, NEWLINE,
371+
NEWLINE,
372+
{ pen = COLOR_WHITE, text = 'Missing nemesis records have been known to cause' }, NEWLINE,
373+
{ pen = COLOR_WHITE, text = 'crashes during game save and when retiring forts.' }, NEWLINE,
374+
NEWLINE,
375+
{ pen = COLOR_WHITE, text = 'Units with missing nemesis records will' }, NEWLINE,
376+
{ pen = COLOR_RED, text = 'permanently disappear' },
377+
{ pen = COLOR_WHITE, text = ' if they leave the map or' }, NEWLINE,
378+
{ pen = COLOR_WHITE, text = 'if the fort is retired.' }, NEWLINE,
379+
NEWLINE,
380+
}
381+
local redtext = get_units_with_missing_nemesis_records()
382+
if #redtext > 0 then
383+
table.insert(message, { pen = COLOR_RED,
384+
text = 'These active units are missing their nemesis records:' })
385+
table.insert(message, NEWLINE)
386+
for _, line in ipairs(redtext) do
387+
table.insert(message, { pen = COLOR_LIGHTRED, text = ' ' .. line })
379388
table.insert(message, NEWLINE)
380389
end
381390
end
382-
table.insert(message, -- indentation MATTERS here!
383-
(([[Suggested course of action:
384-
* Read all of these steps before continuing.
385-
386-
* Press `Esc` to show the "Dwarf Fortress"
387-
menu, and choose "Save and continue playing".
388-
Name the savegame "corrupt-nemesis".
389-
390-
* If the save succeeds, open that menu again
391-
and choose "Quit without saving". This may
392-
crash the game! If the game doesn't crash,
393-
choose "Quit" at the main menu.
394-
395-
* Restart Dwarf Fortress and try to load the
396-
"corrupt-nemesis" savegame.
397-
398-
* If it loads, things are probably fine, and
399-
you can disable this notification by clicking
400-
the gear symbol to get the notifications
401-
settings, then clicking on "missing_nemesis"
402-
to change it to Disabled.
403-
]] ):trim():gsub(string.rep(' ',24), '')) )
404-
dlg.showMessage(get_citizens_with_missing_nemesis_records() ~= ''
405-
and 'Citizens are missing nemesis records' or 'Missing nemesis records',
406-
message, COLOR_WHITE)
391+
dlg.showMessage((#redtext > 0 and 'Active units are' or 'This world is')
392+
.. ' missing nemesis records',message, COLOR_WHITE)
407393
end,
408394
},
409395
{

0 commit comments

Comments
 (0)