API Reference

Class List

pc.Tags

Set of tag names

Summary

Properties

sizeNumber of tags in set[read only]

Methods

addAdd a tag, duplicates are ignored.
clearRemove all tags.
hasCheck if tags satisfy filters.
listReturns immutable array of tags
removeRemove tag.

Events

add
changeFires when tags been added / removed.
remove

Details

Constructor

Tags([parent])

Create an instance of a Tags.

Parameters

parentObjectParent object who tags belong to. Note: Tags are used as addition of `pc.Entity` and `pc.Asset` as `tags` field.

Properties

Numbersize

Number of tags in set[read only]

Methods

add(name)

Add a tag, duplicates are ignored. Can be array or comma separated arguments for multiple tags.

tags.add('level-1');
tags.add('ui', 'settings');
tags.add([ 'level-2', 'mob' ]);

Parameters

nameStringName of a tag, or array of tags

Returns

Boolean true if any tag were added

clear()

Remove all tags.

tags.clear();

has(name)

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.

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)

Parameters

nameStringof tag, or array of names

Returns

Boolean true if filters are satisfied

list()

Returns immutable array of tags

Returns

String[] copy of tags array

remove(name)

Remove tag.

tags.remove('level-1');
tags.remove('ui', 'settings');
tags.remove([ 'level-2', 'mob' ]);

Parameters

nameStringName of a tag or array of tags

Returns

Boolean true if any tag were removed

Events

add

Parameters

tagStringName of a tag added to a set.
parentObjectParent object who tags belong to.

change

Fires when tags been added / removed. It will fire once on bult changes, while `add`/`remove` will fire on each tag operation

Parameters

parentObjectParent object who tags belong to.

remove

Parameters

tagStringName of a tag removed from a set.
parentObjectParent object who tags belong to.