rename pagemanager to pageregistry
This commit is contained in:
parent
6f0c35ac30
commit
3dcc54320c
|
@ -1,22 +1,22 @@
|
||||||
require "common.globals"
|
require "common.globals"
|
||||||
require "common.class"
|
require "common.class"
|
||||||
|
|
||||||
---@type PageManager
|
---@type PageRegistry
|
||||||
local instance = nil
|
local instance = nil
|
||||||
|
|
||||||
---@class PageManager
|
---@class PageRegistry
|
||||||
---@field pages Page[]
|
---@field pages Page[]
|
||||||
local PageManager = {
|
local PageRegistry = {
|
||||||
__name = "PageManager"
|
__name = "PageManager"
|
||||||
}
|
}
|
||||||
|
|
||||||
---Create new PageManager instance
|
---Create new PageManager instance
|
||||||
---@param params? PageManager
|
---@param params? PageRegistry
|
||||||
---@return PageManager
|
---@return PageRegistry
|
||||||
function PageManager.new(params)
|
function PageRegistry.new(params)
|
||||||
params = params or {}
|
params = params or {}
|
||||||
|
|
||||||
local self = CreateInstance(PageManager, params)
|
local self = CreateInstance(PageRegistry, params)
|
||||||
|
|
||||||
self.pages = params.pages or {}
|
self.pages = params.pages or {}
|
||||||
|
|
||||||
|
@ -24,10 +24,10 @@ function PageManager.new(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Get PageManager instance
|
---Get PageManager instance
|
||||||
---@return PageManager
|
---@return PageRegistry
|
||||||
function PageManager.get()
|
function PageRegistry.get()
|
||||||
if not instance then
|
if not instance then
|
||||||
instance = PageManager.new()
|
instance = PageRegistry.new()
|
||||||
end
|
end
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
@ -35,18 +35,26 @@ end
|
||||||
|
|
||||||
---Store page with default name
|
---Store page with default name
|
||||||
---@param page Page
|
---@param page Page
|
||||||
function PageManager:storePage(page)
|
function PageRegistry:register(page)
|
||||||
if self.pages[page.__name] then
|
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)
|
game.Log(self.__name .. ":storePage() : page `" .. tostring(page) .. "` already stored, overwriting...", game.LOGGER_WARNING)
|
||||||
else
|
else
|
||||||
game.Log(self.__name .. ":storePage() : stored page `" .. tostring(page) .. "` with key '" .. page.__name .. "'", game.LOGGER_DEBUG)
|
game.Log(self.__name .. ":storePage() : stored page `" .. tostring(page) .. "` with key '" .. page.__name .. "'", game.LOGGER_DEBUG)
|
||||||
end
|
end
|
||||||
self.pages[page.__name] = page
|
|
||||||
|
self.pages[name] = page
|
||||||
end
|
end
|
||||||
|
|
||||||
---Get page by name or by class (default name)
|
---Get page by name or by class (default name)
|
||||||
---@param page string|Page
|
---@param page string|Page
|
||||||
function PageManager:getPage(page)
|
function PageRegistry:getPage(page)
|
||||||
if type(page) == "string" then
|
if type(page) == "string" then
|
||||||
return self.pages[page]
|
return self.pages[page]
|
||||||
elseif type(page) == "table" and page.__name then
|
elseif type(page) == "table" and page.__name then
|
||||||
|
@ -57,4 +65,4 @@ function PageManager:getPage(page)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return PageManager
|
return PageRegistry
|
Loading…
Reference in New Issue