EntityModifier¶
import { EntityModifier } from "encompass-ecs";
An EntityModifier is a subclass of Engine that provides a structure for a common pattern - collecting all EntityMessages of a particular type that reference the same Entity.
The first message type given in the @Reads
decorator is assumed to be the target EntityMessage type.
Abstracts¶
-
modify
(entity, messages, dt)¶ This callback runs during the modify pass of World update when one or more EntityMessages of
message_type
are produced during the detection pass.Arguments: - entity (Entity) – The Entity attached to the EntityMessage tracked by the EntityModifier.
- messages (GCOptimizedList<EntityMessage>) – A GCOptimizedSet of all the messages of message_type created during the detection pass.
- dt (number) – The delta time value given to the World update function.
Example¶
import { Component, Entity, EntityModifier, Message, Reads, Type } from "encompass-ecs";
import { AddComponentMessage } from "hyperspace/messages/entity/add_component";
import { GCOptimizedSet } from "encompass-gc-optimized-collections";
type MessageSet = GCOptimizedSet<AddComponentMessage<Component>>;
@Reads(AddComponentMessage)
export class AddComponentModifier extends EntityModifier {
protected modify(entity: Entity, messages: MessageSet) {
for (const message of messages.iterable()) {
entity.add_component(message.component_to_add, message.args);
}
}
}