Class
TypeStore
View sourceRegisters component constructors and explicit TypeId values,
mapping each type to a dense ComponentId and retaining its
ComponentInfo metadata.
A World owns one store for its component types. Constructor-based
methods derive a TypeId with typeid; TypeId-based
methods accept that key directly. The first registration of a type receives
the next zero-based component ID. Registering the same TypeId returns
its existing ID and keeps its existing ComponentInfo.
Use the lookup methods to inspect registration and metadata. A returned
ComponentInfo exposes its ComponentHooks through
ComponentInfo#getHooks; normal hook configuration goes through
World#setComponentHooks.
Examples
import { TypeStore } from '@wimaengine/ecs'
class Position {}
const store = new TypeStore()
const id = store.getOrSet(Position)
store.getId(Position) === id // true
store.get(Position)?.getHooks() // the component's ComponentHooks
store.getOrSet(Position) === id // true: registration is idempotentConstructor
Methods
set<T>(type: Constructor<T>): number
View sourceRegisters a component constructor and returns its component ID.
The constructor is converted to a TypeId before registration. If
that TypeId is already registered, this method returns the
existing ID and does not replace its ComponentInfo; otherwise it
assigns the next zero-based ID and creates a metadata record.
setByTypeId(id: TypeId): number
View sourcehas<T>(type: Constructor<T>): boolean
View sourceChecks whether a component constructor has been registered.
This is a lookup only: it derives the constructor’s TypeId and
does not add an entry when the type is missing.
hasId(id: number): boolean
View sourceChecks whether a component ID is within the store’s current ID range.
The check uses only the numeric bounds 0 <= id < getInfos().length; it
does not read or validate the entry at that index.
get<T>(type: Constructor<T>): ComponentInfo
View sourceLooks up ComponentInfo metadata by a component constructor.
The constructor is converted to its TypeId. Missing types are not
registered and return undefined.
getById(id: number): ComponentInfo
View sourceLooks up ComponentInfo metadata by component ID.
getByTypeId(typeId: TypeId): ComponentInfo
View sourceLooks up ComponentInfo metadata by an explicit component
TypeId.
getId<T>(type: Constructor<T>): number
View sourceLooks up a component ID by constructor without registering the type.
getIdByTypeId(id: TypeId): number
View sourceLooks up a component ID by explicit TypeId without registering
the type.
getOrSet<T>(component: Constructor<T>): number
View sourceReturns the existing component ID or registers a constructor when missing.
The constructor is converted to a TypeId. This is equivalent to
calling TypeStore#set; both preserve an existing registration.
getOrSetByTypeId(typeId: TypeId): number
View sourceReturns the existing component ID or registers a TypeId when
missing.
A missing TypeId is registered with
TypeStore#setByTypeId; an existing TypeId keeps its
current ID and metadata.
getInfos(): Iterable<ComponentInfo, any, any>
View sourceReturns the component metadata records in component-ID order.
The returned value is the store’s live backing array, not a snapshot.
Entries are ComponentInfo values, so their
ComponentInfo#getHooks method exposes the associated
ComponentHooks.
