DesitionManager
This commit is contained in:
@@ -7,6 +7,7 @@ init/init.context.lua
|
||||
data/data.songs.lua
|
||||
system/system.print.lua
|
||||
system/system.desitions.lua
|
||||
system/system.desition_manager.lua
|
||||
system/system.input.lua
|
||||
system/system.audio.lua
|
||||
system/system.ui.lua
|
||||
|
||||
@@ -50,85 +50,41 @@ local function get_initial_data()
|
||||
id = "home",
|
||||
name = "Home",
|
||||
decisions = {
|
||||
Util.create_decision(
|
||||
"go_to_toilet",
|
||||
"Go to Toilet",
|
||||
Desitions.go_to_toilet
|
||||
),
|
||||
Util.create_decision(
|
||||
"go_to_walking_to_office",
|
||||
"Go to Walking to office",
|
||||
Desitions.go_to_walking_to_office
|
||||
),
|
||||
"go_to_toilet",
|
||||
"go_to_walking_to_office",
|
||||
}
|
||||
},
|
||||
{
|
||||
id = "toilet",
|
||||
name = "Toilet",
|
||||
decisions = {
|
||||
Util.create_decision(
|
||||
"go_to_home",
|
||||
"Go to Home",
|
||||
Desitions.go_to_home
|
||||
),
|
||||
"go_to_home",
|
||||
}
|
||||
},
|
||||
{
|
||||
id = "walking_to_office",
|
||||
name = "Walking to office",
|
||||
decisions = {
|
||||
Util.create_decision(
|
||||
"go_to_home",
|
||||
"Go to Home",
|
||||
Desitions.go_to_home
|
||||
),
|
||||
Util.create_decision(
|
||||
"go_to_office",
|
||||
"Go to Office",
|
||||
Desitions.go_to_office
|
||||
),
|
||||
"go_to_home",
|
||||
"go_to_office",
|
||||
}
|
||||
},
|
||||
{
|
||||
id = "office",
|
||||
name = "Office",
|
||||
decisions = {
|
||||
Util.create_decision(
|
||||
"play_button_mash",
|
||||
"Play Button Mash",
|
||||
Desitions.start_minigame_mash
|
||||
),
|
||||
Util.create_decision(
|
||||
"play_rhythm",
|
||||
"Play Rhythm Game",
|
||||
Desitions.start_minigame_rhythm
|
||||
),
|
||||
Util.create_decision(
|
||||
"play_ddr",
|
||||
"Play DDR (Random)",
|
||||
Desitions.start_minigame_ddr
|
||||
),
|
||||
Util.create_decision(
|
||||
"go_to_walking_to_home",
|
||||
"Go to Walking to home",
|
||||
Desitions.go_to_walking_to_home
|
||||
),
|
||||
"play_button_mash",
|
||||
"play_rhythm",
|
||||
"play_ddr",
|
||||
"go_to_walking_to_home",
|
||||
}
|
||||
},
|
||||
{
|
||||
id = "walking_to_home",
|
||||
name = "Walking to home",
|
||||
decisions = {
|
||||
Util.create_decision(
|
||||
"go_to_home",
|
||||
"Go to Home",
|
||||
Desitions.go_to_home
|
||||
),
|
||||
Util.create_decision(
|
||||
"go_to_office",
|
||||
"Go to Office",
|
||||
Desitions.go_to_office
|
||||
),
|
||||
"go_to_home",
|
||||
"go_to_office",
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -12,6 +12,7 @@ local MinigameDDRWindow = {}
|
||||
local Util = {}
|
||||
local Context = {}
|
||||
local Desitions = {}
|
||||
local DesitionManager = {}
|
||||
local UI = {}
|
||||
local Print = {}
|
||||
local Input = {}
|
||||
|
||||
42
inc/system/system.desition_manager.lua
Normal file
42
inc/system/system.desition_manager.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
DesitionManager = {}
|
||||
|
||||
local _desitions = {} -- Private table to store all desitions
|
||||
|
||||
-- Registers a new desition with the manager
|
||||
-- id: unique string identifier for the desition
|
||||
-- label: string label to display for the desition
|
||||
-- handler: function to execute when the desition is selected
|
||||
function DesitionManager.register(id, label, handler)
|
||||
if _desitions[id] then
|
||||
-- Optional: warning if overwriting an existing desition
|
||||
-- trace("Warning: Overwriting desition with id: " .. id)
|
||||
end
|
||||
_desitions[id] = Util.create_decision(id, label, handler)
|
||||
end
|
||||
|
||||
-- Retrieves a desition by its id
|
||||
-- id: unique string identifier of the desition
|
||||
-- Returns the desition object, or nil if not found
|
||||
function DesitionManager.get(id)
|
||||
return _desitions[id]
|
||||
end
|
||||
|
||||
-- Optional: a way to get all registered desitions, if needed (e.g., for debug)
|
||||
function DesitionManager.get_all()
|
||||
return _desitions
|
||||
end
|
||||
|
||||
-- Register all game desitions
|
||||
-- Home Screen Decisions
|
||||
DesitionManager.register("go_to_toilet", "Go to Toilet", Desitions.go_to_toilet)
|
||||
DesitionManager.register("go_to_walking_to_office", "Go to Walking to office", Desitions.go_to_walking_to_office)
|
||||
|
||||
-- Minigame functions
|
||||
DesitionManager.register("play_button_mash", "Play Button Mash", Desitions.start_minigame_mash)
|
||||
DesitionManager.register("play_rhythm", "Play Rhythm Game", Desitions.start_minigame_rhythm)
|
||||
DesitionManager.register("play_ddr", "Play DDR (Random)", Desitions.start_minigame_ddr)
|
||||
|
||||
-- Navigation functions
|
||||
DesitionManager.register("go_to_home", "Go to Home", Desitions.go_to_home)
|
||||
DesitionManager.register("go_to_office", "Go to Office", Desitions.go_to_office)
|
||||
DesitionManager.register("go_to_walking_to_home", "Go to Walking to home", Desitions.go_to_walking_to_home)
|
||||
@@ -4,7 +4,11 @@ function GameWindow.draw()
|
||||
UI.draw_top_bar(currentScreenData.name)
|
||||
|
||||
if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then
|
||||
UI.draw_desition_selector(currentScreenData.decisions, Context.selected_desition_index)
|
||||
local display_decisions = {}
|
||||
for _, desition_id in ipairs(currentScreenData.decisions) do
|
||||
table.insert(display_decisions, DesitionManager.get(desition_id))
|
||||
end
|
||||
UI.draw_desition_selector(display_decisions, Context.selected_desition_index)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,11 +35,16 @@ function GameWindow.update()
|
||||
end
|
||||
|
||||
local currentScreenData = Context.screens[Context.current_screen]
|
||||
|
||||
|
||||
if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then
|
||||
local display_decisions = {}
|
||||
for _, desition_id in ipairs(currentScreenData.decisions) do
|
||||
table.insert(display_decisions, DesitionManager.get(desition_id))
|
||||
end
|
||||
|
||||
-- Update selected decision using left/right inputs
|
||||
local new_selected_desition_index = UI.update_desition_selector(
|
||||
currentScreenData.decisions,
|
||||
display_decisions,
|
||||
Context.selected_desition_index
|
||||
)
|
||||
|
||||
@@ -46,7 +55,7 @@ function GameWindow.update()
|
||||
|
||||
-- Execute selected decision on Input.select()
|
||||
if Input.select() then
|
||||
local selected_desition = currentScreenData.decisions[Context.selected_desition_index]
|
||||
local selected_desition = display_decisions[Context.selected_desition_index]
|
||||
if selected_desition and selected_desition.handler then
|
||||
Audio.sfx_select() -- Play sound for selection
|
||||
selected_desition.handler()
|
||||
@@ -58,4 +67,4 @@ end
|
||||
function GameWindow.set_state(new_state)
|
||||
Context.active_window = new_state
|
||||
-- Add any state-specific initialization/cleanup here later if needed
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user