koota 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -210,7 +210,7 @@ const dwarf = world.spawn(Desires(gold));
210
210
 
211
211
  const constainsSilver = world.query(Contains(silver)); // Returns [inventory]
212
212
  const containsAnything = world.query(Contains('*')); // Returns [inventory, chest]
213
- const relatesToGold = world.query(Widlcard(gold)); // Returns [inventory, chest, dwarf]
213
+ const relatesToGold = world.query(Wildcard(gold)); // Returns [inventory, chest, dwarf]
214
214
  ```
215
215
 
216
216
  ### Query modifiers
@@ -594,7 +594,7 @@ var cachedSet = /* @__PURE__ */ new Set();
594
594
  var cachedQueue = [];
595
595
  function destroyEntity(world, entity) {
596
596
  const ctx = world[$internal];
597
- if (!world.has(entity)) return;
597
+ if (!world.has(entity)) throw new Error("Koota: The entity being destroyed does not exist.");
598
598
  const entityQueue = cachedQueue;
599
599
  const processedEntities = cachedSet;
600
600
  entityQueue.length = 0;
package/dist/index.cjs CHANGED
@@ -629,7 +629,7 @@ var cachedSet = /* @__PURE__ */ new Set();
629
629
  var cachedQueue = [];
630
630
  function destroyEntity(world, entity) {
631
631
  const ctx = world[$internal];
632
- if (!world.has(entity)) return;
632
+ if (!world.has(entity)) throw new Error("Koota: The entity being destroyed does not exist.");
633
633
  const entityQueue = cachedQueue;
634
634
  const processedEntities = cachedSet;
635
635
  entityQueue.length = 0;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import { S as Schema, T as Trait, N as Norm, M as ModifierData, W as World, Q as QueryParameter, R as Relation, a as RelationTarget } from './world-nBQgHwIP.cjs';
2
- export { $ as $internal, A as AoSFactory, C as ConfigurableTrait, k as Entity, i as ExtractIsTag, E as ExtractSchema, h as ExtractStore, j as ExtractStores, q as InstancesFromParameters, r as IsNotModifier, I as IsTag, l as QueryModifier, o as QueryResult, n as QueryResultOptions, m as QuerySubscriber, g as Store, p as StoresFromParameters, f as TraitInstance, e as TraitTuple, b as TraitType, d as TraitValue, c as createWorld } from './world-nBQgHwIP.cjs';
3
- import 'src';
1
+ import { S as Schema, T as Trait, N as Norm, M as ModifierData, W as World, Q as QueryParameter, R as Relation, a as RelationTarget } from './world-B-pehncS.cjs';
2
+ export { $ as $internal, A as AoSFactory, C as ConfigurableTrait, k as Entity, i as ExtractIsTag, E as ExtractSchema, h as ExtractStore, j as ExtractStores, q as InstancesFromParameters, r as IsNotModifier, I as IsTag, l as QueryModifier, o as QueryResult, n as QueryResultOptions, m as QuerySubscriber, g as Store, p as StoresFromParameters, f as TraitInstance, e as TraitTuple, b as TraitType, d as TraitValue, c as createWorld } from './world-B-pehncS.cjs';
4
3
 
5
4
  declare function defineTrait<S extends Schema = {}>(schema?: S): Trait<Norm<S>>;
6
5
  declare const trait: typeof defineTrait;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { S as Schema, T as Trait, N as Norm, M as ModifierData, W as World, Q as QueryParameter, R as Relation, a as RelationTarget } from './world-nBQgHwIP.js';
2
- export { $ as $internal, A as AoSFactory, C as ConfigurableTrait, k as Entity, i as ExtractIsTag, E as ExtractSchema, h as ExtractStore, j as ExtractStores, q as InstancesFromParameters, r as IsNotModifier, I as IsTag, l as QueryModifier, o as QueryResult, n as QueryResultOptions, m as QuerySubscriber, g as Store, p as StoresFromParameters, f as TraitInstance, e as TraitTuple, b as TraitType, d as TraitValue, c as createWorld } from './world-nBQgHwIP.js';
3
- import 'src';
1
+ import { S as Schema, T as Trait, N as Norm, M as ModifierData, W as World, Q as QueryParameter, R as Relation, a as RelationTarget } from './world-B-pehncS.js';
2
+ export { $ as $internal, A as AoSFactory, C as ConfigurableTrait, k as Entity, i as ExtractIsTag, E as ExtractSchema, h as ExtractStore, j as ExtractStores, q as InstancesFromParameters, r as IsNotModifier, I as IsTag, l as QueryModifier, o as QueryResult, n as QueryResultOptions, m as QuerySubscriber, g as Store, p as StoresFromParameters, f as TraitInstance, e as TraitTuple, b as TraitType, d as TraitValue, c as createWorld } from './world-B-pehncS.js';
4
3
 
5
4
  declare function defineTrait<S extends Schema = {}>(schema?: S): Trait<Norm<S>>;
6
5
  declare const trait: typeof defineTrait;
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  relation,
12
12
  trait,
13
13
  universe
14
- } from "./chunk-XN4M3U5V.js";
14
+ } from "./chunk-5UTSDPRH.js";
15
15
  export {
16
16
  $internal,
17
17
  Not,
package/dist/react.cjs CHANGED
@@ -51,7 +51,7 @@ var WorldContext = (0, import_react.createContext)(null);
51
51
  // ../react/src/world/use-world.ts
52
52
  function useWorld() {
53
53
  const world = (0, import_react2.useContext)(WorldContext);
54
- if (!world) throw new Error("Koota ECS: Hooks can only be used within the World component!");
54
+ if (!world) throw new Error("Koota: Hooks can only be used within the World component!");
55
55
  return world;
56
56
  }
57
57
 
@@ -95,14 +95,23 @@ function WorldProvider({ children, world }) {
95
95
  }
96
96
 
97
97
  // ../react/src/actions/create-actions.ts
98
+ var actionCache = /* @__PURE__ */ new WeakMap();
98
99
  function createActions(actionSet) {
100
+ const getMemoizedActions = (world) => {
101
+ let actions = actionCache.get(world);
102
+ if (!actions) {
103
+ actions = actionSet(world);
104
+ actionCache.set(world, actions);
105
+ }
106
+ return actions;
107
+ };
99
108
  return Object.assign(
100
109
  () => {
101
110
  const world = useWorld();
102
- return actionSet(world);
111
+ return getMemoizedActions(world);
103
112
  },
104
113
  {
105
- get: (world) => actionSet(world)
114
+ get: (world) => getMemoizedActions(world)
106
115
  }
107
116
  );
108
117
  }
@@ -680,7 +689,7 @@ var cachedSet = /* @__PURE__ */ new Set();
680
689
  var cachedQueue = [];
681
690
  function destroyEntity(world, entity) {
682
691
  const ctx = world[$internal];
683
- if (!world.has(entity)) return;
692
+ if (!world.has(entity)) throw new Error("Koota: The entity being destroyed does not exist.");
684
693
  const entityQueue = cachedQueue;
685
694
  const processedEntities = cachedSet;
686
695
  entityQueue.length = 0;
package/dist/react.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import { Q as QueryParameter, o as QueryResult, W as World, T as Trait, k as Entity, f as TraitInstance } from './world-nBQgHwIP.cjs';
1
+ import { Q as QueryParameter, o as QueryResult, W as World, T as Trait, k as Entity, f as TraitInstance } from './world-B-pehncS.cjs';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
- import 'src';
4
3
 
5
4
  declare function useQuery<T extends QueryParameter[]>(...parameters: T): QueryResult<T>;
6
5
 
package/dist/react.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Q as QueryParameter, o as QueryResult, W as World, T as Trait, k as Entity, f as TraitInstance } from './world-nBQgHwIP.js';
1
+ import { Q as QueryParameter, o as QueryResult, W as World, T as Trait, k as Entity, f as TraitInstance } from './world-B-pehncS.js';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
- import 'src';
4
3
 
5
4
  declare function useQuery<T extends QueryParameter[]>(...parameters: T): QueryResult<T>;
6
5
 
package/dist/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  $internal
3
- } from "./chunk-XN4M3U5V.js";
3
+ } from "./chunk-5UTSDPRH.js";
4
4
 
5
5
  // ../react/src/hooks/use-query.ts
6
6
  import { useEffect, useMemo, useReducer } from "react";
@@ -15,7 +15,7 @@ var WorldContext = createContext(null);
15
15
  // ../react/src/world/use-world.ts
16
16
  function useWorld() {
17
17
  const world = useContext(WorldContext);
18
- if (!world) throw new Error("Koota ECS: Hooks can only be used within the World component!");
18
+ if (!world) throw new Error("Koota: Hooks can only be used within the World component!");
19
19
  return world;
20
20
  }
21
21
 
@@ -59,14 +59,23 @@ function WorldProvider({ children, world }) {
59
59
  }
60
60
 
61
61
  // ../react/src/actions/create-actions.ts
62
+ var actionCache = /* @__PURE__ */ new WeakMap();
62
63
  function createActions(actionSet) {
64
+ const getMemoizedActions = (world) => {
65
+ let actions = actionCache.get(world);
66
+ if (!actions) {
67
+ actions = actionSet(world);
68
+ actionCache.set(world, actions);
69
+ }
70
+ return actions;
71
+ };
63
72
  return Object.assign(
64
73
  () => {
65
74
  const world = useWorld();
66
- return actionSet(world);
75
+ return getMemoizedActions(world);
67
76
  },
68
77
  {
69
- get: (world) => actionSet(world)
78
+ get: (world) => getMemoizedActions(world)
70
79
  }
71
80
  );
72
81
  }
@@ -1,5 +1,3 @@
1
- import * as src from 'src';
2
-
3
1
  declare const $internal: unique symbol;
4
2
 
5
3
  type RelationTarget = number | string;
@@ -127,7 +125,7 @@ type QuerySubscriber = (entity: Entity) => void;
127
125
  type QueryResultOptions = {
128
126
  changeDetection?: boolean;
129
127
  };
130
- type QueryResult<T extends QueryParameter[]> = readonly Entity[] & {
128
+ type QueryResult<T extends QueryParameter[] = QueryParameter[]> = readonly Entity[] & {
131
129
  updateEach: (callback: (state: InstancesFromParameters<T>, entity: Entity, index: number) => void, options?: QueryResultOptions) => QueryResult<T>;
132
130
  useStores: (callback: (stores: StoresFromParameters<T>, entities: readonly Entity[]) => void) => QueryResult<T>;
133
131
  select<U extends QueryParameter[]>(...params: U): QueryResult<U>;
@@ -219,7 +217,7 @@ declare class World {
219
217
  has(trait: Trait): boolean;
220
218
  add(...traits: ConfigurableTrait[]): void;
221
219
  remove(...traits: Trait[]): void;
222
- get<T extends Trait>(trait: T): src.TraitInstance<ExtractSchema<T>>;
220
+ get<T extends Trait>(trait: T): TraitInstance<ExtractSchema<T>>;
223
221
  set<T extends Trait>(trait: T, value: TraitValue<ExtractSchema<T>>): void;
224
222
  destroy(): void;
225
223
  reset(): void;
@@ -1,5 +1,3 @@
1
- import * as src from 'src';
2
-
3
1
  declare const $internal: unique symbol;
4
2
 
5
3
  type RelationTarget = number | string;
@@ -127,7 +125,7 @@ type QuerySubscriber = (entity: Entity) => void;
127
125
  type QueryResultOptions = {
128
126
  changeDetection?: boolean;
129
127
  };
130
- type QueryResult<T extends QueryParameter[]> = readonly Entity[] & {
128
+ type QueryResult<T extends QueryParameter[] = QueryParameter[]> = readonly Entity[] & {
131
129
  updateEach: (callback: (state: InstancesFromParameters<T>, entity: Entity, index: number) => void, options?: QueryResultOptions) => QueryResult<T>;
132
130
  useStores: (callback: (stores: StoresFromParameters<T>, entities: readonly Entity[]) => void) => QueryResult<T>;
133
131
  select<U extends QueryParameter[]>(...params: U): QueryResult<U>;
@@ -219,7 +217,7 @@ declare class World {
219
217
  has(trait: Trait): boolean;
220
218
  add(...traits: ConfigurableTrait[]): void;
221
219
  remove(...traits: Trait[]): void;
222
- get<T extends Trait>(trait: T): src.TraitInstance<ExtractSchema<T>>;
220
+ get<T extends Trait>(trait: T): TraitInstance<ExtractSchema<T>>;
223
221
  set<T extends Trait>(trait: T, value: TraitValue<ExtractSchema<T>>): void;
224
222
  destroy(): void;
225
223
  reset(): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koota",
3
- "version": "0.1.1",
4
- "description": "🌎 Performant data-oriented state management for React and TypeScript.",
3
+ "version": "0.1.3",
4
+ "description": "🌎 Performant real-time state management for React and TypeScript",
5
5
  "license": "ISC",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
package/react/index.cjs CHANGED
@@ -51,7 +51,7 @@ var WorldContext = (0, import_react.createContext)(null);
51
51
  // ../react/src/world/use-world.ts
52
52
  function useWorld() {
53
53
  const world = (0, import_react2.useContext)(WorldContext);
54
- if (!world) throw new Error("Koota ECS: Hooks can only be used within the World component!");
54
+ if (!world) throw new Error("Koota: Hooks can only be used within the World component!");
55
55
  return world;
56
56
  }
57
57
 
@@ -95,14 +95,23 @@ function WorldProvider({ children, world }) {
95
95
  }
96
96
 
97
97
  // ../react/src/actions/create-actions.ts
98
+ var actionCache = /* @__PURE__ */ new WeakMap();
98
99
  function createActions(actionSet) {
100
+ const getMemoizedActions = (world) => {
101
+ let actions = actionCache.get(world);
102
+ if (!actions) {
103
+ actions = actionSet(world);
104
+ actionCache.set(world, actions);
105
+ }
106
+ return actions;
107
+ };
99
108
  return Object.assign(
100
109
  () => {
101
110
  const world = useWorld();
102
- return actionSet(world);
111
+ return getMemoizedActions(world);
103
112
  },
104
113
  {
105
- get: (world) => actionSet(world)
114
+ get: (world) => getMemoizedActions(world)
106
115
  }
107
116
  );
108
117
  }
@@ -680,7 +689,7 @@ var cachedSet = /* @__PURE__ */ new Set();
680
689
  var cachedQueue = [];
681
690
  function destroyEntity(world, entity) {
682
691
  const ctx = world[$internal];
683
- if (!world.has(entity)) return;
692
+ if (!world.has(entity)) throw new Error("Koota: The entity being destroyed does not exist.");
684
693
  const entityQueue = cachedQueue;
685
694
  const processedEntities = cachedSet;
686
695
  entityQueue.length = 0;
package/react/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import { Q as QueryParameter, o as QueryResult, W as World, T as Trait, k as Entity, f as TraitInstance } from './world-nBQgHwIP.cjs';
1
+ import { Q as QueryParameter, o as QueryResult, W as World, T as Trait, k as Entity, f as TraitInstance } from './world-B-pehncS.cjs';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
- import 'src';
4
3
 
5
4
  declare function useQuery<T extends QueryParameter[]>(...parameters: T): QueryResult<T>;
6
5
 
package/react/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Q as QueryParameter, o as QueryResult, W as World, T as Trait, k as Entity, f as TraitInstance } from './world-nBQgHwIP.js';
1
+ import { Q as QueryParameter, o as QueryResult, W as World, T as Trait, k as Entity, f as TraitInstance } from './world-B-pehncS.js';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
- import 'src';
4
3
 
5
4
  declare function useQuery<T extends QueryParameter[]>(...parameters: T): QueryResult<T>;
6
5
 
package/react/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  $internal
3
- } from "./chunk-XN4M3U5V.js";
3
+ } from "./chunk-5UTSDPRH.js";
4
4
 
5
5
  // ../react/src/hooks/use-query.ts
6
6
  import { useEffect, useMemo, useReducer } from "react";
@@ -15,7 +15,7 @@ var WorldContext = createContext(null);
15
15
  // ../react/src/world/use-world.ts
16
16
  function useWorld() {
17
17
  const world = useContext(WorldContext);
18
- if (!world) throw new Error("Koota ECS: Hooks can only be used within the World component!");
18
+ if (!world) throw new Error("Koota: Hooks can only be used within the World component!");
19
19
  return world;
20
20
  }
21
21
 
@@ -59,14 +59,23 @@ function WorldProvider({ children, world }) {
59
59
  }
60
60
 
61
61
  // ../react/src/actions/create-actions.ts
62
+ var actionCache = /* @__PURE__ */ new WeakMap();
62
63
  function createActions(actionSet) {
64
+ const getMemoizedActions = (world) => {
65
+ let actions = actionCache.get(world);
66
+ if (!actions) {
67
+ actions = actionSet(world);
68
+ actionCache.set(world, actions);
69
+ }
70
+ return actions;
71
+ };
63
72
  return Object.assign(
64
73
  () => {
65
74
  const world = useWorld();
66
- return actionSet(world);
75
+ return getMemoizedActions(world);
67
76
  },
68
77
  {
69
- get: (world) => actionSet(world)
78
+ get: (world) => getMemoizedActions(world)
70
79
  }
71
80
  );
72
81
  }
@@ -12,13 +12,15 @@ type Relation<T> = T & {
12
12
 
13
13
  type IsEmpty<T> = T extends Record<string, never> ? true : false;
14
14
 
15
+ type TraitType = 'aos' | 'soa';
16
+ type TraitValue<TSchema extends Schema> = TSchema extends AoSFactory ? ReturnType<TSchema> : Partial<TraitInstance<TSchema>>;
15
17
  type Trait<TSchema extends Schema = any, TStore = Store<TSchema>, TTag extends boolean = IsEmpty<TSchema>> = {
16
18
  schema: TSchema;
17
19
  [$internal]: {
18
- set: (index: number, store: TStore, values: Partial<TraitInstanceFromSchema<TSchema>>) => void;
19
- fastSet: (index: number, store: TStore, values: Partial<TraitInstanceFromSchema<TSchema>>) => void;
20
- fastSetWithChangeDetection: (index: number, store: TStore, values: Partial<TraitInstanceFromSchema<TSchema>>) => boolean;
21
- get: (index: number, store: TStore) => TraitInstanceFromSchema<TSchema>;
20
+ set: (index: number, store: any, value: TraitValue<TSchema>) => void;
21
+ fastSet: (index: number, store: any, value: TraitValue<TSchema>) => boolean;
22
+ fastSetWithChangeDetection: (index: number, store: any, value: TraitValue<TSchema>) => boolean;
23
+ get: (index: number, store: any) => TraitInstance<TSchema>;
22
24
  stores: TStore[];
23
25
  id: number;
24
26
  createStore: () => TStore;
@@ -26,31 +28,34 @@ type Trait<TSchema extends Schema = any, TStore = Store<TSchema>, TTag extends b
26
28
  relation: Relation<any> | null;
27
29
  pairTarget: RelationTarget | null;
28
30
  isTag: TTag;
31
+ type: TraitType;
29
32
  };
30
- } & ((params: Partial<TraitInstanceFromSchema<TSchema>>) => [Trait<TSchema, TStore>, Partial<TSchema>]);
33
+ } & ((params?: TraitValue<TSchema>) => [Trait<TSchema, TStore, TTag>, TraitValue<TSchema>]);
31
34
  type TraitTuple<T extends Trait = Trait> = [
32
35
  T,
33
- T extends Trait<infer S, any> ? Partial<TraitInstanceFromSchema<S>> : never
36
+ T extends Trait<infer S, any> ? S extends AoSFactory ? ReturnType<S> : Partial<TraitInstance<S>> : never
34
37
  ];
35
38
  type ConfigurableTrait<T extends Trait = Trait> = T | TraitTuple<T>;
36
- type TraitInstanceFromSchema<T extends Schema> = {
37
- [P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]> : T[P];
38
- };
39
- type TraitInstance<T extends Trait> = {
39
+ type TraitInstanceFromTrait<T extends Trait> = T['schema'] extends AoSFactory ? ReturnType<T['schema']> : {
40
40
  [P in keyof T['schema']]: T['schema'][P] extends (...args: any[]) => any ? ReturnType<T['schema'][P]> : T['schema'][P];
41
41
  };
42
+ type TraitInstanceFromSchema<T extends Schema> = T extends AoSFactory ? ReturnType<T> : {
43
+ [P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]> : T[P];
44
+ };
45
+ type TraitInstance<T extends Trait | Schema> = T extends Trait ? TraitInstanceFromTrait<T> : TraitInstanceFromSchema<T>;
42
46
  type Schema = {
43
47
  [key: string]: number | string | boolean | any[] | object | null | undefined;
44
- };
45
- type Store<T extends Schema = any> = {
48
+ } | AoSFactory;
49
+ type AoSFactory = () => Record<string, any>;
50
+ type Store<T extends Schema = any> = T extends AoSFactory ? ReturnType<T>[] : {
46
51
  [P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]>[] : T[P][];
47
52
  };
48
- type Norm<T extends Schema> = {
53
+ type Norm<T extends Schema> = T extends AoSFactory ? () => ReturnType<T> extends number ? number : ReturnType<T> extends boolean ? boolean : ReturnType<T> extends string ? string : ReturnType<T> : {
49
54
  [K in keyof T]: T[K] extends boolean ? boolean : T[K];
50
55
  };
51
- type TraitSnapshot<T extends Trait> = T extends Trait<infer S, any> ? TraitInstanceFromSchema<S> : never;
52
56
  type ExtractSchema<T extends Trait> = T extends Trait<infer S, any> ? S : never;
53
57
  type ExtractStore<T extends Trait> = T extends Trait<any, infer S> ? S : never;
58
+ type ExtractIsTag<T extends Trait> = T extends Trait<any, any, infer Tag> ? Tag : false;
54
59
  type ExtractStores<T extends [Trait, ...Trait[]]> = T extends [infer C] ? C extends Trait<any, Store<any>> ? ExtractStore<C> : never : {
55
60
  [K in keyof T]: ExtractStore<T[K]>;
56
61
  };
@@ -62,8 +67,8 @@ type Entity = number & {
62
67
  has: (trait: Trait) => boolean;
63
68
  destroy: () => void;
64
69
  changed: (trait: Trait) => void;
65
- set: <T extends Trait>(trait: T, value: Partial<TraitInstanceFromSchema<ExtractSchema<T>>>, flagChanged?: boolean) => void;
66
- get: <T extends Trait>(trait: T) => TraitInstanceFromSchema<ExtractSchema<T>>;
70
+ set: <T extends Trait>(trait: T, value: TraitValue<ExtractSchema<T>>, flagChanged?: boolean) => void;
71
+ get: <T extends Trait>(trait: T) => TraitInstance<ExtractSchema<T>>;
67
72
  targetFor: <T>(relation: Relation<T>) => Entity | undefined;
68
73
  targetsFor: <T>(relation: Relation<T>) => Entity[];
69
74
  id: () => number;
@@ -82,6 +87,18 @@ type EntityIndex = {
82
87
  worldId: number;
83
88
  };
84
89
 
90
+ declare class TraitData<T extends Trait = Trait, S extends Schema = ExtractSchema<T>> {
91
+ generationId: number;
92
+ bitflag: number;
93
+ trait: Trait;
94
+ store: Store<S>;
95
+ queries: Set<Query>;
96
+ notQueries: Set<Query>;
97
+ schema: S;
98
+ changedSubscriptions: Set<(entity: Entity) => void>;
99
+ constructor(world: World, trait: T);
100
+ }
101
+
85
102
  declare class SparseSet {
86
103
  #private;
87
104
  has(val: number): boolean;
@@ -106,10 +123,10 @@ type QueryModifier = (...components: Trait[]) => ModifierData;
106
123
  type QueryParameter = Trait | ReturnType<QueryModifier>;
107
124
  type QuerySubscriber = (entity: Entity) => void;
108
125
  type QueryResultOptions = {
109
- passive?: boolean;
126
+ changeDetection?: boolean;
110
127
  };
111
- type QueryResult<T extends QueryParameter[]> = readonly Entity[] & {
112
- updateEach: (callback: (state: SnapshotFromParameters<T>, entity: Entity, index: number) => void, options?: QueryResultOptions) => QueryResult<T>;
128
+ type QueryResult<T extends QueryParameter[] = QueryParameter[]> = readonly Entity[] & {
129
+ updateEach: (callback: (state: InstancesFromParameters<T>, entity: Entity, index: number) => void, options?: QueryResultOptions) => QueryResult<T>;
113
130
  useStores: (callback: (stores: StoresFromParameters<T>, entities: readonly Entity[]) => void) => QueryResult<T>;
114
131
  select<U extends QueryParameter[]>(...params: U): QueryResult<U>;
115
132
  };
@@ -118,12 +135,12 @@ type StoresFromParameters<T extends QueryParameter[]> = T extends [infer First,
118
135
  ...(First extends Trait ? [ExtractStore<First>] : First extends ModifierData<any> ? StoresFromParameters<UnwrapModifierData<First>> : []),
119
136
  ...(Rest extends QueryParameter[] ? StoresFromParameters<Rest> : [])
120
137
  ] : [];
121
- type SnapshotFromParameters<T extends QueryParameter[]> = T extends [
138
+ type InstancesFromParameters<T extends QueryParameter[]> = T extends [
122
139
  infer First,
123
140
  ...infer Rest
124
141
  ] ? [
125
- ...(First extends Trait ? IsTag<First> extends false ? [TraitSnapshot<First>] : [] : First extends ModifierData<any> ? IsNotModifier<First> extends true ? [] : SnapshotFromParameters<UnwrapModifierData<First>> : []),
126
- ...(Rest extends QueryParameter[] ? SnapshotFromParameters<Rest> : [])
142
+ ...(First extends Trait ? IsTag<First> extends false ? ExtractSchema<First> extends AoSFactory ? [ReturnType<ExtractSchema<First>>] : [TraitInstance<First>] : [] : First extends ModifierData<any> ? IsNotModifier<First> extends true ? [] : InstancesFromParameters<UnwrapModifierData<First>> : []),
143
+ ...(Rest extends QueryParameter[] ? InstancesFromParameters<Rest> : [])
127
144
  ] : [];
128
145
  type IsNotModifier<T> = T extends ModifierData<any, infer TType> ? TType extends 'not' ? true : false : false;
129
146
 
@@ -171,18 +188,6 @@ declare class Query {
171
188
  resetTrackingBitmasks(eid: number): void;
172
189
  }
173
190
 
174
- declare class TraitData<T extends Trait = Trait, S extends Schema = ExtractSchema<T>> {
175
- generationId: number;
176
- bitflag: number;
177
- trait: Trait;
178
- store: Store<S>;
179
- queries: Set<Query>;
180
- notQueries: Set<Query>;
181
- schema: S;
182
- changedSubscriptions: Set<(entity: Entity) => void>;
183
- constructor(world: World, trait: T);
184
- }
185
-
186
191
  declare class World {
187
192
  #private;
188
193
  [$internal]: {
@@ -212,8 +217,8 @@ declare class World {
212
217
  has(trait: Trait): boolean;
213
218
  add(...traits: ConfigurableTrait[]): void;
214
219
  remove(...traits: Trait[]): void;
215
- get<T extends Trait>(trait: T): TraitInstanceFromSchema<ExtractSchema<T>>;
216
- set<T extends Trait>(trait: T, value: Partial<TraitInstanceFromSchema<ExtractSchema<T>>>): void;
220
+ get<T extends Trait>(trait: T): TraitInstance<ExtractSchema<T>>;
221
+ set<T extends Trait>(trait: T, value: TraitValue<ExtractSchema<T>>): void;
217
222
  destroy(): void;
218
223
  reset(): void;
219
224
  query<T extends QueryParameter[]>(key: string): QueryResult<T>;
@@ -226,4 +231,4 @@ declare class World {
226
231
  }
227
232
  declare function createWorld(...traits: ConfigurableTrait[]): World;
228
233
 
229
- export { $internal as $, type ConfigurableTrait as C, type ExtractSchema as E, type IsTag as I, ModifierData as M, type Norm as N, type QueryParameter as Q, type Relation as R, type Schema as S, type Trait as T, World as W, type RelationTarget as a, type TraitTuple as b, createWorld as c, type TraitInstanceFromSchema as d, type TraitInstance as e, type Store as f, type TraitSnapshot as g, type ExtractStore as h, type ExtractStores as i, type Entity as j, type QueryModifier as k, type QuerySubscriber as l, type QueryResultOptions as m, type QueryResult as n, type StoresFromParameters as o, type SnapshotFromParameters as p, type IsNotModifier as q };
234
+ export { $internal as $, type AoSFactory as A, type ConfigurableTrait as C, type ExtractSchema as E, type IsTag as I, ModifierData as M, type Norm as N, type QueryParameter as Q, type Relation as R, type Schema as S, type Trait as T, World as W, type RelationTarget as a, type TraitType as b, createWorld as c, type TraitValue as d, type TraitTuple as e, type TraitInstance as f, type Store as g, type ExtractStore as h, type ExtractIsTag as i, type ExtractStores as j, type Entity as k, type QueryModifier as l, type QuerySubscriber as m, type QueryResultOptions as n, type QueryResult as o, type StoresFromParameters as p, type InstancesFromParameters as q, type IsNotModifier as r };
@@ -12,13 +12,15 @@ type Relation<T> = T & {
12
12
 
13
13
  type IsEmpty<T> = T extends Record<string, never> ? true : false;
14
14
 
15
+ type TraitType = 'aos' | 'soa';
16
+ type TraitValue<TSchema extends Schema> = TSchema extends AoSFactory ? ReturnType<TSchema> : Partial<TraitInstance<TSchema>>;
15
17
  type Trait<TSchema extends Schema = any, TStore = Store<TSchema>, TTag extends boolean = IsEmpty<TSchema>> = {
16
18
  schema: TSchema;
17
19
  [$internal]: {
18
- set: (index: number, store: TStore, values: Partial<TraitInstanceFromSchema<TSchema>>) => void;
19
- fastSet: (index: number, store: TStore, values: Partial<TraitInstanceFromSchema<TSchema>>) => void;
20
- fastSetWithChangeDetection: (index: number, store: TStore, values: Partial<TraitInstanceFromSchema<TSchema>>) => boolean;
21
- get: (index: number, store: TStore) => TraitInstanceFromSchema<TSchema>;
20
+ set: (index: number, store: any, value: TraitValue<TSchema>) => void;
21
+ fastSet: (index: number, store: any, value: TraitValue<TSchema>) => boolean;
22
+ fastSetWithChangeDetection: (index: number, store: any, value: TraitValue<TSchema>) => boolean;
23
+ get: (index: number, store: any) => TraitInstance<TSchema>;
22
24
  stores: TStore[];
23
25
  id: number;
24
26
  createStore: () => TStore;
@@ -26,31 +28,34 @@ type Trait<TSchema extends Schema = any, TStore = Store<TSchema>, TTag extends b
26
28
  relation: Relation<any> | null;
27
29
  pairTarget: RelationTarget | null;
28
30
  isTag: TTag;
31
+ type: TraitType;
29
32
  };
30
- } & ((params: Partial<TraitInstanceFromSchema<TSchema>>) => [Trait<TSchema, TStore>, Partial<TSchema>]);
33
+ } & ((params?: TraitValue<TSchema>) => [Trait<TSchema, TStore, TTag>, TraitValue<TSchema>]);
31
34
  type TraitTuple<T extends Trait = Trait> = [
32
35
  T,
33
- T extends Trait<infer S, any> ? Partial<TraitInstanceFromSchema<S>> : never
36
+ T extends Trait<infer S, any> ? S extends AoSFactory ? ReturnType<S> : Partial<TraitInstance<S>> : never
34
37
  ];
35
38
  type ConfigurableTrait<T extends Trait = Trait> = T | TraitTuple<T>;
36
- type TraitInstanceFromSchema<T extends Schema> = {
37
- [P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]> : T[P];
38
- };
39
- type TraitInstance<T extends Trait> = {
39
+ type TraitInstanceFromTrait<T extends Trait> = T['schema'] extends AoSFactory ? ReturnType<T['schema']> : {
40
40
  [P in keyof T['schema']]: T['schema'][P] extends (...args: any[]) => any ? ReturnType<T['schema'][P]> : T['schema'][P];
41
41
  };
42
+ type TraitInstanceFromSchema<T extends Schema> = T extends AoSFactory ? ReturnType<T> : {
43
+ [P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]> : T[P];
44
+ };
45
+ type TraitInstance<T extends Trait | Schema> = T extends Trait ? TraitInstanceFromTrait<T> : TraitInstanceFromSchema<T>;
42
46
  type Schema = {
43
47
  [key: string]: number | string | boolean | any[] | object | null | undefined;
44
- };
45
- type Store<T extends Schema = any> = {
48
+ } | AoSFactory;
49
+ type AoSFactory = () => Record<string, any>;
50
+ type Store<T extends Schema = any> = T extends AoSFactory ? ReturnType<T>[] : {
46
51
  [P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]>[] : T[P][];
47
52
  };
48
- type Norm<T extends Schema> = {
53
+ type Norm<T extends Schema> = T extends AoSFactory ? () => ReturnType<T> extends number ? number : ReturnType<T> extends boolean ? boolean : ReturnType<T> extends string ? string : ReturnType<T> : {
49
54
  [K in keyof T]: T[K] extends boolean ? boolean : T[K];
50
55
  };
51
- type TraitSnapshot<T extends Trait> = T extends Trait<infer S, any> ? TraitInstanceFromSchema<S> : never;
52
56
  type ExtractSchema<T extends Trait> = T extends Trait<infer S, any> ? S : never;
53
57
  type ExtractStore<T extends Trait> = T extends Trait<any, infer S> ? S : never;
58
+ type ExtractIsTag<T extends Trait> = T extends Trait<any, any, infer Tag> ? Tag : false;
54
59
  type ExtractStores<T extends [Trait, ...Trait[]]> = T extends [infer C] ? C extends Trait<any, Store<any>> ? ExtractStore<C> : never : {
55
60
  [K in keyof T]: ExtractStore<T[K]>;
56
61
  };
@@ -62,8 +67,8 @@ type Entity = number & {
62
67
  has: (trait: Trait) => boolean;
63
68
  destroy: () => void;
64
69
  changed: (trait: Trait) => void;
65
- set: <T extends Trait>(trait: T, value: Partial<TraitInstanceFromSchema<ExtractSchema<T>>>, flagChanged?: boolean) => void;
66
- get: <T extends Trait>(trait: T) => TraitInstanceFromSchema<ExtractSchema<T>>;
70
+ set: <T extends Trait>(trait: T, value: TraitValue<ExtractSchema<T>>, flagChanged?: boolean) => void;
71
+ get: <T extends Trait>(trait: T) => TraitInstance<ExtractSchema<T>>;
67
72
  targetFor: <T>(relation: Relation<T>) => Entity | undefined;
68
73
  targetsFor: <T>(relation: Relation<T>) => Entity[];
69
74
  id: () => number;
@@ -82,6 +87,18 @@ type EntityIndex = {
82
87
  worldId: number;
83
88
  };
84
89
 
90
+ declare class TraitData<T extends Trait = Trait, S extends Schema = ExtractSchema<T>> {
91
+ generationId: number;
92
+ bitflag: number;
93
+ trait: Trait;
94
+ store: Store<S>;
95
+ queries: Set<Query>;
96
+ notQueries: Set<Query>;
97
+ schema: S;
98
+ changedSubscriptions: Set<(entity: Entity) => void>;
99
+ constructor(world: World, trait: T);
100
+ }
101
+
85
102
  declare class SparseSet {
86
103
  #private;
87
104
  has(val: number): boolean;
@@ -106,10 +123,10 @@ type QueryModifier = (...components: Trait[]) => ModifierData;
106
123
  type QueryParameter = Trait | ReturnType<QueryModifier>;
107
124
  type QuerySubscriber = (entity: Entity) => void;
108
125
  type QueryResultOptions = {
109
- passive?: boolean;
126
+ changeDetection?: boolean;
110
127
  };
111
- type QueryResult<T extends QueryParameter[]> = readonly Entity[] & {
112
- updateEach: (callback: (state: SnapshotFromParameters<T>, entity: Entity, index: number) => void, options?: QueryResultOptions) => QueryResult<T>;
128
+ type QueryResult<T extends QueryParameter[] = QueryParameter[]> = readonly Entity[] & {
129
+ updateEach: (callback: (state: InstancesFromParameters<T>, entity: Entity, index: number) => void, options?: QueryResultOptions) => QueryResult<T>;
113
130
  useStores: (callback: (stores: StoresFromParameters<T>, entities: readonly Entity[]) => void) => QueryResult<T>;
114
131
  select<U extends QueryParameter[]>(...params: U): QueryResult<U>;
115
132
  };
@@ -118,12 +135,12 @@ type StoresFromParameters<T extends QueryParameter[]> = T extends [infer First,
118
135
  ...(First extends Trait ? [ExtractStore<First>] : First extends ModifierData<any> ? StoresFromParameters<UnwrapModifierData<First>> : []),
119
136
  ...(Rest extends QueryParameter[] ? StoresFromParameters<Rest> : [])
120
137
  ] : [];
121
- type SnapshotFromParameters<T extends QueryParameter[]> = T extends [
138
+ type InstancesFromParameters<T extends QueryParameter[]> = T extends [
122
139
  infer First,
123
140
  ...infer Rest
124
141
  ] ? [
125
- ...(First extends Trait ? IsTag<First> extends false ? [TraitSnapshot<First>] : [] : First extends ModifierData<any> ? IsNotModifier<First> extends true ? [] : SnapshotFromParameters<UnwrapModifierData<First>> : []),
126
- ...(Rest extends QueryParameter[] ? SnapshotFromParameters<Rest> : [])
142
+ ...(First extends Trait ? IsTag<First> extends false ? ExtractSchema<First> extends AoSFactory ? [ReturnType<ExtractSchema<First>>] : [TraitInstance<First>] : [] : First extends ModifierData<any> ? IsNotModifier<First> extends true ? [] : InstancesFromParameters<UnwrapModifierData<First>> : []),
143
+ ...(Rest extends QueryParameter[] ? InstancesFromParameters<Rest> : [])
127
144
  ] : [];
128
145
  type IsNotModifier<T> = T extends ModifierData<any, infer TType> ? TType extends 'not' ? true : false : false;
129
146
 
@@ -171,18 +188,6 @@ declare class Query {
171
188
  resetTrackingBitmasks(eid: number): void;
172
189
  }
173
190
 
174
- declare class TraitData<T extends Trait = Trait, S extends Schema = ExtractSchema<T>> {
175
- generationId: number;
176
- bitflag: number;
177
- trait: Trait;
178
- store: Store<S>;
179
- queries: Set<Query>;
180
- notQueries: Set<Query>;
181
- schema: S;
182
- changedSubscriptions: Set<(entity: Entity) => void>;
183
- constructor(world: World, trait: T);
184
- }
185
-
186
191
  declare class World {
187
192
  #private;
188
193
  [$internal]: {
@@ -212,8 +217,8 @@ declare class World {
212
217
  has(trait: Trait): boolean;
213
218
  add(...traits: ConfigurableTrait[]): void;
214
219
  remove(...traits: Trait[]): void;
215
- get<T extends Trait>(trait: T): TraitInstanceFromSchema<ExtractSchema<T>>;
216
- set<T extends Trait>(trait: T, value: Partial<TraitInstanceFromSchema<ExtractSchema<T>>>): void;
220
+ get<T extends Trait>(trait: T): TraitInstance<ExtractSchema<T>>;
221
+ set<T extends Trait>(trait: T, value: TraitValue<ExtractSchema<T>>): void;
217
222
  destroy(): void;
218
223
  reset(): void;
219
224
  query<T extends QueryParameter[]>(key: string): QueryResult<T>;
@@ -226,4 +231,4 @@ declare class World {
226
231
  }
227
232
  declare function createWorld(...traits: ConfigurableTrait[]): World;
228
233
 
229
- export { $internal as $, type ConfigurableTrait as C, type ExtractSchema as E, type IsTag as I, ModifierData as M, type Norm as N, type QueryParameter as Q, type Relation as R, type Schema as S, type Trait as T, World as W, type RelationTarget as a, type TraitTuple as b, createWorld as c, type TraitInstanceFromSchema as d, type TraitInstance as e, type Store as f, type TraitSnapshot as g, type ExtractStore as h, type ExtractStores as i, type Entity as j, type QueryModifier as k, type QuerySubscriber as l, type QueryResultOptions as m, type QueryResult as n, type StoresFromParameters as o, type SnapshotFromParameters as p, type IsNotModifier as q };
234
+ export { $internal as $, type AoSFactory as A, type ConfigurableTrait as C, type ExtractSchema as E, type IsTag as I, ModifierData as M, type Norm as N, type QueryParameter as Q, type Relation as R, type Schema as S, type Trait as T, World as W, type RelationTarget as a, type TraitType as b, createWorld as c, type TraitValue as d, type TraitTuple as e, type TraitInstance as f, type Store as g, type ExtractStore as h, type ExtractIsTag as i, type ExtractStores as j, type Entity as k, type QueryModifier as l, type QuerySubscriber as m, type QueryResultOptions as n, type QueryResult as o, type StoresFromParameters as p, type InstancesFromParameters as q, type IsNotModifier as r };
@@ -1,17 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __typeError = (msg) => {
3
- throw TypeError(msg);
4
- };
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
8
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
-
12
- export {
13
- __publicField,
14
- __privateGet,
15
- __privateAdd,
16
- __privateSet
17
- };