@georgeluo/ecs 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +93 -8
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @simeval/ecs
1
+ # @georgeluo/ecs
2
2
 
3
3
  Reusable ECS core extracted from `workspaces/Describing_Simulation_0/src/core`.
4
4
 
@@ -11,15 +11,15 @@ Reusable ECS core extracted from `workspaces/Describing_Simulation_0/src/core`.
11
11
  ## Install
12
12
 
13
13
  ```bash
14
- npm install @simeval/ecs
14
+ npm install @georgeluo/ecs
15
15
  ```
16
16
 
17
17
  ```bash
18
- pnpm add @simeval/ecs
18
+ pnpm add @georgeluo/ecs
19
19
  ```
20
20
 
21
21
  ```bash
22
- yarn add @simeval/ecs
22
+ yarn add @georgeluo/ecs
23
23
  ```
24
24
 
25
25
  For this monorepo before publish, use a local file dependency:
@@ -27,7 +27,7 @@ For this monorepo before publish, use a local file dependency:
27
27
  ```json
28
28
  {
29
29
  "dependencies": {
30
- "@simeval/ecs": "file:../../packages/ecs"
30
+ "@georgeluo/ecs": "file:../../packages/ecs"
31
31
  }
32
32
  }
33
33
  ```
@@ -48,10 +48,84 @@ import {
48
48
  type Frame,
49
49
  type Acknowledgement,
50
50
  type System,
51
- } from '@simeval/ecs';
51
+ } from '@georgeluo/ecs';
52
52
  ```
53
53
 
54
- ## Inject systems into EvaluationPlayer
54
+ ## Quick Start (SimulationPlayer)
55
+
56
+ ```ts
57
+ import {
58
+ EntityManager,
59
+ ComponentManager,
60
+ SystemManager,
61
+ SimulationPlayer,
62
+ Bus,
63
+ FrameFilter,
64
+ TimeSystem,
65
+ type Frame,
66
+ type Acknowledgement,
67
+ } from '@georgeluo/ecs';
68
+
69
+ const entities = new EntityManager();
70
+ const components = new ComponentManager();
71
+ const systems = new SystemManager(entities, components);
72
+ const inbound = new Bus<unknown>();
73
+ const outbound = new Bus<Frame | Acknowledgement>();
74
+ const player = new SimulationPlayer(systems, inbound, outbound, new FrameFilter());
75
+
76
+ const systemId = player.injectSystem({ system: new TimeSystem() });
77
+ outbound.subscribe((message) => {
78
+ console.log('outbound:', message);
79
+ });
80
+
81
+ player.start();
82
+ setTimeout(() => player.pause(), 200);
83
+ setTimeout(() => player.stop(), 500);
84
+ setTimeout(() => player.ejectSystem({ systemId }), 800);
85
+ ```
86
+
87
+ ## Control Simulation via Inbound Bus
88
+
89
+ ```ts
90
+ import { SimulationMessageType } from '@georgeluo/ecs';
91
+
92
+ inbound.publish({ type: SimulationMessageType.START, payload: { messageId: 'm-1' } });
93
+ inbound.publish({ type: SimulationMessageType.PAUSE, payload: { messageId: 'm-2' } });
94
+ inbound.publish({ type: SimulationMessageType.STOP, payload: { messageId: 'm-3' } });
95
+ ```
96
+
97
+ ## Custom Component + System
98
+
99
+ ```ts
100
+ import { System, type SystemContext, type ComponentType } from '@georgeluo/ecs';
101
+
102
+ const TemperatureComponent: ComponentType<{ value: number }> = {
103
+ id: 'temperature',
104
+ validate: (payload) => Number.isFinite(payload?.value),
105
+ };
106
+
107
+ class TemperatureSystem extends System {
108
+ private entity: number | null = null;
109
+
110
+ initialize(context: SystemContext): void {
111
+ this.entity = context.entityManager.create();
112
+ context.componentManager.addComponent(this.entity, TemperatureComponent, { value: 72 });
113
+ }
114
+
115
+ update(context: SystemContext): void {
116
+ if (this.entity === null) {
117
+ return;
118
+ }
119
+ const current = context.componentManager.getComponent(this.entity, TemperatureComponent);
120
+ const nextValue = (current?.payload.value ?? 72) + 0.25;
121
+ context.componentManager.addComponent(this.entity, TemperatureComponent, { value: nextValue });
122
+ }
123
+ }
124
+
125
+ player.injectSystem({ system: new TemperatureSystem() });
126
+ ```
127
+
128
+ ## EvaluationPlayer: Inject Systems
55
129
 
56
130
  ```ts
57
131
  const entities = new EntityManager();
@@ -65,7 +139,7 @@ const systemId = player.injectSystem({ system: myEvaluationSystem });
65
139
  player.ejectSystem({ systemId });
66
140
  ```
67
141
 
68
- ## Inject frames into EvaluationPlayer
142
+ ## EvaluationPlayer: Inject Frames
69
143
 
70
144
  ```ts
71
145
  inbound.publish({
@@ -85,3 +159,14 @@ player.injectFrame({
85
159
  frame: { tick: 1, entities: {} },
86
160
  });
87
161
  ```
162
+
163
+ ## API Surface
164
+
165
+ - Managers:
166
+ - `EntityManager`, `ComponentManager`, `SystemManager`
167
+ - Players:
168
+ - `Player`, `IOPlayer`, `SimulationPlayer`, `EvaluationPlayer`
169
+ - Base model:
170
+ - `System`, `SystemContext`, `ComponentType`, `Frame`, `Acknowledgement`
171
+ - Messaging:
172
+ - `Bus`, `FrameFilter`, `SimulationMessageType`, `EvaluationMessageType`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@georgeluo/ecs",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Reusable ECS engine and simulation players for SimEval.",
5
5
  "keywords": [
6
6
  "ecs",
@@ -11,7 +11,7 @@
11
11
  "license": "ISC",
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git+https://github.com/GeorgeLuo/simtest0.git",
14
+ "url": "https://github.com/GeorgeLuo/simtest0.git",
15
15
  "directory": "packages/ecs"
16
16
  },
17
17
  "bugs": {