Removed deprecated functionality

Removed hasName/getName on Systems and Worlds.

Removed Entity.__components since it had a duplicate version of the components stored in the Entity itself.
This commit is contained in:
Pablo Ariel Mayobre 2023-02-14 18:14:23 -03:00
parent 695cc2dfe3
commit 50249d5ad3
3 changed files with 12 additions and 37 deletions

View file

@ -6,6 +6,7 @@ local PATH = (...):gsub('%.[^%.]+$', '')
local Components = require(PATH..".components")
local Type = require(PATH..".type")
local Utils = require(PATH..".utils")
local Entity = {}
Entity.__mt = {
@ -22,7 +23,6 @@ function Entity.new(world)
local e = setmetatable({
__world = nil,
__components = {},
__isEntity = true,
}, Entity.__mt)
@ -38,14 +38,12 @@ local function give(e, name, componentClass, ...)
local component = componentClass:__initialize(...)
e[name] = component
e.__components[name] = component
e:__dirty()
end
local function remove(e, name, componentClass)
local function remove(e, name)
e[name] = nil
e.__components[name] = nil
e:__dirty()
end
@ -76,7 +74,7 @@ function Entity:ensure(name, ...)
local ok, componentClass = Components.try(name)
if not ok then
error("bad argument #1 to 'Entity:get' ("..componentClass..")", 2)
error("bad argument #1 to 'Entity:ensure' ("..componentClass..")", 2)
end
if self[name] then
@ -95,10 +93,10 @@ function Entity:remove(name)
local ok, componentClass = Components.try(name)
if not ok then
error("bad argument #1 to 'Entity:get' ("..componentClass..")", 2)
error("bad argument #1 to 'Entity:remove' ("..componentClass..")", 2)
end
remove(self, name, componentClass)
remove(self, name)
return self
end
@ -169,7 +167,11 @@ end
-- Use Entity:give/ensure/remove instead
-- @treturn table Table of all Components the Entity has
function Entity:getComponents()
return self.__components
local components = Utils.shallowCopy(self)
components.__world = nil
components.__isEntity = nil
return components
end
--- Returns true if the Entity is in a World.
@ -187,8 +189,8 @@ end
function Entity:serialize()
local data = {}
for _, component in pairs(self.__components) do
if component.__name then
for name, component in pairs(self) do
if name ~= "__world" and name ~= "__isEntity" and component.__name == name then
local componentData = component:serialize()
if componentData ~= nil then
@ -215,7 +217,6 @@ function Entity:deserialize(data)
component:deserialize(componentData)
self[componentData.__name] = component
self.__components[componentData.__name] = component
self:__dirty()
end

View file

@ -85,7 +85,6 @@ function System.new(definition)
local systemClass = setmetatable({
__filters = filters,
__name = nil,
__isSystemClass = true,
}, System.mt)
systemClass.__index = systemClass
@ -161,18 +160,6 @@ function System:getWorld()
return self.__world
end
--- Returns true if the System has a name.
-- @treturn boolean
function System:hasName()
return self.__name and true or false
end
--- Returns the name of the System.
-- @treturn string
function System:getName()
return self.__name
end
--- Callbacks
-- @section Callbacks

View file

@ -34,7 +34,6 @@ function World.new()
__systemLookup = {},
__name = nil,
__isWorld = true,
}, World.__mt)
@ -349,18 +348,6 @@ function World:deserialize(data, append)
self:__flush()
end
--- Returns true if the World has a name.
-- @treturn boolean
function World:hasName()
return self.__name and true or false
end
--- Returns the name of the World.
-- @treturn string
function World:getName()
return self.__name
end
--- Callback for when an Entity is added to the World.
-- @tparam Entity e The Entity that was added
function World:onEntityAdded(e) -- luacheck: ignore