diff --git a/.luacheckrc b/.luacheckrc index 3d329af..eae275a 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -3,7 +3,7 @@ globals = { "Util", - "DesitionManager", + "DecisionManager", "ScreenManager", "UI", "Print", diff --git a/impostor.inc b/impostor.inc index 19e2ee8..ab191dd 100644 --- a/impostor.inc +++ b/impostor.inc @@ -1,17 +1,18 @@ meta/meta.header.lua init/init.modules.lua init/init.config.lua +init/init.minigames.lua system/system.util.lua init/init.windows.lua -desition/desition.manager.lua -desition/desition.go_to_home.lua -desition/desition.go_to_toilet.lua -desition/desition.go_to_walking_to_office.lua -desition/desition.go_to_office.lua -desition/desition.go_to_walking_to_home.lua -desition/desition.play_button_mash.lua -desition/desition.play_rhythm.lua -desition/desition.play_ddr.lua +decision/decision.manager.lua +decision/decision.go_to_home.lua +decision/decision.go_to_toilet.lua +decision/decision.go_to_walking_to_office.lua +decision/decision.go_to_office.lua +decision/decision.go_to_walking_to_home.lua +decision/decision.play_button_mash.lua +decision/decision.play_rhythm.lua +decision/decision.play_ddr.lua map/map.manager.lua map/map.bedroom.lua screen/screen.manager.lua diff --git a/inc/desition/desition.go_to_home.lua b/inc/decision/decision.go_to_home.lua similarity index 85% rename from inc/desition/desition.go_to_home.lua rename to inc/decision/decision.go_to_home.lua index 89ed3a4..f906f5d 100644 --- a/inc/desition/desition.go_to_home.lua +++ b/inc/decision/decision.go_to_home.lua @@ -1,4 +1,4 @@ -DesitionManager.register({ +DecisionManager.register({ id = "go_to_home", label = "Go to Home", handle = function() diff --git a/inc/desition/desition.go_to_office.lua b/inc/decision/decision.go_to_office.lua similarity index 85% rename from inc/desition/desition.go_to_office.lua rename to inc/decision/decision.go_to_office.lua index 75b47ac..72118a7 100644 --- a/inc/desition/desition.go_to_office.lua +++ b/inc/decision/decision.go_to_office.lua @@ -1,4 +1,4 @@ -DesitionManager.register({ +DecisionManager.register({ id = "go_to_office", label = "Go to Office", handle = function() diff --git a/inc/desition/desition.go_to_toilet.lua b/inc/decision/decision.go_to_toilet.lua similarity index 85% rename from inc/desition/desition.go_to_toilet.lua rename to inc/decision/decision.go_to_toilet.lua index 7127b94..6525cbf 100644 --- a/inc/desition/desition.go_to_toilet.lua +++ b/inc/decision/decision.go_to_toilet.lua @@ -1,4 +1,4 @@ -DesitionManager.register({ +DecisionManager.register({ id = "go_to_toilet", label = "Go to Toilet", handle = function() diff --git a/inc/desition/desition.go_to_walking_to_home.lua b/inc/decision/decision.go_to_walking_to_home.lua similarity index 87% rename from inc/desition/desition.go_to_walking_to_home.lua rename to inc/decision/decision.go_to_walking_to_home.lua index d98395b..9accc3d 100644 --- a/inc/desition/desition.go_to_walking_to_home.lua +++ b/inc/decision/decision.go_to_walking_to_home.lua @@ -1,4 +1,4 @@ -DesitionManager.register({ +DecisionManager.register({ id = "go_to_walking_to_home", label = "Walking to home", handle = function() diff --git a/inc/desition/desition.go_to_walking_to_office.lua b/inc/decision/decision.go_to_walking_to_office.lua similarity index 87% rename from inc/desition/desition.go_to_walking_to_office.lua rename to inc/decision/decision.go_to_walking_to_office.lua index 8048f68..265401a 100644 --- a/inc/desition/desition.go_to_walking_to_office.lua +++ b/inc/decision/decision.go_to_walking_to_office.lua @@ -1,4 +1,4 @@ -DesitionManager.register({ +DecisionManager.register({ id = "go_to_walking_to_office", label = "Walking to office", handle = function() diff --git a/inc/decision/decision.manager.lua b/inc/decision/decision.manager.lua new file mode 100644 index 0000000..8a660eb --- /dev/null +++ b/inc/decision/decision.manager.lua @@ -0,0 +1,31 @@ +local _decisions = {} + +function DecisionManager.register(decision) + if not decision or not decision.id then + PopupWindow.show({"Error: Invalid decision object registered (missing id)!"}) + return + end + if not decision.label then + PopupWindow.show({"Error: Invalid decision object registered (missing label)!"}) + return + end + + if not decision.condition then + decision.condition = function() return true end + end + if not decision.handle then + decision.handle = function() end + end + if _decisions[decision.id] then + trace("Warning: Overwriting decision with id: " .. decision.id) + end + _decisions[decision.id] = decision +end + +function DecisionManager.get(id) + return _decisions[id] +end + +function DecisionManager.get_all() + return _decisions +end diff --git a/inc/desition/desition.play_button_mash.lua b/inc/decision/decision.play_button_mash.lua similarity index 86% rename from inc/desition/desition.play_button_mash.lua rename to inc/decision/decision.play_button_mash.lua index 754e292..6fc26ff 100644 --- a/inc/desition/desition.play_button_mash.lua +++ b/inc/decision/decision.play_button_mash.lua @@ -1,4 +1,4 @@ -DesitionManager.register({ +DecisionManager.register({ id = "play_button_mash", label = "Play Button Mash", handle = function() MinigameButtonMashWindow.start(WINDOW_GAME) end, diff --git a/inc/desition/desition.play_ddr.lua b/inc/decision/decision.play_ddr.lua similarity index 85% rename from inc/desition/desition.play_ddr.lua rename to inc/decision/decision.play_ddr.lua index f03be37..4274832 100644 --- a/inc/desition/desition.play_ddr.lua +++ b/inc/decision/decision.play_ddr.lua @@ -1,4 +1,4 @@ -DesitionManager.register({ +DecisionManager.register({ id = "play_ddr", label = "Play DDR (Random)", handle = function() MinigameDDRWindow.start(WINDOW_GAME, nil) end, diff --git a/inc/desition/desition.play_rhythm.lua b/inc/decision/decision.play_rhythm.lua similarity index 85% rename from inc/desition/desition.play_rhythm.lua rename to inc/decision/decision.play_rhythm.lua index 82688ec..a0c9483 100644 --- a/inc/desition/desition.play_rhythm.lua +++ b/inc/decision/decision.play_rhythm.lua @@ -1,4 +1,4 @@ -DesitionManager.register({ +DecisionManager.register({ id = "play_rhythm", label = "Play Rhythm Game", handle = function() MinigameRhythmWindow.start(WINDOW_GAME) end, diff --git a/inc/desition/desition.manager.lua b/inc/desition/desition.manager.lua deleted file mode 100644 index 3d0ea4f..0000000 --- a/inc/desition/desition.manager.lua +++ /dev/null @@ -1,31 +0,0 @@ -local _desitions = {} - -function DesitionManager.register(desition) - if not desition or not desition.id then - PopupWindow.show({"Error: Invalid desition object registered (missing id)!"}) - return - end - if not desition.label then - PopupWindow.show({"Error: Invalid desition object registered (missing label)!"}) - return - end - - if not desition.condition then - desition.condition = function() return true end - end - if not desition.handle then - desition.handle = function() end - end - if _desitions[desition.id] then - trace("Warning: Overwriting desition with id: " .. desition.id) - end - _desitions[desition.id] = desition -end - -function DesitionManager.get(id) - return _desitions[id] -end - -function DesitionManager.get_all() - return _desitions -end diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index 54f4cb6..7a40c4a 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -39,9 +39,12 @@ on than meets the eye.]] }, menu_items = {}, selected_menu_item = 1, - selected_desition_index = 1, + selected_decision_index = 1, game_in_progress = false, - screens = {} + screens = {}, + minigame_ddr = Minigames.get_default_ddr(), + minigame_button_mash = Minigames.get_default_button_mash(), + minigame_rhythm = Minigames.get_default_rhythm() } end @@ -66,7 +69,8 @@ local function reset_context_to_initial_state() local screen_data = ScreenManager.get_by_id(screen_id) if screen_data then table.insert(Context.screens, screen_data) - Context.screen_indices_by_id[screen_id] = i else + Context.screen_indices_by_id[screen_id] = i + else PopupWindow.show({"Error: Screen '" .. screen_id .. "' not registered!"}) end end diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index 0620467..dc01748 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -9,7 +9,8 @@ local MinigameButtonMashWindow = {} local MinigameRhythmWindow = {} local MinigameDDRWindow = {} Util = {} -DesitionManager = {} +Minigames = {} +DecisionManager = {} ScreenManager = {} MapManager = {} UI = {} diff --git a/inc/system/system.ui.lua b/inc/system/system.ui.lua index 3008260..e950559 100644 --- a/inc/system/system.ui.lua +++ b/inc/system/system.ui.lua @@ -84,26 +84,26 @@ function UI.create_action_item(label, action) } end -function UI.draw_desition_selector(desitions, selected_desition_index) +function UI.draw_decision_selector(decisions, selected_decision_index) local bar_height = 16 local bar_y = Config.screen.height - bar_height rect(0, bar_y, Config.screen.width, bar_height, Config.colors.dark_grey) - if #desitions > 0 then - local selected_desition = desitions[selected_desition_index] - local desition_label = selected_desition.label - local text_width = #desition_label * 4 local text_y = bar_y + 4 + if #decisions > 0 then + local selected_decision = decisions[selected_decision_index] + local decision_label = selected_decision.label + local text_width = #decision_label * 4 local text_y = bar_y + 4 local text_x = (Config.screen.width - text_width) / 2 Print.text("<", 2, text_y, Config.colors.green) - Print.text(desition_label, text_x, text_y, Config.colors.item) Print.text(">", Config.screen.width - 6, text_y, Config.colors.green) end + Print.text(decision_label, text_x, text_y, Config.colors.item) Print.text(">", Config.screen.width - 6, text_y, Config.colors.green) end end -function UI.update_desition_selector(desitions, selected_desition_index) +function UI.update_decision_selector(decisions, selected_decision_index) if Input.left() then Audio.sfx_beep() - selected_desition_index = Util.safeindex(desitions, selected_desition_index - 1) + selected_decision_index = Util.safeindex(decisions, selected_decision_index - 1) elseif Input.right() then Audio.sfx_beep() - selected_desition_index = Util.safeindex(desitions, selected_desition_index + 1) + selected_decision_index = Util.safeindex(decisions, selected_decision_index + 1) end - return selected_desition_index + return selected_decision_index end \ No newline at end of file diff --git a/inc/system/system.util.lua b/inc/system/system.util.lua index cee625a..2c128e3 100644 --- a/inc/system/system.util.lua +++ b/inc/system/system.util.lua @@ -8,7 +8,7 @@ function Util.go_to_screen_by_id(screen_id) local screen_index = Context.screen_indices_by_id[screen_id] if screen_index then Context.current_screen = screen_index - Context.selected_desition_index = 1 else + Context.selected_decision_index = 1 else PopupWindow.show({"Error: Screen '" .. screen_id .. "' not found or not indexed!"}) end end \ No newline at end of file diff --git a/inc/window/window.audiotest.lua b/inc/window/window.audiotest.lua index 8a29b97..2b30a8b 100644 --- a/inc/window/window.audiotest.lua +++ b/inc/window/window.audiotest.lua @@ -10,7 +10,7 @@ function AudioTestWindow.generate_menuitems(list_func, index_func) return { { label = "Play music/sound: " .. (list_func[index_func] or "?"), - desition = function() + decision = function() local current_func = Audio[list_func[index_func]] if current_func then current_func() @@ -21,13 +21,13 @@ function AudioTestWindow.generate_menuitems(list_func, index_func) }, { label = "Stop playing music", - desition = function() + decision = function() Audio.music_stop() end }, { label = "Back", - desition = function() + decision = function() AudioTestWindow.back() end }, @@ -90,7 +90,7 @@ function AudioTestWindow.update() AudioTestWindow.list_func, AudioTestWindow.index_func ) elseif Input.menu_confirm() then - AudioTestWindow.menuitems[AudioTestWindow.index_menu].desition() + AudioTestWindow.menuitems[AudioTestWindow.index_menu].decision() elseif Input.menu_back() then AudioTestWindow.back() end diff --git a/inc/window/window.configuration.lua b/inc/window/window.configuration.lua index b9bc4cf..2147eaf 100644 --- a/inc/window/window.configuration.lua +++ b/inc/window/window.configuration.lua @@ -5,11 +5,11 @@ ConfigurationWindow = { function ConfigurationWindow.init() ConfigurationWindow.controls = { - UI.create_desition_item( + UI.create_decision_item( "Save", function() Config.save() end ), - UI.create_desition_item( + UI.create_decision_item( "Restore Defaults", function() Config.restore_defaults() end ), @@ -40,7 +40,7 @@ function ConfigurationWindow.draw() Print.text(label_text, x_start, current_y, color) Print.text(value_text, value_x, current_y, color) end - elseif control.type == "desition_item" then + elseif control.type == "decision_item" then local label_text = control.label if i == ConfigurationWindow.selected_control then color = Config.colors.item @@ -82,9 +82,9 @@ function ConfigurationWindow.update() elseif btnp(3) then local new_value = math.min(control.max, current_value + control.step) control.set(new_value) end - elseif control.type == "desition_item" then + elseif control.type == "decision_item" then if Input.menu_confirm() then - control.desition() + control.decision() end end end diff --git a/inc/window/window.game.lua b/inc/window/window.game.lua index 815f64a..fbf322f 100644 --- a/inc/window/window.game.lua +++ b/inc/window/window.game.lua @@ -3,15 +3,15 @@ function GameWindow.draw() MapManager.draw(screen.background) UI.draw_top_bar(screen.name) if screen and screen.decisions and #screen.decisions > 0 then - local available_desitions = {} - for _, desition_id in ipairs(screen.decisions) do - local desition = DesitionManager.get(desition_id) - if desition and desition.condition() then - table.insert(available_desitions, desition) + local available_decisions = {} + for _, decision_id in ipairs(screen.decisions) do + local decision = DecisionManager.get(decision_id) + if decision and decision.condition() then + table.insert(available_decisions, decision) end end - if #available_desitions > 0 then - UI.draw_desition_selector(available_desitions, Context.selected_desition_index) + if #available_decisions > 0 then + UI.draw_decision_selector(available_decisions, Context.selected_decision_index) end end end @@ -28,36 +28,36 @@ function GameWindow.update() if Context.current_screen < 1 then Context.current_screen = #Context.screens end - Context.selected_desition_index = 1 elseif Input.down() then + Context.selected_decision_index = 1 elseif Input.down() then Context.current_screen = Context.current_screen + 1 if Context.current_screen > #Context.screens then Context.current_screen = 1 end - Context.selected_desition_index = 1 end + Context.selected_decision_index = 1 end local screen = Context.screens[Context.current_screen] if screen and screen.decisions and #screen.decisions > 0 then - local available_desitions = {} - for _, desition_id in ipairs(screen.decisions) do - local desition = DesitionManager.get(desition_id) - if desition and desition.condition() then table.insert(available_desitions, desition) + local available_decisions = {} + for _, decision_id in ipairs(screen.decisions) do + local decision = DecisionManager.get(decision_id) + if decision and decision.condition() then table.insert(available_decisions, decision) end end - if #available_desitions == 0 then return end + if #available_decisions == 0 then return end - local new_selected_desition_index = UI.update_desition_selector( - available_desitions, - Context.selected_desition_index + local new_selected_decision_index = UI.update_decision_selector( + available_decisions, + Context.selected_decision_index ) - if new_selected_desition_index ~= Context.selected_desition_index then - Context.selected_desition_index = new_selected_desition_index + if new_selected_decision_index ~= Context.selected_decision_index then + Context.selected_decision_index = new_selected_decision_index end if Input.select() then - local selected_desition = available_desitions[Context.selected_desition_index] - if selected_desition and selected_desition.handle then Audio.sfx_select() selected_desition.handle() + local selected_decision = available_decisions[Context.selected_decision_index] + if selected_decision and selected_decision.handle then Audio.sfx_select() selected_decision.handle() end end end diff --git a/inc/window/window.menu.lua b/inc/window/window.menu.lua index 1c7d02b..5b6cfbb 100644 --- a/inc/window/window.menu.lua +++ b/inc/window/window.menu.lua @@ -8,9 +8,9 @@ function MenuWindow.update() if Input.menu_confirm() then local selected_item = Context.menu_items[Context.selected_menu_item] - if selected_item and selected_item.desition then + if selected_item and selected_item.decision then Audio.sfx_select() - selected_item.desition() + selected_item.decision() end end end @@ -47,14 +47,14 @@ end function MenuWindow.refresh_menu_items() Context.menu_items = {} if Context.game_in_progress then - table.insert(Context.menu_items, {label = "Resume Game", desition = MenuWindow.resume_game}) - table.insert(Context.menu_items, {label = "Save Game", desition = MenuWindow.save_game}) + table.insert(Context.menu_items, {label = "Resume Game", decision = MenuWindow.resume_game}) + table.insert(Context.menu_items, {label = "Save Game", decision = MenuWindow.save_game}) end - table.insert(Context.menu_items, {label = "New Game", desition = MenuWindow.new_game}) - table.insert(Context.menu_items, {label = "Load Game", desition = MenuWindow.load_game}) - table.insert(Context.menu_items, {label = "Configuration", desition = MenuWindow.configuration}) - table.insert(Context.menu_items, {label = "Audio Test", desition = MenuWindow.audio_test}) - table.insert(Context.menu_items, {label = "Exit", desition = MenuWindow.exit}) + table.insert(Context.menu_items, {label = "New Game", decision = MenuWindow.new_game}) + table.insert(Context.menu_items, {label = "Load Game", decision = MenuWindow.load_game}) + table.insert(Context.menu_items, {label = "Configuration", decision = MenuWindow.configuration}) + table.insert(Context.menu_items, {label = "Audio Test", decision = MenuWindow.audio_test}) + table.insert(Context.menu_items, {label = "Exit", decision = MenuWindow.exit}) Context.selected_menu_item = 1 end