screen exit handler #37

Merged
mr.zero merged 1 commits from screen-exit-handler into master 2026-03-17 22:33:51 +00:00
3 changed files with 11 additions and 4 deletions
Showing only changes of commit 883ad5fcbf - Show all commits

View File

@@ -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

View File

@@ -14,10 +14,14 @@ end
--- @within Util
--- @param screen_id string The ID of the screen to go to.<br/>
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

View File

@@ -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")