Filter
List of component names for one filter (`!name` to reject).
Require
Section titled “Require”If the concord folder is in the root directory of your game, you can import this module like so:
Filter = require('concord.filter')Filter
Section titled “Filter”Used to filter Entities with specific Components
A Filter has an associated Pool that can contain any amount of Entities.
validate
Section titled “validate”Validates a Filter Definition to make sure every component is valid.
Also checks that def.constructor is callable when present, unless onComponent is provided.
Filter.validate( errorLevel, name, def, onComponent )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
errorLevel |
integer | Extra stack level added to error reports |
name |
string | Name for the Filter. If omitted, errors refer to a World:query filter. |
def |
FilterDefinition | Table containing the Filter Definition |
onComponent |
fun(component: string, reject: string|false) | Called with (component, reject) when a component is valid. reject is the stripped Component name when the entry had the Reject Prefix, otherwise false. |
Parses a Filter Definition into a single interleaved table.
Entries are stored as name, required pairs: {name, true, name, false, …} where true means the Component is required and false means it is rejected.
parsedFilter = Filter.parse( name, def )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
name |
string | Name for the Filter. |
def |
FilterDefinition | Table containing the Filter Definition |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
parsedFilter |
ParsedFilter | Parsed filter |
Returns true if the Entity matches a parsed Filter.
boolean = Filter.match( e, filter )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
e |
Entity | Entity to check |
filter |
ParsedFilter | Parsed filter from Filter.parse |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
boolean |
boolean |
isValidPool
Section titled “isValidPool”Checks that a custom Pool implements add, remove, has, and clear as callables.
The Pool may be a table, userdata, lightuserdata, or cdata.
Filter.isValidPool( name, pool )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
name |
string | Name of the Filter / Pool |
pool |
Pool | Pool returned by a custom constructor |
Creates a new Filter
If definition.constructor is set, it is called with the definition to create the Pool.
filter = Filter.new( name, def )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
name |
string | Name for the Filter. |
def |
FilterDefinition | Table containing the Filter Definition |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
filter |
Filter | filter The new Filter |
pool |
Pool | pool The associated Pool |
eligible
Section titled “eligible”Checks if an Entity fulfills the Filter requirements.
boolean = filter:eligible( e )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
e |
Entity | Entity to check |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
boolean |
boolean |
evaluate
Section titled “evaluate”Evaluates an Entity against this Filter and updates the Pool.
Adds the Entity if it became eligible, removes it if it no longer is.
filter = filter:evaluate( e )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
e |
Entity | Entity to evaluate |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
filter |
Filter |
Adds an Entity to the Pool, if it passes the Filter.
filter = filter:add( e, bypass )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
e |
Entity | Entity to add |
bypass |
boolean | Whether to bypass the Filter or not. |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
filter |
Filter | |
boolean |
boolean | added Whether the entity was added or not. |
remove
Section titled “remove”Removes an Entity from the Pool associated to this Filter.
filter = filter:remove( e )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
e |
Entity | Entity to remove |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
filter |
Filter |
Clears the Pool associated to this Filter.
Arguments are forwarded to the Pool’s clear method.
filter = filter:clear( ... )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
... |
any | Forwarded to pool:clear |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
filter |
Filter |
Checks if the Pool associated to this Filter contains the passed Entity.
boolean = filter:has( e )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
e |
Entity | Entity to check |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
boolean |
boolean | Whether the Entity exists. |
getName
Section titled “getName”Gets the name of the Filter
string = filter:getName()Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
string |
string |
FilterDefinition
Section titled “FilterDefinition”List of component names for one filter (!name to reject).
Optional constructor creates a custom pool instead of the default List.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
[integer] |
string | |
constructor? |
fun(def: FilterDefinition): Pool |
Entity collection backing a Filter. Default instances are List; custom constructors must implement add, remove, has, and clear.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
add |
fun(self: Pool, e: Entity): Pool | |
remove |
fun(self: Pool, e: Entity): Pool|nil | |
has |
fun(self: Pool, e: Entity): boolean | |
clear |
fun(self: Pool, …: any): Pool |
ParsedFilter
Section titled “ParsedFilter”Interleaved component names and required flags from Filter.parse (name, required, …).
(string|boolean)[]