feature/refactor-npc-handling-to-desition-handling #3
@@ -7,6 +7,7 @@ init/init.context.lua
|
|||||||
data/data.songs.lua
|
data/data.songs.lua
|
||||||
system/system.print.lua
|
system/system.print.lua
|
||||||
system/system.desitions.lua
|
system/system.desitions.lua
|
||||||
|
system/system.desition_manager.lua
|
||||||
system/system.input.lua
|
system/system.input.lua
|
||||||
system/system.audio.lua
|
system/system.audio.lua
|
||||||
system/system.ui.lua
|
system/system.ui.lua
|
||||||
|
|||||||
@@ -50,85 +50,41 @@ local function get_initial_data()
|
|||||||
id = "home",
|
id = "home",
|
||||||
name = "Home",
|
name = "Home",
|
||||||
decisions = {
|
decisions = {
|
||||||
Util.create_decision(
|
"go_to_toilet",
|
||||||
"go_to_toilet",
|
"go_to_walking_to_office",
|
||||||
"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
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = "toilet",
|
id = "toilet",
|
||||||
name = "Toilet",
|
name = "Toilet",
|
||||||
decisions = {
|
decisions = {
|
||||||
Util.create_decision(
|
"go_to_home",
|
||||||
"go_to_home",
|
|
||||||
"Go to Home",
|
|
||||||
Desitions.go_to_home
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = "walking_to_office",
|
id = "walking_to_office",
|
||||||
name = "Walking to office",
|
name = "Walking to office",
|
||||||
decisions = {
|
decisions = {
|
||||||
Util.create_decision(
|
"go_to_home",
|
||||||
"go_to_home",
|
"go_to_office",
|
||||||
"Go to Home",
|
|
||||||
Desitions.go_to_home
|
|
||||||
),
|
|
||||||
Util.create_decision(
|
|
||||||
"go_to_office",
|
|
||||||
"Go to Office",
|
|
||||||
Desitions.go_to_office
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = "office",
|
id = "office",
|
||||||
name = "Office",
|
name = "Office",
|
||||||
decisions = {
|
decisions = {
|
||||||
Util.create_decision(
|
"play_button_mash",
|
||||||
"play_button_mash",
|
"play_rhythm",
|
||||||
"Play Button Mash",
|
"play_ddr",
|
||||||
Desitions.start_minigame_mash
|
"go_to_walking_to_home",
|
||||||
),
|
|
||||||
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
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = "walking_to_home",
|
id = "walking_to_home",
|
||||||
name = "Walking to home",
|
name = "Walking to home",
|
||||||
decisions = {
|
decisions = {
|
||||||
Util.create_decision(
|
"go_to_home",
|
||||||
"go_to_home",
|
"go_to_office",
|
||||||
"Go to Home",
|
|
||||||
Desitions.go_to_home
|
|
||||||
),
|
|
||||||
Util.create_decision(
|
|
||||||
"go_to_office",
|
|
||||||
"Go to Office",
|
|
||||||
Desitions.go_to_office
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ local MinigameDDRWindow = {}
|
|||||||
local Util = {}
|
local Util = {}
|
||||||
local Context = {}
|
local Context = {}
|
||||||
local Desitions = {}
|
local Desitions = {}
|
||||||
|
local DesitionManager = {}
|
||||||
local UI = {}
|
local UI = {}
|
||||||
local Print = {}
|
local Print = {}
|
||||||
local Input = {}
|
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)
|
UI.draw_top_bar(currentScreenData.name)
|
||||||
|
|
||||||
if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -33,9 +37,14 @@ function GameWindow.update()
|
|||||||
local currentScreenData = Context.screens[Context.current_screen]
|
local currentScreenData = Context.screens[Context.current_screen]
|
||||||
|
|
||||||
if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then
|
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
|
-- Update selected decision using left/right inputs
|
||||||
local new_selected_desition_index = UI.update_desition_selector(
|
local new_selected_desition_index = UI.update_desition_selector(
|
||||||
currentScreenData.decisions,
|
display_decisions,
|
||||||
Context.selected_desition_index
|
Context.selected_desition_index
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,7 +55,7 @@ function GameWindow.update()
|
|||||||
|
|
||||||
-- Execute selected decision on Input.select()
|
-- Execute selected decision on Input.select()
|
||||||
if Input.select() then
|
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
|
if selected_desition and selected_desition.handler then
|
||||||
Audio.sfx_select() -- Play sound for selection
|
Audio.sfx_select() -- Play sound for selection
|
||||||
selected_desition.handler()
|
selected_desition.handler()
|
||||||
|
|||||||
Reference in New Issue
Block a user