/* eslint-disable @typescript-eslint/no-explicit-any */ import type { Entity, EntityDataRegistry, EntityRegistry } from './'; import type { AbleRegistry } from './able'; // import type { Layer } from './layer'; import { ABLES_DECO_KEY, ENTITIES_DECO_KEY, HANDLE_DECO_KEY, PAYLOAD_DECO_KEY, createRegistryDecorator, RegistryValueGetter } from './playground-decorator-helper'; export function able(registry: AbleRegistry): any { const getValue: RegistryValueGetter = (target: any) => ( target.entityBindedList.getEntitiesByAble(registry) ); return createRegistryDecorator(ABLES_DECO_KEY, [registry], getValue); } /** * @param andAbles - 多个able,条件且 * @param orAbles - 多个able,条件或 */ export function ables(andAbles: AbleRegistry[], orAbles: AbleRegistry[] = []): any { const getValue: RegistryValueGetter = (target: any) => ( target.entityBindedList.getEntitiesByAbles(andAbles, orAbles) ); return createRegistryDecorator(ABLES_DECO_KEY, andAbles.concat(orAbles), getValue); } export function entity(registry: EntityRegistry): any { const getValue: RegistryValueGetter = (target: any) => ( target.entityBindedList.get(registry)! ); return createRegistryDecorator(ENTITIES_DECO_KEY, registry, getValue); } export function entities(registry: EntityRegistry): any { const getValue: RegistryValueGetter = (target: any) => ( target.entityBindedList.getEntities(registry) ); return createRegistryDecorator(ENTITIES_DECO_KEY, registry, getValue); } export function payload(payloadKey: string | Symbol): any { const check = (target: any, method: string) => { if (method !== 'payload') throw new Error(`@payload() should be used by "payload" method but get "${method}".`); }; return createRegistryDecorator(PAYLOAD_DECO_KEY, payloadKey, undefined, check); } export function params(...registries: EntityDataRegistry[]): any { const check = (target: any, method: string) => { if (method !== 'handle') throw new Error(`@params() should be used by "handle" method but get "${method}".`); }; return createRegistryDecorator(HANDLE_DECO_KEY, registries, undefined, check); }