Merge pull request 'screen exit handler' (#37) from screen-exit-handler into master
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #37
This commit was merged in pull request #37.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user