diff --git a/concord/assemblage.lua b/concord/assemblage.lua index f989a63..e6125b7 100644 --- a/concord/assemblage.lua +++ b/concord/assemblage.lua @@ -14,6 +14,7 @@ function Assemblage.new(assemble) local assemblage = setmetatable({ __assemble = assemble, + __name = nil, __isAssemblage = true, }, Assemblage.__mt) @@ -30,6 +31,18 @@ function Assemblage:assemble(e, ...) return self end +--- Returns true if the Assemblage has a name. +-- @return True if the Assemblage has a name, false otherwise +function Assemblage:hasName() + return self.__name and true or false +end + +--- Returns the name of the Assemblage. +-- @return Name of the Assemblage +function Assemblage:getName() + return self.__name +end + return setmetatable(Assemblage, { __call = function(_, ...) return Assemblage.new(...) diff --git a/concord/assemblages.lua b/concord/assemblages.lua index f34e3b9..2e5b6ad 100644 --- a/concord/assemblages.lua +++ b/concord/assemblages.lua @@ -24,8 +24,24 @@ function Assemblages.register(name, assemblage) end Assemblages[name] = assemblage + assemblage.__name = name end +--- Returns true if the containter has the Assemblage with the name +-- @param name Name of the Assemblage to check +-- @return True if the containter has the Assemblage with the name, false otherwise +function Assemblages.has(name) + return Assemblages[name] and true or false +end + +--- Returns the Assemblage with the name +-- @param name Name of the Assemblage to get +-- @return Assemblage with the name +function Assemblages.get(name) + return Assemblages[name] +end + + return setmetatable(Assemblages, { __index = function(_, name) error("Attempt to index assemblage '"..tostring(name).."' that does not exist / was not registered", 2) diff --git a/concord/component.lua b/concord/component.lua index eece914..202e873 100644 --- a/concord/component.lua +++ b/concord/component.lua @@ -63,10 +63,14 @@ function Component:__initialize(...) return component end +--- Returns true if the Component has a name. +-- @return True if the Component has a name, false otherwise function Component:hasName() return self.__name and true or false end +--- Returns the name of the Component. +-- @return Name of the Component function Component:getName() return self.__name end diff --git a/concord/components.lua b/concord/components.lua index 522cf78..e67ec23 100644 --- a/concord/components.lua +++ b/concord/components.lua @@ -27,15 +27,20 @@ function Components.register(name, componentClass) componentClass.__name = name end +--- Returns true if the containter has the ComponentClass with the name +-- @param name Name of the ComponentClass to check +-- @return True if the containter has the ComponentClass with the name, false otherwise function Components.has(name) return Components[name] and true or false end +--- Returns the ComponentClass with the name +-- @param name Name of the ComponentClass to get +-- @return ComponentClass with the name function Components.get(name) return Components[name] end - return setmetatable(Components, { __index = function(_, name) error("Attempt to index ComponentClass '"..tostring(name).."' that does not exist / was not registered", 2) diff --git a/concord/system.lua b/concord/system.lua index 589d8ac..8eeb12d 100644 --- a/concord/system.lua +++ b/concord/system.lua @@ -53,8 +53,10 @@ System.mt = { -- @return A new SystemClass function System.new(...) local systemClass = setmetatable({ - __isSystemClass = true, __filter = {...}, + + __name = nil, + __isSystemClass = true, }, System.mt) systemClass.__index = systemClass @@ -178,6 +180,18 @@ function System:getWorld() return self.__world end +--- Returns true if the System has a name. +-- @return True if the System has a name, false otherwise +function System:hasName() + return self.__name and true or false +end + +--- Returns the name of the System. +-- @return Name of the System +function System:getName() + return self.__name +end + --- Callback for system initialization. -- @param world The World the System was added to function System:init(world) -- luacheck: ignore diff --git a/concord/systems.lua b/concord/systems.lua index 81e6b2e..4781f1d 100644 --- a/concord/systems.lua +++ b/concord/systems.lua @@ -24,6 +24,21 @@ function Systems.register(name, systemClass) end Systems[name] = systemClass + systemClass.__name = name +end + +--- Returns true if the containter has the SystemClass with the name +-- @param name Name of the SystemClass to check +-- @return True if the containter has the SystemClass with the name, false otherwise +function Systems.has(name) + return Systems[name] and true or false +end + +--- Returns the SystemClass with the name +-- @param name Name of the SystemClass to get +-- @return SystemClass with the name +function Systems.get(name) + return Systems[name] end return setmetatable(Systems, { diff --git a/concord/world.lua b/concord/world.lua index 18520cd..4461da0 100644 --- a/concord/world.lua +++ b/concord/world.lua @@ -33,6 +33,7 @@ function World.new() __systemLookup = {}, + __name = nil, __isWorld = true, }, World.__mt) @@ -316,6 +317,18 @@ function World:deserialize(data, append) self:__flush() end +--- Returns true if the World has a name. +-- @return True if the World has a name, false otherwise +function World:hasName() + return self.__name and true or false +end + +--- Returns the name of the World. +-- @return Name of the World +function World:getName() + return self.__name +end + --- Callback for when an Entity is added to the World. -- @param e The Entity that was added function World:onEntityAdded(e) -- luacheck: ignore diff --git a/concord/worlds.lua b/concord/worlds.lua index 0ec2574..9ac18ef 100644 --- a/concord/worlds.lua +++ b/concord/worlds.lua @@ -24,6 +24,21 @@ function Worlds.register(name, world) end Worlds[name] = world + world.__name = name +end + +--- Returns true if the containter has the World with the name +-- @param name Name of the World to check +-- @return True if the containter has the World with the name, false otherwise +function Worlds.has(name) + return Worlds[name] and true or false +end + +--- Returns the World with the name +-- @param name Name of the World to get +-- @return World with the name +function Worlds.get(name) + return Worlds[name] end return setmetatable(Worlds, {