From ef4876b0830d7b7b9de74b5fec820d711fd53519 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 20:23:11 +0100 Subject: [PATCH] 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