refact
This commit is contained in:
@@ -1,34 +1,35 @@
|
||||
local DEFAULT_CONFIG = {
|
||||
screen = {
|
||||
width = 240,
|
||||
height = 136
|
||||
},
|
||||
colors = {
|
||||
black = 0,
|
||||
light_grey = 13,
|
||||
dark_grey = 14,
|
||||
red = 2,
|
||||
green = 6,
|
||||
blue = 9,
|
||||
white = 12,
|
||||
item = 12,
|
||||
meter_bg = 12
|
||||
},
|
||||
player = {
|
||||
sprite_id = 1
|
||||
},
|
||||
timing = {
|
||||
splash_duration = 120
|
||||
}
|
||||
}
|
||||
Config = {}
|
||||
|
||||
-- Game configuration settings.
|
||||
Config = {
|
||||
screen = DEFAULT_CONFIG.screen,
|
||||
colors = DEFAULT_CONFIG.colors,
|
||||
player = DEFAULT_CONFIG.player,
|
||||
timing = DEFAULT_CONFIG.timing,
|
||||
}
|
||||
function Config.initial_data()
|
||||
return {
|
||||
screen = {
|
||||
width = 240,
|
||||
height = 136
|
||||
},
|
||||
colors = {
|
||||
black = 0,
|
||||
light_grey = 13,
|
||||
dark_grey = 14,
|
||||
red = 2,
|
||||
green = 6,
|
||||
blue = 9,
|
||||
white = 12,
|
||||
item = 12,
|
||||
meter_bg = 12
|
||||
},
|
||||
timing = {
|
||||
splash_duration = 120
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
--- Restores default configuration settings.
|
||||
function Config.reset()
|
||||
local initial = Config.initial_data()
|
||||
Config.screen = initial.screen
|
||||
Config.colors = initial.colors
|
||||
Config.timing = initial.timing
|
||||
end
|
||||
|
||||
local CONFIG_SAVE_BANK = 7
|
||||
local CONFIG_MAGIC_VALUE_ADDRESS = 2
|
||||
@@ -38,6 +39,7 @@ local CONFIG_MAGIC_VALUE = 0xDE
|
||||
--- Saves the current configuration.
|
||||
function Config.save()
|
||||
mset(CONFIG_MAGIC_VALUE, CONFIG_MAGIC_VALUE_ADDRESS, CONFIG_SAVE_BANK)
|
||||
mset(Config.timing.splash_duration, CONFIG_SPLASH_DURATION_ADDRESS, CONFIG_SAVE_BANK)
|
||||
end
|
||||
|
||||
--- Loads saved configuration.
|
||||
@@ -45,13 +47,8 @@ function Config.load()
|
||||
if mget(CONFIG_MAGIC_VALUE_ADDRESS, CONFIG_SAVE_BANK) == CONFIG_MAGIC_VALUE then
|
||||
Config.timing.splash_duration = mget(CONFIG_SPLASH_DURATION_ADDRESS, CONFIG_SAVE_BANK)
|
||||
else
|
||||
Config.restore_defaults()
|
||||
Config.reset()
|
||||
end
|
||||
end
|
||||
|
||||
--- Restores default configuration settings.
|
||||
function Config.restore_defaults()
|
||||
Config.timing.splash_duration = DEFAULT_CONFIG.timing.splash_duration
|
||||
end
|
||||
|
||||
Config.load()
|
||||
|
||||
@@ -2,66 +2,34 @@ local SAVE_GAME_BANK = 6
|
||||
local SAVE_GAME_MAGIC_VALUE_ADDRESS = 0
|
||||
local SAVE_GAME_MAGIC_VALUE = 0xCA
|
||||
|
||||
local SAVE_GAME_CURRENT_SCREEN_ADDRESS = 6
|
||||
--- Global game context.
|
||||
Context = {}
|
||||
|
||||
--- Gets initial data for Context.
|
||||
-- @return table Initial context data.
|
||||
local function get_initial_data()
|
||||
function Context.initial_data()
|
||||
return {
|
||||
active_window = WINDOW_SPLASH,
|
||||
intro = {
|
||||
y = Config.screen.height,
|
||||
speed = 0.5,
|
||||
text = [[Norman Reds’ everyday life
|
||||
seems ordinary: work,
|
||||
meetings, coffee, and
|
||||
endless notifications.
|
||||
But beneath the surface
|
||||
— within him, or around
|
||||
him — something is
|
||||
constantly building, and
|
||||
it soon becomes clear
|
||||
that there is more going
|
||||
on than meets the eye.]]
|
||||
},
|
||||
current_screen = 1,
|
||||
current_menu_item = 1,
|
||||
splash_timer = Config.timing.splash_duration,
|
||||
popup = {
|
||||
show = false,
|
||||
content = {}
|
||||
},
|
||||
player = {
|
||||
sprite_id = Config.player.sprite_id
|
||||
},
|
||||
ground = {
|
||||
x = 0,
|
||||
y = Config.screen.height,
|
||||
w = Config.screen.width,
|
||||
h = 8
|
||||
},
|
||||
menu_items = {},
|
||||
selected_menu_item = 1,
|
||||
selected_decision_index = 1,
|
||||
game_in_progress = false,
|
||||
screens = {},
|
||||
minigame_ddr = Minigame.get_default_ddr(),
|
||||
minigame_button_mash = Minigame.get_default_button_mash(),
|
||||
minigame_rhythm = Minigame.get_default_rhythm(),
|
||||
meters = Meter.get_initial(),
|
||||
--- Active sprites.
|
||||
sprites = {},
|
||||
--- Current situation ID.
|
||||
current_situation = nil,
|
||||
game = {
|
||||
current_screen = "home",
|
||||
current_situation = nil,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
--- Global game context.
|
||||
Context = {}
|
||||
|
||||
--- Resets game context to initial state.
|
||||
local function reset_context_to_initial_state()
|
||||
local initial_data = get_initial_data()
|
||||
|
||||
function Context.reset()
|
||||
local initial_data = Context.initial_data()
|
||||
for k in pairs(Context) do
|
||||
if type(Context[k]) ~= "function" then Context[k] = nil
|
||||
end
|
||||
@@ -70,37 +38,20 @@ local function reset_context_to_initial_state()
|
||||
for k, v in pairs(initial_data) do
|
||||
Context[k] = v
|
||||
end
|
||||
|
||||
Context.screens = {}
|
||||
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 = Screen.get_by_id(screen_id)
|
||||
if screen_data then
|
||||
table.insert(Context.screens, screen_data)
|
||||
Context.screen_indices_by_id[screen_id] = i
|
||||
else
|
||||
PopupWindow.show({"Error: Screen '" .. screen_id .. "' not registered!"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
reset_context_to_initial_state()
|
||||
|
||||
--- Starts a new game.
|
||||
function Context.new_game()
|
||||
reset_context_to_initial_state()
|
||||
Context.reset()
|
||||
Context.game_in_progress = true
|
||||
MenuWindow.refresh_menu_items()
|
||||
Context.screens[Context.current_screen].init()
|
||||
Screen.get_by_id(Context.game.current_screen).init()
|
||||
end
|
||||
|
||||
--- Saves the current game state.
|
||||
function Context.save_game()
|
||||
if not Context.game_in_progress then return end
|
||||
|
||||
mset(SAVE_GAME_MAGIC_VALUE, SAVE_GAME_MAGIC_VALUE_ADDRESS, SAVE_GAME_BANK)
|
||||
mset(Context.current_screen, SAVE_GAME_CURRENT_SCREEN_ADDRESS, SAVE_GAME_BANK)
|
||||
end
|
||||
|
||||
--- Loads a saved game state.
|
||||
@@ -109,11 +60,8 @@ function Context.load_game()
|
||||
Context.new_game()
|
||||
return
|
||||
end
|
||||
|
||||
reset_context_to_initial_state()
|
||||
Context.current_screen = mget(SAVE_GAME_CURRENT_SCREEN_ADDRESS, SAVE_GAME_BANK)
|
||||
|
||||
Context.reset()
|
||||
Context.game_in_progress = true
|
||||
MenuWindow.refresh_menu_items()
|
||||
Context.screens[Context.current_screen].init()
|
||||
Screen.get_by_id(Context.game.current_screen).init()
|
||||
end
|
||||
|
||||
13
inc/init/init.module.lua
Normal file
13
inc/init/init.module.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
Window = {}
|
||||
Util = {}
|
||||
Meter = {}
|
||||
Minigame = {}
|
||||
Decision = {}
|
||||
Situation = {}
|
||||
Screen = {}
|
||||
Map = {}
|
||||
UI = {}
|
||||
Print = {}
|
||||
Input = {}
|
||||
Sprite = {}
|
||||
Audio = {}
|
||||
@@ -1,22 +0,0 @@
|
||||
SplashWindow = {}
|
||||
IntroWindow = {}
|
||||
MenuWindow = {}
|
||||
GameWindow = {}
|
||||
PopupWindow = {}
|
||||
ConfigurationWindow = {}
|
||||
AudioTestWindow = {}
|
||||
MinigameButtonMashWindow = {}
|
||||
MinigameRhythmWindow = {}
|
||||
MinigameDDRWindow = {}
|
||||
Util = {}
|
||||
Meter = {}
|
||||
Minigame = {}
|
||||
Decision = {}
|
||||
Situation = {}
|
||||
Screen = {}
|
||||
Map = {}
|
||||
UI = {}
|
||||
Print = {}
|
||||
Input = {}
|
||||
Sprite = {}
|
||||
Audio = {}
|
||||
0
inc/init/init.window.lua
Normal file
0
inc/init/init.window.lua
Normal file
@@ -1,10 +0,0 @@
|
||||
local WINDOW_SPLASH = 0
|
||||
local WINDOW_INTRO = 1
|
||||
local WINDOW_MENU = 2
|
||||
local WINDOW_GAME = 3
|
||||
local WINDOW_POPUP = 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
|
||||
Reference in New Issue
Block a user