remove ai generated comments
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful

This commit is contained in:
2026-02-18 19:29:06 +01:00
parent 6303781534
commit 1cf09de1fb
15 changed files with 56 additions and 155 deletions

View File

@@ -8,7 +8,7 @@ local DEFAULT_CONFIG = {
light_grey = 13,
dark_grey = 14,
green = 6,
item = 12 -- yellow
item = 12
},
player = {
sprite_id = 1
@@ -19,7 +19,6 @@ local DEFAULT_CONFIG = {
}
local Config = {
-- Copy default values initially
screen = DEFAULT_CONFIG.screen,
colors = DEFAULT_CONFIG.colors,
player = DEFAULT_CONFIG.player,
@@ -28,28 +27,23 @@ 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
local CONFIG_SPLASH_DURATION_ADDRESS = 3
local CONFIG_MAGIC_VALUE = 0xDE
function Config.save()
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)
mset(CONFIG_MAGIC_VALUE, CONFIG_MAGIC_VALUE_ADDRESS, CONFIG_SAVE_BANK)
end
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()
end
end
function Config.restore_defaults()
Config.timing.splash_duration = DEFAULT_CONFIG.timing.splash_duration
-- Any other configurable items should be reset here
end
-- Load configuration on startup
Config.load()

View File

@@ -4,20 +4,6 @@ local SAVE_GAME_MAGIC_VALUE = 0xCA
local SAVE_GAME_CURRENT_SCREEN_ADDRESS = 6
-- Helper for deep copying tables
-- local function clone_table(t)
-- local copy = {}
-- for k, v in pairs(t) do
-- if type(v) == "table" then
-- copy[k] = clone_table(v)
-- else
-- copy[k] = v
-- end
-- end
-- return copy
-- end
-- This function returns a table containing only the initial *data* for Context
local function get_initial_data()
return {
active_window = WINDOW_SPLASH,
@@ -38,9 +24,9 @@ on than meets the eye.]]
},
current_screen = 1,
splash_timer = Config.timing.splash_duration,
popup = { -- New popup table
popup = {
show = false,
content = {} -- Array of strings
content = {}
},
player = {
sprite_id = Config.player.sprite_id
@@ -53,9 +39,9 @@ on than meets the eye.]]
},
menu_items = {},
selected_menu_item = 1,
selected_desition_index = 1, -- New desition index
game_in_progress = false, -- New flag
screens = {} -- Initialize as empty, populated on reset
selected_desition_index = 1,
game_in_progress = false,
screens = {}
}
end
@@ -64,39 +50,30 @@ Context = {}
local function reset_context_to_initial_state()
local initial_data = get_initial_data()
-- Clear existing data properties from Context (but not methods)
for k in pairs(Context) do
if type(Context[k]) ~= "function" then -- Only clear data, leave functions
Context[k] = nil
if type(Context[k]) ~= "function" then Context[k] = nil
end
end
-- Copy all initial data properties into Context
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
Context.screen_indices_by_id = {}
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
Context.screen_indices_by_id[screen_id] = i else
PopupWindow.show({"Error: Screen '" .. screen_id .. "' not registered!"})
end
end
end
-- Initially populate Context with data
reset_context_to_initial_state()
-- Now define the methods for Context
function Context.new_game()
reset_context_to_initial_state()
Context.game_in_progress = true
@@ -112,13 +89,11 @@ end
function Context.load_game()
if mget(SAVE_GAME_MAGIC_VALUE_ADDRESS, SAVE_GAME_BANK) ~= SAVE_GAME_MAGIC_VALUE then
-- No saved game found, start a new one
Context.new_game()
Context.new_game()
return
end
reset_context_to_initial_state() -- Reset data, preserve methods
reset_context_to_initial_state()
Context.current_screen = mget(SAVE_GAME_CURRENT_SCREEN_ADDRESS, SAVE_GAME_BANK)
Context.game_in_progress = true

View File

@@ -7,4 +7,4 @@ local WINDOW_CONFIGURATION = 7
local WINDOW_MINIGAME_BUTTON_MASH = 8
local WINDOW_MINIGAME_RHYTHM = 9
local WINDOW_MINIGAME_DDR = 10
local WINDOW_AUDIOTEST = 9001 -- because it's a debug screen lol
local WINDOW_AUDIOTEST = 9001