ecsjs 1.0.0-beta.8 → 1.0.0

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
@@ -10,54 +10,65 @@ An entity component system library for JavaScript
10
10
 
11
11
  ## Install
12
12
 
13
- ### NPM
14
- - Install: `npm install --save ecsjs`
13
+ `npm install --save ecsjs`
15
14
 
16
- ## Usage
15
+ ## Documentation
17
16
 
18
- [Examples](http://ecsjs.gitlab.io/ecs-examples/)
17
+ - [Reference Documentation](https://ecsjs.gitlab.io/ecs)
19
18
 
20
- ### Browser Module
19
+ ## Examples
21
20
 
22
- ```js
23
- import {ecs} from './some-path/ecs.js'
24
-
25
- class PositionComponent {
26
- constructor(x, y) {
27
- this.x = x
28
- this.y = y
29
- }
30
- }
21
+ - [Classic Asteroids](https://gitlab.com/ecsjs/example-astroids)
22
+ - [Classic Kung Fu](https://gitlab.com/ecsjs/example-kungfu)
23
+ - [Misc Examples](https://gitlab.com/ecsjs/ecs-examples)
31
24
 
32
- // register a component
33
- ecs.register(PositionComponent)
34
-
35
- // create an entity
36
- const entityId = ecs.getNextId()
37
- ecs.set(entityId, new PositionComponent(25, 25))
38
- ```
39
-
40
- ### Browser
25
+ #### Browser
41
26
 
42
27
  ```html
43
28
  <script type="application/javascript" src="./some-path/ecs.js"></script>
44
29
  <script>
45
- class PositionComponent {
30
+ // define a component
31
+ class Position {
46
32
  constructor(x, y) {
47
33
  this.x = x
48
34
  this.y = y
49
35
  }
50
36
  }
51
37
 
52
- // register a component
53
- ecs.register(PositionComponent)
38
+ // register the component
39
+ ecs.register(Position)
54
40
 
55
41
  // create an entity
56
42
  const entityId = ecs.getNextId()
57
- ecs.set(entityId, new PositionComponent(25, 25))
43
+
44
+ // add or update the entity data
45
+ ecs.set(entityId, new Position(25, 25))
58
46
  </script>
59
47
  ```
60
48
 
49
+ #### Module import
50
+ ```js
51
+ import { ecs } from 'ecsjs'
52
+
53
+ // define a component
54
+ class Position {
55
+ constructor(x, y) {
56
+ this.x = x
57
+ this.y = y
58
+ }
59
+ }
60
+
61
+ // register the component
62
+ ecs.register(Position)
63
+
64
+ // create an entity
65
+ const entityId = ecs.getNextId()
66
+
67
+ // add or update the entity data
68
+ ecs.set(entityId, new Position(25, 25))
69
+ ```
70
+
71
+
61
72
  ## License
62
73
 
63
74
  Licensed under GNU GPL v3
package/dist/ecs.js CHANGED
@@ -1,2 +1,2 @@
1
- var a=class extends Map{constructor(e=[]){super(e)}firstEntry(){return this.size===0?void 0:this.entries().next().value}firstKey(){return this.size===0?void 0:this.keys().next().value}firstValue(){return this.size===0?void 0:this.values().next().value}toJSON(){return{__KeyMap__:1,iterable:[...this.entries()]}}toTable(e=!1){let t=[];for(let[n,r]of this.entries()){let o=r,s={};e==!1&&(s["entity.key"]=n),s["entity.type"]=o.constructor.name,t.push({...s,...o})}return t}printTable(e=!1){console.table(this.toTable(e))}entries(){return super.entries().filter(e=>e!=null)}keys(){return super.keys().filter(e=>e!=null)}values(){return super.values().filter(e=>e!=null)}static get[Symbol.species](){return Map}};var p=class i{componentMaps=new a;nextId=0;constructor(){}register(...e){for(let t of e){let n=t.name;if(n===void 0)throw new ReferenceError("The component class does not have a name defined. i.e. a constructor name");let r=new a;this.componentMaps.set(n,r)}return this}getMap(e){return this.componentMaps.get(e.name)}firstEntry(e){return this.getMap(e)?.firstEntry()}firstKey(e){return this.getMap(e)?.firstKey()}firstValue(e){return this.getMap(e)?.firstValue()}get(e,t){let n=this.componentMaps.get(t.name);if(n===void 0)throw new ReferenceError(`"${t}" component class does not exist in the componentMaps`);return n.get(e)}getValues(e,...t){return t.map(n=>this.get(e,n))}getByKey(e,t){let n=this.componentMaps.get(t);if(n===void 0)throw new ReferenceError(`"${t}" component does not exist in the componentMaps`);return n.get(e)}has(e,t){let n=this.componentMaps.get(t.name);return n===void 0?!1:n.has(e)}set(e,t){let n=this.componentMaps.get(t.constructor.name);if(n===void 0)throw new ReferenceError(`Component map does not exist using the name: ${t.constructor.name}`);return n.set(e,t),t}setValues(e,...t){return t.map(n=>this.set(e,n))}remove(e,...t){for(let n of t)this.removeByKey(e,n.name)}removeByKey(e,t){let n=this.componentMaps.get(t);if(n===void 0)throw new ReferenceError(`A registered entity map does not exist for the given key: ${t}`);return n.get(e)===void 0?!1:n.delete(e)}destroyEntity(e){for(let t of this.componentMaps.values())t.has(e)&&t.delete(e)}getNextId(){return this.nextId++,this.nextId}clear(){return this.componentMaps.clear(),this}printTable(){return this.componentMaps.forEach(e=>console.table(e.toTable(!0))),this}printEntity(e){for(let t of this.componentMaps.values()){if(t.has(e)===!1)continue;let n=t.get(e),r={name:n.constructor.name,...n};console.table({[e]:r})}return this}static parse(e){let t=new i,n=JSON.parse(e,function(r,o){return o.hasOwnProperty("componentMaps")?(Reflect.setPrototypeOf(o,i.prototype),o):o.hasOwnProperty("__KeyMap__")?new a(o.iterable):this[r]});return t.componentMaps=n.componentMaps,t.nextId=n.nextId,t}static createWithTracing(e){let t={get(n,r){let o=n[r];return typeof o=="function"&&(e.length===0||e.includes(r))?function(...s){return console.groupCollapsed("ecs trace",r,s),console.trace(),console.groupEnd(),o.apply(this,s)}:o}};return new Proxy(new i,t)}};var u=new p;typeof window<"u"?window.ecs=u:typeof module<"u"&&module!==null&&(module.exports={ecs:u});export{u as ecs};
1
+ var C="ComponentMap",c="ComponentClassesMap";var i=class extends Map{constructor(e=[]){super(e)}firstEntry(){return this.size===0?void 0:this.entries().next().value}firstKey(){return this.size===0?void 0:this.keys().next().value}firstValue(){return this.size===0?void 0:this.values().next().value}toJSON(){return{[C]:1,iterable:[...this.entries()]}}toTable(e=!1){let n=[];for(let[t,o]of this.entries()){let s=o,r={};e==!1&&(r["entity.key"]=t),r["entity.type"]=s.constructor.name,n.push({...r,...s})}return n}printTable(e=!1){console.table(this.toTable(e))}entries(){return super.entries().filter(e=>e!=null)}keys(){return super.keys().filter(e=>e!=null)}values(){return super.values().filter(e=>e!=null)}},m=class extends Map{constructor(e=[]){super(e)}toJSON(){return{[c]:1,iterable:[...this.entries()]}}};var y=class extends Error{constructor(){super("Component type is missing the 'name' parameter. i.e. a constructor name")}},p=class extends Error{constructor(n){super(`Component map does not exist for '${n}'`);this.componentName=n}};var u=class{constructor(e,n,...t){this.ecs=e;this.key=n;this.keyMap=this.ecs.getMap(n),this.entries=this.keyMap.entries(),this.components=t.map(o=>this.ecs.getMap(o))}keyMap;components;entries;next(){let e=this.entries.next(),{value:n,done:t}=e;if(t)return{value:n,done:t};let[o,s]=n,r=[o,s];for(let d of this.components)r.push(d.get(o));return{value:r,done:!1}}reset(){this.entries=this.keyMap.entries()}[Symbol.iterator](){return this}};var l=class a{components=new m;nextId=0;register(...e){for(let n of e){let t=n.name;if(t===void 0)throw new y;let o=new i;this.components.set(t,o)}return this}getMap(e){let n=this.components.get(e.name);if(n===void 0)throw new p(e.name);return n}firstEntry(e){return this.getMap(e)?.firstEntry()}firstKey(e,...n){let t=this.getMap(e)?.firstKey();if(arguments.length===1)return t;if(t!==void 0)return[t,...n.map(o=>this.getEntity(t,o))]}firstValue(e,...n){if(arguments.length===1)return this.getMap(e)?.firstValue();let[t,o]=this.getMap(e)?.firstEntry()??[];if(t!==void 0)return[o,...n.map(s=>this.getEntity(t,s))]}getEntity(e,n){let t=this.components.get(n.name);if(t===void 0)throw new p(n.name);return t.get(e)}get(e,...n){return n.length>1?n.map(t=>this.getEntity(e,t)):this.getEntity(e,n[0])}has(e,n){let t=this.components.get(n.name);return t===void 0?!1:t.has(e)}setEntity(e,n){let t=this.components.get(n.constructor.name);if(t===void 0)throw new p(n.constructor.name);return t.set(e,n),n}set(e,...n){return n.length>1?n.map(t=>this.setEntity(e,t)):this.setEntity(e,n[0])}remove(e,...n){for(let t of n)this.removeByKey(e,t.name)}removeByKey(e,n){let t=this.components.get(n);if(t===void 0)throw new p(n);return t.get(e)===void 0?!1:t.delete(e)}destroyEntity(...e){for(let n=0;n<e.length;n++){let t=e[n];for(let o of this.components.values())o.has(t)&&o.delete(t)}}getNextId(){return this.nextId++,this.nextId}clear(){return this.components.clear(),this}clearComponents(){return this.components.forEach(e=>e.clear()),this}iterator(e,...n){return new u(this,e,...n)}printTable(){return this.components.forEach(e=>console.table(e.toTable(!0))),this}printEntity(e){for(let n of this.components.values()){if(n.has(e)===!1)continue;let t=n.get(e),o={name:t.constructor.name,...t};console.table({[e]:o})}return this}static parse(e){return JSON.parse(e,function(t,o){return o.hasOwnProperty("components")?(Reflect.setPrototypeOf(o,a.prototype),o):o.hasOwnProperty(C)?new i(o.iterable):o.hasOwnProperty(c)?new m(o.iterable):this[t]})}static createWithTracing(e){let n={get(t,o){let s=t[o];return typeof s=="function"&&(e.length===0||e.includes(o))?function(...r){return console.groupCollapsed("ecs trace",o,r),console.trace(),console.groupEnd(),s.apply(this,r)}:s}};return new Proxy(new a,n)}};var f=new l;typeof window<"u"?window.ecs=f:typeof module<"u"&&module!==null&&(module.exports={ecs:f});export{m as ComponentClassesMap,u as ComponentIterator,i as ComponentMap,l as EntityMap,f as ecs};
2
2
  //# sourceMappingURL=ecs.js.map
package/dist/ecs.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/key-map.ts", "../src/entity-map.ts", "../src/ecs.ts"],
4
- "sourcesContent": ["/*\n ecsjs is an entity component system library for JavaScript\n Copyright (C) 2014 Peter Flannery\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU Affero General Public License as\n published by the Free Software Foundation, either version 3 of the\n License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Affero General Public License for more details.\n\n You should have received a copy of the GNU Affero General Public License\n along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport type { KeyCollection } from './definitions.js';\n\n/**\n * Class for storing keys and values\n */\nexport class KeyMap<TKey, TValue> extends Map<TKey, TValue> {\n\n constructor(entries: any[] = []) {\n super(entries)\n }\n\n firstEntry(): [key: TKey, value: TValue] | undefined {\n if (this.size === 0) return undefined;\n\n const iterator = this.entries();\n const result = iterator.next();\n return result.value;\n }\n\n firstKey(): TKey | undefined {\n if (this.size === 0) return undefined;\n\n const iterator = this.keys();\n const result = iterator.next();\n return result.value;\n }\n\n firstValue(): TValue | undefined {\n if (this.size === 0) return undefined;\n\n const iterator = this.values();\n const result = iterator.next();\n return result.value;\n }\n\n toJSON() {\n return { __KeyMap__: 1, iterable: [...this.entries()] }\n }\n\n toTable(excludeKeys = false): any[] {\n const table = []\n for (const [key, value] of this.entries()) {\n const entity = value as { new(): TValue }\n const meta: KeyCollection<any> = {}\n if (excludeKeys == false) meta[\"entity.key\"] = key\n meta[\"entity.type\"] = entity.constructor.name\n table.push({ ...meta, ...entity })\n }\n return table\n }\n\n /**\n * Outputs keys and values in a tabular format to the console\n */\n printTable(excludeKeys = false): void {\n console.table(this.toTable(excludeKeys))\n }\n\n entries(): MapIterator<[TKey, TValue]> {\n return super.entries().filter(x => x !== undefined && x !== null)\n }\n\n keys(): MapIterator<TKey> {\n return super.keys().filter(x => x !== undefined && x !== null)\n }\n\n values(): MapIterator<TValue> {\n return super.values().filter(x => x !== undefined && x !== null)\n }\n\n static get [Symbol.species]() { return Map; }\n\n}", "/*\n ecsjs is an entity component system library for JavaScript\n Copyright (C) 2014 Peter Flannery\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU Affero General Public License as\n published by the Free Software Foundation, either version 3 of the\n License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Affero General Public License for more details.\n\n You should have received a copy of the GNU Affero General Public License\n along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\n/**\n * @module ecsjs\n */\nimport {\n type ComponentClass,\n type ComponentDataMap,\n type ComponentMap,\n type IComponent\n} from './definitions.js';\nimport { KeyMap } from './key-map.js';\n\n/**\n * Class for storing entities and their relationships\n * \n * @class EntityMap\n */\nexport class EntityMap {\n\n // entity class maps\n private componentMaps: ComponentMap = new KeyMap()\n\n private nextId: number = 0\n\n constructor() { }\n\n /**\n * Registers a component class\n * \n * @example\n *\n * ```javascript\n * // component class\n * class MyComponent {\n * constructor(x) {\n * this.x = x;\n * }\n * }\n *\n * ecs.register(MyComponent);\n * // or\n * ecs.register(MyComponent1, MyComponent2);\n * ```\n */\n register(...component: ComponentClass<any>[]) {\n for (const definition of component) {\n const componentName = definition.name;\n if (componentName === undefined)\n throw new ReferenceError(\"The component class does not have a name defined. i.e. a constructor name\");\n\n // create the component map\n const componentDataMap: ComponentDataMap<any> = new KeyMap();\n this.componentMaps.set(componentName, componentDataMap);\n }\n\n // chain\n return this;\n }\n\n /**\n * Retrieves an entity map by it's registered type\n */\n getMap<T>(component: ComponentClass<T>): ComponentDataMap<T> | undefined {\n return this.componentMaps.get(component.name);\n }\n\n /**\n * Get the first entity entry for a component class\n * \n * @example\n *\n * ```javascript\n * const [entityId, player] = ecs.firstEntry(PlayerComponent) ?? [];\n * ```\n */\n firstEntry<T>(component: ComponentClass<T>) {\n return this.getMap(component)?.firstEntry();\n }\n\n /**\n * Get the first entity id for a component class\n * \n * @example\n *\n * ```javascript\n * const entityId = ecs.firstKey(PlayerComponent);\n * ```\n */\n firstKey<T>(component: ComponentClass<T>) {\n return this.getMap(component)?.firstKey();\n }\n\n /**\n * Get the first entity component value for a component class\n * \n * @example\n *\n * ```javascript\n * const player = ecs.firstValue(PlayerComponent);\n * ```\n */\n firstValue<T>(component: ComponentClass<T>) {\n return this.getMap(component)?.firstValue();\n }\n\n /**\n * Retrieves an entity from its registered entity map\n *\n * @example\n *\n * ```javascript\n * // get an entity\n * let positionData = ecs.get(entityId, Components.PositionComponent);\n * ```\n */\n get<T>(entityId: number, component: ComponentClass<T>): T {\n const map = this.componentMaps.get(component.name);\n if (map === undefined)\n throw new ReferenceError(`\"${component}\" component class does not exist in the componentMaps`);\n\n return map.get(entityId);\n }\n\n /**\n * Get multiple component values related to an entity\n * \n * @param entityId\n * @param components: ComponentClass<any>[]\n * \n * @example\n *\n * ```javascript\n * // get an entity\n * const [player, position] = ecs.getValues(entityId, PlayerComponent, PositionComponent);\n * ```\n */\n getValues<T1, T2, T3, T4, T5, T6, T7, T8>(\n entityId: number,\n c1: ComponentClass<T1>,\n c2: ComponentClass<T2>,\n c3?: ComponentClass<T3>,\n c4?: ComponentClass<T4>,\n c5?: ComponentClass<T5>,\n c6?: ComponentClass<T6>,\n c7?: ComponentClass<T7>,\n c8?: ComponentClass<T8>\n ): [T1, T2, T3, T4, T5, T6, T7, T8];\n getValues<T>(entityId: number, ...components: ComponentClass<T>[]): T[] {\n return components.map(x => this.get(entityId, x))\n }\n\n /**\n * Retrieves an entity from its registered entity map\n *\n * @example\n *\n * ```javascript\n * // get an entity\n * let positionData = ecs.getByKey(entityId, \"PositionComponent\");\n * ```\n */\n getByKey(entityId: number, componentName: string) {\n // get the component map\n let map = this.componentMaps.get(componentName);\n if (map === undefined)\n throw new ReferenceError(`\"${componentName}\" component does not exist in the componentMaps`);\n\n return map.get(entityId);\n }\n\n /**\n * Checks if the entity exists in it's registed component map\n * The entity type must be registered before calling this method\n * \n * @example\n *\n * ```javascript\n * // get an entity\n * let exists = ecs.has(entityId, PositionComponent);\n * ```\n */\n has<T>(entityId: number, component: ComponentClass<T>): boolean {\n // get the component map\n let map = this.componentMaps.get(component.name);\n if (map === undefined) return false\n\n return map.has(entityId);\n }\n\n /**\n * Adds or updates an entity to it's registered entity map\n *\n * @example\n *\n * ```javascript\n * // add/update an entity\n * let playerPos = ecs.set(entityId, new Components.PositionComponent(0, 0));\n * ```\n */\n set<T extends IComponent>(entityId: number, componentData: T): T {\n // get the component map\n let map = this.componentMaps.get(componentData.constructor.name);\n if (map === undefined)\n throw new ReferenceError(\n `Component map does not exist using the name: ${componentData.constructor.name}`\n );\n\n // set the entity on the entity map\n map.set(entityId, componentData);\n\n // return instance\n return componentData;\n }\n\n /**\n * Set multiple component values for an entity\n * \n * @param entityId\n * @param components: ComponentClass<any>[]\n * \n * @example\n *\n * ```javascript\n * // write the component values to the entity\n * ecs.setValues(entityId, new PlayerComponent(), new PositionComponent());\n * ```\n */\n setValues<T extends IComponent[]>(entityId: number, ...args: [...T]): [...T];\n setValues(entityId: number, ...components: IComponent[]): IComponent[] {\n return components.map(x => this.set(entityId, x))\n }\n\n /**\n * Removes an entity from its entity map.\n * Removes any related Node entities that are mapped to the entity\n * \n * @example\n *\n * ```javascript\n * // remove an entity from its entity map\n * EntityMap.remove(entityId, Components.PositionComponent);\n * ```\n */\n remove<T>(entityId: number, ...components: ComponentClass<T>[]) {\n for (const component of components) {\n this.removeByKey(entityId, component.name)\n }\n }\n\n /**\n * Removes an entity from its entity map.\n * Removes any related Node entities that are mapped to the entity\n * \n * @example\n *\n * ```javascript\n * // remove an entity from its entity map\n * EntityMap.removeByKey(entityId, \"PositionComponent\");\n * ```\n */\n removeByKey(entityId: number, componentName: string) {\n // get the entity map\n let entityMap = this.componentMaps.get(componentName);\n\n // ensure the map is defined\n if (entityMap === undefined)\n throw new ReferenceError(`A registered entity map does not exist for the given key: ${componentName}`);\n\n // get the entity\n let entity = entityMap.get(entityId);\n if (entity === undefined) return false;\n\n // remove the entity from the entity map\n return entityMap.delete(entityId);\n }\n\n /**\n * Destroys an entity across all component maps\n */\n destroyEntity(entityId: number) {\n for (const map of this.componentMaps.values()) {\n if (map.has(entityId)) map.delete(entityId);\n }\n }\n\n // TODO generate a non repeatable id for network play?\n getNextId() {\n this.nextId++;\n return this.nextId;\n }\n\n clear() {\n this.componentMaps.clear();\n return this;\n }\n\n /**\n * Prints all component maps in a tabular format to the console\n */\n printTable() {\n this.componentMaps.forEach(map => console.table(map.toTable(true)));\n return this;\n }\n\n /**\n * Prints an entity component data in tabular format to the console\n */\n printEntity(entityId: number) {\n for (const map of this.componentMaps.values()) {\n if (map.has(entityId) === false) continue;\n\n const data = map.get(entityId);\n const columns = {\n name: data.constructor.name,\n ...data\n };\n console.table({ [entityId]: columns });\n }\n\n return this;\n }\n\n /**\n * Parse's the JSON and returns an EntityMap object\n * \n * @example\n *\n * ```javascript\n * // remove an entity from its entity map\n * const json = JSON.stringfy(ecs);\n * const restoredMap = EntityMap.parse(json);\n * ```\n */\n static parse(json: string) {\n const ecs = new EntityMap();\n\n const restored = JSON.parse(json, function (key: string, value: any) {\n\n if (value.hasOwnProperty('componentMaps')) {\n Reflect.setPrototypeOf(value, EntityMap.prototype);\n return value;\n }\n\n if (value.hasOwnProperty('__KeyMap__')) {\n return new KeyMap(value.iterable);\n }\n\n return this[key];\n });\n\n ecs.componentMaps = restored.componentMaps;\n ecs.nextId = restored.nextId;\n return ecs;\n }\n\n /**\n * A tracing method used for debugging.\n * Intercepts all functions specified and logs each call to the console.\n * \n * @method createWithTracing\n * @static\n * @param {Array} funcFilter A list of function names you want to intercept. If no function names are specified then will log all functions called\n * @return {EntityMap} A new entity map with tracing enabled\n */\n static createWithTracing(funcFilter: any) {\n let traceHandler = {\n get(target: any, propKey: string) {\n const targetValue = target[propKey]\n\n if (typeof targetValue === 'function' && (funcFilter.length === 0 || funcFilter.includes(propKey))) {\n return function (this: any, ...args: any[]) {\n console.groupCollapsed('ecs trace', propKey, args);\n console.trace();\n console.groupEnd();\n return targetValue.apply(this, args);\n }\n }\n\n return targetValue;\n }\n }\n\n return new Proxy(new EntityMap(), traceHandler)\n }\n\n}", "/*\n ecsjs is an entity component system library for JavaScript\n Copyright (C) 2014 Peter Flannery\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU Affero General Public License as\n published by the Free Software Foundation, either version 3 of the\n License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Affero General Public License for more details.\n\n You should have received a copy of the GNU Affero General Public License\n along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\n/**\n * ### An entity component system library for JavaScript\n *\n * @module ecsjs\n * @main ecsjs\n */\nimport { EntityMap } from './entity-map.js'\n\nexport const ecs = new EntityMap()\n\nif (typeof window !== 'undefined') {\n // @ts-ignore: exports to window\n window.ecs = ecs\n} else if (typeof module !== 'undefined' && module !== null) {\n // exports to nodejs\n module.exports = { ecs };\n}"],
5
- "mappings": "AAsBO,IAAMA,EAAN,cAAmC,GAAkB,CAE1D,YAAYC,EAAiB,CAAC,EAAG,CAC/B,MAAMA,CAAO,CACf,CAEA,YAAqD,CACnD,OAAI,KAAK,OAAS,EAAG,OAEJ,KAAK,QAAQ,EACN,KAAK,EACf,KAChB,CAEA,UAA6B,CAC3B,OAAI,KAAK,OAAS,EAAG,OAEJ,KAAK,KAAK,EACH,KAAK,EACf,KAChB,CAEA,YAAiC,CAC/B,OAAI,KAAK,OAAS,EAAG,OAEJ,KAAK,OAAO,EACL,KAAK,EACf,KAChB,CAEA,QAAS,CACP,MAAO,CAAE,WAAY,EAAG,SAAU,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAE,CACxD,CAEA,QAAQC,EAAc,GAAc,CAClC,IAAMC,EAAQ,CAAC,EACf,OAAW,CAACC,EAAKC,CAAK,IAAK,KAAK,QAAQ,EAAG,CACzC,IAAMC,EAASD,EACTE,EAA2B,CAAC,EAC9BL,GAAe,KAAOK,EAAK,YAAY,EAAIH,GAC/CG,EAAK,aAAa,EAAID,EAAO,YAAY,KACzCH,EAAM,KAAK,CAAE,GAAGI,EAAM,GAAGD,CAAO,CAAC,CACnC,CACA,OAAOH,CACT,CAKA,WAAWD,EAAc,GAAa,CACpC,QAAQ,MAAM,KAAK,QAAQA,CAAW,CAAC,CACzC,CAEA,SAAuC,CACrC,OAAO,MAAM,QAAQ,EAAE,OAAOM,GAAwBA,GAAM,IAAI,CAClE,CAEA,MAA0B,CACxB,OAAO,MAAM,KAAK,EAAE,OAAOA,GAAwBA,GAAM,IAAI,CAC/D,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K,YAAY,KACvB,GAAGA,CACL,EACA,QAAQ,MAAM,CAAE,CAACN,CAAQ,EAAGO,CAAQ,CAAC,CACvC,CAEA,OAAO,IACT,CAaA,OAAO,MAAMC,EAAc,CACzB,IAAMC,EAAM,IAAIf,EAEVgB,EAAW,KAAK,MAAMF,EAAM,SAAUG,EAAaC,EAAY,CAEnE,OAAIA,EAAM,eAAe,eAAe,GACtC,QAAQ,eAAeA,EAAOlB,EAAU,SAAS,EAC1CkB,GAGLA,EAAM,eAAe,YAAY,EAC5B,IAAIjB,EAAOiB,EAAM,QAAQ,EAG3B,KAAKD,CAAG,CACjB,CAAC,EAED,OAAAF,EAAI,cAAgBC,EAAS,cAC7BD,EAAI,OAASC,EAAS,OACfD,CACT,CAWA,OAAO,kBAAkBI,EAAiB,CACxC,IAAIC,EAAe,CACjB,IAAIC,EAAaC,EAAiB,CAChC,IAAMC,EAAcF,EAAOC,CAAO,EAElC,OAAI,OAAOC,GAAgB,aAAeJ,EAAW,SAAW,GAAKA,EAAW,SAASG,CAAO,GACvF,YAAwBE,EAAa,CAC1C,eAAQ,eAAe,YAAaF,EAASE,CAAI,EACjD,QAAQ,MAAM,EACd,QAAQ,SAAS,EACVD,EAAY,MAAM,KAAMC,CAAI,CACrC,EAGKD,CACT,CACF,EAEA,OAAO,IAAI,MAAM,IAAIvB,EAAaoB,CAAY,CAChD,CAEF,ECxXO,IAAMK,EAAM,IAAIC,EAEnB,OAAO,OAAW,IAEpB,OAAO,IAAMD,EACJ,OAAO,OAAW,KAAe,SAAW,OAErD,OAAO,QAAU,CAAE,IAAAA,CAAI",
6
- "names": ["KeyMap", "entries", "excludeKeys", "table", "key", "value", "entity", "meta", "x", "EntityMap", "_EntityMap", "KeyMap", "component", "definition", "componentName", "componentDataMap", "entityId", "map", "components", "x", "componentData", "entityMap", "data", "columns", "json", "ecs", "restored", "key", "value", "funcFilter", "traceHandler", "target", "propKey", "targetValue", "args", "ecs", "EntityMap"]
3
+ "sources": ["../src/types.ts", "../src/component-map.ts", "../src/errors.ts", "../src/iterators.ts", "../src/entity-map.ts", "../src/ecs.ts"],
4
+ "sourcesContent": ["export const ComponentMapKey = \"ComponentMap\"\nexport const ComponentClassesMapKey = \"ComponentClassesMap\"\n\nexport type KeyCollection<T> = { [key: string]: T }\n\nexport interface Component { }\n\n/**\n * @category Types\n * @example\n * \n * class PositionComponent {\n * constructor(x, y) {\n * this.x = x;\n * this.y = y;\n * }\n * }\n */\nexport type ComponentClass<ComponentInstance> = new (...args: any[]) => ComponentInstance\n\n/**\n* Used for infering generic type spread for classes\n*/\nexport type ComponentClasses<TClasses extends Component[]> =\n { [Index in keyof TClasses]: TClasses[Index] }\n\n/**\n * Used for infering generic type spread for class instances\n */\nexport type ComponentInstances<TClasses extends ComponentClass<any>[]> =\n // return a single variadic item when only 1 item is specified\n TClasses['length'] extends 1 ? TClasses[0] extends ComponentClass<infer R> ? R : never\n // otherwise return an array of variadic types\n : {\n [Index in keyof TClasses]: TClasses[Index] extends ComponentClass<infer R> ? R : never\n }\n\nexport type IteratorResult<T> = {\n done: boolean,\n value: T\n}\n\nexport type Iterator<T> = {\n next: () => IteratorResult<T>\n reset: () => void\n [Symbol.iterator]: () => Iterator<T>\n}\n\n/**\n * @category Types\n * @description\n * allow late bound assignment type for intellisense\n * @example\n * \n * let someIterator: IComponentIterator<[Player, Position]>\n * \n * // assignment made somewhere else in the code\n * const [player, position] = someIterator(Player, Position) ?? []\n * position?.x = 123 // position will have intellisense\n */\nexport type IComponentIterator<T extends Component[]>\n = Iterator<ComponentClasses<[number, ...T]>>", "/*\n ecsjs is an entity component system library for JavaScript\n Copyright (C) 2014 Peter Flannery\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU Affero General Public License as\n published by the Free Software Foundation, either version 3 of the\n License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Affero General Public License for more details.\n\n You should have received a copy of the GNU Affero General Public License\n along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { ComponentClassesMapKey, ComponentMapKey, type KeyCollection } from './types.js';\n\n/**\n * @category Maps\n * @description Component map for storing entity ids and related component data\n */\nexport class ComponentMap<TComponentInstance> extends Map<number, TComponentInstance> {\n\n constructor(entries: [number, TComponentInstance][] = []) {\n super(entries);\n }\n\n /**\n * @description Returns the first entity entry\n */\n firstEntry(): [entityId: number, value: TComponentInstance] | undefined {\n if (this.size === 0) return undefined;\n\n const iterator = this.entries();\n const result = iterator.next();\n return result.value;\n }\n\n /**\n * @description Returns the first entity id\n */\n firstKey(): number | undefined {\n if (this.size === 0) return undefined;\n\n const iterator = this.keys();\n const result = iterator.next();\n return result.value;\n }\n\n /**\n * @description Returns the first entity value\n */\n firstValue(): TComponentInstance | undefined {\n if (this.size === 0) return undefined;\n\n const iterator = this.values();\n const result = iterator.next();\n return result.value;\n }\n\n /**\n * @description Called when using JSON.stringify\n */\n toJSON() {\n return { [ComponentMapKey]: 1, iterable: [...this.entries()] };\n }\n\n toTable(excludeKeys = false): any[] {\n const table = []\n for (const [key, value] of this.entries()) {\n const entity = value as { new(): TComponentInstance };\n const meta: KeyCollection<any> = {};\n if (excludeKeys == false) meta[\"entity.key\"] = key;\n meta[\"entity.type\"] = entity.constructor.name;\n table.push({ ...meta, ...entity });\n }\n return table;\n }\n\n /**\n * @description Prints entity data in a tabular format to the console\n */\n printTable(excludeKeys = false): void {\n console.table(this.toTable(excludeKeys));\n }\n\n entries(): MapIterator<[number, TComponentInstance]> {\n return super.entries().filter(x => x !== undefined && x !== null);\n }\n\n keys(): MapIterator<number> {\n return super.keys().filter(x => x !== undefined && x !== null);\n }\n\n values(): MapIterator<TComponentInstance> {\n return super.values().filter(x => x !== undefined && x !== null);\n }\n\n}\n\n/**\n * @category Maps\n * @description Component class map for storing registered component maps\n */\nexport class ComponentClassesMap extends Map<string, ComponentMap<any>> {\n\n constructor(entries: [string, ComponentMap<any>][] = []) {\n super(entries);\n }\n\n /**\n * @description Called when using JSON.stringify\n */\n toJSON() {\n return { [ComponentClassesMapKey]: 1, iterable: [...this.entries()] };\n }\n\n}", "/**\n * @category Errors\n * @description\n * Thrown when trying to register a component that is missing a 'name' parameter\n */\nexport class ComponentTypeKeyMissing extends Error {\n constructor() {\n super(`Component type is missing the 'name' parameter. i.e. a constructor name`);\n }\n}\n\n/**\n * @category Errors\n * @description\n * Thrown when a trying to access a component that has not been registered\n */\nexport class ComponentNotRegistered extends Error {\n constructor(public componentName: string) {\n super(`Component map does not exist for '${componentName}'`);\n }\n}", "import type { ComponentMap } from './component-map.js';\nimport type { EntityMap } from './entity-map.js';\nimport type { ComponentClass, ComponentInstances, IteratorResult } from './types.js';\n\n/**\n * @category Iterators\n * @example\n * // construct an instance\n * const iterator = new ComponentIterator(entityMap, Player, Position)\n * \n * // iterate each component value that is related to the Player\n * for(const [entityId, player, position] of iterator) { }\n * \n * // you can also reset the iterator back to the start \n * // without having to create a new ComponentIterator instance\n * iterator.reset()\n * for(const [entityId, player, position] of iterator) { }\n */\nexport class ComponentIterator<\n TComponentKey extends ComponentClass<any>,\n TComponentClasses extends ComponentClass<any>[]\n> {\n\n private keyMap: ComponentMap<any>\n private components: ComponentMap<any>[]\n // iteration state\n private entries: MapIterator<[number, TComponentKey]>\n\n /**\n * @throwsError {@link ComponentNotRegistered} when any of specified component(s) are not registered\n */\n constructor(public ecs: EntityMap, public key: TComponentKey, ...components: TComponentClasses) {\n this.keyMap = this.ecs.getMap(key)!;\n this.entries = this.keyMap.entries();\n this.components = components.map(x => this.ecs.getMap(x)!);\n }\n\n /**\n * @description gets the next iterator value\n */\n next(): IteratorResult<ComponentInstances<[ComponentClass<number>, TComponentKey, ...TComponentClasses]>> {\n const entry = this.entries.next();\n const { value, done } = entry;\n if (done) return { value: value as any, done };\n\n const [entityId, entityValue] = value;\n const results = [entityId, entityValue]\n for (const x of this.components) {\n results.push(x.get(entityId));\n }\n\n return { value: results as any, done: false };\n }\n\n /**\n * @description resets the iterator back to the first entry\n */\n reset() {\n this.entries = this.keyMap.entries();\n }\n\n [Symbol.iterator]() { return this; }\n\n}", "/*\n ecsjs is an entity component system library for JavaScript\n Copyright (C) 2014 Peter Flannery\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU Affero General Public License as\n published by the Free Software Foundation, either version 3 of the\n License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Affero General Public License for more details.\n\n You should have received a copy of the GNU Affero General Public License\n along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { ComponentClassesMap, ComponentMap } from './component-map.js';\nimport { ComponentNotRegistered, ComponentTypeKeyMissing } from './errors.js';\nimport { ComponentIterator } from './iterators.js';\nimport {\n ComponentClassesMapKey,\n ComponentMapKey,\n type Component,\n type ComponentClass,\n type ComponentInstances\n} from './types.js';\n\n/**\n * @category Maps\n * @description\n * Class for storing entities and their relationships\n */\nexport class EntityMap {\n /**\n * @description Registered component classes that contain the component instance data\n */\n public components = new ComponentClassesMap()\n\n private nextId: number = 0\n\n /**\n * @description Registers component classes with the {@link EntityMap}\n * @throwsError {@link ComponentTypeKeyMissing} when the specified component type is missing a 'name' parameter\n * @example\n * // component class\n * class MyComponent {\n * constructor(x) {\n * this.x = x;\n * }\n * }\n *\n * ecs.register(MyComponent);\n * // or mulitple\n * ecs.register(MyComponent1, MyComponent2);\n */\n register<TComponentClasses extends ComponentClass<any>[]>(...componentClasses: TComponentClasses) {\n for (const componentClass of componentClasses) {\n const componentName = componentClass.name;\n if (componentName === undefined) throw new ComponentTypeKeyMissing()\n\n // create the component map\n const componentDataMap: ComponentMap<any> = new ComponentMap();\n this.components.set(componentName, componentDataMap);\n }\n\n // chain\n return this;\n }\n\n /**\n * @description Gets a component class map\n * @throwsError {@link ComponentNotRegistered} when the specified component is not registered\n * @example\n * const positionMap = ecs.getMap(Position)\n * for(const [entityId, position] of positionMap) {\n * position.x += 1\n * }\n */\n getMap<T>(component: ComponentClass<T>): ComponentMap<T> | undefined {\n const map = this.components.get(component.name);\n if (map === undefined) throw new ComponentNotRegistered(component.name)\n return map\n }\n\n /**\n * @description Gets the first entity entry for a component class\n * @throwsError {@link ComponentNotRegistered} when the specified component is not registered\n * @example\n * const [entityId, player] = ecs.firstEntry(Player) ?? []\n */\n firstEntry<TComponent>(component: ComponentClass<TComponent>) {\n return this.getMap(component)?.firstEntry();\n }\n\n /**\n * @description Gets the first entity id for a component class \n * and optionally any related component data\n * @throwsError {@link ComponentNotRegistered} when any of specified component(s) are not registered\n * @example\n * // return the first entity id\n * const entityId = ecs.firstKey(Player)\n * \n * // or return multiple related component in addition to entity id\n * const [entityId, position, direction] = ecs.firstKey(\n * Player,\n * Position,\n * Direction\n * ) ?? []\n */\n firstKey<TKey extends ComponentClass<any>, T extends ComponentClass<any>[]>(\n keyComponent: TKey,\n ...components: T\n ): ComponentInstances<[ComponentClass<number>, ...T]> | undefined;\n firstKey(keyComponent: ComponentClass<any>, ...components: ComponentClass<any>[]) {\n const entityId = this.getMap(keyComponent)?.firstKey();\n\n // single component key\n if (arguments.length === 1) return entityId;\n if (entityId === undefined) return undefined;\n\n // attach multiple related component values\n return [entityId, ...components.map(x => this.getEntity(entityId, x))];\n }\n\n /**\n * @description Gets the first entity component data for a component class\n * and optionally any related component data\n * @throwsError {@link ComponentNotRegistered} when any of specified component(s) are not registered\n * @example\n * // return the first component value\n * const player = ecs.firstValue(Player)\n * \n * // or multiple related values in addition to the first component\n * const [player, position, direction] = ecs.firstValue(\n * Player,\n * Position,\n * Direction\n * )\n */\n firstValue<TKey extends ComponentClass<any>, T extends ComponentClass<any>[]>(\n keyComponent: TKey,\n ...components: T\n ): ComponentInstances<[TKey, ...T]> | undefined;\n firstValue(keyComponent: ComponentClass<any>, ...components: ComponentClass<any>[]) {\n // single component\n if (arguments.length === 1) return this.getMap(keyComponent)?.firstValue();\n\n // get the first entry\n const [entityId, value] = this.getMap(keyComponent)?.firstEntry() ?? [];\n if (entityId === undefined) return undefined;\n\n // attach multiple related components\n return [value, ...components.map(x => this.getEntity(entityId, x))]\n }\n\n /**\n * @throwsError {@link ComponentNotRegistered} when the specified component is not registered \n */\n private getEntity<T>(entityId: number, component: ComponentClass<T>): T | undefined {\n const map = this.components.get(component.name);\n if (map === undefined) throw new ComponentNotRegistered(component.name)\n\n return map.get(entityId);\n }\n\n /**\n * @description Gets component values related to an entity id\n * @throwsError {@link ComponentNotRegistered} when any of specified component(s) are not registered\n * @example\n * // get one\n * const player = ecs.get(entityId, Player)\n * \n * // or get multiple\n * const [player, position] = ecs.get(entityId, Player, Position) ?? []\n */\n get<T extends ComponentClass<any>[]>(\n entityId: number,\n ...components: T\n ): ComponentInstances<T> | undefined;\n get<T extends Component>(entityId: number, ...components: ComponentClass<T>[]): T | (T | undefined)[] | undefined {\n if (components.length > 1) return components.map(x => this.getEntity(entityId, x))\n\n // return a single component\n return this.getEntity(entityId, components[0])\n }\n\n /**\n * @description Check if a component exists for an entity id\n * @example\n * const exists = ecs.has(entityId, Position)\n */\n has<T>(entityId: number, component: ComponentClass<T>): boolean {\n // get the component map\n const map = this.components.get(component.name);\n if (map === undefined) return false\n\n return map.has(entityId);\n }\n\n private setEntity<T extends Component>(entityId: number, componentData: T): T {\n // get the component map\n const map = this.components.get(componentData.constructor.name);\n if (map === undefined) throw new ComponentNotRegistered(componentData.constructor.name)\n\n // set the entity on the entity map\n map.set(entityId, componentData);\n\n // return instance\n return componentData;\n }\n\n /**\n * @description Add or update multiple component values for an entity\n * @example\n * // set one\n * const player = ecs.set(entityId, new Player());\n * \n * // or set multiple\n * const [player, position] = ecs.set(\n * entityId,\n * new Player(),\n * new Position()\n * );\n */\n set<T extends Component>(entityId: number, component: T): T;\n set<T extends Component[]>(entityId: number, ...components: T): T;\n set(entityId: number, ...components: Component[]): Component | Component[] {\n if (components.length > 1) return components.map(x => this.setEntity(entityId, x))\n\n // set and return a single component\n return this.setEntity(entityId, components[0])\n }\n\n /**\n * @description Removes the specified component(s) from an entity\n * @example\n * ecs.remove(entityId, Position);\n */\n remove<T extends ComponentClass<any>[]>(entityId: number, ...components: T) {\n for (const component of components) {\n this.removeByKey(entityId, component.name)\n }\n }\n\n /**\n * @description Removes the specified component from an entity\n * @throwsError {@link ComponentNotRegistered} when the specified component is not registered\n * @example\n * ecs.removeByKey(entityId, \"Position\");\n */\n removeByKey(entityId: number, componentName: string) {\n // get the entity map\n const entityMap = this.components.get(componentName);\n\n // ensure the map is defined\n if (entityMap === undefined) throw new ComponentNotRegistered(componentName);\n\n // get the entity\n const entity = entityMap.get(entityId);\n if (entity === undefined) return false;\n\n // remove the entity from the entity map\n return entityMap.delete(entityId);\n }\n\n /**\n * @description Deletes all components from an entity\n * @example\n * ecs.destroyEntity(entityId1)\n * \n * // or multiple\n * ecs.destroyEntity(entityId1, entityId2)\n */\n destroyEntity(...entityIds: number[]) {\n for (let index = 0; index < entityIds.length; index++) {\n const entityId = entityIds[index];\n for (const map of this.components.values()) {\n if (map.has(entityId)) map.delete(entityId);\n }\n }\n }\n\n // TODO create id generator\n /**\n * @description Creates a new entity id for the EntityMap\n * @example\n * const newEntityId = ecs.getNextId()\n * ecs.set(newEntityId, new Player())\n */\n getNextId(): number {\n this.nextId++;\n return this.nextId;\n }\n\n /**\n * @description Clears all registered components\n */\n clear() {\n this.components.clear();\n return this;\n }\n\n /**\n * @description Clears all component data\n */\n clearComponents() {\n this.components.forEach(x => x.clear())\n return this;\n }\n\n /**\n * @description Iterates over each component value that is related to the key component\n * @throwsError {@link ComponentNotRegistered} when any of specified component(s) are not registered\n * @example\n * // iterate each component value that is related to the Player entity\n * const iterator = ecs.iterator(Player, Position)\n * \n * for(const [playerId, player, position] of iterator) { }\n * \n * // you can also declare the type of iterator before it's assigned\n * let iterator: IComponentIterator<[Player, Position]>\n * \n * // then with late bound assignment (keeping the iterator intellisense)\n * iterator = ecs.iterator(Player, Position)\n * \n * for(const [playerId, player, position] of iterator) {\n * const moving = player.isMoving\n * }\n */\n iterator<K extends ComponentClass<any>, T extends ComponentClass<any>[]>(\n keyComponent: K,\n ...components: T\n ): ComponentIterator<K, T>\n iterator(keyComponent: ComponentClass<any>, ...components: ComponentClass<any>[]) {\n return new ComponentIterator(this, keyComponent, ...components) as any;\n }\n\n /**\n * @description Prints all component maps in a tabular format to the console\n */\n printTable() {\n this.components.forEach(map => console.table(map.toTable(true)));\n return this;\n }\n\n /**\n * @description Prints all component data for the specified entity id in a tabular format to the console\n */\n printEntity(entityId: number) {\n for (const map of this.components.values()) {\n if (map.has(entityId) === false) continue;\n\n const data = map.get(entityId);\n const columns = {\n name: data.constructor.name,\n ...data\n };\n console.table({ [entityId]: columns });\n }\n\n return this;\n }\n\n /**\n * @description Parse's the JSON and returns an EntityMap object\n * @example\n * const json = JSON.stringfy(ecs);\n * const restoredMap = ecs.parse(json);\n */\n static parse(json: string): EntityMap {\n const restored = JSON.parse(json, function (key: string, value: any) {\n if (value.hasOwnProperty('components')) {\n Reflect.setPrototypeOf(value, EntityMap.prototype);\n return value;\n }\n if (value.hasOwnProperty(ComponentMapKey)) return new ComponentMap(value.iterable);\n if (value.hasOwnProperty(ComponentClassesMapKey)) return new ComponentClassesMap(value.iterable);\n return this[key];\n });\n return restored;\n }\n\n /**\n * A tracing method used for debugging.\n * Intercepts all functions specified and logs each call to the console.\n * @param {Array} funcFilter A list of function names you want to intercept. If no function names are specified then will log all functions called\n * @return {EntityMap} A new entity map with tracing enabled\n */\n static createWithTracing(funcFilter: any) {\n const traceHandler = {\n get(target: any, propKey: string) {\n const targetValue = target[propKey]\n\n if (typeof targetValue === 'function' && (funcFilter.length === 0 || funcFilter.includes(propKey))) {\n return function (this: any, ...args: any[]) {\n console.groupCollapsed('ecs trace', propKey, args);\n console.trace();\n console.groupEnd();\n return targetValue.apply(this, args);\n }\n }\n\n return targetValue;\n }\n }\n\n return new Proxy(new EntityMap(), traceHandler)\n }\n\n}", "/*\n ecsjs is an entity component system library for JavaScript\n Copyright (C) 2014 Peter Flannery\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU Affero General Public License as\n published by the Free Software Foundation, either version 3 of the\n License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Affero General Public License for more details.\n\n You should have received a copy of the GNU Affero General Public License\n along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\n/**\n * @description An entity component system library for JavaScript\n * @showCategories\n * @module ecsjs\n */\nimport { EntityMap } from './entity-map.js'\nexport { ComponentClassesMap, ComponentMap } from './component-map.js'\nexport { EntityMap } from './entity-map.js'\nexport type { ComponentNotRegistered, ComponentTypeKeyMissing } from './errors.js'\nexport { ComponentIterator } from './iterators.js'\nexport type { ComponentClass, IComponentIterator } from './types.js'\n\n/**\n * @category Constants\n * @description\n * Global instance of an {@link EntityMap}\n * @example\n * ecs.register(Player, Position)\n * ecs.set(1, new Player(), new Position(10, 40))\n * \n * const [player, position] = ecs.firstValue(Player, Position) ?? []\n */\nexport const ecs = new EntityMap()\n\nif (typeof window !== 'undefined') {\n // @ts-ignore: exports to window\n window.ecs = ecs\n} else if (typeof module !== 'undefined' && module !== null) {\n // exports to nodejs\n module.exports = { ecs };\n}"],
5
+ "mappings": "AAAO,IAAMA,EAAkB,eAClBC,EAAyB,sBCsB/B,IAAMC,EAAN,cAA+C,GAAgC,CAEpF,YAAYC,EAA0C,CAAC,EAAG,CACxD,MAAMA,CAAO,CACf,CAKA,YAAwE,CACtE,OAAI,KAAK,OAAS,EAAG,OAEJ,KAAK,QAAQ,EACN,KAAK,EACf,KAChB,CAKA,UAA+B,CAC7B,OAAI,KAAK,OAAS,EAAG,OAEJ,KAAK,KAAK,EACH,KAAK,EACf,KAChB,CAKA,YAA6C,CAC3C,OAAI,KAAK,OAAS,EA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C,CAEA,OAAO,IACT,CAQA,OAAO,MAAMC,EAAyB,CAUpC,OATiB,KAAK,MAAMA,EAAM,SAAUC,EAAaT,EAAY,CACnE,OAAIA,EAAM,eAAe,YAAY,GACnC,QAAQ,eAAeA,EAAOf,EAAU,SAAS,EAC1Ce,GAELA,EAAM,eAAeU,CAAe,EAAU,IAAIlB,EAAaQ,EAAM,QAAQ,EAC7EA,EAAM,eAAeW,CAAsB,EAAU,IAAIzB,EAAoBc,EAAM,QAAQ,EACxF,KAAKS,CAAG,CACjB,CAAC,CAEH,CAQA,OAAO,kBAAkBG,EAAiB,CACxC,IAAMC,EAAe,CACnB,IAAIC,EAAaC,EAAiB,CAChC,IAAMC,EAAcF,EAAOC,CAAO,EAElC,OAAI,OAAOC,GAAgB,aAAeJ,EAAW,SAAW,GAAKA,EAAW,SAASG,CAAO,GACvF,YAAwBE,EAAa,CAC1C,eAAQ,eAAe,YAAaF,EAASE,CAAI,EACjD,QAAQ,MAAM,EACd,QAAQ,SAAS,EACVD,EAAY,MAAM,KAAMC,CAAI,CACrC,EAGKD,CACT,CACF,EAEA,OAAO,IAAI,MAAM,IAAI/B,EAAa4B,CAAY,CAChD,CAEF,EClXO,IAAMK,EAAM,IAAIC,EAEnB,OAAO,OAAW,IAEpB,OAAO,IAAMD,EACJ,OAAO,OAAW,KAAe,SAAW,OAErD,OAAO,QAAU,CAAE,IAAAA,CAAI",
6
+ "names": ["ComponentMapKey", "ComponentClassesMapKey", "ComponentMap", "entries", "ComponentMapKey", "excludeKeys", "table", "key", "value", "entity", "meta", "x", "ComponentClassesMap", "ComponentClassesMapKey", "ComponentTypeKeyMissing", "ComponentNotRegistered", "componentName", "ComponentIterator", "ecs", "key", "components", "x", "entry", "value", "done", "entityId", "entityValue", "results", "EntityMap", "_EntityMap", "ComponentClassesMap", "componentClasses", "componentClass", "componentName", "ComponentTypeKeyMissing", "componentDataMap", "ComponentMap", "component", "map", "ComponentNotRegistered", "keyComponent", "components", "entityId", "x", "value", "componentData", "entityMap", "entityIds", "index", "ComponentIterator", "data", "columns", "json", "key", "ComponentMapKey", "ComponentClassesMapKey", "funcFilter", "traceHandler", "target", "propKey", "targetValue", "args", "ecs", "EntityMap"]
7
7
  }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @category Maps
3
+ * @description Component map for storing entity ids and related component data
4
+ */
5
+ export declare class ComponentMap<TComponentInstance> extends Map<number, TComponentInstance> {
6
+ constructor(entries?: [number, TComponentInstance][]);
7
+ /**
8
+ * @description Returns the first entity entry
9
+ */
10
+ firstEntry(): [entityId: number, value: TComponentInstance] | undefined;
11
+ /**
12
+ * @description Returns the first entity id
13
+ */
14
+ firstKey(): number | undefined;
15
+ /**
16
+ * @description Returns the first entity value
17
+ */
18
+ firstValue(): TComponentInstance | undefined;
19
+ /**
20
+ * @description Called when using JSON.stringify
21
+ */
22
+ toJSON(): {
23
+ ComponentMap: number;
24
+ iterable: [number, TComponentInstance][];
25
+ };
26
+ toTable(excludeKeys?: boolean): any[];
27
+ /**
28
+ * @description Prints entity data in a tabular format to the console
29
+ */
30
+ printTable(excludeKeys?: boolean): void;
31
+ entries(): MapIterator<[number, TComponentInstance]>;
32
+ keys(): MapIterator<number>;
33
+ values(): MapIterator<TComponentInstance>;
34
+ }
35
+ /**
36
+ * @category Maps
37
+ * @description Component class map for storing registered component maps
38
+ */
39
+ export declare class ComponentClassesMap extends Map<string, ComponentMap<any>> {
40
+ constructor(entries?: [string, ComponentMap<any>][]);
41
+ /**
42
+ * @description Called when using JSON.stringify
43
+ */
44
+ toJSON(): {
45
+ ComponentClassesMap: number;
46
+ iterable: [string, ComponentMap<any>][];
47
+ };
48
+ }
49
+ //# sourceMappingURL=component-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-map.d.ts","sourceRoot":"","sources":["../../../src/component-map.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,qBAAa,YAAY,CAAC,kBAAkB,CAAE,SAAQ,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC;gBAEvE,OAAO,GAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAAO;IAIxD;;OAEG;IACH,UAAU,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,CAAC,GAAG,SAAS;IAQvE;;OAEG;IACH,QAAQ,IAAI,MAAM,GAAG,SAAS;IAQ9B;;OAEG;IACH,UAAU,IAAI,kBAAkB,GAAG,SAAS;IAQ5C;;OAEG;IACH,MAAM;;;;IAIN,OAAO,CAAC,WAAW,UAAQ,GAAG,GAAG,EAAE;IAYnC;;OAEG;IACH,UAAU,CAAC,WAAW,UAAQ,GAAG,IAAI;IAIrC,OAAO,IAAI,WAAW,CAAC,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAIpD,IAAI,IAAI,WAAW,CAAC,MAAM,CAAC;IAI3B,MAAM,IAAI,WAAW,CAAC,kBAAkB,CAAC;CAI1C;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;gBAEzD,OAAO,GAAE,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,EAAO;IAIvD;;OAEG;IACH,MAAM;;;;CAIP"}
@@ -1,9 +1,23 @@
1
1
  /**
2
- * ### An entity component system library for JavaScript
3
- *
2
+ * @description An entity component system library for JavaScript
3
+ * @showCategories
4
4
  * @module ecsjs
5
- * @main ecsjs
6
5
  */
7
6
  import { EntityMap } from './entity-map.js';
7
+ export { ComponentClassesMap, ComponentMap } from './component-map.js';
8
+ export { EntityMap } from './entity-map.js';
9
+ export type { ComponentNotRegistered, ComponentTypeKeyMissing } from './errors.js';
10
+ export { ComponentIterator } from './iterators.js';
11
+ export type { ComponentClass, IComponentIterator } from './types.js';
12
+ /**
13
+ * @category Constants
14
+ * @description
15
+ * Global instance of an {@link EntityMap}
16
+ * @example
17
+ * ecs.register(Player, Position)
18
+ * ecs.set(1, new Player(), new Position(10, 40))
19
+ *
20
+ * const [player, position] = ecs.firstValue(Player, Position) ?? []
21
+ */
8
22
  export declare const ecs: EntityMap;
9
23
  //# sourceMappingURL=ecs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecs.d.ts","sourceRoot":"","sources":["../../../src/ecs.ts"],"names":[],"mappings":"AAkBA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,eAAO,MAAM,GAAG,WAAkB,CAAA"}
1
+ {"version":3,"file":"ecs.d.ts","sourceRoot":"","sources":["../../../src/ecs.ts"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,YAAY,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpE;;;;;;;;;GASG;AACH,eAAO,MAAM,GAAG,WAAkB,CAAA"}