diff --git a/impostor.inc b/impostor.inc index 002d650..044b83d 100644 --- a/impostor.inc +++ b/impostor.inc @@ -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 diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index f15ac9a..61f5afb 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.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", } } }) diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index 098e38a..23df024 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -12,6 +12,7 @@ local MinigameDDRWindow = {} local Util = {} local Context = {} local Desitions = {} +local DesitionManager = {} local UI = {} local Print = {} local Input = {} diff --git a/inc/system/system.desition_manager.lua b/inc/system/system.desition_manager.lua new file mode 100644 index 0000000..aae6183 --- /dev/null +++ b/inc/system/system.desition_manager.lua @@ -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) diff --git a/inc/window/window.game.lua b/inc/window/window.game.lua index 35c675f..f0826b5 100644 --- a/inc/window/window.game.lua +++ b/inc/window/window.game.lua @@ -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 \ No newline at end of file