Skip to main content

Defining Facets

Facets are simple data classes. Here are a couple examples:

class Transform extends Facet<Position> {
position? = new Vector2(0, 0);
rotation? = 0;
}
class Health extends Facet<Position> {
current? = 100;
max? = 100;
}
class Invincible extends Facet<Position> {}

Facet Classes#

Every facet must extend Facet<T>, with itself as the T type parameter.

Facet attributes are declared as class fields.

You can either provide a default:

position? = new Vector2(0, 0)

...in which case you should mark the field as optional. This is so the corresponding Facet Prop is also optional.

Or you can provide a type:

position: Vector2;

...in which case you should not mark the field as options. This is to ensure the corresponding Facet Prop is also required.

Facet Tags#

Facets may have no fields, in which case they may be used as marker tags:

class IsEnemy extends Facet<IsEnemy> {}

Facet Components#

Facets are automatically valid React Components. Use them within an Entity Declaration to associate them with an Entity:

<Entity>
<Transform />
<Velocity />
<Health max={500} />
</Entity>