remove npc and item handling
This commit is contained in:
@@ -28,19 +28,26 @@ local Config = {
|
|||||||
|
|
||||||
local CONFIG_SAVE_BANK = 7
|
local CONFIG_SAVE_BANK = 7
|
||||||
local CONFIG_MAGIC_VALUE_ADDRESS = 2
|
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
|
local CONFIG_MAGIC_VALUE = 0xDE -- A magic number to check if config is saved
|
||||||
|
|
||||||
function Config.save()
|
function Config.save()
|
||||||
-- Save physics settings
|
|
||||||
mset(CONFIG_MAGIC_VALUE, CONFIG_MAGIC_VALUE_ADDRESS, CONFIG_SAVE_BANK) -- Mark as saved
|
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
|
end
|
||||||
|
|
||||||
function Config.load()
|
function Config.load()
|
||||||
|
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()
|
Config.restore_defaults()
|
||||||
-- Check if config has been saved before using a magic value
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Config.restore_defaults()
|
function Config.restore_defaults()
|
||||||
|
Config.timing.splash_duration = DEFAULT_CONFIG.timing.splash_duration
|
||||||
-- Any other configurable items should be reset here
|
-- Any other configurable items should be reset here
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,9 @@ local function get_initial_data()
|
|||||||
},
|
},
|
||||||
current_screen = 1,
|
current_screen = 1,
|
||||||
splash_timer = Config.timing.splash_duration,
|
splash_timer = Config.timing.splash_duration,
|
||||||
dialog = {
|
popup = { -- New popup table
|
||||||
text = "",
|
show = false,
|
||||||
menu_items = {},
|
content = {} -- Array of strings
|
||||||
selected_menu_item = 1,
|
|
||||||
active_entity = nil,
|
|
||||||
showing_description = false,
|
|
||||||
current_node_key = nil
|
|
||||||
},
|
},
|
||||||
player = {
|
player = {
|
||||||
sprite_id = Config.player.sprite_id
|
sprite_id = Config.player.sprite_id
|
||||||
@@ -51,36 +47,17 @@ local function get_initial_data()
|
|||||||
screens = clone_table({
|
screens = clone_table({
|
||||||
{
|
{
|
||||||
name = "Screen 1",
|
name = "Screen 1",
|
||||||
items = {
|
|
||||||
{
|
|
||||||
name = "Key",
|
|
||||||
sprite_id = 4,
|
|
||||||
desc = "A rusty old key. It might open something."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
-- Screen 2
|
|
||||||
name = "Screen 2",
|
name = "Screen 2",
|
||||||
items = {
|
|
||||||
{
|
|
||||||
name = "Potion",
|
|
||||||
sprite_id = 7,
|
|
||||||
desc = "A glowing red potion. It looks potent."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
-- Screen 3
|
|
||||||
name = "Screen 3",
|
name = "Screen 3",
|
||||||
items = {}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
Context = {}
|
|
||||||
|
|
||||||
local function reset_context_to_initial_state()
|
local function reset_context_to_initial_state()
|
||||||
local initial_data = get_initial_data()
|
local initial_data = get_initial_data()
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ local MinigameRhythmWindow = {}
|
|||||||
local MinigameDDRWindow = {}
|
local MinigameDDRWindow = {}
|
||||||
|
|
||||||
local Util = {}
|
local Util = {}
|
||||||
local Actions = {}
|
local Context = {}
|
||||||
local UI = {}
|
local UI = {}
|
||||||
local Print = {}
|
local Print = {}
|
||||||
local Input = {}
|
local Input = {}
|
||||||
local Player = {}
|
local Player = {}
|
||||||
local Audio = {}local Audio = {}
|
local Audio = {}
|
||||||
|
local Actions = {}
|
||||||
|
|||||||
@@ -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()
|
function Actions.start_minigame_mash()
|
||||||
MinigameButtonMashWindow.start(WINDOW_GAME)
|
MinigameButtonMashWindow.start(WINDOW_GAME)
|
||||||
@@ -25,7 +10,3 @@ end
|
|||||||
function Actions.start_minigame_ddr(song_key)
|
function Actions.start_minigame_ddr(song_key)
|
||||||
MinigameDDRWindow.start(WINDOW_GAME, song_key)
|
MinigameDDRWindow.start(WINDOW_GAME, song_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actions.examine_item(item_data)
|
|
||||||
PopupWindow.show_description_dialog(item_data, item_data.desc)
|
|
||||||
end
|
|
||||||
@@ -304,7 +304,7 @@ function MinigameDDRWindow.draw()
|
|||||||
if mg.bar_fill > 66 then
|
if mg.bar_fill > 66 then
|
||||||
bar_color = Config.colors.item -- yellow
|
bar_color = Config.colors.item -- yellow
|
||||||
elseif mg.bar_fill > 33 then
|
elseif mg.bar_fill > 33 then
|
||||||
bar_color = Config.colors.npc
|
bar_color = Config.colors.bar
|
||||||
end
|
end
|
||||||
|
|
||||||
rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color)
|
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)
|
-- Draw falling arrows (blue)
|
||||||
if mg.arrows then
|
if mg.arrows then
|
||||||
for _, arrow in ipairs(mg.arrows) do
|
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
|
||||||
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)
|
Print.text_center("Pattern Len:" .. #mg.current_song.pattern .. " Index:" .. mg.pattern_index, Config.screen.width / 2, debug_y + 10, Config.colors.green)
|
||||||
end
|
end
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ function MinigameButtonMashWindow.draw()
|
|||||||
if mg.bar_fill > 66 then
|
if mg.bar_fill > 66 then
|
||||||
bar_color = Config.colors.item -- yellow
|
bar_color = Config.colors.item -- yellow
|
||||||
elseif mg.bar_fill > 33 then
|
elseif mg.bar_fill > 33 then
|
||||||
bar_color = Config.colors.npc -- medium color
|
bar_color = Config.colors.bar -- medium color
|
||||||
end
|
end
|
||||||
|
|
||||||
rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color)
|
rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color)
|
||||||
|
|||||||
@@ -1,128 +1,44 @@
|
|||||||
function PopupWindow.set_dialog_node(node_key)
|
-- Simplified PopupWindow module
|
||||||
-- Special handling for minigame trigger
|
local POPUP_X = 40
|
||||||
if node_key == "__MINIGAME_BUTTON_MASH__" then
|
local POPUP_Y = 40
|
||||||
MinigameButtonMashWindow.start(WINDOW_GAME)
|
local POPUP_WIDTH = 160
|
||||||
return
|
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
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
-- Special handling for rhythm minigame trigger
|
function PopupWindow.hide()
|
||||||
if node_key == "__MINIGAME_RHYTHM__" then
|
Context.popup.show = false
|
||||||
MinigameRhythmWindow.start(WINDOW_GAME)
|
Context.popup.content = {} -- Clear content
|
||||||
return
|
GameWindow.set_state(WINDOW_GAME) -- Return to game window
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function PopupWindow.update()
|
function PopupWindow.update()
|
||||||
if Context.dialog.showing_description then
|
if Context.popup.show then
|
||||||
if Input.menu_confirm() or Input.menu_back() then
|
if Input.menu_confirm() or Input.menu_back() then -- Allow either A or B to close
|
||||||
Context.dialog.showing_description = false
|
PopupWindow.hide()
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
if Input.menu_back() then
|
|
||||||
GameWindow.set_state(WINDOW_GAME)
|
|
||||||
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
|
end
|
||||||
|
|
||||||
function PopupWindow.draw()
|
function PopupWindow.draw()
|
||||||
rect(40, 40, 160, 80, Config.colors.black)
|
if Context.popup.show then
|
||||||
rectb(40, 40, 160, 80, Config.colors.green)
|
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
|
local current_y = TEXT_MARGIN_Y
|
||||||
if Context.dialog.active_entity and Context.dialog.active_entity.name then
|
for _, line in ipairs(Context.popup.content) do
|
||||||
Print.text(Context.dialog.active_entity.name, 120 - #Context.dialog.active_entity.name * 2, 45, Config.colors.green)
|
Print.text(line, TEXT_MARGIN_X, current_y, Config.colors.light_grey)
|
||||||
|
current_y = current_y + LINE_HEIGHT
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Display the dialog content (description for "look at", or initial name/dialog for others)
|
-- Instruction to close
|
||||||
local wrapped_lines = UI.word_wrap(Context.dialog.text, 25) -- Max 25 chars per line
|
Print.text("[A] Close", TEXT_MARGIN_X, POPUP_Y + POPUP_HEIGHT - LINE_HEIGHT - 2, Config.colors.green)
|
||||||
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)
|
|
||||||
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
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user