situation handling
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful

This commit is contained in:
2026-02-21 22:31:49 +01:00
parent 3b9b67e2fa
commit ed2354b0fa
8 changed files with 63 additions and 9 deletions

View File

@@ -0,0 +1,8 @@
Decision.register({
id = "have_a_coffee",
label = "Have a Coffee",
handle = function()
Situation.apply("drink_coffee")
end,
condition = function() return true end
})

View File

@@ -12,6 +12,7 @@ Util = {}
Meters = {}
Minigames = {}
Decision = {}
Situation = {}
Screen = {}
Map = {}
UI = {}

View File

@@ -1,17 +1,12 @@
local _screens = {}
function Screen.get_screens_array()
local screens_array = {}
for _, screen_data in pairs(_screens) do
table.insert(screens_array, screen_data)
end
return screens_array
end
function Screen.register(screen_data)
if _screens[screen_data.id] then
trace("Warning: Overwriting screen with id: " .. screen_data.id)
end
if not screen_data.situations then
screen_data.situations = {}
end
_screens[screen_data.id] = screen_data
end

View File

@@ -6,5 +6,9 @@ Screen.register({
"play_rhythm",
"play_ddr",
"go_to_walking_to_home",
}
"have_a_coffee",
},
situations = {
"drink_coffee",
},
})

View File

@@ -0,0 +1,6 @@
Situation.register({
id = "drink_coffee",
handle = function()
Audio.sfx_select()
end,
})

View File

@@ -0,0 +1,36 @@
local _situations = {}
function Situation.register(situation)
if not situation or not situation.id then
PopupWindow.show({"Error: Invalid situation object registered (missing id)!"})
return
end
if not situation.handle then
situation.handle = function() end
end
if _situations[situation.id] then
trace("Warning: Overwriting situation with id: " .. situation.id)
end
_situations[situation.id] = situation
end
function Situation.get(id)
return _situations[id]
end
function Situation.apply(id)
local situation = Situation.get(id)
if not situation then
trace("Error: No situation found with id: " .. id)
return
end
local current_screen_obj = Screen.get_by_id(Context.current_screen)
if current_screen_obj and not current_screen_obj.situations[id] then
trace("Info: Situation " .. id .. " cannot be applied to current screen (id: " .. Context.current_screen .. ").")
return
end
situation.handle()
end