Constructor
new Tags(parentopt)
Create an instance of a Tags.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parent |
Object |
<optional> |
Parent object who tags belong to. Note: Tags are used as addition of `pc.Entity` and `pc.Asset` as `tags` field. |
- Source:
Members
(readonly) size :Number
Number of tags in set
Type:
- Number
- Source:
Methods
add(name) → {Boolean}
Add a tag, duplicates are ignored. Can be array or comma separated arguments for multiple tags.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of a tag, or array of tags |
- Source:
Returns:
true if any tag were added
- Type
- Boolean
Examples
tags.add('level-1');
tags.add('ui', 'settings');
tags.add([ 'level-2', 'mob' ]);
clear()
Remove all tags.
- Source:
Example
tags.clear();
has(name) → {Boolean}
Check if tags satisfy filters.
Filters can be provided by simple name of tag, as well as by array of tags.
When an array is provided it will check if tags contain each tag within the array.
If any of comma separated argument is satisfied, then it will return true.
Any number of combinations are valid, and order is irrelevant.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | of tag, or array of names |
- Source:
Returns:
true if filters are satisfied
- Type
- Boolean
Examples
tags.has('player'); // player
tags.has('mob', 'player'); // player OR mob
tags.has([ 'level-1', 'mob' ]); // monster AND level-1
tags.has([ 'ui', 'settings' ], [ 'ui', 'levels' ]); // (ui AND settings) OR (ui AND levels)
list() → {Array.<String>}
Returns immutable array of tags
- Source:
Returns:
copy of tags array
- Type
- Array.<String>
remove(name) → {Boolean}
Remove tag.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of a tag or array of tags |
- Source:
Returns:
true if any tag were removed
- Type
- Boolean
Examples
tags.remove('level-1');
tags.remove('ui', 'settings');
tags.remove([ 'level-2', 'mob' ]);
Events
add
Parameters:
Name | Type | Description |
---|---|---|
tag |
String | Name of a tag added to a set. |
parent |
Object | Parent object who tags belong to. |
- Source:
change
Fires when tags been added / removed.
It will fire once on bulk changes, while `add`/`remove` will fire on each tag operation
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parent |
Object |
<optional> |
Parent object who tags belong to. |
- Source:
remove
Parameters:
Name | Type | Description |
---|---|---|
tag |
String | Name of a tag removed from a set. |
parent |
Object | Parent object who tags belong to. |
- Source: