mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 20:33:54 -04:00
Polishing
This commit is contained in:
parent
58549d6b0a
commit
2d21fe97a5
8 changed files with 136 additions and 109 deletions
|
@ -1,17 +1,21 @@
|
|||
local PATH = (...):gsub('%.[^%.]+$', '')
|
||||
|
||||
local List = require(PATH..".list")
|
||||
|
||||
local Pool = {}
|
||||
Pool.__index = Pool
|
||||
|
||||
function Pool.new(name, filter)
|
||||
local pool = setmetatable({
|
||||
__filter = filter,
|
||||
__name = name,
|
||||
}, Pool)
|
||||
local pool = setmetatable(List(), Pool)
|
||||
|
||||
pool.name = name
|
||||
pool.filter = filter
|
||||
|
||||
return pool
|
||||
end
|
||||
|
||||
function Pool:eligible(e)
|
||||
for _, component in ipairs(self.__filter) do
|
||||
for _, component in ipairs(self.filter) do
|
||||
if not e.components[component] then
|
||||
return false
|
||||
end
|
||||
|
@ -20,38 +24,7 @@ function Pool:eligible(e)
|
|||
return true
|
||||
end
|
||||
|
||||
function Pool:add(e)
|
||||
local key = #self + 1
|
||||
|
||||
self[key] = e
|
||||
e.keys[self] = key
|
||||
end
|
||||
|
||||
function Pool:has(e)
|
||||
return e.keys[self] and true
|
||||
end
|
||||
|
||||
function Pool:remove(e, pool)
|
||||
local key = e.keys[self]
|
||||
|
||||
if key then
|
||||
local count = #self
|
||||
|
||||
if key == count then
|
||||
self[key] = nil
|
||||
e.keys[self] = nil
|
||||
else
|
||||
local swap = self[count]
|
||||
|
||||
self[key] = swap
|
||||
self[count] = nil
|
||||
swap.keys[self] = key
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable(Pool, {
|
||||
__call = function(_, ...) return Pool.new(...) end,
|
||||
__index = List,
|
||||
__call = function(_, ...) return Pool.new(...) end,
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue