ecspresso
Version:
A minimal Entity-Component-System library for typescript and javascript.
30 lines (29 loc) • 1.17 kB
TypeScript
import type ECSpresso from 'ecspresso';
/**
* React context for providing the ECS instance to the component tree.
* Wrap your UI root with `<EcsContext.Provider value={ecs}>`.
*/
declare const EcsContext: import("react").Context<ECSpresso<any, string, string, string, string> | null>;
export { EcsContext };
/**
* Creates typed hooks bound to a specific world config.
*
* Call once at module scope with your world type, then use the
* returned hooks in components anywhere under the `EcsContext.Provider`.
*
* @example
* ```tsx
* const ecs = ECSpresso.create()
* .withResourceTypes<{ score: number; health: number }>()
* .withEventTypes<{ enemyKilled: { id: number } }>()
* .build();
*
* type ECS = typeof ecs;
* const { useResource, useEvent, useEcs } = createEcsHooks<ECS>();
* ```
*/
export declare function createEcsHooks<W extends ECSpresso<any>>(): {
readonly useEcs: () => W;
readonly useResource: <K extends keyof W["_cfg"]["resources"] & string>(key: K) => W["_cfg"]["resources"][K];
readonly useEvent: <E extends keyof W["_cfg"]["events"] & string>(type: E, callback: (data: W["_cfg"]["events"][E]) => void) => void;
};