react-encompass-ecs
Version:
Sync data from encompass-ecs to React
32 lines (31 loc) • 1.44 kB
TypeScript
import React, { Context } from 'react';
import { Component, Entity, Type } from 'encompass-ecs';
export interface IEntityMap {
[name: string]: Entity;
}
export interface IEntityResultMap {
[name: string]: {
[id: number]: Entity;
};
}
export declare const GameEntitiesContext: React.Context<IEntityMap>;
/**
* Select entity with provided components, return components inside entity
* ```js
* const { box } = useComponents({ box: [PositionComponent] });
* const position = box ? box[0] : { x: 20, y: 20 };
* ```
* Above example return singleton component inside box, if you warp some component in array, it will return an array of that type of components (not supported now due to my TypeScript knowledge limitation)
*
* @param {boolean} [forceRender=false] reRender component on draw tick, only enable this when update you component 60 times per second is not costly
*/
export declare function useComponent<TComponent extends Component, T extends Type<TComponent>>(descriptions: {
[name: string]: Array<Type<TComponent>>;
}, forceRender?: boolean, context?: Context<IEntityMap>): {
[name: string]: Array<Array</* T extends Array<Type<TComponent>> ? GCOptimizedList<Readonly<TComponent>> : */ Readonly<TComponent>>>;
};
export declare function Provider(props: {
children: React.ReactNode;
entities: IEntityMap;
context?: Context<IEntityMap>;
}): JSX.Element;