rename pagemanager to pageregistry

This commit is contained in:
Hersi 2022-08-08 21:41:32 +02:00
parent 6f0c35ac30
commit 3dcc54320c
1 changed files with 23 additions and 15 deletions

View File

@ -1,22 +1,22 @@
require "common.globals"
require "common.class"
---@type PageManager
---@type PageRegistry
local instance = nil
---@class PageManager
---@class PageRegistry
---@field pages Page[]
local PageManager = {
local PageRegistry = {
__name = "PageManager"
}
---Create new PageManager instance
---@param params? PageManager
---@return PageManager
function PageManager.new(params)
---@param params? PageRegistry
---@return PageRegistry
function PageRegistry.new(params)
params = params or {}
local self = CreateInstance(PageManager, params)
local self = CreateInstance(PageRegistry, params)
self.pages = params.pages or {}
@ -24,10 +24,10 @@ function PageManager.new(params)
end
---Get PageManager instance
---@return PageManager
function PageManager.get()
---@return PageRegistry
function PageRegistry.get()
if not instance then
instance = PageManager.new()
instance = PageRegistry.new()
end
return instance
@ -35,18 +35,26 @@ end
---Store page with default name
---@param page Page
function PageManager:storePage(page)
if self.pages[page.__name] then
function PageRegistry:register(page)
self:addPage(page, page.__name)
end
---Add page to page registry
---@param page Page
---@param name string
function PageRegistry:addPage(page, name)
if self:getPage(page) then
game.Log(self.__name .. ":storePage() : page `" .. tostring(page) .. "` already stored, overwriting...", game.LOGGER_WARNING)
else
game.Log(self.__name .. ":storePage() : stored page `" .. tostring(page) .. "` with key '" .. page.__name .. "'", game.LOGGER_DEBUG)
end
self.pages[page.__name] = page
self.pages[name] = page
end
---Get page by name or by class (default name)
---@param page string|Page
function PageManager:getPage(page)
function PageRegistry:getPage(page)
if type(page) == "string" then
return self.pages[page]
elseif type(page) == "table" and page.__name then
@ -57,4 +65,4 @@ function PageManager:getPage(page)
return nil
end
return PageManager
return PageRegistry