mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-06 14:17:45 -04:00
Replaced Pools with Filters
Filters allow for a Pool constructor (defaults to Lists) that can be used to define Custom Pools. The constructor is a function that takes the Filter Definition and returns a Custom Pool with these functions: :add(e) - Add the Entity to the pool :remove(e) - Remove the Entity from the pool :has(e) boolean - Checks if the Entity exists in the pool :clear() - Clears the Pool from Entities Fixes #40
This commit is contained in:
parent
eec6f4f29e
commit
d854e93e70
6 changed files with 221 additions and 163 deletions
|
@ -16,7 +16,7 @@ end
|
|||
|
||||
--- Adds an object to the List.
|
||||
-- Object must be of reference type
|
||||
-- Object may not be the string 'size'
|
||||
-- Object may not be the string 'size', 'onAdded' or 'onRemoved'
|
||||
-- @param obj Object to add
|
||||
-- @treturn List self
|
||||
function List:add(obj)
|
||||
|
@ -26,6 +26,7 @@ function List:add(obj)
|
|||
self[obj] = size
|
||||
self.size = size
|
||||
|
||||
if self.onAdded then self:onAdded(obj) end
|
||||
return self
|
||||
end
|
||||
|
||||
|
@ -51,6 +52,7 @@ function List:remove(obj)
|
|||
self[obj] = nil
|
||||
self.size = size - 1
|
||||
|
||||
if self.onRemoved then self:onRemoved(obj) end
|
||||
return self
|
||||
end
|
||||
|
||||
|
@ -108,6 +110,16 @@ function List:sort(order)
|
|||
return self
|
||||
end
|
||||
|
||||
--- Callback for when an item is added to the List.
|
||||
-- @param obj Object that was added
|
||||
function List:onAdded (obj) --luacheck: ignore
|
||||
end
|
||||
|
||||
--- Callback for when an item is removed to the List.
|
||||
-- @param obj Object that was removed
|
||||
function List:onRemoved (obj) --luacheck: ignore
|
||||
end
|
||||
|
||||
return setmetatable(List, {
|
||||
__call = function()
|
||||
return List.new()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue