From 9a65891afaa64829d8d770652933833aeb82b925 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 16:51:30 +0100 Subject: [PATCH 01/10] remove items and npcs --- impostor.inc | 5 +- inc/entity/entity.item.lua | 7 - inc/entity/entity.npc.lua | 13 -- inc/init/init.config.lua | 1 - inc/init/init.context.lua | 355 ---------------------------------- inc/init/init.modules.lua | 5 +- inc/system/system.actions.lua | 31 +++ inc/system/system.util.lua | 8 + inc/window/window.game.lua | 15 -- inc/window/window.popup.lua | 2 +- 10 files changed, 44 insertions(+), 398 deletions(-) delete mode 100644 inc/entity/entity.item.lua delete mode 100644 inc/entity/entity.npc.lua create mode 100644 inc/system/system.actions.lua diff --git a/impostor.inc b/impostor.inc index ed729fd..76dc724 100644 --- a/impostor.inc +++ b/impostor.inc @@ -1,13 +1,12 @@ meta/meta.header.lua init/init.modules.lua init/init.config.lua +system/system.util.lua init/init.windows.lua init/init.context.lua data/data.songs.lua system/system.print.lua -system/system.util.lua -entity/entity.npc.lua -entity/entity.item.lua +system/system.actions.lua system/system.input.lua system/system.audio.lua system/system.ui.lua diff --git a/inc/entity/entity.item.lua b/inc/entity/entity.item.lua deleted file mode 100644 index 44b9dc6..0000000 --- a/inc/entity/entity.item.lua +++ /dev/null @@ -1,7 +0,0 @@ -function Item.use() - Print.text("Used item: " .. Context.dialog.active_entity.name) -end -function Item.look_at() - PopupWindow.show_description_dialog(Context.dialog.active_entity, Context.dialog.active_entity.desc) -end - diff --git a/inc/entity/entity.npc.lua b/inc/entity/entity.npc.lua deleted file mode 100644 index c4a90e2..0000000 --- a/inc/entity/entity.npc.lua +++ /dev/null @@ -1,13 +0,0 @@ -function NPC.talk_to() - local npc = Context.dialog.active_entity - if npc.dialog and npc.dialog.start then - PopupWindow.set_dialog_node("start") - else - -- if no dialog, go back - GameWindow.set_state(WINDOW_GAME) - end -end -function NPC.fight() end -function NPC.go_back() - GameWindow.set_state(WINDOW_GAME) -end diff --git a/inc/init/init.config.lua b/inc/init/init.config.lua index 82f454c..a9672bf 100644 --- a/inc/init/init.config.lua +++ b/inc/init/init.config.lua @@ -8,7 +8,6 @@ local DEFAULT_CONFIG = { light_grey = 13, dark_grey = 14, green = 6, - npc = 8, item = 12 -- yellow }, player = { diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index 9199b60..8337ed2 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -51,137 +51,6 @@ local function get_initial_data() screens = clone_table({ { name = "Screen 1", - npcs = { - { - name = "Button Mash Minigame", - sprite_id = 4, - dialog = { - start = { - text = "Ready to test your reflexes? Prove your speed!", - options = { - {label = "Let's do it!", next_node = "__MINIGAME_BUTTON_MASH__"}, - {label = "Not now.", next_node = "dialog_end"} - } - }, - dialog_end = { - text = "Come back when you're ready.", - options = {} - } - } - }, - { - name = "Trinity", - sprite_id = 2, - dialog = { - start = { - text = "Hello, Neo.", - options = { - {label = "Who are you?", next_node = "who_are_you"}, - {label = "My name is not Neo.", next_node = "not_neo"}, - {label = "...", next_node = "silent"} - } - }, - who_are_you = { - text = "I am Trinity. I've been looking for you.", - options = { - {label = "The famous hacker?", next_node = "famous_hacker"}, - {label = "Why me?", next_node = "why_me"} - } - }, - not_neo = { - text = "I know. But you will be.", - options = { - {label = "What are you talking about?", next_node = "who_are_you"} - } - }, - silent = { - text = "You're not much of a talker, are you?", - options = { - {label = "I guess not.", next_node = "dialog_end"} - } - }, - famous_hacker = { - text = "The one and only.", - options = { - {label = "Wow.", next_node = "dialog_end"} - } - }, - why_me = { - text = "Morpheus believes you are The One.", - options = { - {label = "The One?", next_node = "the_one"} - } - }, - the_one = { - text = "The one who will save us all.", - options = { - {label = "I'm just a programmer.", next_node = "dialog_end"} - } - }, - dialog_end = { - text = "We'll talk later.", - options = {} -- No options, ends conversation - } - } - }, - { - name = "Oracle", - sprite_id = 3, - dialog = { - start = { - text = "I know what you're thinking. 'Am I in the right place?'", - options = { - {label = "Who are you?", next_node = "who_are_you"}, - {label = "I guess I am.", next_node = "you_are"} - } - }, - who_are_are = { - text = "I'm the Oracle. And you're right on time. Want a cookie?", - options = { - {label = "Sure.", next_node = "cookie"}, - {label = "No, thank you.", next_node = "no_cookie"} - } - }, - you_are = { - text = "Of course you are. Sooner or later, everyone comes to see me. Want a cookie?", - options = { - {label = "Yes, please.", next_node = "cookie"}, - {label = "I'm good.", next_node = "no_cookie"} - } - }, - cookie = { - text = "Here you go. Now, what's really on your mind?", - options = { - {label = "Am I The One?", next_node = "the_one"}, - {label = "What is the Matrix?", next_node = "the_matrix"} - } - }, - no_cookie = { - text = "Suit yourself. Now, what's troubling you?", - options = { - {label = "Am I The One?", next_node = "the_one"}, - {label = "What is the Matrix?", next_node = "the_matrix"} - } - }, - the_one = { - text = "Being The One is just like being in love. No one can tell you you're in love, you just know it. Through and through. Balls to bones.", - options = { - {label = "So I'm not?", next_node = "dialog_end"} - } - }, - the_matrix = { - text = "The Matrix is a system, Neo. That system is our enemy. But when you're inside, you look around, what do you see? The very minds of the people we are trying to save.", - options = { - {label = "I see.", next_node = "dialog_end"} - } - }, - dialog_end = { - text = "You have to understand, most of these people are not ready to be unplugged.", - options = {} - } - } - }, - }, items = { { name = "Key", @@ -193,102 +62,6 @@ local function get_initial_data() { -- Screen 2 name = "Screen 2", - npcs = { - { - name = "Rhythm Master", - sprite_id = 4, - dialog = { - start = { - text = "Test your timing! Hit the mark when the moment is right.", - options = { - {label = "Let's go!", next_node = "__MINIGAME_RHYTHM__"}, - {label = "Not now.", next_node = "dialog_end"} - } - }, - dialog_end = { - text = "Come back when you're ready to test your reflexes.", - options = {} - } - } - }, - { - name = "Morpheus", - sprite_id = 5, - dialog = { - start = { - text = "At last. Welcome, Neo. As you no doubt have guessed, I am Morpheus.", - options = { - {label = "It's an honor to meet you.", next_node = "honor"}, - {label = "You've been looking for me.", next_node = "looking_for_me"} - } - }, - honor = { - text = "No, the honor is mine.", - options = { - {label = "What is this place?", next_node = "what_is_this_place"} - } - }, - looking_for_me = { - text = "I have. For some time.", - options = { - {label = "What is this place?", next_node = "what_is_this_place"} - } - }, - what_is_this_place = { - text = "This is the construct. It's our loading program. We can load anything from clothing, to equipment, weapons, training simulations. Anything we need.", - options = { - {label = "Right.", next_node = "dialog_end"} - } - }, - dialog_end = { - text = "I've been waiting for you, Neo. We have much to discuss.", - options = {} -- Ends conversation - } - } - }, - { - name = "Tank", - sprite_id = 6, - dialog = { - start = { - text = "Hey, Neo! Welcome to the construct. I'm Tank.", - options = { - {label = "Good to meet you.", next_node = "good_to_meet_you"}, - {label = "This place is incredible.", next_node = "incredible"} - } - }, - good_to_meet_you = { - text = "You too! We've been waiting for you. Need anything? Training? Weapons?", - options = { - {label = "Training?", next_node = "training"}, - {label = "I'm good for now.", next_node = "dialog_end"} - } - }, - incredible = { - text = "Isn't it? The boss's design. We can load anything we need. What do you want to learn?", - options = { - {label = "Show me.", next_node = "training"} - } - }, - training = { - text = "Jujitsu? Kung Fu? How about... all of them?", - options = { - {label = "All of them.", next_node = "all_of_them"} - } - }, - all_of_them = { - text = "Operator, load the combat training program.", - options = { - {label = "...", next_node = "dialog_end"} - } - }, - dialog_end = { - text = "Just holler if you need anything. Anything at all.", - options = {} - } - } - } - }, items = { { name = "Potion", @@ -300,134 +73,6 @@ local function get_initial_data() { -- Screen 3 name = "Screen 3", - npcs = { - { - name = "DDR Rhythm Master", - sprite_id = 4, - dialog = { - start = { - text = "Test your reflexes! Hit the arrows in time with the music. Choose your difficulty:", - options = { - {label = "Test Song", next_node = "test"}, - {label = "Test Song 2", next_node = "test_2"}, - {label = "Random Mode", next_node = "random"}, - {label = "Not now.", next_node = "dialog_end"} - } - }, - test = { - text = "Test song selected. Show me what you got!", - options = { - {label = "Start!", next_node = "__MINIGAME_DDR:test_song__"} - } - }, - test_2 = { - text = "Test song 2 selected. Show me what you got!", - options = { - {label = "Start!", next_node = "__MINIGAME_DDR:test_song_2__"} - } - }, - random = { - text = "Random arrows! No pattern, just react!", - options = { - {label = "Start!", next_node = "__MINIGAME_DDR__"} - } - }, - dialog_end = { - text = "Come back when you're ready to dance!", - options = {} - } - } - }, - { - name = "Agent Smith", - sprite_id = 8, - dialog = { - start = { - text = "Mr. Anderson. We've been expecting you.", - options = { - {label = "My name is Neo.", next_node = "name_is_neo"}, - {label = "...", next_node = "silent"} - } - }, - name_is_neo = { - text = "Whatever you say. You're here for a reason.", - options = { - {label = "What reason?", next_node = "what_reason"} - } - }, - silent = { - text = "The silent type. It doesn't matter. You are an anomaly.", - options = { - {label = "What do you want?", next_node = "what_reason"} - } - }, - what_reason = { - text = "To be deleted. The system has no place for your kind.", - options = { - {label = "I won't let you.", next_node = "wont_let_you"} - } - }, - wont_let_you = { - text = "You hear that, Mr. Anderson? That is the sound of inevitability.", - options = { - {label = "...", next_node = "dialog_end"} - } - }, - dialog_end = { - text = "It is purpose that created us. Purpose that connects us. Purpose that pulls us. That guides us. That drives us. It is purpose that defines. Purpose that binds us.", - options = {} - } - } - }, - { - name = "Cypher", - sprite_id = 9, - dialog = { - start = { - text = "Well, well. The new messiah. Welcome to the real world.", - options = { - {label = "You don't seem happy.", next_node = "not_happy"}, - {label = "...", next_node = "silent"} - } - }, - not_happy = { - text = "Happy? Ignorance is bliss, Neo. We've been fighting this war for years. For what?", - options = { - {label = "For freedom.", next_node = "freedom"} - } - }, - silent = { - text = "Not a talker, huh? Smart. Less to regret later. Want a drink?", - options = { - {label = "Sure.", next_node = "drink"}, - {label = "No thanks.", next_node = "no_drink"} - } - }, - drink = { - text = "Good stuff. The little things you miss, you know? Like a good steak.", - options = { - {label = "I guess.", next_node = "dialog_end"} - } - }, - no_drink = { - text = "Your loss. More for me.", - options = { - {label = "...", next_node = "dialog_end"} - } - }, - freedom = { - text = "Freedom... right. If Morpheus told you you could fly, would you believe him?", - options = { - {label = "He's our leader.", next_node = "dialog_end"} - } - }, - dialog_end = { - text = "Just be careful who you trust.", - options = {} - } - } - } - }, items = {} } }) diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index 033a857..c439bb1 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -10,10 +10,9 @@ local MinigameRhythmWindow = {} local MinigameDDRWindow = {} local Util = {} +local Actions = {} local UI = {} local Print = {} local Input = {} -local NPC = {} -local Item = {} local Player = {} -local Audio = {} +local Audio = {}local Audio = {} diff --git a/inc/system/system.actions.lua b/inc/system/system.actions.lua new file mode 100644 index 0000000..79d8fe8 --- /dev/null +++ b/inc/system/system.actions.lua @@ -0,0 +1,31 @@ +Actions = {} + +function Actions.start_dialog(dialog_data, active_entity_name, start_node) + -- This function will handle initiating a dialog. + -- It needs access to the full dialog structure, the entity that owns it (for display), and the starting node. + -- The active_entity_name is just for display purposes; the full dialog_data should contain all nodes. + + -- Create a dummy entity for PopupWindow.show_menu_dialog (which expects an entity) + local dummy_entity = { name = active_entity_name, dialog = dialog_data } + + -- This is a temporary solution. The final refactor will remove show_menu_dialog. + -- For now, we'll mimic the old behavior as much as possible for dialogs. + Context.dialog.active_entity = dummy_entity + PopupWindow.set_dialog_node(start_node) +end + +function Actions.start_minigame_mash() + MinigameButtonMashWindow.start(WINDOW_GAME) +end + +function Actions.start_minigame_rhythm() + MinigameRhythmWindow.start(WINDOW_GAME) +end + +function Actions.start_minigame_ddr(song_key) + MinigameDDRWindow.start(WINDOW_GAME, song_key) +end + +function Actions.examine_item(item_data) + PopupWindow.show_description_dialog(item_data, item_data.desc) +end \ No newline at end of file diff --git a/inc/system/system.util.lua b/inc/system/system.util.lua index 909defa..a1d0e19 100644 --- a/inc/system/system.util.lua +++ b/inc/system/system.util.lua @@ -1,5 +1,13 @@ 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 diff --git a/inc/window/window.game.lua b/inc/window/window.game.lua index 8b116b3..4af01c0 100644 --- a/inc/window/window.game.lua +++ b/inc/window/window.game.lua @@ -17,21 +17,6 @@ function GameWindow.update() Context.current_screen = Context.current_screen + 1 end end - - if Input.player_interact() then - -- Get the current screen's NPCs - local currentScreenData = Context.screens[Context.current_screen] - if currentScreenData and currentScreenData.npcs and #currentScreenData.npcs > 0 then - -- For now, interact with the first NPC on the screen - -- TODO: Add proximity detection to find nearest NPC - local npc = currentScreenData.npcs[1] - PopupWindow.show_menu_dialog(npc, { - {label = "Talk to", action = NPC.talk_to}, - {label = "Fight", action = NPC.fight}, - {label = "Go back", action = NPC.go_back} - }, WINDOW_POPUP) - end - end end function GameWindow.set_state(new_state) diff --git a/inc/window/window.popup.lua b/inc/window/window.popup.lua index 501a45c..729da7c 100644 --- a/inc/window/window.popup.lua +++ b/inc/window/window.popup.lua @@ -125,4 +125,4 @@ function PopupWindow.draw() else Print.text("[A] Go Back", 50, current_y + 10, Config.colors.green) end -end +end \ No newline at end of file -- 2.49.1 From ef4876b0830d7b7b9de74b5fec820d711fd53519 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 20:23:11 +0100 Subject: [PATCH 02/10] remove npc and item handling --- inc/init/init.config.lua | 13 ++- inc/init/init.context.lua | 31 +----- inc/init/init.modules.lua | 5 +- inc/system/system.actions.lua | 19 ---- inc/window/window.minigame.ddr.lua | 6 +- inc/window/window.minigame.mash.lua | 2 +- inc/window/window.popup.lua | 146 ++++++---------------------- 7 files changed, 52 insertions(+), 170 deletions(-) diff --git a/inc/init/init.config.lua b/inc/init/init.config.lua index a9672bf..a0d6ab3 100644 --- a/inc/init/init.config.lua +++ b/inc/init/init.config.lua @@ -28,19 +28,26 @@ local Config = { local CONFIG_SAVE_BANK = 7 local CONFIG_MAGIC_VALUE_ADDRESS = 2 +local CONFIG_SPLASH_DURATION_ADDRESS = 3 -- New address for splash duration local CONFIG_MAGIC_VALUE = 0xDE -- A magic number to check if config is saved function Config.save() - -- Save physics settings mset(CONFIG_MAGIC_VALUE, CONFIG_MAGIC_VALUE_ADDRESS, CONFIG_SAVE_BANK) -- Mark as saved + --mset(Config.timing.splash_duration, CONFIG_SPLASH_DURATION_ADDRESS, CONFIG_SAVE_BANK) end function Config.load() - Config.restore_defaults() - -- Check if config has been saved before using a magic value + if mget(CONFIG_MAGIC_VALUE_ADDRESS, CONFIG_SAVE_BANK) == CONFIG_MAGIC_VALUE then + -- Config has been saved, load values + Config.timing.splash_duration = mget(CONFIG_SPLASH_DURATION_ADDRESS, CONFIG_SAVE_BANK) + else + -- No saved config, restore defaults + Config.restore_defaults() + end end function Config.restore_defaults() + Config.timing.splash_duration = DEFAULT_CONFIG.timing.splash_duration -- Any other configurable items should be reset here end diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index 8337ed2..1ae5635 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -28,13 +28,9 @@ local function get_initial_data() }, current_screen = 1, splash_timer = Config.timing.splash_duration, - dialog = { - text = "", - menu_items = {}, - selected_menu_item = 1, - active_entity = nil, - showing_description = false, - current_node_key = nil + popup = { -- New popup table + show = false, + content = {} -- Array of strings }, player = { sprite_id = Config.player.sprite_id @@ -51,36 +47,17 @@ local function get_initial_data() screens = clone_table({ { name = "Screen 1", - items = { - { - name = "Key", - sprite_id = 4, - desc = "A rusty old key. It might open something." - } - } }, { - -- Screen 2 name = "Screen 2", - items = { - { - name = "Potion", - sprite_id = 7, - desc = "A glowing red potion. It looks potent." - } - } }, { - -- Screen 3 name = "Screen 3", - items = {} } }) } end -Context = {} - local function reset_context_to_initial_state() local initial_data = get_initial_data() @@ -127,4 +104,4 @@ function Context.load_game() Context.game_in_progress = true MenuWindow.refresh_menu_items() -end \ No newline at end of file +end diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index c439bb1..f7e323d 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -10,9 +10,10 @@ local MinigameRhythmWindow = {} local MinigameDDRWindow = {} local Util = {} -local Actions = {} +local Context = {} local UI = {} local Print = {} local Input = {} local Player = {} -local Audio = {}local Audio = {} +local Audio = {} +local Actions = {} diff --git a/inc/system/system.actions.lua b/inc/system/system.actions.lua index 79d8fe8..52d698b 100644 --- a/inc/system/system.actions.lua +++ b/inc/system/system.actions.lua @@ -1,18 +1,3 @@ -Actions = {} - -function Actions.start_dialog(dialog_data, active_entity_name, start_node) - -- This function will handle initiating a dialog. - -- It needs access to the full dialog structure, the entity that owns it (for display), and the starting node. - -- The active_entity_name is just for display purposes; the full dialog_data should contain all nodes. - - -- Create a dummy entity for PopupWindow.show_menu_dialog (which expects an entity) - local dummy_entity = { name = active_entity_name, dialog = dialog_data } - - -- This is a temporary solution. The final refactor will remove show_menu_dialog. - -- For now, we'll mimic the old behavior as much as possible for dialogs. - Context.dialog.active_entity = dummy_entity - PopupWindow.set_dialog_node(start_node) -end function Actions.start_minigame_mash() MinigameButtonMashWindow.start(WINDOW_GAME) @@ -25,7 +10,3 @@ end function Actions.start_minigame_ddr(song_key) MinigameDDRWindow.start(WINDOW_GAME, song_key) end - -function Actions.examine_item(item_data) - PopupWindow.show_description_dialog(item_data, item_data.desc) -end \ No newline at end of file diff --git a/inc/window/window.minigame.ddr.lua b/inc/window/window.minigame.ddr.lua index 5c24460..1b52cb7 100644 --- a/inc/window/window.minigame.ddr.lua +++ b/inc/window/window.minigame.ddr.lua @@ -304,7 +304,7 @@ function MinigameDDRWindow.draw() if mg.bar_fill > 66 then bar_color = Config.colors.item -- yellow elseif mg.bar_fill > 33 then - bar_color = Config.colors.npc + bar_color = Config.colors.bar end rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color) @@ -326,7 +326,7 @@ function MinigameDDRWindow.draw() -- Draw falling arrows (blue) if mg.arrows then for _, arrow in ipairs(mg.arrows) do - draw_arrow(arrow.x, arrow.y, arrow.dir, Config.colors.npc) -- blue color + draw_arrow(arrow.x, arrow.y, arrow.dir, Config.colors.bar) -- blue color end end @@ -345,6 +345,6 @@ function MinigameDDRWindow.draw() Print.text_center("Pattern Len:" .. #mg.current_song.pattern .. " Index:" .. mg.pattern_index, Config.screen.width / 2, debug_y + 10, Config.colors.green) end else - Print.text_center("RANDOM MODE", Config.screen.width / 2, debug_y, Config.colors.npc) + Print.text_center("RANDOM MODE", Config.screen.width / 2, debug_y, Config.colors.bar) end end diff --git a/inc/window/window.minigame.mash.lua b/inc/window/window.minigame.mash.lua index ecd2765..abae6e2 100644 --- a/inc/window/window.minigame.mash.lua +++ b/inc/window/window.minigame.mash.lua @@ -83,7 +83,7 @@ function MinigameButtonMashWindow.draw() if mg.bar_fill > 66 then bar_color = Config.colors.item -- yellow elseif mg.bar_fill > 33 then - bar_color = Config.colors.npc -- medium color + bar_color = Config.colors.bar -- medium color end rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color) diff --git a/inc/window/window.popup.lua b/inc/window/window.popup.lua index 729da7c..f8342f8 100644 --- a/inc/window/window.popup.lua +++ b/inc/window/window.popup.lua @@ -1,128 +1,44 @@ -function PopupWindow.set_dialog_node(node_key) - -- Special handling for minigame trigger - if node_key == "__MINIGAME_BUTTON_MASH__" then - MinigameButtonMashWindow.start(WINDOW_GAME) - return - end +-- Simplified PopupWindow module +local POPUP_X = 40 +local POPUP_Y = 40 +local POPUP_WIDTH = 160 +local POPUP_HEIGHT = 80 +local TEXT_MARGIN_X = POPUP_X + 10 +local TEXT_MARGIN_Y = POPUP_Y + 10 +local LINE_HEIGHT = 8 -- Assuming 8 pixels per line for default font - -- Special handling for rhythm minigame trigger - if node_key == "__MINIGAME_RHYTHM__" then - MinigameRhythmWindow.start(WINDOW_GAME) - return - end +function PopupWindow.show(content_strings) + Context.popup.show = true + Context.popup.content = content_strings or {} -- Ensure it's a table + GameWindow.set_state(WINDOW_POPUP) -- Set active window to popup +end - -- Special handling for DDR minigame trigger - -- Format: __MINIGAME_DDR__ or __MINIGAME_DDR:song_key__ - local song_key = node_key:match("^__MINIGAME_DDR:(.+)__$") - if song_key then - -- Extract song key from the node (format: __MINIGAME_DDR/test_song__) - trace('Playing song: ' .. song_key) - MinigameDDRWindow.start(WINDOW_GAME, song_key) - return - end - if node_key == "__MINIGAME_DDR__" then - MinigameDDRWindow.start(WINDOW_GAME, nil) - return - end - - local npc = Context.dialog.active_entity - local node = npc.dialog[node_key] - - if not node then - GameWindow.set_state(WINDOW_GAME) - return - end - - Context.dialog.current_node_key = node_key - Context.dialog.text = node.text - - local menu_items = {} - if node.options then - for _, option in ipairs(node.options) do - table.insert(menu_items, { - label = option.label, - action = function() - PopupWindow.set_dialog_node(option.next_node) - end - }) - end - end - - -- if no options, it's the end of this branch. - if #menu_items == 0 then - table.insert(menu_items, { - label = "Go back", - action = function() GameWindow.set_state(WINDOW_GAME) end - }) - end - - Context.dialog.menu_items = menu_items - Context.dialog.selected_menu_item = 1 - Context.dialog.showing_description = false - GameWindow.set_state(WINDOW_POPUP) +function PopupWindow.hide() + Context.popup.show = false + Context.popup.content = {} -- Clear content + GameWindow.set_state(WINDOW_GAME) -- Return to game window end function PopupWindow.update() - if Context.dialog.showing_description then - if Input.menu_confirm() or Input.menu_back() then - Context.dialog.showing_description = false - Context.dialog.text = "" -- Clear the description text - -- No need to change active_window, as it remains in WINDOW_POPUP - end - else - Context.dialog.selected_menu_item = UI.update_menu(Context.dialog.menu_items, Context.dialog.selected_menu_item) - - if Input.menu_confirm() then - local selected_item = Context.dialog.menu_items[Context.dialog.selected_menu_item] - if selected_item and selected_item.action then - selected_item.action() - end - end - - if Input.menu_back() then - GameWindow.set_state(WINDOW_GAME) + if Context.popup.show then + if Input.menu_confirm() or Input.menu_back() then -- Allow either A or B to close + PopupWindow.hide() end end end -function PopupWindow.show_menu_dialog(entity, menu_items, dialog_active_window) - Context.dialog.active_entity = entity - Context.dialog.text = "" -- Initial dialog text is empty, name is title - GameWindow.set_state(dialog_active_window or WINDOW_POPUP) - Context.dialog.showing_description = false - Context.dialog.menu_items = menu_items - Context.dialog.selected_menu_item = 1 -end - -function PopupWindow.show_description_dialog(entity, description_text) - Context.dialog.active_entity = entity - Context.dialog.text = description_text - GameWindow.set_state(WINDOW_POPUP) - Context.dialog.showing_description = true - -- No menu items needed for description dialog -end - function PopupWindow.draw() - rect(40, 40, 160, 80, Config.colors.black) - rectb(40, 40, 160, 80, Config.colors.green) + if Context.popup.show then + rect(POPUP_X, POPUP_Y, POPUP_WIDTH, POPUP_HEIGHT, Config.colors.black) + rectb(POPUP_X, POPUP_Y, POPUP_WIDTH, POPUP_HEIGHT, Config.colors.green) - -- Display the entity's name as the dialog title - if Context.dialog.active_entity and Context.dialog.active_entity.name then - Print.text(Context.dialog.active_entity.name, 120 - #Context.dialog.active_entity.name * 2, 45, Config.colors.green) - end + local current_y = TEXT_MARGIN_Y + for _, line in ipairs(Context.popup.content) do + Print.text(line, TEXT_MARGIN_X, current_y, Config.colors.light_grey) + current_y = current_y + LINE_HEIGHT + end - -- Display the dialog content (description for "look at", or initial name/dialog for others) - local wrapped_lines = UI.word_wrap(Context.dialog.text, 25) -- Max 25 chars per line - local current_y = 55 -- Starting Y position for the first line of content - for _, line in ipairs(wrapped_lines) do - Print.text(line, 50, current_y, Config.colors.light_grey) - current_y = current_y + 8 -- Move to the next line (8 pixels for default font height + padding) + -- Instruction to close + Print.text("[A] Close", TEXT_MARGIN_X, POPUP_Y + POPUP_HEIGHT - LINE_HEIGHT - 2, Config.colors.green) end - - -- Adjust menu position based on the number of wrapped lines - if not Context.dialog.showing_description then - UI.draw_menu(Context.dialog.menu_items, Context.dialog.selected_menu_item, 50, current_y + 2) - else - Print.text("[A] Go Back", 50, current_y + 10, Config.colors.green) - end -end \ No newline at end of file +end -- 2.49.1 From d20ef85ceb535b8f5daa377aff836094d468f666 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 20:26:42 +0100 Subject: [PATCH 03/10] rename action to desition --- impostor.inc | 2 +- inc/init/init.modules.lua | 2 +- ...system.actions.lua => system.desitions.lua} | 6 +++--- inc/system/system.ui.lua | 6 +++--- inc/window/window.audiotest.lua | 8 ++++---- inc/window/window.configuration.lua | 10 +++++----- inc/window/window.menu.lua | 18 +++++++++--------- 7 files changed, 26 insertions(+), 26 deletions(-) rename inc/system/{system.actions.lua => system.desitions.lua} (53%) diff --git a/impostor.inc b/impostor.inc index 76dc724..002d650 100644 --- a/impostor.inc +++ b/impostor.inc @@ -6,7 +6,7 @@ init/init.windows.lua init/init.context.lua data/data.songs.lua system/system.print.lua -system/system.actions.lua +system/system.desitions.lua system/system.input.lua system/system.audio.lua system/system.ui.lua diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index f7e323d..d93f72a 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -16,4 +16,4 @@ local Print = {} local Input = {} local Player = {} local Audio = {} -local Actions = {} +local Desitions = {} diff --git a/inc/system/system.actions.lua b/inc/system/system.desitions.lua similarity index 53% rename from inc/system/system.actions.lua rename to inc/system/system.desitions.lua index 52d698b..7467807 100644 --- a/inc/system/system.actions.lua +++ b/inc/system/system.desitions.lua @@ -1,12 +1,12 @@ -function Actions.start_minigame_mash() +function Desitions.start_minigame_mash() MinigameButtonMashWindow.start(WINDOW_GAME) end -function Actions.start_minigame_rhythm() +function Desitions.start_minigame_rhythm() MinigameRhythmWindow.start(WINDOW_GAME) end -function Actions.start_minigame_ddr(song_key) +function Desitions.start_minigame_ddr(song_key) MinigameDDRWindow.start(WINDOW_GAME, song_key) end diff --git a/inc/system/system.ui.lua b/inc/system/system.ui.lua index 375c602..4f21ee1 100644 --- a/inc/system/system.ui.lua +++ b/inc/system/system.ui.lua @@ -80,10 +80,10 @@ function UI.create_numeric_stepper(label, value_getter, value_setter, min, max, } end -function UI.create_action_item(label, action) +function UI.create_desition_item(label, desition) return { label = label, - action = action, - type = "action_item" + desition = desition, + type = "desition_item" } end diff --git a/inc/window/window.audiotest.lua b/inc/window/window.audiotest.lua index cbe7a7f..3ea5e5d 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 "?"), - action = function() + desition = 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", - action = function() + desition = function() Audio.music_stop() end }, { label = "Back", - action = function() + desition = function() AudioTestWindow.back() end }, @@ -78,7 +78,7 @@ function AudioTestWindow.update() AudioTestWindow.index_func = Util.safeindex(AudioTestWindow.list_func, AudioTestWindow.index_func + 1) AudioTestWindow.menuitems = AudioTestWindow.generate_menuitems(AudioTestWindow.list_func, AudioTestWindow.index_func) elseif Input.menu_confirm() then - AudioTestWindow.menuitems[AudioTestWindow.index_menu].action() + AudioTestWindow.menuitems[AudioTestWindow.index_menu].desition() elseif Input.menu_back() then AudioTestWindow.back() end diff --git a/inc/window/window.configuration.lua b/inc/window/window.configuration.lua index 6f1c619..77acd11 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_action_item( + UI.create_desition_item( "Save", function() Config.save() end ), - UI.create_action_item( + UI.create_desition_item( "Restore Defaults", function() Config.restore_defaults() end ), @@ -46,7 +46,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 == "action_item" then + elseif control.type == "desition_item" then local label_text = control.label if i == ConfigurationWindow.selected_control then color = Config.colors.item @@ -91,9 +91,9 @@ function ConfigurationWindow.update() local new_value = math.min(control.max, current_value + control.step) control.set(new_value) end - elseif control.type == "action_item" then + elseif control.type == "desition_item" then if Input.menu_confirm() then - control.action() + control.desition() end end end diff --git a/inc/window/window.menu.lua b/inc/window/window.menu.lua index a5318ce..3fe597a 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.action then + if selected_item and selected_item.desition then Audio.sfx_select() - selected_item.action() + selected_item.desition() end end end @@ -51,15 +51,15 @@ function MenuWindow.refresh_menu_items() Context.menu_items = {} -- Start with an empty table if Context.game_in_progress then - table.insert(Context.menu_items, {label = "Resume Game", action = MenuWindow.resume_game}) - table.insert(Context.menu_items, {label = "Save Game", action = MenuWindow.save_game}) + table.insert(Context.menu_items, {label = "Resume Game", desition = MenuWindow.resume_game}) + table.insert(Context.menu_items, {label = "Save Game", desition = MenuWindow.save_game}) end - table.insert(Context.menu_items, {label = "New Game", action = MenuWindow.new_game}) - table.insert(Context.menu_items, {label = "Load Game", action = MenuWindow.load_game}) - table.insert(Context.menu_items, {label = "Configuration", action = MenuWindow.configuration}) - table.insert(Context.menu_items, {label = "Audio Test", action = MenuWindow.audio_test}) - table.insert(Context.menu_items, {label = "Exit", action = MenuWindow.exit}) + 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}) Context.selected_menu_item = 1 -- Reset selection after refreshing end -- 2.49.1 From 99b178262f9a5f777e4584614bbacd8cdd264bd0 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 20:36:04 +0100 Subject: [PATCH 04/10] DesitionSelector --- inc/init/init.context.lua | 22 ++++++++++++++++ inc/init/init.modules.lua | 2 +- inc/system/system.desitions.lua | 1 - inc/system/system.ui.lua | 39 +++++++++++++++++++++++++--- inc/window/window.game.lua | 46 +++++++++++++++++++++++++++++---- 5 files changed, 100 insertions(+), 10 deletions(-) diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index 1ae5635..a916b88 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -43,16 +43,38 @@ local function get_initial_data() }, menu_items = {}, selected_menu_item = 1, + selected_desition_index = 1, -- New desition index game_in_progress = false, -- New flag screens = clone_table({ { name = "Screen 1", + decisions = { + Util.create_decision( + "play_button_mash", + "Play Button Mash", + function() Desitions.start_minigame_mash() end + ), + } }, { name = "Screen 2", + decisions = { + Util.create_decision( + "play_rhythm", + "Play Rhythm Game", + function() Desitions.start_minigame_rhythm() end + ), + } }, { name = "Screen 3", + decisions = { + Util.create_decision( + "play_ddr", + "Play DDR (Random)", + function() Desitions.start_minigame_ddr(nil) end + ), + } } }) } diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index d93f72a..098e38a 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -11,9 +11,9 @@ local MinigameDDRWindow = {} local Util = {} local Context = {} +local Desitions = {} local UI = {} local Print = {} local Input = {} local Player = {} local Audio = {} -local Desitions = {} diff --git a/inc/system/system.desitions.lua b/inc/system/system.desitions.lua index 7467807..2d311ea 100644 --- a/inc/system/system.desitions.lua +++ b/inc/system/system.desitions.lua @@ -1,4 +1,3 @@ - function Desitions.start_minigame_mash() MinigameButtonMashWindow.start(WINDOW_GAME) end diff --git a/inc/system/system.ui.lua b/inc/system/system.ui.lua index 4f21ee1..4ebc1ad 100644 --- a/inc/system/system.ui.lua +++ b/inc/system/system.ui.lua @@ -80,10 +80,43 @@ function UI.create_numeric_stepper(label, value_getter, value_setter, min, max, } end -function UI.create_desition_item(label, desition) +function UI.create_action_item(label, action) return { label = label, - desition = desition, - type = "desition_item" + action = action, + type = "action_item" } end + +function UI.draw_desition_selector(desitions, selected_desition_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 -- Assuming 4 pixels per char + local text_x = (Config.screen.width - text_width) / 2 + local text_y = bar_y + 4 + + -- Draw left arrow + Print.text("<", text_x - 10, text_y, Config.colors.green) + -- Draw selected desition label + Print.text(desition_label, text_x, text_y, Config.colors.item) -- Highlight color + -- Draw right arrow + Print.text(">", text_x + text_width + 6, text_y, Config.colors.green) + end +end + +function UI.update_desition_selector(desitions, selected_desition_index) + if Input.left() then + Audio.sfx_beep() + selected_desition_index = Util.safeindex(desitions, selected_desition_index - 1) + elseif Input.right() then + Audio.sfx_beep() + selected_desition_index = Util.safeindex(desitions, selected_desition_index + 1) + end + return selected_desition_index +end diff --git a/inc/window/window.game.lua b/inc/window/window.game.lua index 4af01c0..35c675f 100644 --- a/inc/window/window.game.lua +++ b/inc/window/window.game.lua @@ -2,6 +2,10 @@ function GameWindow.draw() local currentScreenData = Context.screens[Context.current_screen] 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) + end end function GameWindow.update() @@ -10,11 +14,43 @@ function GameWindow.update() MenuWindow.refresh_menu_items() return end - if Input.select() then - if Context.current_screen == #Context.screens then + + -- Handle screen changing using up/down + if Input.up() then + Context.current_screen = Context.current_screen - 1 + if Context.current_screen < 1 then + Context.current_screen = #Context.screens + end + Context.selected_desition_index = 1 -- Reset selected decision on screen change + elseif Input.down() then + Context.current_screen = Context.current_screen + 1 + if Context.current_screen > #Context.screens then Context.current_screen = 1 - else - Context.current_screen = Context.current_screen + 1 + end + Context.selected_desition_index = 1 -- Reset selected decision on screen change + end + + local currentScreenData = Context.screens[Context.current_screen] + + if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then + -- Update selected decision using left/right inputs + local new_selected_desition_index = UI.update_desition_selector( + currentScreenData.decisions, + Context.selected_desition_index + ) + + -- Only update Context if the selection actually changed to avoid unnecessary re-assignment + if new_selected_desition_index ~= Context.selected_desition_index then + Context.selected_desition_index = new_selected_desition_index + end + + -- Execute selected decision on Input.select() + if Input.select() then + local selected_desition = currentScreenData.decisions[Context.selected_desition_index] + if selected_desition and selected_desition.handler then + Audio.sfx_select() -- Play sound for selection + selected_desition.handler() + end end end end @@ -22,4 +58,4 @@ end function GameWindow.set_state(new_state) Context.active_window = new_state -- Add any state-specific initialization/cleanup here later if needed -end \ No newline at end of file +end -- 2.49.1 From ec84f23ad5efb7803c96e1e6d59ca7ecbb69e1aa Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 20:45:57 +0100 Subject: [PATCH 05/10] base loop --- inc/init/init.context.lua | 72 +++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index a916b88..1922361 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -47,33 +47,83 @@ local function get_initial_data() game_in_progress = false, -- New flag screens = clone_table({ { - name = "Screen 1", + name = "Home", + decisions = { + Util.create_decision( + "go_to_toilet", + "Go to Toilet", + function() Context.current_screen = 2; Context.selected_desition_index = 1 end + ), + Util.create_decision( + "go_to_walking_to_office", + "Go to Walking to office", + function() Context.current_screen = 3; Context.selected_desition_index = 1 end + ), + } + }, + { + name = "Toilet", + decisions = { + Util.create_decision( + "go_to_home", + "Go to Home", + function() Context.current_screen = 1; Context.selected_desition_index = 1 end + ), + } + }, + { + name = "Walking to office", + decisions = { + Util.create_decision( + "go_to_home", + "Go to Home", + function() Context.current_screen = 1; Context.selected_desition_index = 1 end + ), + Util.create_decision( + "go_to_office", + "Go to Office", + function() Context.current_screen = 4; Context.selected_desition_index = 1 end + ), + } + }, + { + name = "Office", decisions = { Util.create_decision( "play_button_mash", "Play Button Mash", function() Desitions.start_minigame_mash() end ), - } - }, - { - name = "Screen 2", - decisions = { Util.create_decision( "play_rhythm", "Play Rhythm Game", function() Desitions.start_minigame_rhythm() end ), - } - }, - { - name = "Screen 3", - decisions = { Util.create_decision( "play_ddr", "Play DDR (Random)", function() Desitions.start_minigame_ddr(nil) end ), + Util.create_decision( + "go_to_walking_to_home", + "Go to Walking to home", + function() Context.current_screen = 5; Context.selected_desition_index = 1 end + ), + } + }, + { + name = "Walking to home", + decisions = { + Util.create_decision( + "go_to_home", + "Go to Home", + function() Context.current_screen = 1; Context.selected_desition_index = 1 end + ), + Util.create_decision( + "go_to_office", + "Go to Office", + function() Context.current_screen = 4; Context.selected_desition_index = 1 end + ), } } }) -- 2.49.1 From 31b98dcdf662e86d1b089769851d62be13ae8996 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 20:48:58 +0100 Subject: [PATCH 06/10] fix DesitionSelector arrows --- inc/system/system.ui.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/inc/system/system.ui.lua b/inc/system/system.ui.lua index 4ebc1ad..d3e4694 100644 --- a/inc/system/system.ui.lua +++ b/inc/system/system.ui.lua @@ -98,15 +98,17 @@ function UI.draw_desition_selector(desitions, selected_desition_index) local selected_desition = desitions[selected_desition_index] local desition_label = selected_desition.label local text_width = #desition_label * 4 -- Assuming 4 pixels per char - local text_x = (Config.screen.width - text_width) / 2 local text_y = bar_y + 4 - -- Draw left arrow - Print.text("<", text_x - 10, text_y, Config.colors.green) + -- Center the decision label + local text_x = (Config.screen.width - text_width) / 2 + + -- Draw left arrow at the far left + Print.text("<", 2, text_y, Config.colors.green) -- Draw selected desition label Print.text(desition_label, text_x, text_y, Config.colors.item) -- Highlight color - -- Draw right arrow - Print.text(">", text_x + text_width + 6, text_y, Config.colors.green) + -- Draw right arrow at the far right + Print.text(">", Config.screen.width - 6, text_y, Config.colors.green) -- 6 = 2 (right margin) + 4 (char width) end end -- 2.49.1 From d1720a0a50e4296e6dcae42f9e44870535b7aa3b Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 20:56:06 +0100 Subject: [PATCH 07/10] named desition handler functions --- inc/init/init.context.lua | 27 ++++++++++++++++----------- inc/system/system.desitions.lua | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index 1922361..f15ac9a 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -47,82 +47,87 @@ local function get_initial_data() game_in_progress = false, -- New flag screens = clone_table({ { + id = "home", name = "Home", decisions = { Util.create_decision( "go_to_toilet", "Go to Toilet", - function() Context.current_screen = 2; Context.selected_desition_index = 1 end + Desitions.go_to_toilet ), Util.create_decision( "go_to_walking_to_office", "Go to Walking to office", - function() Context.current_screen = 3; Context.selected_desition_index = 1 end + Desitions.go_to_walking_to_office ), } }, { + id = "toilet", name = "Toilet", decisions = { Util.create_decision( "go_to_home", "Go to Home", - function() Context.current_screen = 1; Context.selected_desition_index = 1 end + Desitions.go_to_home ), } }, { + id = "walking_to_office", name = "Walking to office", decisions = { Util.create_decision( "go_to_home", "Go to Home", - function() Context.current_screen = 1; Context.selected_desition_index = 1 end + Desitions.go_to_home ), Util.create_decision( "go_to_office", "Go to Office", - function() Context.current_screen = 4; Context.selected_desition_index = 1 end + Desitions.go_to_office ), } }, { + id = "office", name = "Office", decisions = { Util.create_decision( "play_button_mash", "Play Button Mash", - function() Desitions.start_minigame_mash() end + Desitions.start_minigame_mash ), Util.create_decision( "play_rhythm", "Play Rhythm Game", - function() Desitions.start_minigame_rhythm() end + Desitions.start_minigame_rhythm ), Util.create_decision( "play_ddr", "Play DDR (Random)", - function() Desitions.start_minigame_ddr(nil) end + Desitions.start_minigame_ddr ), Util.create_decision( "go_to_walking_to_home", "Go to Walking to home", - function() Context.current_screen = 5; Context.selected_desition_index = 1 end + Desitions.go_to_walking_to_home ), } }, { + id = "walking_to_home", name = "Walking to home", decisions = { Util.create_decision( "go_to_home", "Go to Home", - function() Context.current_screen = 1; Context.selected_desition_index = 1 end + Desitions.go_to_home ), Util.create_decision( "go_to_office", "Go to Office", - function() Context.current_screen = 4; Context.selected_desition_index = 1 end + Desitions.go_to_office ), } } diff --git a/inc/system/system.desitions.lua b/inc/system/system.desitions.lua index 2d311ea..c5c5f6a 100644 --- a/inc/system/system.desitions.lua +++ b/inc/system/system.desitions.lua @@ -1,3 +1,25 @@ +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 @@ -8,4 +30,4 @@ end function Desitions.start_minigame_ddr(song_key) MinigameDDRWindow.start(WINDOW_GAME, song_key) -end +end \ No newline at end of file -- 2.49.1 From 11b92f64d6965f14de3581fc5fa574cfde7a3da9 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 21:02:20 +0100 Subject: [PATCH 08/10] DesitionManager --- impostor.inc | 1 + inc/init/init.context.lua | 66 +++++--------------------- inc/init/init.modules.lua | 1 + inc/system/system.desition_manager.lua | 42 ++++++++++++++++ inc/window/window.game.lua | 19 ++++++-- 5 files changed, 69 insertions(+), 60 deletions(-) create mode 100644 inc/system/system.desition_manager.lua 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 -- 2.49.1 From 0357eb415e8efc8fb28bf312bbab92b938471173 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 21:37:53 +0100 Subject: [PATCH 09/10] desition and screen magement refactor --- impostor.inc | 17 ++++- inc/desition/desition.go_to_home.lua | 14 +++++ inc/desition/desition.go_to_office.lua | 14 +++++ inc/desition/desition.go_to_toilet.lua | 14 +++++ .../desition.go_to_walking_to_home.lua | 14 +++++ .../desition.go_to_walking_to_office.lua | 14 +++++ inc/desition/desition.manager.lua | 42 +++++++++++++ inc/desition/desition.play_button_mash.lua | 6 ++ inc/desition/desition.play_ddr.lua | 6 ++ inc/desition/desition.play_rhythm.lua | 6 ++ inc/init/init.context.lua | 62 ++++++------------- inc/init/init.modules.lua | 3 +- inc/screen/screen.home.lua | 8 +++ inc/screen/screen.manager.lua | 27 ++++++++ inc/screen/screen.office.lua | 10 +++ inc/screen/screen.toilet.lua | 7 +++ inc/screen/screen.walking_to_home.lua | 8 +++ inc/screen/screen.walking_to_office.lua | 8 +++ inc/system/system.desition_manager.lua | 42 ------------- inc/system/system.desitions.lua | 33 ---------- inc/system/system.util.lua | 10 +-- inc/window/window.game.lua | 32 +++++++--- 22 files changed, 256 insertions(+), 141 deletions(-) create mode 100644 inc/desition/desition.go_to_home.lua create mode 100644 inc/desition/desition.go_to_office.lua create mode 100644 inc/desition/desition.go_to_toilet.lua create mode 100644 inc/desition/desition.go_to_walking_to_home.lua create mode 100644 inc/desition/desition.go_to_walking_to_office.lua create mode 100644 inc/desition/desition.manager.lua create mode 100644 inc/desition/desition.play_button_mash.lua create mode 100644 inc/desition/desition.play_ddr.lua create mode 100644 inc/desition/desition.play_rhythm.lua create mode 100644 inc/screen/screen.home.lua create mode 100644 inc/screen/screen.manager.lua create mode 100644 inc/screen/screen.office.lua create mode 100644 inc/screen/screen.toilet.lua create mode 100644 inc/screen/screen.walking_to_home.lua create mode 100644 inc/screen/screen.walking_to_office.lua delete mode 100644 inc/system/system.desition_manager.lua delete mode 100644 inc/system/system.desitions.lua diff --git a/impostor.inc b/impostor.inc index 044b83d..d69c758 100644 --- a/impostor.inc +++ b/impostor.inc @@ -3,11 +3,24 @@ init/init.modules.lua init/init.config.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 +screen/screen.manager.lua +screen/screen.home.lua +screen/screen.toilet.lua +screen/screen.walking_to_office.lua +screen/screen.office.lua +screen/screen.walking_to_home.lua 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/desition/desition.go_to_home.lua b/inc/desition/desition.go_to_home.lua new file mode 100644 index 0000000..3bcdd99 --- /dev/null +++ b/inc/desition/desition.go_to_home.lua @@ -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 +}) diff --git a/inc/desition/desition.go_to_office.lua b/inc/desition/desition.go_to_office.lua new file mode 100644 index 0000000..ff0c32f --- /dev/null +++ b/inc/desition/desition.go_to_office.lua @@ -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 +}) diff --git a/inc/desition/desition.go_to_toilet.lua b/inc/desition/desition.go_to_toilet.lua new file mode 100644 index 0000000..e3d5d52 --- /dev/null +++ b/inc/desition/desition.go_to_toilet.lua @@ -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 +}) diff --git a/inc/desition/desition.go_to_walking_to_home.lua b/inc/desition/desition.go_to_walking_to_home.lua new file mode 100644 index 0000000..4bfe117 --- /dev/null +++ b/inc/desition/desition.go_to_walking_to_home.lua @@ -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 +}) diff --git a/inc/desition/desition.go_to_walking_to_office.lua b/inc/desition/desition.go_to_walking_to_office.lua new file mode 100644 index 0000000..f424b0a --- /dev/null +++ b/inc/desition/desition.go_to_walking_to_office.lua @@ -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 +}) diff --git a/inc/desition/desition.manager.lua b/inc/desition/desition.manager.lua new file mode 100644 index 0000000..1c43b7f --- /dev/null +++ b/inc/desition/desition.manager.lua @@ -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 diff --git a/inc/desition/desition.play_button_mash.lua b/inc/desition/desition.play_button_mash.lua new file mode 100644 index 0000000..754e292 --- /dev/null +++ b/inc/desition/desition.play_button_mash.lua @@ -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 +}) diff --git a/inc/desition/desition.play_ddr.lua b/inc/desition/desition.play_ddr.lua new file mode 100644 index 0000000..f03be37 --- /dev/null +++ b/inc/desition/desition.play_ddr.lua @@ -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 +}) diff --git a/inc/desition/desition.play_rhythm.lua b/inc/desition/desition.play_rhythm.lua new file mode 100644 index 0000000..82688ec --- /dev/null +++ b/inc/desition/desition.play_rhythm.lua @@ -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 +}) diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index 61f5afb..6f3a949 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -45,52 +45,12 @@ local function get_initial_data() selected_menu_item = 1, selected_desition_index = 1, -- New desition index game_in_progress = false, -- New flag - screens = clone_table({ - { - id = "home", - name = "Home", - decisions = { - "go_to_toilet", - "go_to_walking_to_office", - } - }, - { - id = "toilet", - name = "Toilet", - decisions = { - "go_to_home", - } - }, - { - id = "walking_to_office", - name = "Walking to office", - decisions = { - "go_to_home", - "go_to_office", - } - }, - { - id = "office", - name = "Office", - decisions = { - "play_button_mash", - "play_rhythm", - "play_ddr", - "go_to_walking_to_home", - } - }, - { - id = "walking_to_home", - name = "Walking to home", - decisions = { - "go_to_home", - "go_to_office", - } - } - }) + screens = {} -- Initialize as empty, populated on reset } end +Context = {} + local function reset_context_to_initial_state() local initial_data = get_initial_data() @@ -105,6 +65,22 @@ local function reset_context_to_initial_state() for k, v in pairs(initial_data) do Context[k] = v end + + -- Populate Context.screens from ScreenManager, ensuring indexed array + Context.screens = {} + Context.screen_indices_by_id = {} -- Renamed for clarity, stores index + -- The screen order needs to be explicit to ensure consistent numerical indices + local screen_order = {"home", "toilet", "walking_to_office", "office", "walking_to_home"} + for i, screen_id in ipairs(screen_order) do + 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 -- Store index + else + -- Handle error if a screen is not registered + PopupWindow.show({"Error: Screen '" .. screen_id .. "' not registered!"}) + end + end end -- Initially populate Context with data diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index 23df024..e98cb49 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -10,9 +10,8 @@ local MinigameRhythmWindow = {} local MinigameDDRWindow = {} local Util = {} -local Context = {} -local Desitions = {} local DesitionManager = {} +local ScreenManager = {} -- New declaration local UI = {} local Print = {} local Input = {} diff --git a/inc/screen/screen.home.lua b/inc/screen/screen.home.lua new file mode 100644 index 0000000..efb059c --- /dev/null +++ b/inc/screen/screen.home.lua @@ -0,0 +1,8 @@ +ScreenManager.register({ + id = "home", + name = "Home", + decisions = { + "go_to_toilet", + "go_to_walking_to_office", + } +}) diff --git a/inc/screen/screen.manager.lua b/inc/screen/screen.manager.lua new file mode 100644 index 0000000..8a2a08f --- /dev/null +++ b/inc/screen/screen.manager.lua @@ -0,0 +1,27 @@ +ScreenManager = {} + +local _screens = {} -- Internal list to hold screen data + +-- Public property to access the registered screens as an indexed array +function ScreenManager.get_screens_array() + local screens_array = {} + for _, screen_data in pairs(_screens) do + table.insert(screens_array, screen_data) + end + return screens_array +end + +-- Registers a screen with the manager +-- screen_data: A table containing id, name, and decisions for the screen +function ScreenManager.register(screen_data) + if _screens[screen_data.id] then + -- Optional: warning if overwriting an existing screen + -- trace("Warning: Overwriting screen with id: " .. screen_data.id) + end + _screens[screen_data.id] = screen_data +end + +-- Retrieves a screen by its id (if needed directly) +function ScreenManager.get_by_id(screen_id) + return _screens[screen_id] +end diff --git a/inc/screen/screen.office.lua b/inc/screen/screen.office.lua new file mode 100644 index 0000000..7a619b0 --- /dev/null +++ b/inc/screen/screen.office.lua @@ -0,0 +1,10 @@ +ScreenManager.register({ + id = "office", + name = "Office", + decisions = { + "play_button_mash", + "play_rhythm", + "play_ddr", + "go_to_walking_to_home", + } +}) diff --git a/inc/screen/screen.toilet.lua b/inc/screen/screen.toilet.lua new file mode 100644 index 0000000..ebe9543 --- /dev/null +++ b/inc/screen/screen.toilet.lua @@ -0,0 +1,7 @@ +ScreenManager.register({ + id = "toilet", + name = "Toilet", + decisions = { + "go_to_home", + } +}) diff --git a/inc/screen/screen.walking_to_home.lua b/inc/screen/screen.walking_to_home.lua new file mode 100644 index 0000000..a12739f --- /dev/null +++ b/inc/screen/screen.walking_to_home.lua @@ -0,0 +1,8 @@ +ScreenManager.register({ + id = "walking_to_home", + name = "Walking to home", + decisions = { + "go_to_home", + "go_to_office", + } +}) diff --git a/inc/screen/screen.walking_to_office.lua b/inc/screen/screen.walking_to_office.lua new file mode 100644 index 0000000..95a89df --- /dev/null +++ b/inc/screen/screen.walking_to_office.lua @@ -0,0 +1,8 @@ +ScreenManager.register({ + id = "walking_to_office", + name = "Walking to office", + decisions = { + "go_to_home", + "go_to_office", + } +}) diff --git a/inc/system/system.desition_manager.lua b/inc/system/system.desition_manager.lua deleted file mode 100644 index aae6183..0000000 --- a/inc/system/system.desition_manager.lua +++ /dev/null @@ -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) diff --git a/inc/system/system.desitions.lua b/inc/system/system.desitions.lua deleted file mode 100644 index c5c5f6a..0000000 --- a/inc/system/system.desitions.lua +++ /dev/null @@ -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 \ No newline at end of file diff --git a/inc/system/system.util.lua b/inc/system/system.util.lua index a1d0e19..0bbcf5e 100644 --- a/inc/system/system.util.lua +++ b/inc/system/system.util.lua @@ -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 \ No newline at end of file diff --git a/inc/window/window.game.lua b/inc/window/window.game.lua index f0826b5..4bede42 100644 --- a/inc/window/window.game.lua +++ b/inc/window/window.game.lua @@ -4,11 +4,17 @@ function GameWindow.draw() UI.draw_top_bar(currentScreenData.name) if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then - local display_decisions = {} + local available_desitions = {} for _, desition_id in ipairs(currentScreenData.decisions) do - table.insert(display_decisions, DesitionManager.get(desition_id)) + local desition_obj = DesitionManager.get(desition_id) + if desition_obj and desition_obj.condition() then -- Check condition directly + table.insert(available_desitions, desition_obj) + end + end + -- If no available desitions, display nothing or a message + if #available_desitions > 0 then + UI.draw_desition_selector(available_desitions, Context.selected_desition_index) end - UI.draw_desition_selector(display_decisions, Context.selected_desition_index) end end @@ -37,14 +43,20 @@ function GameWindow.update() local currentScreenData = Context.screens[Context.current_screen] if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then - local display_decisions = {} + local available_desitions = {} for _, desition_id in ipairs(currentScreenData.decisions) do - table.insert(display_decisions, DesitionManager.get(desition_id)) + local desition_obj = DesitionManager.get(desition_id) + if desition_obj and desition_obj.condition() then -- Check condition directly + table.insert(available_desitions, desition_obj) + end end + -- If no available desitions, we can't update or execute + if #available_desitions == 0 then return end + -- Update selected decision using left/right inputs local new_selected_desition_index = UI.update_desition_selector( - display_decisions, + available_desitions, Context.selected_desition_index ) @@ -55,10 +67,10 @@ function GameWindow.update() -- Execute selected decision on Input.select() if Input.select() then - local selected_desition = display_decisions[Context.selected_desition_index] - if selected_desition and selected_desition.handler then + local selected_desition = available_desitions[Context.selected_desition_index] + if selected_desition and selected_desition.handle then -- Call handle directly Audio.sfx_select() -- Play sound for selection - selected_desition.handler() + selected_desition.handle() end end end @@ -67,4 +79,4 @@ end function GameWindow.set_state(new_state) Context.active_window = new_state -- Add any state-specific initialization/cleanup here later if needed -end \ No newline at end of file +end -- 2.49.1 From 9eef8fd6e0f239dd2d3ba85a937777a86aabdb3a Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 21:58:22 +0100 Subject: [PATCH 10/10] Util.go_to_screen_by_id --- inc/desition/desition.go_to_home.lua | 8 +------- inc/desition/desition.go_to_office.lua | 8 +------- inc/desition/desition.go_to_toilet.lua | 8 +------- inc/desition/desition.go_to_walking_to_home.lua | 8 +------- inc/desition/desition.go_to_walking_to_office.lua | 8 +------- inc/system/system.util.lua | 10 ++++++++++ 6 files changed, 15 insertions(+), 35 deletions(-) diff --git a/inc/desition/desition.go_to_home.lua b/inc/desition/desition.go_to_home.lua index 3bcdd99..89ed3a4 100644 --- a/inc/desition/desition.go_to_home.lua +++ b/inc/desition/desition.go_to_home.lua @@ -2,13 +2,7 @@ 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 + Util.go_to_screen_by_id("home") end, condition = function() return true end }) diff --git a/inc/desition/desition.go_to_office.lua b/inc/desition/desition.go_to_office.lua index ff0c32f..75b47ac 100644 --- a/inc/desition/desition.go_to_office.lua +++ b/inc/desition/desition.go_to_office.lua @@ -2,13 +2,7 @@ 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 + Util.go_to_screen_by_id("office") end, condition = function() return true end }) diff --git a/inc/desition/desition.go_to_toilet.lua b/inc/desition/desition.go_to_toilet.lua index e3d5d52..7127b94 100644 --- a/inc/desition/desition.go_to_toilet.lua +++ b/inc/desition/desition.go_to_toilet.lua @@ -2,13 +2,7 @@ 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 + Util.go_to_screen_by_id("toilet") end, condition = function() return true end }) diff --git a/inc/desition/desition.go_to_walking_to_home.lua b/inc/desition/desition.go_to_walking_to_home.lua index 4bfe117..46cc488 100644 --- a/inc/desition/desition.go_to_walking_to_home.lua +++ b/inc/desition/desition.go_to_walking_to_home.lua @@ -2,13 +2,7 @@ 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 + Util.go_to_screen_by_id("walking_to_home") end, condition = function() return true end }) diff --git a/inc/desition/desition.go_to_walking_to_office.lua b/inc/desition/desition.go_to_walking_to_office.lua index f424b0a..458b3a8 100644 --- a/inc/desition/desition.go_to_walking_to_office.lua +++ b/inc/desition/desition.go_to_walking_to_office.lua @@ -2,13 +2,7 @@ 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 + Util.go_to_screen_by_id("walking_to_office") end, condition = function() return true end }) diff --git a/inc/system/system.util.lua b/inc/system/system.util.lua index 0bbcf5e..139a377 100644 --- a/inc/system/system.util.lua +++ b/inc/system/system.util.lua @@ -2,4 +2,14 @@ Util = {} function Util.safeindex(array, index) return ((index - 1 + #array) % #array) + 1 +end + +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 -- Reset selected decision on new screen + else + PopupWindow.show({"Error: Screen '" .. screen_id .. "' not found or not indexed!"}) + end end \ No newline at end of file -- 2.49.1