From 4bd7f4f09604bd96617ec43281b36aeef1c235d4 Mon Sep 17 00:00:00 2001 From: notnotmelon Date: Thu, 30 Nov 2023 12:29:31 -0600 Subject: [PATCH] add hooks to register callbacks when a wiki page is closed --- changelog.txt | 1 + scripts/wiki/wiki.lua | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index 328f2fcf..f8ee7adb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,6 +4,7 @@ Date: ? Changes: - Fixed a crash when configuring AMFM beacons (https://github.com/pyanodon/pybugreports/issues/349) - Removed burner assembling machine wiki page. It's info was outdated after previous patch which removed the ingredient limit. + - Fixed a crash when viewing a wiki page that doesn't exist --------------------------------------------------------------------------------------------------- Version: 2.1.8 Date: 2023-11-21 diff --git a/scripts/wiki/wiki.lua b/scripts/wiki/wiki.lua index 981cc787..51a0f3a8 100644 --- a/scripts/wiki/wiki.lua +++ b/scripts/wiki/wiki.lua @@ -91,7 +91,15 @@ end function Wiki.close_wiki(player) local main_frame = Wiki.get_wiki_gui(player) - if main_frame then main_frame.destroy() end + if not main_frame then return end + + local pages = Wiki.get_pages(player) + local page_data = pages.tags.contents[pages.selected_index] + if page_data and page_data.on_closed then + local on_closed = page_data.on_closed + remote.call(on_closed[1], on_closed[2], contents, player) + end + main_frame.destroy() end Gui.on_click('py_open_wiki', function(event) @@ -137,10 +145,19 @@ function Wiki.open_page(player, index) local page_data = pages.tags.contents[index] if page_data.is_section then - Wiki.open_page(player, global.currently_opened_wiki_page[player.index] or 1) + local previous_index = global.currently_opened_wiki_page[player.index] or 1 + if previous_index ~= index then Wiki.open_page(player, previous_index) end return end + if global.currently_opened_wiki_page[player.index] then + local previous_page_data = pages.tags.contents[global.currently_opened_wiki_page[player.index]] + if previous_page_data and previous_page_data.on_closed then + local on_closed = previous_page_data.on_closed + remote.call(on_closed[1], on_closed[2], contents, player) + end + end + title.clear() local localised_title = {'pywiki-sections.' .. (page_data.title or page_data.name)} title.add{type = 'label', style = 'subheader_label', name = 'page_title', caption = {'', '[font=default-semibold][color=255,230,192]', localised_title, '[/color][/font]'}}