diff --git a/packages/ecs/src/api.ts b/packages/ecs/src/api.ts index 1bb3e41943..e5bff42272 100644 --- a/packages/ecs/src/api.ts +++ b/packages/ecs/src/api.ts @@ -6,6 +6,7 @@ import type { IID, INotify, IRelease, + Maybe, Type, TypedArray, UIntArray, @@ -44,9 +45,9 @@ export interface IComponent has(id: number): boolean; add(id: number, val?: SET): boolean; delete(id: number): boolean; - get(id: number): GET | undefined; + get(id: number): Maybe; set(i: number, val: SET): boolean; - getIndex(i: number): GET | undefined; + getIndex(i: number): Maybe; setIndex(i: number, val: SET): boolean; setIndexUnsafe(i: number, val: SET, notify?: boolean): void; @@ -89,7 +90,7 @@ export interface GroupOpts { export interface ICache extends IClear, IRelease { keys(): Iterable; set(key: number, val: T): T; - get(key: number): T | undefined; + get(key: number): Maybe; getSet(key: number, notFound: Fn0): T; delete(key: number): boolean; } diff --git a/packages/ecs/src/caches/null.ts b/packages/ecs/src/caches/null.ts index c7b2385f59..02888eff49 100644 --- a/packages/ecs/src/caches/null.ts +++ b/packages/ecs/src/caches/null.ts @@ -1,4 +1,4 @@ -import type { Fn0 } from "@thi.ng/api"; +import type { Fn0, Maybe } from "@thi.ng/api"; import type { ICache } from "../api.js"; export class NullCache implements ICache { @@ -14,7 +14,7 @@ export class NullCache implements ICache { return val; } - get(_: number): T | undefined { + get(_: number): Maybe { return; } diff --git a/packages/ecs/src/caches/unbounded.ts b/packages/ecs/src/caches/unbounded.ts index 3b4b8eebdd..0c7111eb8c 100644 --- a/packages/ecs/src/caches/unbounded.ts +++ b/packages/ecs/src/caches/unbounded.ts @@ -1,4 +1,4 @@ -import type { Fn0 } from "@thi.ng/api"; +import type { Fn0, Maybe } from "@thi.ng/api"; import type { ICache } from "../api.js"; export class UnboundedCache implements ICache { @@ -26,7 +26,7 @@ export class UnboundedCache implements ICache { return val; } - get(key: number): T | undefined { + get(key: number): Maybe { return this.index.get(key); } diff --git a/packages/ecs/src/components/acomponent.ts b/packages/ecs/src/components/acomponent.ts index 8fe11ea36b..1e91eaad29 100644 --- a/packages/ecs/src/components/acomponent.ts +++ b/packages/ecs/src/components/acomponent.ts @@ -1,4 +1,11 @@ -import type { Event, IID, INotify, Listener, UIntArray } from "@thi.ng/api"; +import type { + Event, + IID, + INotify, + Listener, + Maybe, + UIntArray, +} from "@thi.ng/api"; import { INotifyMixin } from "@thi.ng/api/mixins/inotify"; import { isFunction } from "@thi.ng/checks/is-function"; import type { IMemPoolArray } from "@thi.ng/malloc"; @@ -52,9 +59,9 @@ export abstract class AComponent return i < this.n && this.dense[i] === id; } - abstract get(id: number): GET | undefined; + abstract get(id: number): Maybe; - abstract getIndex(i: number): GET | undefined; + abstract getIndex(i: number): Maybe; valueIndexForID(id: number) { const i = this.sparse[id]; diff --git a/packages/ecs/src/ecs.ts b/packages/ecs/src/ecs.ts index c223a697bf..2831ca3c64 100644 --- a/packages/ecs/src/ecs.ts +++ b/packages/ecs/src/ecs.ts @@ -1,4 +1,4 @@ -import type { Event, INotify, Listener } from "@thi.ng/api"; +import type { Event, INotify, Listener, Maybe } from "@thi.ng/api"; import { INotifyMixin } from "@thi.ng/api/mixins/inotify"; import { uintTypeForSize } from "@thi.ng/api/typedarray"; import { bitSize } from "@thi.ng/binary/count"; @@ -70,10 +70,10 @@ export class ECS implements INotify { defComponent>( opts: MemMappedComponentOpts - ): MemMappedComponent | undefined; + ): Maybe>; defComponent>( opts: ObjectComponentOpts - ): ObjectComponent | undefined; + ): Maybe>; defComponent>(opts: any) { assert( !this.components.has(opts.id),