@esengine/ecs-framework 2.4.1 → 2.4.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 ADDED
@@ -0,0 +1,188 @@
1
+ <h1 align="center">
2
+ @esengine/ecs-framework
3
+ </h1>
4
+
5
+ <p align="center">
6
+ <strong>High-performance ECS Framework for JavaScript Game Engines</strong>
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/@esengine/ecs-framework"><img src="https://img.shields.io/npm/v/@esengine/ecs-framework?style=flat-square&color=blue" alt="npm"></a>
11
+ <a href="https://github.com/esengine/esengine/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="license"></a>
12
+ <img src="https://img.shields.io/badge/TypeScript-5.0+-blue?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript">
13
+ <img src="https://img.shields.io/badge/zero-dependencies-brightgreen?style=flat-square" alt="zero dependencies">
14
+ </p>
15
+
16
+ <p align="center">
17
+ <b>English</b> | <a href="./README_CN.md">中文</a>
18
+ </p>
19
+
20
+ ---
21
+
22
+ ## Overview
23
+
24
+ A standalone, zero-dependency ECS (Entity-Component-System) framework designed for use with **any** JavaScript game engine:
25
+
26
+ - **Cocos Creator**
27
+ - **Laya**
28
+ - **Egret**
29
+ - **Phaser**
30
+ - **Or your own engine**
31
+
32
+ This package is the core of [ESEngine](https://github.com/esengine/esengine), but can be used completely independently.
33
+
34
+ ## Installation
35
+
36
+ ### npm / pnpm / yarn
37
+
38
+ ```bash
39
+ npm install @esengine/ecs-framework
40
+ ```
41
+
42
+ ### Clone Source Code Only
43
+
44
+ If you only want the ECS framework source code (not the full ESEngine):
45
+
46
+ ```bash
47
+ # Step 1: Clone repo skeleton without downloading files (requires Git 2.25+)
48
+ git clone --filter=blob:none --sparse https://github.com/esengine/esengine.git
49
+
50
+ # Step 2: Enter directory
51
+ cd esengine
52
+
53
+ # Step 3: Specify which folder to checkout
54
+ git sparse-checkout set packages/core
55
+
56
+ # Now you only have packages/core/ - other folders are not downloaded
57
+ ```
58
+
59
+ ## Quick Start
60
+
61
+ ```typescript
62
+ import {
63
+ Core, Scene, Entity, Component, EntitySystem,
64
+ Matcher, Time, ECSComponent, ECSSystem
65
+ } from '@esengine/ecs-framework';
66
+
67
+ // Define components (pure data)
68
+ @ECSComponent('Position')
69
+ class Position extends Component {
70
+ x = 0;
71
+ y = 0;
72
+ }
73
+
74
+ @ECSComponent('Velocity')
75
+ class Velocity extends Component {
76
+ dx = 0;
77
+ dy = 0;
78
+ }
79
+
80
+ // Define system (logic)
81
+ @ECSSystem('Movement')
82
+ class MovementSystem extends EntitySystem {
83
+ constructor() {
84
+ super(Matcher.all(Position, Velocity));
85
+ }
86
+
87
+ protected process(entities: readonly Entity[]): void {
88
+ for (const entity of entities) {
89
+ const pos = entity.getComponent(Position);
90
+ const vel = entity.getComponent(Velocity);
91
+ pos.x += vel.dx * Time.deltaTime;
92
+ pos.y += vel.dy * Time.deltaTime;
93
+ }
94
+ }
95
+ }
96
+
97
+ // Initialize
98
+ Core.create();
99
+ const scene = new Scene();
100
+ scene.addSystem(new MovementSystem());
101
+
102
+ const player = scene.createEntity('Player');
103
+ player.addComponent(new Position());
104
+ player.addComponent(new Velocity());
105
+
106
+ Core.setScene(scene);
107
+
108
+ // Game loop (integrate with your engine's loop)
109
+ function update(dt: number) {
110
+ Core.update(dt);
111
+ }
112
+ ```
113
+
114
+ ## Integration Examples
115
+
116
+ ### With Cocos Creator
117
+
118
+ ```typescript
119
+ import { _decorator, Component as CCComponent } from 'cc';
120
+ import { Core, Scene } from '@esengine/ecs-framework';
121
+
122
+ const { ccclass } = _decorator;
123
+
124
+ @ccclass('GameManager')
125
+ export class GameManager extends CCComponent {
126
+ private scene: Scene;
127
+
128
+ onLoad() {
129
+ Core.create();
130
+ this.scene = new Scene();
131
+ // Register your systems...
132
+ Core.setScene(this.scene);
133
+ }
134
+
135
+ update(dt: number) {
136
+ Core.update(dt);
137
+ }
138
+ }
139
+ ```
140
+
141
+ ### With Laya
142
+
143
+ ```typescript
144
+ import { Core, Scene } from '@esengine/ecs-framework';
145
+
146
+ export class Main {
147
+ private scene: Scene;
148
+
149
+ constructor() {
150
+ Core.create();
151
+ this.scene = new Scene();
152
+ Core.setScene(this.scene);
153
+
154
+ Laya.timer.frameLoop(1, this, this.onUpdate);
155
+ }
156
+
157
+ onUpdate() {
158
+ Core.update(Laya.timer.delta / 1000);
159
+ }
160
+ }
161
+ ```
162
+
163
+ ## Features
164
+
165
+ | Feature | Description |
166
+ |---------|-------------|
167
+ | **Zero Dependencies** | No external runtime dependencies |
168
+ | **Type-Safe Queries** | Fluent API with full TypeScript support |
169
+ | **Change Detection** | Epoch-based dirty tracking for optimization |
170
+ | **Serialization** | Built-in scene serialization and snapshots |
171
+ | **Service Container** | Dependency injection for systems |
172
+ | **Performance Monitoring** | Built-in profiling tools |
173
+
174
+ ## Documentation
175
+
176
+ - [API Reference](https://esengine.cn/api/README)
177
+ - [Architecture Guide](https://esengine.cn/guide/)
178
+ - [Full ESEngine Documentation](https://esengine.cn/)
179
+
180
+ ## License
181
+
182
+ MIT License - Use freely in commercial and open source projects.
183
+
184
+ ---
185
+
186
+ <p align="center">
187
+ Part of <a href="https://github.com/esengine/esengine">ESEngine</a> · Can be used standalone
188
+ </p>