desition and screen magement refactor
This commit is contained in:
14
inc/desition/desition.go_to_home.lua
Normal file
14
inc/desition/desition.go_to_home.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
DesitionManager.register({
|
||||
id = "go_to_home",
|
||||
label = "Go to Home",
|
||||
handle = function()
|
||||
local screen_index = Context.screen_indices_by_id["home"]
|
||||
if screen_index then
|
||||
Context.current_screen = screen_index
|
||||
Context.selected_desition_index = 1
|
||||
else
|
||||
PopupWindow.show({"Error: Screen 'home' not found or not indexed!"})
|
||||
end
|
||||
end,
|
||||
condition = function() return true end
|
||||
})
|
||||
14
inc/desition/desition.go_to_office.lua
Normal file
14
inc/desition/desition.go_to_office.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
DesitionManager.register({
|
||||
id = "go_to_office",
|
||||
label = "Go to Office",
|
||||
handle = function()
|
||||
local screen_index = Context.screen_indices_by_id["office"]
|
||||
if screen_index then
|
||||
Context.current_screen = screen_index
|
||||
Context.selected_desition_index = 1
|
||||
else
|
||||
PopupWindow.show({"Error: Screen 'office' not found or not indexed!"})
|
||||
end
|
||||
end,
|
||||
condition = function() return true end
|
||||
})
|
||||
14
inc/desition/desition.go_to_toilet.lua
Normal file
14
inc/desition/desition.go_to_toilet.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
DesitionManager.register({
|
||||
id = "go_to_toilet",
|
||||
label = "Go to Toilet",
|
||||
handle = function()
|
||||
local screen_index = Context.screen_indices_by_id["toilet"]
|
||||
if screen_index then
|
||||
Context.current_screen = screen_index
|
||||
Context.selected_desition_index = 1
|
||||
else
|
||||
PopupWindow.show({"Error: Screen 'toilet' not found or not indexed!"})
|
||||
end
|
||||
end,
|
||||
condition = function() return true end
|
||||
})
|
||||
14
inc/desition/desition.go_to_walking_to_home.lua
Normal file
14
inc/desition/desition.go_to_walking_to_home.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
DesitionManager.register({
|
||||
id = "go_to_walking_to_home",
|
||||
label = "Go to Walking to home",
|
||||
handle = function()
|
||||
local screen_index = Context.screen_indices_by_id["walking_to_home"]
|
||||
if screen_index then
|
||||
Context.current_screen = screen_index
|
||||
Context.selected_desition_index = 1
|
||||
else
|
||||
PopupWindow.show({"Error: Screen 'walking_to_home' not found or not indexed!"})
|
||||
end
|
||||
end,
|
||||
condition = function() return true end
|
||||
})
|
||||
14
inc/desition/desition.go_to_walking_to_office.lua
Normal file
14
inc/desition/desition.go_to_walking_to_office.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
DesitionManager.register({
|
||||
id = "go_to_walking_to_office",
|
||||
label = "Go to Walking to office",
|
||||
handle = function()
|
||||
local screen_index = Context.screen_indices_by_id["walking_to_office"]
|
||||
if screen_index then
|
||||
Context.current_screen = screen_index
|
||||
Context.selected_desition_index = 1
|
||||
else
|
||||
PopupWindow.show({"Error: Screen 'walking_to_office' not found or not indexed!"})
|
||||
end
|
||||
end,
|
||||
condition = function() return true end
|
||||
})
|
||||
42
inc/desition/desition.manager.lua
Normal file
42
inc/desition/desition.manager.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
DesitionManager = {}
|
||||
|
||||
local _desitions = {} -- Private table to store all desitions
|
||||
|
||||
-- Registers a decision object with the manager
|
||||
-- desition_object: A table containing id, label, handle(), and condition()
|
||||
function DesitionManager.register(desition_object)
|
||||
if not desition_object or not desition_object.id then
|
||||
PopupWindow.show({"Error: Invalid desition object registered (missing id)!"})
|
||||
return
|
||||
end
|
||||
if not desition_object.label then
|
||||
PopupWindow.show({"Error: Invalid desition object registered (missing label)!"})
|
||||
return
|
||||
end
|
||||
|
||||
-- Ensure handle() and condition() methods exist with defaults if missing
|
||||
if not desition_object.condition then
|
||||
desition_object.condition = function() return true end
|
||||
end
|
||||
if not desition_object.handle then
|
||||
desition_object.handle = function() end
|
||||
end
|
||||
|
||||
if _desitions[desition_object.id] then
|
||||
-- Optional: warning if overwriting an existing desition
|
||||
-- trace("Warning: Overwriting desition with id: " .. desition_object.id)
|
||||
end
|
||||
_desitions[desition_object.id] = desition_object
|
||||
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
|
||||
6
inc/desition/desition.play_button_mash.lua
Normal file
6
inc/desition/desition.play_button_mash.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
DesitionManager.register({
|
||||
id = "play_button_mash",
|
||||
label = "Play Button Mash",
|
||||
handle = function() MinigameButtonMashWindow.start(WINDOW_GAME) end,
|
||||
condition = function() return true end
|
||||
})
|
||||
6
inc/desition/desition.play_ddr.lua
Normal file
6
inc/desition/desition.play_ddr.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
DesitionManager.register({
|
||||
id = "play_ddr",
|
||||
label = "Play DDR (Random)",
|
||||
handle = function() MinigameDDRWindow.start(WINDOW_GAME, nil) end,
|
||||
condition = function() return true end
|
||||
})
|
||||
6
inc/desition/desition.play_rhythm.lua
Normal file
6
inc/desition/desition.play_rhythm.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
DesitionManager.register({
|
||||
id = "play_rhythm",
|
||||
label = "Play Rhythm Game",
|
||||
handle = function() MinigameRhythmWindow.start(WINDOW_GAME) end,
|
||||
condition = function() return true end
|
||||
})
|
||||
Reference in New Issue
Block a user