This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
local _screens = {}
|
||||
|
||||
--- Registers a new screen definition with the Screen manager.
|
||||
-- Overwrites existing screen if an ID conflict occurs.
|
||||
-- @param screen_data table A table containing the screen definition.
|
||||
-- Must include an `id` field (string).
|
||||
-- Optional fields:
|
||||
-- - `situations` (table): A table of situation IDs allowed on this screen. Defaults to an empty table.
|
||||
-- - `init` (function): Function to execute once when the screen becomes active. Defaults to an empty function.
|
||||
-- - `update` (function): Function to execute each frame while the screen is active. Defaults to an empty function.
|
||||
function Screen.register(screen_data)
|
||||
if _screens[screen_data.id] then
|
||||
trace("Warning: Overwriting screen with id: " .. screen_data.id)
|
||||
@@ -7,9 +15,18 @@ function Screen.register(screen_data)
|
||||
if not screen_data.situations then
|
||||
screen_data.situations = {}
|
||||
end
|
||||
if not screen_data.init then
|
||||
screen_data.init = function() end
|
||||
end
|
||||
if not screen_data.update then
|
||||
screen_data.update = function() end
|
||||
end
|
||||
_screens[screen_data.id] = screen_data
|
||||
end
|
||||
|
||||
--- Retrieves a registered screen by its ID.
|
||||
-- @param screen_id string The ID of the screen to retrieve.
|
||||
-- @return table The screen table, or `nil` if not found.
|
||||
function Screen.get_by_id(screen_id)
|
||||
return _screens[screen_id]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user