From 883ad5fcbf419618e9d983ee2866d71539fb58cd Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Mar 2026 23:33:13 +0100 Subject: [PATCH] screen exit handler --- inc/screen/screen.manager.lua | 3 +++ inc/system/system.util.lua | 10 +++++++--- inc/window/window.end.lua | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/inc/screen/screen.manager.lua b/inc/screen/screen.manager.lua index a97756d..c56419a 100644 --- a/inc/screen/screen.manager.lua +++ b/inc/screen/screen.manager.lua @@ -21,6 +21,9 @@ function Screen.register(screen_data) end if not screen_data.init then screen_data.init = function() end + end + if not screen_data.exit then + screen_data.exit = function() end end if not screen_data.update then screen_data.update = function() end diff --git a/inc/system/system.util.lua b/inc/system/system.util.lua index 0d9c322..f9c286e 100644 --- a/inc/system/system.util.lua +++ b/inc/system/system.util.lua @@ -14,10 +14,14 @@ end --- @within Util --- @param screen_id string The ID of the screen to go to.
function Util.go_to_screen_by_id(screen_id) - local screen = Screen.get_by_id(screen_id) - if screen then + local prev_screen = Screen.get_by_id(Context.game.current_screen) + local new_screen = Screen.get_by_id(screen_id) + if new_screen then Context.game.current_screen = screen_id - screen.init() + if prev_screen and prev_screen.exit then + prev_screen.exit() + end + new_screen.init() else PopupWindow.show({"Error: Screen '" .. screen_id .. "' not found!"}) end diff --git a/inc/window/window.end.lua b/inc/window/window.end.lua index 8d2b8f5..d3c08e1 100644 --- a/inc/window/window.end.lua +++ b/inc/window/window.end.lua @@ -59,7 +59,7 @@ function EndWindow.update() else -- NO: increment day and go home Day.increase() - Context.game.current_screen = "home" + Util.go_to_screen_by_id("home") Window.set_current("game") -- Initialize home screen local home_screen = Screen.get_by_id("home") -- 2.49.1