import { ComponentConstructor } from "./Component"; import { Entity } from "./Entity"; export interface EntityView { entities: T[]; onEntityAdded?: (entity: T) => void; onEntityRemoved?: (entity: T) => void; components: ComponentConstructor[]; _isEntityView: boolean; }; interface EntityViewInitializator { components: compsT; onEntityAdded?: Function onEntityRemoved?: Function; } export class EntityViewFactory { static createView: createEntityViewFunc = ((data: EntityViewInitializator): EntityView => { const view = { entities: [], components: data.components, onEntityAdded: data.onEntityAdded, onEntityRemoved: data.onEntityRemoved, _isEntityView: true } return view; }) as any; } type NonFunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T]; type NonFunctionProperties = Pick>; type ComponentOf = NonFunctionProperties; type createEntityViewFunc = (data: EntityViewInitializator>) => EntityView<(ComponentOf & ComponentOf & ComponentOf & ComponentOf & ComponentOf & ComponentOf & ComponentOf & ComponentOf & ComponentOf & ComponentOf & NonFunctionProperties)> ; type ComponentsInitList = Partial<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]> | { length: any } & { '0'?: T1; '1'?: T2; '2'?: T3; '3'?: T4; '4'?: T5; '5'?: T6; '6'?: T7; '7'?: T8; '8'?: T9; '9'?: T10; }