desition and screen magement refactor
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
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)
|
||||
@@ -1,33 +0,0 @@
|
||||
Desitions = {}
|
||||
|
||||
function Desitions.go_to_screen(screen_id)
|
||||
for i, screen_data in ipairs(Context.screens) do
|
||||
if screen_data.id == screen_id then
|
||||
Context.current_screen = i
|
||||
Context.selected_desition_index = 1 -- Reset selected decision on new screen
|
||||
return
|
||||
end
|
||||
end
|
||||
-- Handle error: screen_id not found, perhaps show a debug message or a popup
|
||||
PopupWindow.show({"Error: Screen '" .. screen_id .. "' not found!"})
|
||||
end
|
||||
|
||||
-- Specific navigation helpers
|
||||
function Desitions.go_to_home() Desitions.go_to_screen("home") end
|
||||
function Desitions.go_to_toilet() Desitions.go_to_screen("toilet") end
|
||||
function Desitions.go_to_walking_to_office() Desitions.go_to_screen("walking_to_office") end
|
||||
function Desitions.go_to_office() Desitions.go_to_screen("office") end
|
||||
function Desitions.go_to_walking_to_home() Desitions.go_to_screen("walking_to_home") end
|
||||
|
||||
-- Minigame functions
|
||||
function Desitions.start_minigame_mash()
|
||||
MinigameButtonMashWindow.start(WINDOW_GAME)
|
||||
end
|
||||
|
||||
function Desitions.start_minigame_rhythm()
|
||||
MinigameRhythmWindow.start(WINDOW_GAME)
|
||||
end
|
||||
|
||||
function Desitions.start_minigame_ddr(song_key)
|
||||
MinigameDDRWindow.start(WINDOW_GAME, song_key)
|
||||
end
|
||||
@@ -1,13 +1,5 @@
|
||||
Util = {}
|
||||
|
||||
function Util.create_decision(id, label, handler)
|
||||
return {
|
||||
id = id,
|
||||
label = label,
|
||||
handler = handler
|
||||
}
|
||||
end
|
||||
|
||||
function Util.safeindex(array, index)
|
||||
return ((index - 1 + #array) % #array) + 1
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user