mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 12:24:11 -04:00
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:
parent
695cc2dfe3
commit
50249d5ad3
3 changed files with 12 additions and 37 deletions
|
@ -6,6 +6,7 @@ local PATH = (...):gsub('%.[^%.]+$', '')
|
||||||
|
|
||||||
local Components = require(PATH..".components")
|
local Components = require(PATH..".components")
|
||||||
local Type = require(PATH..".type")
|
local Type = require(PATH..".type")
|
||||||
|
local Utils = require(PATH..".utils")
|
||||||
|
|
||||||
local Entity = {}
|
local Entity = {}
|
||||||
Entity.__mt = {
|
Entity.__mt = {
|
||||||
|
@ -22,7 +23,6 @@ function Entity.new(world)
|
||||||
|
|
||||||
local e = setmetatable({
|
local e = setmetatable({
|
||||||
__world = nil,
|
__world = nil,
|
||||||
__components = {},
|
|
||||||
|
|
||||||
__isEntity = true,
|
__isEntity = true,
|
||||||
}, Entity.__mt)
|
}, Entity.__mt)
|
||||||
|
@ -38,14 +38,12 @@ local function give(e, name, componentClass, ...)
|
||||||
local component = componentClass:__initialize(...)
|
local component = componentClass:__initialize(...)
|
||||||
|
|
||||||
e[name] = component
|
e[name] = component
|
||||||
e.__components[name] = component
|
|
||||||
|
|
||||||
e:__dirty()
|
e:__dirty()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function remove(e, name, componentClass)
|
local function remove(e, name)
|
||||||
e[name] = nil
|
e[name] = nil
|
||||||
e.__components[name] = nil
|
|
||||||
|
|
||||||
e:__dirty()
|
e:__dirty()
|
||||||
end
|
end
|
||||||
|
@ -76,7 +74,7 @@ function Entity:ensure(name, ...)
|
||||||
local ok, componentClass = Components.try(name)
|
local ok, componentClass = Components.try(name)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
error("bad argument #1 to 'Entity:get' ("..componentClass..")", 2)
|
error("bad argument #1 to 'Entity:ensure' ("..componentClass..")", 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self[name] then
|
if self[name] then
|
||||||
|
@ -95,10 +93,10 @@ function Entity:remove(name)
|
||||||
local ok, componentClass = Components.try(name)
|
local ok, componentClass = Components.try(name)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
error("bad argument #1 to 'Entity:get' ("..componentClass..")", 2)
|
error("bad argument #1 to 'Entity:remove' ("..componentClass..")", 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
remove(self, name, componentClass)
|
remove(self, name)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
@ -169,7 +167,11 @@ end
|
||||||
-- Use Entity:give/ensure/remove instead
|
-- Use Entity:give/ensure/remove instead
|
||||||
-- @treturn table Table of all Components the Entity has
|
-- @treturn table Table of all Components the Entity has
|
||||||
function Entity:getComponents()
|
function Entity:getComponents()
|
||||||
return self.__components
|
local components = Utils.shallowCopy(self)
|
||||||
|
components.__world = nil
|
||||||
|
components.__isEntity = nil
|
||||||
|
|
||||||
|
return components
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Returns true if the Entity is in a World.
|
--- Returns true if the Entity is in a World.
|
||||||
|
@ -187,8 +189,8 @@ end
|
||||||
function Entity:serialize()
|
function Entity:serialize()
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
for _, component in pairs(self.__components) do
|
for name, component in pairs(self) do
|
||||||
if component.__name then
|
if name ~= "__world" and name ~= "__isEntity" and component.__name == name then
|
||||||
local componentData = component:serialize()
|
local componentData = component:serialize()
|
||||||
|
|
||||||
if componentData ~= nil then
|
if componentData ~= nil then
|
||||||
|
@ -215,7 +217,6 @@ function Entity:deserialize(data)
|
||||||
component:deserialize(componentData)
|
component:deserialize(componentData)
|
||||||
|
|
||||||
self[componentData.__name] = component
|
self[componentData.__name] = component
|
||||||
self.__components[componentData.__name] = component
|
|
||||||
|
|
||||||
self:__dirty()
|
self:__dirty()
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,7 +85,6 @@ function System.new(definition)
|
||||||
local systemClass = setmetatable({
|
local systemClass = setmetatable({
|
||||||
__filters = filters,
|
__filters = filters,
|
||||||
|
|
||||||
__name = nil,
|
|
||||||
__isSystemClass = true,
|
__isSystemClass = true,
|
||||||
}, System.mt)
|
}, System.mt)
|
||||||
systemClass.__index = systemClass
|
systemClass.__index = systemClass
|
||||||
|
@ -161,18 +160,6 @@ function System:getWorld()
|
||||||
return self.__world
|
return self.__world
|
||||||
end
|
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
|
--- Callbacks
|
||||||
-- @section Callbacks
|
-- @section Callbacks
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ function World.new()
|
||||||
|
|
||||||
__systemLookup = {},
|
__systemLookup = {},
|
||||||
|
|
||||||
__name = nil,
|
|
||||||
__isWorld = true,
|
__isWorld = true,
|
||||||
}, World.__mt)
|
}, World.__mt)
|
||||||
|
|
||||||
|
@ -349,18 +348,6 @@ function World:deserialize(data, append)
|
||||||
self:__flush()
|
self:__flush()
|
||||||
end
|
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.
|
--- Callback for when an Entity is added to the World.
|
||||||
-- @tparam Entity e The Entity that was added
|
-- @tparam Entity e The Entity that was added
|
||||||
function World:onEntityAdded(e) -- luacheck: ignore
|
function World:onEntityAdded(e) -- luacheck: ignore
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue