screen init, update, optional decision condition #11

Merged
mr.zero merged 1 commits from feature/screen-init-update into master 2026-02-21 22:35:24 +00:00
13 changed files with 26 additions and 9 deletions

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function() handle = function()
Util.go_to_screen_by_id("home") Util.go_to_screen_by_id("home")
end, end,
condition = function() return true end
}) })

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function() handle = function()
Util.go_to_screen_by_id("office") Util.go_to_screen_by_id("office")
end, end,
condition = function() return true end
}) })

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function() handle = function()
Util.go_to_screen_by_id("toilet") Util.go_to_screen_by_id("toilet")
end, end,
condition = function() return true end
}) })

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function() handle = function()
Util.go_to_screen_by_id("walking_to_home") Util.go_to_screen_by_id("walking_to_home")
end, end,
condition = function() return true end
}) })

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function() handle = function()
Util.go_to_screen_by_id("walking_to_office") Util.go_to_screen_by_id("walking_to_office")
end, end,
condition = function() return true end
}) })

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function() handle = function()
Situation.apply("drink_coffee") Situation.apply("drink_coffee")
end, end,
condition = function() return true end
}) })

View File

@@ -2,5 +2,4 @@ Decision.register({
id = "play_button_mash", id = "play_button_mash",
label = "Play Button Mash", label = "Play Button Mash",
handle = function() Meters.hide() MinigameButtonMashWindow.start(WINDOW_GAME) end, handle = function() Meters.hide() MinigameButtonMashWindow.start(WINDOW_GAME) end,
condition = function() return true end
}) })

View File

@@ -2,5 +2,4 @@ Decision.register({
id = "play_ddr", id = "play_ddr",
label = "Play DDR (Random)", label = "Play DDR (Random)",
handle = function() Meters.hide() MinigameDDRWindow.start(WINDOW_GAME, nil) end, handle = function() Meters.hide() MinigameDDRWindow.start(WINDOW_GAME, nil) end,
condition = function() return true end
}) })

View File

@@ -2,5 +2,4 @@ Decision.register({
id = "play_rhythm", id = "play_rhythm",
label = "Play Rhythm Game", label = "Play Rhythm Game",
handle = function() Meters.hide() MinigameRhythmWindow.start(WINDOW_GAME) end, handle = function() Meters.hide() MinigameRhythmWindow.start(WINDOW_GAME) end,
condition = function() return true end
}) })

View File

@@ -85,6 +85,7 @@ function Context.new_game()
reset_context_to_initial_state() reset_context_to_initial_state()
Context.game_in_progress = true Context.game_in_progress = true
MenuWindow.refresh_menu_items() MenuWindow.refresh_menu_items()
Context.screens[Context.current_screen].init()
end end
function Context.save_game() function Context.save_game()
@@ -105,4 +106,5 @@ function Context.load_game()
Context.game_in_progress = true Context.game_in_progress = true
MenuWindow.refresh_menu_items() MenuWindow.refresh_menu_items()
Context.screens[Context.current_screen].init()
end end

View File

@@ -7,6 +7,12 @@ function Screen.register(screen_data)
if not screen_data.situations then if not screen_data.situations then
screen_data.situations = {} screen_data.situations = {}
end end
if not screen_data.init then
screen_data.init = function() end
end
if not screen_data.update then
screen_data.update = function() end
end
_screens[screen_data.id] = screen_data _screens[screen_data.id] = screen_data
end end

View File

@@ -8,6 +8,9 @@ function Situation.register(situation)
if not situation.handle then if not situation.handle then
situation.handle = function() end situation.handle = function() end
end end
if not situation.update then
situation.update = function() end
end
if _situations[situation.id] then if _situations[situation.id] then
trace("Warning: Overwriting situation with id: " .. situation.id) trace("Warning: Overwriting situation with id: " .. situation.id)
end end

View File

@@ -18,6 +18,8 @@ function GameWindow.draw()
end end
function GameWindow.update() function GameWindow.update()
local previous_screen_index = Context.current_screen
if Input.menu_back() then if Input.menu_back() then
Context.active_window = WINDOW_MENU Context.active_window = WINDOW_MENU
MenuWindow.refresh_menu_items() MenuWindow.refresh_menu_items()
@@ -37,6 +39,19 @@ function GameWindow.update()
Context.selected_decision_index = 1 end Context.selected_decision_index = 1 end
local screen = Context.screens[Context.current_screen] local screen = Context.screens[Context.current_screen]
screen.update()
if previous_screen_index ~= Context.current_screen then
screen.init()
end
if Context.current_situation then
local current_situation_obj = Situation.get(Context.current_situation)
if current_situation_obj and current_situation_obj.update then
current_situation_obj.update()
end
end
if screen and screen.decisions and #screen.decisions > 0 then if screen and screen.decisions and #screen.decisions > 0 then
local available_decisions = {} local available_decisions = {}
for _, decision_id in ipairs(screen.decisions) do for _, decision_id in ipairs(screen.decisions) do