@esengine/ecs-framework 2.1.51 → 2.1.52
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/index.cjs +2 -2
- package/index.cjs.map +1 -1
- package/index.d.ts +2145 -159
- package/index.es5.js +2 -2
- package/index.es5.js.map +1 -1
- package/index.mjs +2 -2
- package/index.mjs.map +1 -1
- package/index.umd.js +2 -2
- package/index.umd.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @esengine/ecs-framework v2.1.
|
|
2
|
+
* @esengine/ecs-framework v2.1.52
|
|
3
3
|
* TypeScript definitions
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -532,9 +532,226 @@ declare class PoolManager {
|
|
|
532
532
|
reset(): void;
|
|
533
533
|
}
|
|
534
534
|
|
|
535
|
+
/**
|
|
536
|
+
* TypeScript类型工具集
|
|
537
|
+
*
|
|
538
|
+
* 提供高级类型推断和类型安全的工具类型
|
|
539
|
+
*/
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* 组件类型提取器
|
|
543
|
+
* 从组件构造函数中提取实例类型
|
|
544
|
+
*/
|
|
545
|
+
type ComponentInstance<T> = T extends new (...args: any[]) => infer R ? R : never;
|
|
546
|
+
/**
|
|
547
|
+
* 组件构造函数类型
|
|
548
|
+
*
|
|
549
|
+
* 与 ComponentType 保持一致,避免类型转换
|
|
550
|
+
*/
|
|
551
|
+
type ComponentConstructor<T extends IComponent = IComponent> = new (...args: any[]) => T;
|
|
552
|
+
/**
|
|
553
|
+
* 组件类型的通用约束
|
|
554
|
+
*
|
|
555
|
+
* 用于确保类型参数是有效的组件构造函数
|
|
556
|
+
*/
|
|
557
|
+
type AnyComponentConstructor = ComponentConstructor<any>;
|
|
558
|
+
/**
|
|
559
|
+
* 多组件类型提取
|
|
560
|
+
* 从组件构造函数数组中提取所有实例类型的联合
|
|
561
|
+
*/
|
|
562
|
+
type ExtractComponents<T extends readonly ComponentConstructor[]> = {
|
|
563
|
+
[K in keyof T]: ComponentInstance<T[K]>;
|
|
564
|
+
};
|
|
565
|
+
/**
|
|
566
|
+
* 组件类型映射
|
|
567
|
+
* 将组件构造函数数组转换为实例类型的元组
|
|
568
|
+
*/
|
|
569
|
+
type ComponentTypeMap<T extends readonly ComponentConstructor[]> = {
|
|
570
|
+
[K in keyof T]: T[K] extends ComponentConstructor<infer C> ? C : never;
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* 实体with组件的类型
|
|
574
|
+
* 表示一个实体确定拥有某些组件
|
|
575
|
+
*/
|
|
576
|
+
interface EntityWithComponents<T extends readonly ComponentConstructor[]> {
|
|
577
|
+
readonly id: number;
|
|
578
|
+
readonly name: string;
|
|
579
|
+
/**
|
|
580
|
+
* 类型安全的组件获取
|
|
581
|
+
* 确保返回非空的组件实例
|
|
582
|
+
*/
|
|
583
|
+
getComponent<C extends ComponentConstructor>(componentType: C): ComponentInstance<C>;
|
|
584
|
+
/**
|
|
585
|
+
* 检查是否拥有组件
|
|
586
|
+
*/
|
|
587
|
+
hasComponent<C extends ComponentConstructor>(componentType: C): boolean;
|
|
588
|
+
/**
|
|
589
|
+
* 获取所有组件
|
|
590
|
+
*/
|
|
591
|
+
readonly components: ComponentTypeMap<T>;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* 查询结果类型
|
|
595
|
+
* 根据查询条件推断实体必定拥有的组件
|
|
596
|
+
*/
|
|
597
|
+
type QueryResult$1<All extends readonly ComponentConstructor[] = [], Any extends readonly ComponentConstructor[] = [], None extends readonly ComponentConstructor[] = []> = {
|
|
598
|
+
/**
|
|
599
|
+
* 实体列表,确保拥有All中的所有组件
|
|
600
|
+
*/
|
|
601
|
+
readonly entities: ReadonlyArray<EntityWithComponents<All>>;
|
|
602
|
+
/**
|
|
603
|
+
* 实体数量
|
|
604
|
+
*/
|
|
605
|
+
readonly length: number;
|
|
606
|
+
/**
|
|
607
|
+
* 遍历实体
|
|
608
|
+
*/
|
|
609
|
+
forEach(callback: (entity: EntityWithComponents<All>, index: number) => void): void;
|
|
610
|
+
/**
|
|
611
|
+
* 映射转换
|
|
612
|
+
*/
|
|
613
|
+
map<R>(callback: (entity: EntityWithComponents<All>, index: number) => R): R[];
|
|
614
|
+
/**
|
|
615
|
+
* 过滤实体
|
|
616
|
+
*/
|
|
617
|
+
filter(predicate: (entity: EntityWithComponents<All>, index: number) => boolean): QueryResult$1<All, Any, None>;
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* System处理的实体类型
|
|
621
|
+
* 根据Matcher推断System处理的实体类型
|
|
622
|
+
*/
|
|
623
|
+
type SystemEntityType<M> = M extends {
|
|
624
|
+
getCondition(): {
|
|
625
|
+
all: infer All extends readonly ComponentConstructor[];
|
|
626
|
+
};
|
|
627
|
+
} ? EntityWithComponents<All> : never;
|
|
628
|
+
/**
|
|
629
|
+
* 组件字段类型提取
|
|
630
|
+
* 提取组件中所有可序列化的字段
|
|
631
|
+
*/
|
|
632
|
+
type SerializableFields<T> = {
|
|
633
|
+
[K in keyof T]: T[K] extends Function ? never : K;
|
|
634
|
+
}[keyof T];
|
|
635
|
+
/**
|
|
636
|
+
* 只读组件类型
|
|
637
|
+
* 将组件的所有字段转为只读
|
|
638
|
+
*/
|
|
639
|
+
type ReadonlyComponent<T extends IComponent> = {
|
|
640
|
+
readonly [K in keyof T]: T[K];
|
|
641
|
+
};
|
|
642
|
+
/**
|
|
643
|
+
* 部分组件类型
|
|
644
|
+
* 用于组件更新操作
|
|
645
|
+
*/
|
|
646
|
+
type PartialComponent<T extends IComponent> = {
|
|
647
|
+
[K in SerializableFields<T>]?: T[K];
|
|
648
|
+
};
|
|
649
|
+
/**
|
|
650
|
+
* 组件类型约束
|
|
651
|
+
* 确保类型参数是有效的组件
|
|
652
|
+
*/
|
|
653
|
+
type ValidComponent<T> = T extends Component ? T : never;
|
|
654
|
+
/**
|
|
655
|
+
* 组件数组约束
|
|
656
|
+
* 确保数组中的所有元素都是组件构造函数
|
|
657
|
+
*/
|
|
658
|
+
type ValidComponentArray<T extends readonly any[]> = T extends readonly ComponentConstructor[] ? T : never;
|
|
659
|
+
/**
|
|
660
|
+
* 事件处理器类型
|
|
661
|
+
* 提供类型安全的事件处理
|
|
662
|
+
*/
|
|
663
|
+
type TypedEventHandler<T> = (data: T) => void | Promise<void>;
|
|
664
|
+
/**
|
|
665
|
+
* 系统生命周期钩子类型
|
|
666
|
+
*/
|
|
667
|
+
interface SystemLifecycleHooks<T extends readonly ComponentConstructor[]> {
|
|
668
|
+
/**
|
|
669
|
+
* 实体添加到系统时调用
|
|
670
|
+
*/
|
|
671
|
+
onAdded?: (entity: EntityWithComponents<T>) => void;
|
|
672
|
+
/**
|
|
673
|
+
* 实体从系统移除时调用
|
|
674
|
+
*/
|
|
675
|
+
onRemoved?: (entity: EntityWithComponents<T>) => void;
|
|
676
|
+
/**
|
|
677
|
+
* 系统初始化时调用
|
|
678
|
+
*/
|
|
679
|
+
onInitialize?: () => void;
|
|
680
|
+
/**
|
|
681
|
+
* 系统销毁时调用
|
|
682
|
+
*/
|
|
683
|
+
onDestroy?: () => void;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Fluent API构建器类型
|
|
687
|
+
*/
|
|
688
|
+
interface TypeSafeBuilder<T> {
|
|
689
|
+
/**
|
|
690
|
+
* 完成构建
|
|
691
|
+
*/
|
|
692
|
+
build(): T;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* 实体查询条件类型
|
|
696
|
+
*/
|
|
697
|
+
interface TypedQueryCondition<All extends readonly ComponentConstructor[] = [], Any extends readonly ComponentConstructor[] = [], None extends readonly ComponentConstructor[] = []> {
|
|
698
|
+
all: All;
|
|
699
|
+
any: Any;
|
|
700
|
+
none: None;
|
|
701
|
+
tag?: number;
|
|
702
|
+
name?: string;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* 组件类型守卫
|
|
706
|
+
*/
|
|
707
|
+
declare function isComponentType<T extends IComponent>(value: any): value is ComponentConstructor<T>;
|
|
708
|
+
/**
|
|
709
|
+
* 类型安全的组件数组守卫
|
|
710
|
+
*/
|
|
711
|
+
declare function isComponentArray(value: any[]): value is ComponentConstructor[];
|
|
712
|
+
/**
|
|
713
|
+
* 提取组件类型名称(编译时)
|
|
714
|
+
*/
|
|
715
|
+
type ComponentTypeName<T extends ComponentConstructor> = T extends {
|
|
716
|
+
prototype: {
|
|
717
|
+
constructor: {
|
|
718
|
+
name: infer N;
|
|
719
|
+
};
|
|
720
|
+
};
|
|
721
|
+
} ? N : string;
|
|
722
|
+
/**
|
|
723
|
+
* 多组件类型名称联合
|
|
724
|
+
*/
|
|
725
|
+
type ComponentTypeNames<T extends readonly ComponentConstructor[]> = {
|
|
726
|
+
[K in keyof T]: ComponentTypeName<T[K]>;
|
|
727
|
+
}[number];
|
|
728
|
+
/**
|
|
729
|
+
* 深度只读类型
|
|
730
|
+
*/
|
|
731
|
+
type DeepReadonly<T> = {
|
|
732
|
+
readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];
|
|
733
|
+
};
|
|
734
|
+
/**
|
|
735
|
+
* 深度可选类型
|
|
736
|
+
*/
|
|
737
|
+
type DeepPartial<T> = {
|
|
738
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
739
|
+
};
|
|
740
|
+
/**
|
|
741
|
+
* 排除方法的类型
|
|
742
|
+
*/
|
|
743
|
+
type DataOnly<T> = {
|
|
744
|
+
[K in keyof T as T[K] extends Function ? never : K]: T[K];
|
|
745
|
+
};
|
|
746
|
+
/**
|
|
747
|
+
* 可序列化的组件数据
|
|
748
|
+
*/
|
|
749
|
+
type SerializableComponent<T extends IComponent> = DeepPartial<DataOnly<T>>;
|
|
750
|
+
|
|
535
751
|
/**
|
|
536
752
|
* 框架核心类型定义
|
|
537
753
|
*/
|
|
754
|
+
|
|
538
755
|
/**
|
|
539
756
|
* 组件接口
|
|
540
757
|
*
|
|
@@ -1068,30 +1285,23 @@ declare abstract class Component implements IComponent {
|
|
|
1068
1285
|
|
|
1069
1286
|
/**
|
|
1070
1287
|
* 基础 64 位段结构
|
|
1288
|
+
* [低32位,高32位]
|
|
1071
1289
|
*/
|
|
1072
|
-
|
|
1073
|
-
/** 低32位(bit 0-31) */
|
|
1074
|
-
lo: number;
|
|
1075
|
-
/** 高32位(bit 32-63) */
|
|
1076
|
-
hi: number;
|
|
1077
|
-
}
|
|
1290
|
+
type BitMask64Segment = [number, number];
|
|
1078
1291
|
/**
|
|
1079
1292
|
* 位掩码数据结构
|
|
1080
|
-
* 基础模式(64位):使用 lo
|
|
1081
|
-
* 扩展模式(128+位):lo
|
|
1293
|
+
* 基础模式(64位):使用 base[lo , hi] 存储 64 位,segments 为空
|
|
1294
|
+
* 扩展模式(128+位):base[lo , hi] 作为第一段,segments 存储额外的 64 位段
|
|
1082
1295
|
* segments[0] 对应 bit 64-127,segments[1] 对应 bit 128-191,以此类推
|
|
1083
1296
|
*/
|
|
1084
1297
|
interface BitMask64Data {
|
|
1085
|
-
|
|
1086
|
-
lo: number;
|
|
1087
|
-
/** 高32位(bit 32-63) */
|
|
1088
|
-
hi: number;
|
|
1298
|
+
base: BitMask64Segment;
|
|
1089
1299
|
/** 扩展段数组,每个元素是一个 64 位段,用于超过 64 位的场景 */
|
|
1090
1300
|
segments?: BitMask64Segment[];
|
|
1091
1301
|
}
|
|
1092
1302
|
declare class BitMask64Utils {
|
|
1093
1303
|
/** 零掩码常量,所有位都为0 */
|
|
1094
|
-
static readonly ZERO: BitMask64Data
|
|
1304
|
+
static readonly ZERO: Readonly<BitMask64Data>;
|
|
1095
1305
|
/**
|
|
1096
1306
|
* 根据位索引创建64位掩码
|
|
1097
1307
|
* @param bitIndex 位索引,范围 [0, 63]
|
|
@@ -1114,7 +1324,6 @@ declare class BitMask64Utils {
|
|
|
1114
1324
|
static hasAny(mask: BitMask64Data, bits: BitMask64Data): boolean;
|
|
1115
1325
|
/**
|
|
1116
1326
|
* 检查掩码是否包含所有指定的位
|
|
1117
|
-
* 支持扩展模式,自动处理超过 64 位的掩码
|
|
1118
1327
|
* @param mask 要检查的掩码
|
|
1119
1328
|
* @param bits 指定的位模式
|
|
1120
1329
|
* @returns 如果掩码包含bits中的所有位则返回true
|
|
@@ -1132,7 +1341,7 @@ declare class BitMask64Utils {
|
|
|
1132
1341
|
* @param mask 要检查的掩码
|
|
1133
1342
|
* @returns 如果掩码所有位都为0则返回true
|
|
1134
1343
|
*/
|
|
1135
|
-
static isZero(mask: BitMask64Data
|
|
1344
|
+
static isZero(mask: BitMask64Data): boolean;
|
|
1136
1345
|
/**
|
|
1137
1346
|
* 检查两个掩码是否相等
|
|
1138
1347
|
* @param a 第一个掩码
|
|
@@ -1141,17 +1350,22 @@ declare class BitMask64Utils {
|
|
|
1141
1350
|
*/
|
|
1142
1351
|
static equals(a: BitMask64Data, b: BitMask64Data): boolean;
|
|
1143
1352
|
/**
|
|
1144
|
-
* 设置掩码中指定位为1
|
|
1353
|
+
* 设置掩码中指定位为1,必要时自动扩展
|
|
1145
1354
|
* @param mask 要修改的掩码(原地修改)
|
|
1146
|
-
* @param bitIndex
|
|
1355
|
+
* @param bitIndex 位索引,不小于零
|
|
1147
1356
|
* @throws 当位索引超出范围时抛出错误
|
|
1148
1357
|
*/
|
|
1149
1358
|
static setBit(mask: BitMask64Data, bitIndex: number): void;
|
|
1150
1359
|
/**
|
|
1151
|
-
*
|
|
1360
|
+
* 获取掩码中指定位,如果位超出当前掩码的区段长度,则直接返回0
|
|
1361
|
+
* @param mask 掩码
|
|
1362
|
+
* @param bitIndex 位索引,不小于零
|
|
1363
|
+
*/
|
|
1364
|
+
static getBit(mask: BitMask64Data, bitIndex: number): boolean;
|
|
1365
|
+
/**
|
|
1366
|
+
* 清除掩码中指定位为0,如果位超出当前掩码的区段长度,则什么也不做
|
|
1152
1367
|
* @param mask 要修改的掩码(原地修改)
|
|
1153
|
-
* @param bitIndex
|
|
1154
|
-
* @throws 当位索引超出范围时抛出错误
|
|
1368
|
+
* @param bitIndex 位索引,不小于0
|
|
1155
1369
|
*/
|
|
1156
1370
|
static clearBit(mask: BitMask64Data, bitIndex: number): void;
|
|
1157
1371
|
/**
|
|
@@ -1178,7 +1392,7 @@ declare class BitMask64Utils {
|
|
|
1178
1392
|
*/
|
|
1179
1393
|
static clear(mask: BitMask64Data): void;
|
|
1180
1394
|
/**
|
|
1181
|
-
*
|
|
1395
|
+
* 将源掩码的值复制到目标掩码,如果source包含扩展段,则target也会至少扩展到source扩展段的长度
|
|
1182
1396
|
* @param source 源掩码
|
|
1183
1397
|
* @param target 目标掩码(原地修改)
|
|
1184
1398
|
*/
|
|
@@ -1190,13 +1404,13 @@ declare class BitMask64Utils {
|
|
|
1190
1404
|
*/
|
|
1191
1405
|
static clone(mask: BitMask64Data): BitMask64Data;
|
|
1192
1406
|
/**
|
|
1193
|
-
*
|
|
1407
|
+
* 将掩码转换为字符串表示,每个区段之间将使用空格分割。
|
|
1194
1408
|
* @param mask 要转换的掩码
|
|
1195
|
-
* @param radix 进制,支持2(二进制)或16(十六进制),默认为2
|
|
1409
|
+
* @param radix 进制,支持2(二进制)或16(十六进制),默认为2,其他的值被视为2
|
|
1410
|
+
* @param printHead 打印头
|
|
1196
1411
|
* @returns 掩码的字符串表示,二进制不带前缀,十六进制带0x前缀
|
|
1197
|
-
* @throws 当进制不支持时抛出错误
|
|
1198
1412
|
*/
|
|
1199
|
-
static toString(mask: BitMask64Data, radix?:
|
|
1413
|
+
static toString(mask: BitMask64Data, radix?: 2 | 16, printHead?: boolean): string;
|
|
1200
1414
|
/**
|
|
1201
1415
|
* 计算掩码中设置为1的位数
|
|
1202
1416
|
* @param mask 要计算的掩码
|
|
@@ -1204,24 +1418,13 @@ declare class BitMask64Utils {
|
|
|
1204
1418
|
*/
|
|
1205
1419
|
static popCount(mask: BitMask64Data): number;
|
|
1206
1420
|
/**
|
|
1207
|
-
*
|
|
1208
|
-
* @param mask
|
|
1209
|
-
* @param bitIndex
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
/**
|
|
1213
|
-
* 获取扩展位(支持超过 64 位的索引)
|
|
1214
|
-
* @param mask 要检查的掩码
|
|
1215
|
-
* @param bitIndex 位索引(可以超过 63)
|
|
1216
|
-
* @returns 如果位被设置则返回 true
|
|
1217
|
-
*/
|
|
1218
|
-
static getBitExtended(mask: BitMask64Data, bitIndex: number): boolean;
|
|
1219
|
-
/**
|
|
1220
|
-
* 清除扩展位(支持超过 64 位的索引)
|
|
1221
|
-
* @param mask 要修改的掩码(原地修改)
|
|
1222
|
-
* @param bitIndex 位索引(可以超过 63)
|
|
1421
|
+
* 获取包含目标位的BitMask64Segment
|
|
1422
|
+
* @param mask 要操作的掩码
|
|
1423
|
+
* @param bitIndex 目标位
|
|
1424
|
+
* @param createNewSegment 如果bitIndex超过了当前范围,是否自动补充扩展区域,默认为真
|
|
1425
|
+
* @private
|
|
1223
1426
|
*/
|
|
1224
|
-
static
|
|
1427
|
+
private static getSegmentByBitIndex;
|
|
1225
1428
|
}
|
|
1226
1429
|
|
|
1227
1430
|
/**
|
|
@@ -2546,8 +2749,7 @@ declare class IdentifierPool {
|
|
|
2546
2749
|
|
|
2547
2750
|
/**
|
|
2548
2751
|
* 位集合类,用于高效的位操作
|
|
2549
|
-
*
|
|
2550
|
-
* 扩展模式性能略有下降,但仍然比数组遍历快得多
|
|
2752
|
+
* 支持任意位的位运算操作.
|
|
2551
2753
|
*/
|
|
2552
2754
|
declare class Bits {
|
|
2553
2755
|
/** 存储位数据的掩码,支持扩展 */
|
|
@@ -3656,162 +3858,1083 @@ declare class TypeSafeEventSystem {
|
|
|
3656
3858
|
}
|
|
3657
3859
|
|
|
3658
3860
|
/**
|
|
3659
|
-
*
|
|
3861
|
+
* 类型安全的Query查询系统
|
|
3660
3862
|
*
|
|
3661
|
-
*
|
|
3662
|
-
* 推荐使用组合而非继承的方式来构建自定义场景。
|
|
3863
|
+
* 提供完整的TypeScript类型推断,在编译时确保类型安全
|
|
3663
3864
|
*/
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
* 管理场景内所有实体的生命周期。
|
|
3675
|
-
*/
|
|
3676
|
-
readonly entities: EntityList;
|
|
3865
|
+
|
|
3866
|
+
/**
|
|
3867
|
+
* 类型安全的查询结果
|
|
3868
|
+
*
|
|
3869
|
+
* 根据查询条件自动推断实体必定拥有的组件类型
|
|
3870
|
+
*/
|
|
3871
|
+
declare class TypedQueryResult<TAll extends readonly ComponentConstructor[]> {
|
|
3872
|
+
private _entities;
|
|
3873
|
+
private _componentTypes;
|
|
3874
|
+
constructor(entities: readonly Entity[], componentTypes: TAll);
|
|
3677
3875
|
/**
|
|
3678
|
-
*
|
|
3679
|
-
*
|
|
3680
|
-
* 管理场景内所有实体系统的执行。
|
|
3876
|
+
* 获取实体列表
|
|
3681
3877
|
*/
|
|
3682
|
-
|
|
3878
|
+
get entities(): readonly Entity[];
|
|
3683
3879
|
/**
|
|
3684
|
-
*
|
|
3685
|
-
*
|
|
3686
|
-
* 用于分配和回收实体的唯一标识符。
|
|
3880
|
+
* 实体数量
|
|
3687
3881
|
*/
|
|
3688
|
-
|
|
3882
|
+
get length(): number;
|
|
3689
3883
|
/**
|
|
3690
|
-
*
|
|
3884
|
+
* 遍历所有实体
|
|
3691
3885
|
*
|
|
3692
|
-
*
|
|
3886
|
+
* @example
|
|
3887
|
+
* ```typescript
|
|
3888
|
+
* query.forEach((entity) => {
|
|
3889
|
+
* // entity.getComponent返回类型自动推断
|
|
3890
|
+
* const pos = entity.getComponent(Position); // Position类型
|
|
3891
|
+
* const vel = entity.getComponent(Velocity); // Velocity类型
|
|
3892
|
+
* });
|
|
3893
|
+
* ```
|
|
3693
3894
|
*/
|
|
3694
|
-
|
|
3895
|
+
forEach(callback: (entity: Entity, index: number) => void): void;
|
|
3695
3896
|
/**
|
|
3696
|
-
*
|
|
3697
|
-
*
|
|
3698
|
-
* 基于位掩码的高性能实体查询系统。
|
|
3897
|
+
* 映射转换实体
|
|
3699
3898
|
*/
|
|
3700
|
-
|
|
3899
|
+
map<R>(callback: (entity: Entity, index: number) => R): R[];
|
|
3701
3900
|
/**
|
|
3702
|
-
*
|
|
3703
|
-
*
|
|
3704
|
-
* 类型安全的事件系统。
|
|
3901
|
+
* 过滤实体
|
|
3705
3902
|
*/
|
|
3706
|
-
|
|
3903
|
+
filter(predicate: (entity: Entity, index: number) => boolean): TypedQueryResult<TAll>;
|
|
3707
3904
|
/**
|
|
3708
|
-
*
|
|
3905
|
+
* 查找第一个匹配的实体
|
|
3709
3906
|
*/
|
|
3710
|
-
|
|
3907
|
+
find(predicate: (entity: Entity, index: number) => boolean): Entity | undefined;
|
|
3711
3908
|
/**
|
|
3712
|
-
*
|
|
3909
|
+
* 检查是否存在匹配的实体
|
|
3713
3910
|
*/
|
|
3714
|
-
|
|
3911
|
+
some(predicate: (entity: Entity, index: number) => boolean): boolean;
|
|
3715
3912
|
/**
|
|
3716
|
-
*
|
|
3913
|
+
* 检查是否所有实体都匹配
|
|
3717
3914
|
*/
|
|
3718
|
-
|
|
3915
|
+
every(predicate: (entity: Entity, index: number) => boolean): boolean;
|
|
3719
3916
|
/**
|
|
3720
|
-
*
|
|
3721
|
-
*
|
|
3722
|
-
* 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
|
|
3917
|
+
* 获取指定索引的实体
|
|
3723
3918
|
*/
|
|
3724
|
-
|
|
3919
|
+
get(index: number): Entity | undefined;
|
|
3725
3920
|
/**
|
|
3726
|
-
*
|
|
3727
|
-
*
|
|
3728
|
-
* 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
|
|
3921
|
+
* 获取第一个实体
|
|
3729
3922
|
*/
|
|
3730
|
-
|
|
3923
|
+
get first(): Entity | undefined;
|
|
3731
3924
|
/**
|
|
3732
|
-
*
|
|
3733
|
-
*
|
|
3734
|
-
* 在场景被销毁时调用,可以在此方法中执行清理工作。
|
|
3925
|
+
* 获取最后一个实体
|
|
3735
3926
|
*/
|
|
3736
|
-
|
|
3927
|
+
get last(): Entity | undefined;
|
|
3737
3928
|
/**
|
|
3738
|
-
*
|
|
3739
|
-
*
|
|
3740
|
-
* 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
|
|
3929
|
+
* 检查查询结果是否为空
|
|
3741
3930
|
*/
|
|
3742
|
-
|
|
3931
|
+
get isEmpty(): boolean;
|
|
3743
3932
|
/**
|
|
3744
|
-
*
|
|
3745
|
-
*
|
|
3746
|
-
* 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
|
|
3933
|
+
* 转换为数组
|
|
3747
3934
|
*/
|
|
3748
|
-
|
|
3935
|
+
toArray(): Entity[];
|
|
3749
3936
|
/**
|
|
3750
|
-
*
|
|
3937
|
+
* 获取组件类型信息(用于调试)
|
|
3751
3938
|
*/
|
|
3752
|
-
|
|
3939
|
+
getComponentTypes(): readonly ComponentConstructor[];
|
|
3753
3940
|
/**
|
|
3754
|
-
*
|
|
3755
|
-
* @param name 实体名称
|
|
3941
|
+
* 迭代器支持
|
|
3756
3942
|
*/
|
|
3757
|
-
|
|
3943
|
+
[Symbol.iterator](): Iterator<Entity>;
|
|
3944
|
+
}
|
|
3945
|
+
/**
|
|
3946
|
+
* 类型安全的查询构建器
|
|
3947
|
+
*
|
|
3948
|
+
* 支持链式调用,自动推断查询结果的类型
|
|
3949
|
+
*
|
|
3950
|
+
* @example
|
|
3951
|
+
* ```typescript
|
|
3952
|
+
* // 基础查询
|
|
3953
|
+
* const query = new TypedQueryBuilder()
|
|
3954
|
+
* .withAll(Position, Velocity)
|
|
3955
|
+
* .build();
|
|
3956
|
+
*
|
|
3957
|
+
* // 复杂查询
|
|
3958
|
+
* const complexQuery = new TypedQueryBuilder()
|
|
3959
|
+
* .withAll(Transform, Renderer)
|
|
3960
|
+
* .withAny(BoxCollider, CircleCollider)
|
|
3961
|
+
* .withNone(Disabled)
|
|
3962
|
+
* .withTag(EntityTags.Enemy)
|
|
3963
|
+
* .build();
|
|
3964
|
+
* ```
|
|
3965
|
+
*/
|
|
3966
|
+
declare class TypedQueryBuilder<TAll extends readonly ComponentConstructor[] = [], TAny extends readonly ComponentConstructor[] = [], TNone extends readonly ComponentConstructor[] = []> {
|
|
3967
|
+
private _all;
|
|
3968
|
+
private _any;
|
|
3969
|
+
private _none;
|
|
3970
|
+
private _tag?;
|
|
3971
|
+
private _name?;
|
|
3972
|
+
constructor(all?: TAll, any?: TAny, none?: TNone, tag?: number, name?: string);
|
|
3758
3973
|
/**
|
|
3759
|
-
*
|
|
3760
|
-
*
|
|
3974
|
+
* 要求实体拥有所有指定的组件
|
|
3975
|
+
*
|
|
3976
|
+
* @param types 组件类型
|
|
3977
|
+
* @returns 新的查询构建器,类型参数更新
|
|
3761
3978
|
*/
|
|
3762
|
-
|
|
3979
|
+
withAll<TNewAll extends readonly ComponentConstructor[]>(...types: TNewAll): TypedQueryBuilder<readonly [...TAll, ...TNewAll], TAny, TNone>;
|
|
3763
3980
|
/**
|
|
3764
|
-
*
|
|
3765
|
-
*
|
|
3766
|
-
* @param
|
|
3981
|
+
* 要求实体至少拥有一个指定的组件
|
|
3982
|
+
*
|
|
3983
|
+
* @param types 组件类型
|
|
3984
|
+
* @returns 新的查询构建器
|
|
3767
3985
|
*/
|
|
3768
|
-
|
|
3986
|
+
withAny<TNewAny extends readonly ComponentConstructor[]>(...types: TNewAny): TypedQueryBuilder<TAll, readonly [...TAny, ...TNewAny], TNone>;
|
|
3769
3987
|
/**
|
|
3770
|
-
*
|
|
3771
|
-
*
|
|
3772
|
-
* @param
|
|
3773
|
-
* @returns
|
|
3988
|
+
* 排除拥有指定组件的实体
|
|
3989
|
+
*
|
|
3990
|
+
* @param types 组件类型
|
|
3991
|
+
* @returns 新的查询构建器
|
|
3774
3992
|
*/
|
|
3775
|
-
|
|
3993
|
+
withNone<TNewNone extends readonly ComponentConstructor[]>(...types: TNewNone): TypedQueryBuilder<TAll, TAny, readonly [...TNone, ...TNewNone]>;
|
|
3776
3994
|
/**
|
|
3777
|
-
*
|
|
3995
|
+
* 按标签过滤实体
|
|
3996
|
+
*
|
|
3997
|
+
* @param tag 标签值
|
|
3998
|
+
* @returns 新的查询构建器
|
|
3778
3999
|
*/
|
|
3779
|
-
|
|
4000
|
+
withTag(tag: number): TypedQueryBuilder<TAll, TAny, TNone>;
|
|
3780
4001
|
/**
|
|
3781
|
-
*
|
|
4002
|
+
* 按名称过滤实体
|
|
4003
|
+
*
|
|
3782
4004
|
* @param name 实体名称
|
|
4005
|
+
* @returns 新的查询构建器
|
|
3783
4006
|
*/
|
|
3784
|
-
|
|
3785
|
-
/**
|
|
3786
|
-
* 根据ID查找实体
|
|
3787
|
-
* @param id 实体ID
|
|
3788
|
-
*/
|
|
3789
|
-
findEntityById(id: number): Entity | null;
|
|
4007
|
+
withName(name: string): TypedQueryBuilder<TAll, TAny, TNone>;
|
|
3790
4008
|
/**
|
|
3791
|
-
*
|
|
3792
|
-
*
|
|
4009
|
+
* 构建Matcher对象
|
|
4010
|
+
*
|
|
4011
|
+
* @returns Matcher实例,用于传统查询API
|
|
3793
4012
|
*/
|
|
3794
|
-
|
|
4013
|
+
buildMatcher(): Matcher;
|
|
3795
4014
|
/**
|
|
3796
|
-
*
|
|
3797
|
-
*
|
|
4015
|
+
* 获取查询条件
|
|
4016
|
+
*
|
|
4017
|
+
* @returns 查询条件对象
|
|
3798
4018
|
*/
|
|
3799
|
-
|
|
4019
|
+
getCondition(): QueryCondition;
|
|
3800
4020
|
/**
|
|
3801
|
-
*
|
|
3802
|
-
* @param tag 实体标签
|
|
4021
|
+
* 获取required组件类型(用于类型推断)
|
|
3803
4022
|
*/
|
|
3804
|
-
|
|
4023
|
+
getRequiredTypes(): TAll;
|
|
3805
4024
|
/**
|
|
3806
|
-
*
|
|
3807
|
-
* @param processor 处理器
|
|
4025
|
+
* 克隆查询构建器
|
|
3808
4026
|
*/
|
|
3809
|
-
|
|
4027
|
+
clone(): TypedQueryBuilder<TAll, TAny, TNone>;
|
|
4028
|
+
}
|
|
4029
|
+
/**
|
|
4030
|
+
* 创建类型安全的查询构建器
|
|
4031
|
+
*
|
|
4032
|
+
* @example
|
|
4033
|
+
* ```typescript
|
|
4034
|
+
* const query = createQuery()
|
|
4035
|
+
* .withAll(Position, Velocity)
|
|
4036
|
+
* .withNone(Disabled);
|
|
4037
|
+
*
|
|
4038
|
+
* // 在System或Scene中使用
|
|
4039
|
+
* const entities = scene.query(query);
|
|
4040
|
+
* entities.forEach(entity => {
|
|
4041
|
+
* const pos = entity.getComponent(Position); // 自动推断为Position
|
|
4042
|
+
* const vel = entity.getComponent(Velocity); // 自动推断为Velocity
|
|
4043
|
+
* });
|
|
4044
|
+
* ```
|
|
4045
|
+
*/
|
|
4046
|
+
declare function createQuery(): TypedQueryBuilder<[], [], []>;
|
|
4047
|
+
/**
|
|
4048
|
+
* 创建单组件查询的便捷方法
|
|
4049
|
+
*
|
|
4050
|
+
* @param componentType 组件类型
|
|
4051
|
+
* @returns 查询构建器
|
|
4052
|
+
*
|
|
4053
|
+
* @example
|
|
4054
|
+
* ```typescript
|
|
4055
|
+
* const healthEntities = queryFor(HealthComponent);
|
|
4056
|
+
* ```
|
|
4057
|
+
*/
|
|
4058
|
+
declare function queryFor<T extends ComponentConstructor>(componentType: T): TypedQueryBuilder<readonly [T], [], []>;
|
|
4059
|
+
/**
|
|
4060
|
+
* 创建多组件查询的便捷方法
|
|
4061
|
+
*
|
|
4062
|
+
* @param types 组件类型数组
|
|
4063
|
+
* @returns 查询构建器
|
|
4064
|
+
*
|
|
4065
|
+
* @example
|
|
4066
|
+
* ```typescript
|
|
4067
|
+
* const movableEntities = queryForAll(Position, Velocity);
|
|
4068
|
+
* ```
|
|
4069
|
+
*/
|
|
4070
|
+
declare function queryForAll<T extends readonly ComponentConstructor[]>(...types: T): TypedQueryBuilder<T, [], []>;
|
|
4071
|
+
|
|
4072
|
+
/**
|
|
4073
|
+
* 组件序列化器
|
|
4074
|
+
*
|
|
4075
|
+
* 负责组件的序列化和反序列化操作
|
|
4076
|
+
*/
|
|
4077
|
+
|
|
4078
|
+
/**
|
|
4079
|
+
* 序列化后的组件数据
|
|
4080
|
+
*/
|
|
4081
|
+
interface SerializedComponent {
|
|
4082
|
+
/**
|
|
4083
|
+
* 组件类型名称
|
|
4084
|
+
*/
|
|
4085
|
+
type: string;
|
|
4086
|
+
/**
|
|
4087
|
+
* 序列化版本
|
|
4088
|
+
*/
|
|
4089
|
+
version: number;
|
|
4090
|
+
/**
|
|
4091
|
+
* 组件数据
|
|
4092
|
+
*/
|
|
4093
|
+
data: Record<string, any>;
|
|
4094
|
+
}
|
|
4095
|
+
/**
|
|
4096
|
+
* 组件序列化器类
|
|
4097
|
+
*/
|
|
4098
|
+
declare class ComponentSerializer {
|
|
4099
|
+
/**
|
|
4100
|
+
* 序列化单个组件
|
|
4101
|
+
*
|
|
4102
|
+
* @param component 要序列化的组件实例
|
|
4103
|
+
* @returns 序列化后的组件数据,如果组件不可序列化则返回null
|
|
4104
|
+
*/
|
|
4105
|
+
static serialize(component: Component): SerializedComponent | null;
|
|
4106
|
+
/**
|
|
4107
|
+
* 反序列化组件
|
|
4108
|
+
*
|
|
4109
|
+
* @param serializedData 序列化的组件数据
|
|
4110
|
+
* @param componentRegistry 组件类型注册表 (类型名 -> 构造函数)
|
|
4111
|
+
* @returns 反序列化后的组件实例,如果失败则返回null
|
|
4112
|
+
*/
|
|
4113
|
+
static deserialize(serializedData: SerializedComponent, componentRegistry: Map<string, ComponentType>): Component | null;
|
|
4114
|
+
/**
|
|
4115
|
+
* 批量序列化组件
|
|
4116
|
+
*
|
|
4117
|
+
* @param components 组件数组
|
|
4118
|
+
* @returns 序列化后的组件数据数组
|
|
4119
|
+
*/
|
|
4120
|
+
static serializeComponents(components: Component[]): SerializedComponent[];
|
|
4121
|
+
/**
|
|
4122
|
+
* 批量反序列化组件
|
|
4123
|
+
*
|
|
4124
|
+
* @param serializedComponents 序列化的组件数据数组
|
|
4125
|
+
* @param componentRegistry 组件类型注册表
|
|
4126
|
+
* @returns 反序列化后的组件数组
|
|
4127
|
+
*/
|
|
4128
|
+
static deserializeComponents(serializedComponents: SerializedComponent[], componentRegistry: Map<string, ComponentType>): Component[];
|
|
4129
|
+
/**
|
|
4130
|
+
* 默认值序列化
|
|
4131
|
+
*
|
|
4132
|
+
* 处理基本类型、数组、对象等的序列化
|
|
4133
|
+
*/
|
|
4134
|
+
private static serializeValue;
|
|
4135
|
+
/**
|
|
4136
|
+
* 默认值反序列化
|
|
4137
|
+
*/
|
|
4138
|
+
private static deserializeValue;
|
|
4139
|
+
/**
|
|
4140
|
+
* 验证序列化数据的版本
|
|
4141
|
+
*
|
|
4142
|
+
* @param serializedData 序列化数据
|
|
4143
|
+
* @param expectedVersion 期望的版本号
|
|
4144
|
+
* @returns 版本是否匹配
|
|
4145
|
+
*/
|
|
4146
|
+
static validateVersion(serializedData: SerializedComponent, expectedVersion: number): boolean;
|
|
4147
|
+
/**
|
|
4148
|
+
* 获取组件的序列化信息
|
|
4149
|
+
*
|
|
4150
|
+
* @param component 组件实例或组件类
|
|
4151
|
+
* @returns 序列化信息对象,包含类型名、版本、可序列化字段列表
|
|
4152
|
+
*/
|
|
4153
|
+
static getSerializationInfo(component: Component | ComponentType): {
|
|
4154
|
+
type: string;
|
|
4155
|
+
version: number;
|
|
4156
|
+
fields: string[];
|
|
4157
|
+
ignoredFields: string[];
|
|
4158
|
+
isSerializable: boolean;
|
|
4159
|
+
} | null;
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4162
|
+
/**
|
|
4163
|
+
* 实体序列化器
|
|
4164
|
+
*
|
|
4165
|
+
* 负责实体的序列化和反序列化操作
|
|
4166
|
+
*/
|
|
4167
|
+
|
|
4168
|
+
/**
|
|
4169
|
+
* 序列化后的实体数据
|
|
4170
|
+
*/
|
|
4171
|
+
interface SerializedEntity {
|
|
4172
|
+
/**
|
|
4173
|
+
* 实体ID
|
|
4174
|
+
*/
|
|
4175
|
+
id: number;
|
|
4176
|
+
/**
|
|
4177
|
+
* 实体名称
|
|
4178
|
+
*/
|
|
4179
|
+
name: string;
|
|
4180
|
+
/**
|
|
4181
|
+
* 实体标签
|
|
4182
|
+
*/
|
|
4183
|
+
tag: number;
|
|
4184
|
+
/**
|
|
4185
|
+
* 激活状态
|
|
4186
|
+
*/
|
|
4187
|
+
active: boolean;
|
|
4188
|
+
/**
|
|
4189
|
+
* 启用状态
|
|
4190
|
+
*/
|
|
4191
|
+
enabled: boolean;
|
|
4192
|
+
/**
|
|
4193
|
+
* 更新顺序
|
|
4194
|
+
*/
|
|
4195
|
+
updateOrder: number;
|
|
4196
|
+
/**
|
|
4197
|
+
* 组件列表
|
|
4198
|
+
*/
|
|
4199
|
+
components: SerializedComponent[];
|
|
4200
|
+
/**
|
|
4201
|
+
* 子实体列表
|
|
4202
|
+
*/
|
|
4203
|
+
children: SerializedEntity[];
|
|
4204
|
+
/**
|
|
4205
|
+
* 父实体ID(如果有)
|
|
4206
|
+
*/
|
|
4207
|
+
parentId?: number;
|
|
4208
|
+
}
|
|
4209
|
+
/**
|
|
4210
|
+
* 实体序列化器类
|
|
4211
|
+
*/
|
|
4212
|
+
declare class EntitySerializer {
|
|
4213
|
+
/**
|
|
4214
|
+
* 序列化单个实体
|
|
4215
|
+
*
|
|
4216
|
+
* @param entity 要序列化的实体
|
|
4217
|
+
* @param includeChildren 是否包含子实体(默认true)
|
|
4218
|
+
* @returns 序列化后的实体数据
|
|
4219
|
+
*/
|
|
4220
|
+
static serialize(entity: Entity, includeChildren?: boolean): SerializedEntity;
|
|
4221
|
+
/**
|
|
4222
|
+
* 反序列化实体
|
|
4223
|
+
*
|
|
4224
|
+
* @param serializedEntity 序列化的实体数据
|
|
4225
|
+
* @param componentRegistry 组件类型注册表
|
|
4226
|
+
* @param idGenerator 实体ID生成器(用于生成新ID或保持原ID)
|
|
4227
|
+
* @param preserveIds 是否保持原始ID(默认false)
|
|
4228
|
+
* @returns 反序列化后的实体
|
|
4229
|
+
*/
|
|
4230
|
+
static deserialize(serializedEntity: SerializedEntity, componentRegistry: Map<string, ComponentType>, idGenerator: () => number, preserveIds?: boolean): Entity;
|
|
4231
|
+
/**
|
|
4232
|
+
* 批量序列化实体
|
|
4233
|
+
*
|
|
4234
|
+
* @param entities 实体数组
|
|
4235
|
+
* @param includeChildren 是否包含子实体
|
|
4236
|
+
* @returns 序列化后的实体数据数组
|
|
4237
|
+
*/
|
|
4238
|
+
static serializeEntities(entities: Entity[], includeChildren?: boolean): SerializedEntity[];
|
|
4239
|
+
/**
|
|
4240
|
+
* 批量反序列化实体
|
|
4241
|
+
*
|
|
4242
|
+
* @param serializedEntities 序列化的实体数据数组
|
|
4243
|
+
* @param componentRegistry 组件类型注册表
|
|
4244
|
+
* @param idGenerator 实体ID生成器
|
|
4245
|
+
* @param preserveIds 是否保持原始ID
|
|
4246
|
+
* @returns 反序列化后的实体数组
|
|
4247
|
+
*/
|
|
4248
|
+
static deserializeEntities(serializedEntities: SerializedEntity[], componentRegistry: Map<string, ComponentType>, idGenerator: () => number, preserveIds?: boolean): Entity[];
|
|
4249
|
+
/**
|
|
4250
|
+
* 创建实体的深拷贝
|
|
4251
|
+
*
|
|
4252
|
+
* @param entity 要拷贝的实体
|
|
4253
|
+
* @param componentRegistry 组件类型注册表
|
|
4254
|
+
* @param idGenerator ID生成器
|
|
4255
|
+
* @returns 拷贝后的新实体
|
|
4256
|
+
*/
|
|
4257
|
+
static clone(entity: Entity, componentRegistry: Map<string, ComponentType>, idGenerator: () => number): Entity;
|
|
4258
|
+
}
|
|
4259
|
+
|
|
4260
|
+
/**
|
|
4261
|
+
* 场景序列化器
|
|
4262
|
+
*
|
|
4263
|
+
* 负责整个场景的序列化和反序列化,包括实体、组件等
|
|
4264
|
+
*/
|
|
4265
|
+
|
|
4266
|
+
/**
|
|
4267
|
+
* 场景序列化格式
|
|
4268
|
+
*/
|
|
4269
|
+
type SerializationFormat = 'json' | 'binary';
|
|
4270
|
+
/**
|
|
4271
|
+
* 场景序列化策略
|
|
4272
|
+
*/
|
|
4273
|
+
type DeserializationStrategy = 'merge' | 'replace';
|
|
4274
|
+
/**
|
|
4275
|
+
* 版本迁移函数
|
|
4276
|
+
*/
|
|
4277
|
+
type MigrationFunction = (oldVersion: number, newVersion: number, data: any) => any;
|
|
4278
|
+
/**
|
|
4279
|
+
* 场景序列化选项
|
|
4280
|
+
*/
|
|
4281
|
+
interface SceneSerializationOptions {
|
|
4282
|
+
/**
|
|
4283
|
+
* 要序列化的组件类型列表
|
|
4284
|
+
* 如果未指定,则序列化所有可序列化的组件
|
|
4285
|
+
*/
|
|
4286
|
+
components?: ComponentType[];
|
|
4287
|
+
/**
|
|
4288
|
+
* 是否序列化系统状态(当前不支持)
|
|
4289
|
+
*/
|
|
4290
|
+
systems?: boolean;
|
|
4291
|
+
/**
|
|
4292
|
+
* 序列化格式
|
|
4293
|
+
*/
|
|
4294
|
+
format?: SerializationFormat;
|
|
4295
|
+
/**
|
|
4296
|
+
* 是否美化JSON输出(仅在format='json'时有效)
|
|
4297
|
+
*/
|
|
4298
|
+
pretty?: boolean;
|
|
4299
|
+
/**
|
|
4300
|
+
* 是否包含元数据(如序列化时间、版本等)
|
|
4301
|
+
*/
|
|
4302
|
+
includeMetadata?: boolean;
|
|
4303
|
+
}
|
|
4304
|
+
/**
|
|
4305
|
+
* 场景反序列化选项
|
|
4306
|
+
*/
|
|
4307
|
+
interface SceneDeserializationOptions {
|
|
4308
|
+
/**
|
|
4309
|
+
* 反序列化策略
|
|
4310
|
+
* - 'merge': 合并到现有场景
|
|
4311
|
+
* - 'replace': 替换现有场景内容
|
|
4312
|
+
*/
|
|
4313
|
+
strategy?: DeserializationStrategy;
|
|
4314
|
+
/**
|
|
4315
|
+
* 版本迁移函数
|
|
4316
|
+
*/
|
|
4317
|
+
migration?: MigrationFunction;
|
|
4318
|
+
/**
|
|
4319
|
+
* 是否保持原始实体ID
|
|
4320
|
+
*/
|
|
4321
|
+
preserveIds?: boolean;
|
|
4322
|
+
/**
|
|
4323
|
+
* 组件类型注册表
|
|
4324
|
+
* 如果未提供,将尝试从全局注册表获取
|
|
4325
|
+
*/
|
|
4326
|
+
componentRegistry?: Map<string, ComponentType>;
|
|
4327
|
+
}
|
|
4328
|
+
/**
|
|
4329
|
+
* 序列化后的场景数据
|
|
4330
|
+
*/
|
|
4331
|
+
interface SerializedScene {
|
|
4332
|
+
/**
|
|
4333
|
+
* 场景名称
|
|
4334
|
+
*/
|
|
4335
|
+
name: string;
|
|
4336
|
+
/**
|
|
4337
|
+
* 序列化版本
|
|
4338
|
+
*/
|
|
4339
|
+
version: number;
|
|
4340
|
+
/**
|
|
4341
|
+
* 序列化时间戳
|
|
4342
|
+
*/
|
|
4343
|
+
timestamp?: number;
|
|
4344
|
+
/**
|
|
4345
|
+
* 场景自定义数据
|
|
4346
|
+
*
|
|
4347
|
+
* 存储场景级别的配置和状态
|
|
4348
|
+
*/
|
|
4349
|
+
sceneData?: Record<string, any>;
|
|
4350
|
+
/**
|
|
4351
|
+
* 实体列表
|
|
4352
|
+
*/
|
|
4353
|
+
entities: SerializedEntity[];
|
|
4354
|
+
/**
|
|
4355
|
+
* 元数据
|
|
4356
|
+
*/
|
|
4357
|
+
metadata?: {
|
|
4358
|
+
entityCount: number;
|
|
4359
|
+
componentTypeCount: number;
|
|
4360
|
+
serializationOptions?: SceneSerializationOptions;
|
|
4361
|
+
};
|
|
4362
|
+
/**
|
|
4363
|
+
* 组件类型注册信息
|
|
4364
|
+
*/
|
|
4365
|
+
componentTypeRegistry: Array<{
|
|
4366
|
+
typeName: string;
|
|
4367
|
+
version: number;
|
|
4368
|
+
}>;
|
|
4369
|
+
}
|
|
4370
|
+
/**
|
|
4371
|
+
* 场景序列化器类
|
|
4372
|
+
*/
|
|
4373
|
+
declare class SceneSerializer {
|
|
4374
|
+
/**
|
|
4375
|
+
* 当前序列化版本
|
|
4376
|
+
*/
|
|
4377
|
+
private static readonly SERIALIZATION_VERSION;
|
|
4378
|
+
/**
|
|
4379
|
+
* 序列化场景
|
|
4380
|
+
*
|
|
4381
|
+
* @param scene 要序列化的场景
|
|
4382
|
+
* @param options 序列化选项
|
|
4383
|
+
* @returns 序列化后的数据(JSON字符串或二进制Buffer)
|
|
4384
|
+
*/
|
|
4385
|
+
static serialize(scene: IScene, options?: SceneSerializationOptions): string | Buffer;
|
|
4386
|
+
/**
|
|
4387
|
+
* 反序列化场景
|
|
4388
|
+
*
|
|
4389
|
+
* @param scene 目标场景
|
|
4390
|
+
* @param saveData 序列化的数据(JSON字符串或二进制Buffer)
|
|
4391
|
+
* @param options 反序列化选项
|
|
4392
|
+
*/
|
|
4393
|
+
static deserialize(scene: IScene, saveData: string | Buffer, options?: SceneDeserializationOptions): void;
|
|
4394
|
+
/**
|
|
4395
|
+
* 序列化场景自定义数据
|
|
4396
|
+
*
|
|
4397
|
+
* 将 Map<string, any> 转换为普通对象
|
|
4398
|
+
*/
|
|
4399
|
+
private static serializeSceneData;
|
|
4400
|
+
/**
|
|
4401
|
+
* 反序列化场景自定义数据
|
|
4402
|
+
*
|
|
4403
|
+
* 将普通对象还原为 Map<string, any>
|
|
4404
|
+
*/
|
|
4405
|
+
private static deserializeSceneData;
|
|
4406
|
+
/**
|
|
4407
|
+
* 序列化单个值
|
|
4408
|
+
*/
|
|
4409
|
+
private static serializeValue;
|
|
4410
|
+
/**
|
|
4411
|
+
* 反序列化单个值
|
|
4412
|
+
*/
|
|
4413
|
+
private static deserializeValue;
|
|
4414
|
+
/**
|
|
4415
|
+
* 过滤要序列化的实体和组件
|
|
4416
|
+
*/
|
|
4417
|
+
private static filterEntities;
|
|
4418
|
+
/**
|
|
4419
|
+
* 构建组件类型注册表
|
|
4420
|
+
*/
|
|
4421
|
+
private static buildComponentTypeRegistry;
|
|
4422
|
+
/**
|
|
4423
|
+
* 获取全局组件注册表
|
|
4424
|
+
*
|
|
4425
|
+
* 从所有已注册的组件类型构建注册表
|
|
4426
|
+
*/
|
|
4427
|
+
private static getGlobalComponentRegistry;
|
|
4428
|
+
/**
|
|
4429
|
+
* 验证保存数据的有效性
|
|
4430
|
+
*
|
|
4431
|
+
* @param saveData 序列化的数据
|
|
4432
|
+
* @returns 验证结果
|
|
4433
|
+
*/
|
|
4434
|
+
static validate(saveData: string): {
|
|
4435
|
+
valid: boolean;
|
|
4436
|
+
version?: number;
|
|
4437
|
+
errors?: string[];
|
|
4438
|
+
};
|
|
4439
|
+
/**
|
|
4440
|
+
* 获取保存数据的信息(不完全反序列化)
|
|
4441
|
+
*
|
|
4442
|
+
* @param saveData 序列化的数据
|
|
4443
|
+
* @returns 保存数据的元信息
|
|
4444
|
+
*/
|
|
4445
|
+
static getInfo(saveData: string): {
|
|
4446
|
+
name: string;
|
|
4447
|
+
version: number;
|
|
4448
|
+
timestamp?: number;
|
|
4449
|
+
entityCount: number;
|
|
4450
|
+
componentTypeCount: number;
|
|
4451
|
+
} | null;
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
/**
|
|
4455
|
+
* 增量序列化器
|
|
4456
|
+
*
|
|
4457
|
+
* 提供高性能的增量序列化支持,只序列化变更的数据
|
|
4458
|
+
* 适用于网络同步、大场景存档、时间回溯等场景
|
|
4459
|
+
*/
|
|
4460
|
+
|
|
4461
|
+
/**
|
|
4462
|
+
* 变更操作类型
|
|
4463
|
+
*/
|
|
4464
|
+
declare enum ChangeOperation {
|
|
4465
|
+
/** 添加新实体 */
|
|
4466
|
+
EntityAdded = "entity_added",
|
|
4467
|
+
/** 删除实体 */
|
|
4468
|
+
EntityRemoved = "entity_removed",
|
|
4469
|
+
/** 实体属性更新 */
|
|
4470
|
+
EntityUpdated = "entity_updated",
|
|
4471
|
+
/** 添加组件 */
|
|
4472
|
+
ComponentAdded = "component_added",
|
|
4473
|
+
/** 删除组件 */
|
|
4474
|
+
ComponentRemoved = "component_removed",
|
|
4475
|
+
/** 组件数据更新 */
|
|
4476
|
+
ComponentUpdated = "component_updated",
|
|
4477
|
+
/** 场景数据更新 */
|
|
4478
|
+
SceneDataUpdated = "scene_data_updated"
|
|
4479
|
+
}
|
|
4480
|
+
/**
|
|
4481
|
+
* 实体变更记录
|
|
4482
|
+
*/
|
|
4483
|
+
interface EntityChange {
|
|
4484
|
+
/** 操作类型 */
|
|
4485
|
+
operation: ChangeOperation;
|
|
4486
|
+
/** 实体ID */
|
|
4487
|
+
entityId: number;
|
|
4488
|
+
/** 实体名称(用于Added操作) */
|
|
4489
|
+
entityName?: string;
|
|
4490
|
+
/** 实体数据(用于Added/Updated操作) */
|
|
4491
|
+
entityData?: Partial<SerializedEntity>;
|
|
4492
|
+
}
|
|
4493
|
+
/**
|
|
4494
|
+
* 组件变更记录
|
|
4495
|
+
*/
|
|
4496
|
+
interface ComponentChange {
|
|
4497
|
+
/** 操作类型 */
|
|
4498
|
+
operation: ChangeOperation;
|
|
4499
|
+
/** 实体ID */
|
|
4500
|
+
entityId: number;
|
|
4501
|
+
/** 组件类型名称 */
|
|
4502
|
+
componentType: string;
|
|
4503
|
+
/** 组件数据(用于Added/Updated操作) */
|
|
4504
|
+
componentData?: SerializedComponent;
|
|
4505
|
+
}
|
|
4506
|
+
/**
|
|
4507
|
+
* 场景数据变更记录
|
|
4508
|
+
*/
|
|
4509
|
+
interface SceneDataChange {
|
|
4510
|
+
/** 操作类型 */
|
|
4511
|
+
operation: ChangeOperation;
|
|
4512
|
+
/** 变更的键 */
|
|
4513
|
+
key: string;
|
|
4514
|
+
/** 新值 */
|
|
4515
|
+
value: any;
|
|
4516
|
+
/** 是否删除 */
|
|
4517
|
+
deleted?: boolean;
|
|
4518
|
+
}
|
|
4519
|
+
/**
|
|
4520
|
+
* 增量序列化数据
|
|
4521
|
+
*/
|
|
4522
|
+
interface IncrementalSnapshot {
|
|
4523
|
+
/** 快照版本号 */
|
|
4524
|
+
version: number;
|
|
4525
|
+
/** 时间戳 */
|
|
4526
|
+
timestamp: number;
|
|
4527
|
+
/** 场景名称 */
|
|
4528
|
+
sceneName: string;
|
|
4529
|
+
/** 基础版本号(相对于哪个快照的增量) */
|
|
4530
|
+
baseVersion: number;
|
|
4531
|
+
/** 实体变更列表 */
|
|
4532
|
+
entityChanges: EntityChange[];
|
|
4533
|
+
/** 组件变更列表 */
|
|
4534
|
+
componentChanges: ComponentChange[];
|
|
4535
|
+
/** 场景数据变更列表 */
|
|
4536
|
+
sceneDataChanges: SceneDataChange[];
|
|
4537
|
+
}
|
|
4538
|
+
/**
|
|
4539
|
+
* 场景快照(用于对比)
|
|
4540
|
+
*/
|
|
4541
|
+
interface SceneSnapshot {
|
|
4542
|
+
/** 快照版本号 */
|
|
4543
|
+
version: number;
|
|
4544
|
+
/** 实体ID集合 */
|
|
4545
|
+
entityIds: Set<number>;
|
|
4546
|
+
/** 实体数据映射 */
|
|
4547
|
+
entities: Map<number, {
|
|
4548
|
+
name: string;
|
|
4549
|
+
tag: number;
|
|
4550
|
+
active: boolean;
|
|
4551
|
+
enabled: boolean;
|
|
4552
|
+
updateOrder: number;
|
|
4553
|
+
parentId?: number;
|
|
4554
|
+
}>;
|
|
4555
|
+
/** 组件数据映射 (entityId -> componentType -> serializedData) */
|
|
4556
|
+
components: Map<number, Map<string, string>>;
|
|
4557
|
+
/** 场景自定义数据 */
|
|
4558
|
+
sceneData: Map<string, string>;
|
|
4559
|
+
}
|
|
4560
|
+
/**
|
|
4561
|
+
* 增量序列化格式
|
|
4562
|
+
*/
|
|
4563
|
+
type IncrementalSerializationFormat = 'json' | 'binary';
|
|
4564
|
+
/**
|
|
4565
|
+
* 增量序列化选项
|
|
4566
|
+
*/
|
|
4567
|
+
interface IncrementalSerializationOptions {
|
|
4568
|
+
/**
|
|
4569
|
+
* 是否包含组件数据的深度对比
|
|
4570
|
+
* 默认true,设为false可提升性能但可能漏掉组件内部字段变更
|
|
4571
|
+
*/
|
|
4572
|
+
deepComponentComparison?: boolean;
|
|
4573
|
+
/**
|
|
4574
|
+
* 是否跟踪场景数据变更
|
|
4575
|
+
* 默认true
|
|
4576
|
+
*/
|
|
4577
|
+
trackSceneData?: boolean;
|
|
4578
|
+
/**
|
|
4579
|
+
* 是否压缩快照(使用JSON序列化)
|
|
4580
|
+
* 默认false,设为true可减少内存占用但增加CPU开销
|
|
4581
|
+
*/
|
|
4582
|
+
compressSnapshot?: boolean;
|
|
4583
|
+
/**
|
|
4584
|
+
* 序列化格式
|
|
4585
|
+
* - 'json': JSON格式(可读性好,方便调试)
|
|
4586
|
+
* - 'binary': MessagePack二进制格式(体积小,性能高)
|
|
4587
|
+
* 默认 'json'
|
|
4588
|
+
*/
|
|
4589
|
+
format?: IncrementalSerializationFormat;
|
|
4590
|
+
/**
|
|
4591
|
+
* 是否美化JSON输出(仅在format='json'时有效)
|
|
4592
|
+
* 默认false
|
|
4593
|
+
*/
|
|
4594
|
+
pretty?: boolean;
|
|
4595
|
+
}
|
|
4596
|
+
/**
|
|
4597
|
+
* 增量序列化器类
|
|
4598
|
+
*/
|
|
4599
|
+
declare class IncrementalSerializer {
|
|
4600
|
+
/** 当前快照版本号 */
|
|
4601
|
+
private static snapshotVersion;
|
|
4602
|
+
/**
|
|
4603
|
+
* 创建场景快照
|
|
4604
|
+
*
|
|
4605
|
+
* @param scene 要快照的场景
|
|
4606
|
+
* @param options 序列化选项
|
|
4607
|
+
* @returns 场景快照对象
|
|
4608
|
+
*/
|
|
4609
|
+
static createSnapshot(scene: IScene, options?: IncrementalSerializationOptions): SceneSnapshot;
|
|
4610
|
+
/**
|
|
4611
|
+
* 计算增量变更
|
|
4612
|
+
*
|
|
4613
|
+
* @param scene 当前场景
|
|
4614
|
+
* @param baseSnapshot 基础快照
|
|
4615
|
+
* @param options 序列化选项
|
|
4616
|
+
* @returns 增量快照
|
|
4617
|
+
*/
|
|
4618
|
+
static computeIncremental(scene: IScene, baseSnapshot: SceneSnapshot, options?: IncrementalSerializationOptions): IncrementalSnapshot;
|
|
4619
|
+
/**
|
|
4620
|
+
* 检测组件变更
|
|
4621
|
+
*/
|
|
4622
|
+
private static detectComponentChanges;
|
|
4623
|
+
/**
|
|
4624
|
+
* 检测场景数据变更
|
|
4625
|
+
*/
|
|
4626
|
+
private static detectSceneDataChanges;
|
|
4627
|
+
/**
|
|
4628
|
+
* 应用增量变更到场景
|
|
4629
|
+
*
|
|
4630
|
+
* @param scene 目标场景
|
|
4631
|
+
* @param incremental 增量快照
|
|
4632
|
+
* @param componentRegistry 组件类型注册表
|
|
4633
|
+
*/
|
|
4634
|
+
static applyIncremental(scene: IScene, incremental: IncrementalSnapshot, componentRegistry: Map<string, ComponentType>): void;
|
|
4635
|
+
private static applyEntityAdded;
|
|
4636
|
+
private static applyEntityRemoved;
|
|
4637
|
+
private static applyEntityUpdated;
|
|
4638
|
+
private static applyComponentAdded;
|
|
4639
|
+
private static applyComponentRemoved;
|
|
4640
|
+
private static applyComponentUpdated;
|
|
4641
|
+
/**
|
|
4642
|
+
* 序列化增量快照
|
|
4643
|
+
*
|
|
4644
|
+
* @param incremental 增量快照
|
|
4645
|
+
* @param options 序列化选项
|
|
4646
|
+
* @returns 序列化后的数据(JSON字符串或二进制Buffer)
|
|
4647
|
+
*
|
|
4648
|
+
* @example
|
|
4649
|
+
* ```typescript
|
|
4650
|
+
* // JSON格式(默认)
|
|
4651
|
+
* const jsonData = IncrementalSerializer.serializeIncremental(snapshot);
|
|
4652
|
+
*
|
|
4653
|
+
* // 二进制格式
|
|
4654
|
+
* const binaryData = IncrementalSerializer.serializeIncremental(snapshot, {
|
|
4655
|
+
* format: 'binary'
|
|
4656
|
+
* });
|
|
4657
|
+
*
|
|
4658
|
+
* // 美化JSON
|
|
4659
|
+
* const prettyJson = IncrementalSerializer.serializeIncremental(snapshot, {
|
|
4660
|
+
* format: 'json',
|
|
4661
|
+
* pretty: true
|
|
4662
|
+
* });
|
|
4663
|
+
* ```
|
|
4664
|
+
*/
|
|
4665
|
+
static serializeIncremental(incremental: IncrementalSnapshot, options?: {
|
|
4666
|
+
format?: IncrementalSerializationFormat;
|
|
4667
|
+
pretty?: boolean;
|
|
4668
|
+
}): string | Buffer;
|
|
4669
|
+
/**
|
|
4670
|
+
* 反序列化增量快照
|
|
4671
|
+
*
|
|
4672
|
+
* @param data 序列化的数据(JSON字符串或二进制Buffer)
|
|
4673
|
+
* @returns 增量快照
|
|
4674
|
+
*
|
|
4675
|
+
* @example
|
|
4676
|
+
* ```typescript
|
|
4677
|
+
* // 从JSON反序列化
|
|
4678
|
+
* const snapshot = IncrementalSerializer.deserializeIncremental(jsonString);
|
|
4679
|
+
*
|
|
4680
|
+
* // 从二进制反序列化
|
|
4681
|
+
* const snapshot = IncrementalSerializer.deserializeIncremental(buffer);
|
|
4682
|
+
* ```
|
|
4683
|
+
*/
|
|
4684
|
+
static deserializeIncremental(data: string | Buffer): IncrementalSnapshot;
|
|
4685
|
+
/**
|
|
4686
|
+
* 计算增量快照的大小(字节)
|
|
4687
|
+
*
|
|
4688
|
+
* @param incremental 增量快照
|
|
4689
|
+
* @param format 序列化格式,默认为 'json'
|
|
4690
|
+
* @returns 字节数
|
|
4691
|
+
*/
|
|
4692
|
+
static getIncrementalSize(incremental: IncrementalSnapshot, format?: IncrementalSerializationFormat): number;
|
|
4693
|
+
/**
|
|
4694
|
+
* 获取增量快照的统计信息
|
|
4695
|
+
*
|
|
4696
|
+
* @param incremental 增量快照
|
|
4697
|
+
* @returns 统计信息
|
|
4698
|
+
*/
|
|
4699
|
+
static getIncrementalStats(incremental: IncrementalSnapshot): {
|
|
4700
|
+
totalChanges: number;
|
|
4701
|
+
entityChanges: number;
|
|
4702
|
+
componentChanges: number;
|
|
4703
|
+
sceneDataChanges: number;
|
|
4704
|
+
addedEntities: number;
|
|
4705
|
+
removedEntities: number;
|
|
4706
|
+
updatedEntities: number;
|
|
4707
|
+
addedComponents: number;
|
|
4708
|
+
removedComponents: number;
|
|
4709
|
+
updatedComponents: number;
|
|
4710
|
+
};
|
|
4711
|
+
/**
|
|
4712
|
+
* 重置快照版本号(用于测试)
|
|
4713
|
+
*/
|
|
4714
|
+
static resetVersion(): void;
|
|
4715
|
+
}
|
|
4716
|
+
|
|
4717
|
+
/**
|
|
4718
|
+
* 游戏场景默认实现类
|
|
4719
|
+
*
|
|
4720
|
+
* 实现IScene接口,提供场景的基础功能。
|
|
4721
|
+
* 推荐使用组合而非继承的方式来构建自定义场景。
|
|
4722
|
+
*/
|
|
4723
|
+
declare class Scene implements IScene {
|
|
4724
|
+
/**
|
|
4725
|
+
* 场景名称
|
|
4726
|
+
*
|
|
4727
|
+
* 用于标识和调试的友好名称。
|
|
4728
|
+
*/
|
|
4729
|
+
name: string;
|
|
4730
|
+
/**
|
|
4731
|
+
* 场景自定义数据
|
|
4732
|
+
*
|
|
4733
|
+
* 用于存储场景级别的配置和状态数据。
|
|
4734
|
+
*/
|
|
4735
|
+
readonly sceneData: Map<string, any>;
|
|
4736
|
+
/**
|
|
4737
|
+
* 场景中的实体集合
|
|
4738
|
+
*
|
|
4739
|
+
* 管理场景内所有实体的生命周期。
|
|
4740
|
+
*/
|
|
4741
|
+
readonly entities: EntityList;
|
|
4742
|
+
/**
|
|
4743
|
+
* 实体系统处理器集合
|
|
4744
|
+
*
|
|
4745
|
+
* 管理场景内所有实体系统的执行。
|
|
4746
|
+
*/
|
|
4747
|
+
readonly entityProcessors: EntityProcessorList;
|
|
4748
|
+
/**
|
|
4749
|
+
* 实体ID池
|
|
4750
|
+
*
|
|
4751
|
+
* 用于分配和回收实体的唯一标识符。
|
|
4752
|
+
*/
|
|
4753
|
+
readonly identifierPool: IdentifierPool;
|
|
4754
|
+
/**
|
|
4755
|
+
* 组件存储管理器
|
|
4756
|
+
*
|
|
4757
|
+
* 高性能的组件存储和查询系统。
|
|
4758
|
+
*/
|
|
4759
|
+
readonly componentStorageManager: ComponentStorageManager;
|
|
4760
|
+
/**
|
|
4761
|
+
* 查询系统
|
|
4762
|
+
*
|
|
4763
|
+
* 基于位掩码的高性能实体查询系统。
|
|
4764
|
+
*/
|
|
4765
|
+
readonly querySystem: QuerySystem;
|
|
4766
|
+
/**
|
|
4767
|
+
* 事件系统
|
|
4768
|
+
*
|
|
4769
|
+
* 类型安全的事件系统。
|
|
4770
|
+
*/
|
|
4771
|
+
readonly eventSystem: TypeSafeEventSystem;
|
|
4772
|
+
/**
|
|
4773
|
+
* 场景是否已开始运行
|
|
4774
|
+
*/
|
|
4775
|
+
private _didSceneBegin;
|
|
4776
|
+
/**
|
|
4777
|
+
* 获取系统列表(兼容性属性)
|
|
4778
|
+
*/
|
|
4779
|
+
get systems(): EntitySystem[];
|
|
4780
|
+
/**
|
|
4781
|
+
* 创建场景实例
|
|
4782
|
+
*/
|
|
4783
|
+
constructor(config?: ISceneConfig);
|
|
4784
|
+
/**
|
|
4785
|
+
* 初始化场景
|
|
4786
|
+
*
|
|
4787
|
+
* 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
|
|
4788
|
+
*/
|
|
4789
|
+
initialize(): void;
|
|
4790
|
+
/**
|
|
4791
|
+
* 场景开始运行时的回调
|
|
4792
|
+
*
|
|
4793
|
+
* 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
|
|
4794
|
+
*/
|
|
4795
|
+
onStart(): void;
|
|
4796
|
+
/**
|
|
4797
|
+
* 场景卸载时的回调
|
|
4798
|
+
*
|
|
4799
|
+
* 在场景被销毁时调用,可以在此方法中执行清理工作。
|
|
4800
|
+
*/
|
|
4801
|
+
unload(): void;
|
|
4802
|
+
/**
|
|
4803
|
+
* 开始场景,启动实体处理器等
|
|
4804
|
+
*
|
|
4805
|
+
* 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
|
|
4806
|
+
*/
|
|
4807
|
+
begin(): void;
|
|
4808
|
+
/**
|
|
4809
|
+
* 结束场景,清除实体、实体处理器等
|
|
4810
|
+
*
|
|
4811
|
+
* 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
|
|
4812
|
+
*/
|
|
4813
|
+
end(): void;
|
|
4814
|
+
/**
|
|
4815
|
+
* 更新场景
|
|
4816
|
+
*/
|
|
4817
|
+
update(): void;
|
|
4818
|
+
/**
|
|
4819
|
+
* 将实体添加到此场景,并返回它
|
|
4820
|
+
* @param name 实体名称
|
|
4821
|
+
*/
|
|
4822
|
+
createEntity(name: string): Entity;
|
|
4823
|
+
/**
|
|
4824
|
+
* 清除所有EntitySystem的实体缓存
|
|
4825
|
+
* 当实体或组件发生变化时调用
|
|
4826
|
+
*/
|
|
4827
|
+
clearSystemEntityCaches(): void;
|
|
4828
|
+
/**
|
|
4829
|
+
* 在场景的实体列表中添加一个实体
|
|
4830
|
+
* @param entity 要添加的实体
|
|
4831
|
+
* @param deferCacheClear 是否延迟缓存清理(用于批量操作)
|
|
4832
|
+
*/
|
|
4833
|
+
addEntity(entity: Entity, deferCacheClear?: boolean): Entity;
|
|
4834
|
+
/**
|
|
4835
|
+
* 批量创建实体(高性能版本)
|
|
4836
|
+
* @param count 要创建的实体数量
|
|
4837
|
+
* @param namePrefix 实体名称前缀
|
|
4838
|
+
* @returns 创建的实体列表
|
|
4839
|
+
*/
|
|
4840
|
+
createEntities(count: number, namePrefix?: string): Entity[];
|
|
4841
|
+
/**
|
|
4842
|
+
* 从场景中删除所有实体
|
|
4843
|
+
*/
|
|
4844
|
+
destroyAllEntities(): void;
|
|
4845
|
+
/**
|
|
4846
|
+
* 搜索并返回第一个具有名称的实体
|
|
4847
|
+
* @param name 实体名称
|
|
4848
|
+
*/
|
|
4849
|
+
findEntity(name: string): Entity | null;
|
|
4850
|
+
/**
|
|
4851
|
+
* 根据ID查找实体
|
|
4852
|
+
* @param id 实体ID
|
|
4853
|
+
*/
|
|
4854
|
+
findEntityById(id: number): Entity | null;
|
|
4855
|
+
/**
|
|
4856
|
+
* 根据标签查找实体
|
|
4857
|
+
* @param tag 实体标签
|
|
4858
|
+
*/
|
|
4859
|
+
findEntitiesByTag(tag: number): Entity[];
|
|
4860
|
+
/**
|
|
4861
|
+
* 根据名称查找实体(别名方法)
|
|
4862
|
+
* @param name 实体名称
|
|
4863
|
+
*/
|
|
4864
|
+
getEntityByName(name: string): Entity | null;
|
|
4865
|
+
/**
|
|
4866
|
+
* 根据标签查找实体(别名方法)
|
|
4867
|
+
* @param tag 实体标签
|
|
4868
|
+
*/
|
|
4869
|
+
getEntitiesByTag(tag: number): Entity[];
|
|
4870
|
+
/**
|
|
4871
|
+
* 查询拥有所有指定组件的实体
|
|
4872
|
+
*
|
|
4873
|
+
* @param componentTypes - 组件类型数组
|
|
4874
|
+
* @returns 查询结果
|
|
4875
|
+
*
|
|
4876
|
+
* @example
|
|
4877
|
+
* ```typescript
|
|
4878
|
+
* const result = scene.queryAll(Position, Velocity);
|
|
4879
|
+
* for (const entity of result.entities) {
|
|
4880
|
+
* const pos = entity.getComponent(Position);
|
|
4881
|
+
* const vel = entity.getComponent(Velocity);
|
|
4882
|
+
* }
|
|
4883
|
+
* ```
|
|
4884
|
+
*/
|
|
4885
|
+
queryAll(...componentTypes: any[]): {
|
|
4886
|
+
entities: readonly Entity[];
|
|
4887
|
+
};
|
|
4888
|
+
/**
|
|
4889
|
+
* 查询拥有任意一个指定组件的实体
|
|
4890
|
+
*
|
|
4891
|
+
* @param componentTypes - 组件类型数组
|
|
4892
|
+
* @returns 查询结果
|
|
4893
|
+
*/
|
|
4894
|
+
queryAny(...componentTypes: any[]): {
|
|
4895
|
+
entities: readonly Entity[];
|
|
4896
|
+
};
|
|
4897
|
+
/**
|
|
4898
|
+
* 查询不包含指定组件的实体
|
|
4899
|
+
*
|
|
4900
|
+
* @param componentTypes - 组件类型数组
|
|
4901
|
+
* @returns 查询结果
|
|
4902
|
+
*/
|
|
4903
|
+
queryNone(...componentTypes: any[]): {
|
|
4904
|
+
entities: readonly Entity[];
|
|
4905
|
+
};
|
|
4906
|
+
/**
|
|
4907
|
+
* 创建类型安全的查询构建器
|
|
4908
|
+
*
|
|
4909
|
+
* @returns 查询构建器,支持链式调用
|
|
4910
|
+
*
|
|
4911
|
+
* @example
|
|
4912
|
+
* ```typescript
|
|
4913
|
+
* // 使用查询构建器
|
|
4914
|
+
* const matcher = scene.query()
|
|
4915
|
+
* .withAll(Position, Velocity)
|
|
4916
|
+
* .withNone(Disabled)
|
|
4917
|
+
* .buildMatcher();
|
|
4918
|
+
*
|
|
4919
|
+
* // 在System中使用
|
|
4920
|
+
* class MovementSystem extends EntitySystem {
|
|
4921
|
+
* constructor() {
|
|
4922
|
+
* super(matcher);
|
|
4923
|
+
* }
|
|
4924
|
+
* }
|
|
4925
|
+
* ```
|
|
4926
|
+
*/
|
|
4927
|
+
query(): TypedQueryBuilder;
|
|
4928
|
+
/**
|
|
4929
|
+
* 在场景中添加一个EntitySystem处理器
|
|
4930
|
+
* @param processor 处理器
|
|
4931
|
+
*/
|
|
4932
|
+
addEntityProcessor(processor: EntitySystem): EntitySystem<[]>;
|
|
3810
4933
|
/**
|
|
3811
4934
|
* 添加系统到场景(addEntityProcessor的别名)
|
|
3812
4935
|
* @param system 系统
|
|
3813
4936
|
*/
|
|
3814
|
-
addSystem(system: EntitySystem): EntitySystem
|
|
4937
|
+
addSystem(system: EntitySystem): EntitySystem<[]>;
|
|
3815
4938
|
/**
|
|
3816
4939
|
* 从场景中删除EntitySystem处理器
|
|
3817
4940
|
* @param processor 要删除的处理器
|
|
@@ -3856,6 +4979,155 @@ declare class Scene implements IScene {
|
|
|
3856
4979
|
}>;
|
|
3857
4980
|
componentStats: Map<string, any>;
|
|
3858
4981
|
};
|
|
4982
|
+
/**
|
|
4983
|
+
* 序列化场景
|
|
4984
|
+
*
|
|
4985
|
+
* 将场景及其所有实体、组件序列化为JSON字符串或二进制Buffer
|
|
4986
|
+
*
|
|
4987
|
+
* @param options 序列化选项
|
|
4988
|
+
* @returns 序列化后的数据(JSON字符串或二进制Buffer)
|
|
4989
|
+
*
|
|
4990
|
+
* @example
|
|
4991
|
+
* ```typescript
|
|
4992
|
+
* // JSON格式
|
|
4993
|
+
* const jsonData = scene.serialize({
|
|
4994
|
+
* format: 'json',
|
|
4995
|
+
* pretty: true
|
|
4996
|
+
* });
|
|
4997
|
+
*
|
|
4998
|
+
* // 二进制格式(更小、更快)
|
|
4999
|
+
* const binaryData = scene.serialize({
|
|
5000
|
+
* format: 'binary'
|
|
5001
|
+
* });
|
|
5002
|
+
* ```
|
|
5003
|
+
*/
|
|
5004
|
+
serialize(options?: SceneSerializationOptions): string | Buffer;
|
|
5005
|
+
/**
|
|
5006
|
+
* 反序列化场景
|
|
5007
|
+
*
|
|
5008
|
+
* 从序列化数据恢复场景状态
|
|
5009
|
+
*
|
|
5010
|
+
* @param saveData 序列化的数据(JSON字符串或二进制Buffer)
|
|
5011
|
+
* @param options 反序列化选项
|
|
5012
|
+
*
|
|
5013
|
+
* @example
|
|
5014
|
+
* ```typescript
|
|
5015
|
+
* // 从JSON恢复(自动从ComponentRegistry获取组件类型)
|
|
5016
|
+
* scene.deserialize(jsonData, {
|
|
5017
|
+
* strategy: 'replace'
|
|
5018
|
+
* });
|
|
5019
|
+
*
|
|
5020
|
+
* // 从二进制恢复
|
|
5021
|
+
* scene.deserialize(binaryData, {
|
|
5022
|
+
* strategy: 'replace'
|
|
5023
|
+
* });
|
|
5024
|
+
* ```
|
|
5025
|
+
*/
|
|
5026
|
+
deserialize(saveData: string | Buffer, options?: SceneDeserializationOptions): void;
|
|
5027
|
+
/** 增量序列化的基础快照 */
|
|
5028
|
+
private _incrementalBaseSnapshot?;
|
|
5029
|
+
/**
|
|
5030
|
+
* 创建增量序列化的基础快照
|
|
5031
|
+
*
|
|
5032
|
+
* 在需要进行增量序列化前,先调用此方法创建基础快照
|
|
5033
|
+
*
|
|
5034
|
+
* @param options 序列化选项
|
|
5035
|
+
*
|
|
5036
|
+
* @example
|
|
5037
|
+
* ```typescript
|
|
5038
|
+
* // 创建基础快照
|
|
5039
|
+
* scene.createIncrementalSnapshot();
|
|
5040
|
+
*
|
|
5041
|
+
* // 进行一些修改...
|
|
5042
|
+
* entity.addComponent(new PositionComponent(100, 200));
|
|
5043
|
+
*
|
|
5044
|
+
* // 计算增量变更
|
|
5045
|
+
* const incremental = scene.serializeIncremental();
|
|
5046
|
+
* ```
|
|
5047
|
+
*/
|
|
5048
|
+
createIncrementalSnapshot(options?: IncrementalSerializationOptions): void;
|
|
5049
|
+
/**
|
|
5050
|
+
* 增量序列化场景
|
|
5051
|
+
*
|
|
5052
|
+
* 只序列化相对于基础快照的变更部分
|
|
5053
|
+
*
|
|
5054
|
+
* @param options 序列化选项
|
|
5055
|
+
* @returns 增量快照对象
|
|
5056
|
+
*
|
|
5057
|
+
* @example
|
|
5058
|
+
* ```typescript
|
|
5059
|
+
* // 创建基础快照
|
|
5060
|
+
* scene.createIncrementalSnapshot();
|
|
5061
|
+
*
|
|
5062
|
+
* // 修改场景
|
|
5063
|
+
* const entity = scene.createEntity('NewEntity');
|
|
5064
|
+
* entity.addComponent(new PositionComponent(50, 100));
|
|
5065
|
+
*
|
|
5066
|
+
* // 获取增量变更
|
|
5067
|
+
* const incremental = scene.serializeIncremental();
|
|
5068
|
+
* console.log(`变更数量: ${incremental.entityChanges.length}`);
|
|
5069
|
+
*
|
|
5070
|
+
* // 序列化为JSON
|
|
5071
|
+
* const json = IncrementalSerializer.serializeIncremental(incremental);
|
|
5072
|
+
* ```
|
|
5073
|
+
*/
|
|
5074
|
+
serializeIncremental(options?: IncrementalSerializationOptions): IncrementalSnapshot;
|
|
5075
|
+
/**
|
|
5076
|
+
* 应用增量变更到场景
|
|
5077
|
+
*
|
|
5078
|
+
* @param incremental 增量快照数据(IncrementalSnapshot对象、JSON字符串或二进制Buffer)
|
|
5079
|
+
* @param componentRegistry 组件类型注册表(可选,默认使用全局注册表)
|
|
5080
|
+
*
|
|
5081
|
+
* @example
|
|
5082
|
+
* ```typescript
|
|
5083
|
+
* // 应用增量变更对象
|
|
5084
|
+
* scene.applyIncremental(incrementalSnapshot);
|
|
5085
|
+
*
|
|
5086
|
+
* // 从JSON字符串应用
|
|
5087
|
+
* const jsonData = IncrementalSerializer.serializeIncremental(snapshot, { format: 'json' });
|
|
5088
|
+
* scene.applyIncremental(jsonData);
|
|
5089
|
+
*
|
|
5090
|
+
* // 从二进制Buffer应用
|
|
5091
|
+
* const binaryData = IncrementalSerializer.serializeIncremental(snapshot, { format: 'binary' });
|
|
5092
|
+
* scene.applyIncremental(binaryData);
|
|
5093
|
+
* ```
|
|
5094
|
+
*/
|
|
5095
|
+
applyIncremental(incremental: IncrementalSnapshot | string | Buffer, componentRegistry?: Map<string, any>): void;
|
|
5096
|
+
/**
|
|
5097
|
+
* 更新增量快照基准
|
|
5098
|
+
*
|
|
5099
|
+
* 将当前场景状态设为新的增量序列化基准
|
|
5100
|
+
*
|
|
5101
|
+
* @param options 序列化选项
|
|
5102
|
+
*
|
|
5103
|
+
* @example
|
|
5104
|
+
* ```typescript
|
|
5105
|
+
* // 创建初始快照
|
|
5106
|
+
* scene.createIncrementalSnapshot();
|
|
5107
|
+
*
|
|
5108
|
+
* // 进行一些修改并序列化
|
|
5109
|
+
* const incremental1 = scene.serializeIncremental();
|
|
5110
|
+
*
|
|
5111
|
+
* // 更新基准,之后的增量将基于当前状态
|
|
5112
|
+
* scene.updateIncrementalSnapshot();
|
|
5113
|
+
*
|
|
5114
|
+
* // 继续修改
|
|
5115
|
+
* const incremental2 = scene.serializeIncremental();
|
|
5116
|
+
* ```
|
|
5117
|
+
*/
|
|
5118
|
+
updateIncrementalSnapshot(options?: IncrementalSerializationOptions): void;
|
|
5119
|
+
/**
|
|
5120
|
+
* 清除增量快照
|
|
5121
|
+
*
|
|
5122
|
+
* 释放快照占用的内存
|
|
5123
|
+
*/
|
|
5124
|
+
clearIncrementalSnapshot(): void;
|
|
5125
|
+
/**
|
|
5126
|
+
* 检查是否有增量快照
|
|
5127
|
+
*
|
|
5128
|
+
* @returns 如果已创建增量快照返回true
|
|
5129
|
+
*/
|
|
5130
|
+
hasIncrementalSnapshot(): boolean;
|
|
3859
5131
|
}
|
|
3860
5132
|
|
|
3861
5133
|
/**
|
|
@@ -3864,11 +5136,16 @@ declare class Scene implements IScene {
|
|
|
3864
5136
|
* 用于处理一组符合特定条件的实体。系统是ECS架构中的逻辑处理单元,
|
|
3865
5137
|
* 负责对拥有特定组件组合的实体执行业务逻辑。
|
|
3866
5138
|
*
|
|
5139
|
+
* 支持泛型参数以提供类型安全的组件访问:
|
|
5140
|
+
*
|
|
5141
|
+
* @template TComponents - 系统需要的组件类型数组
|
|
5142
|
+
*
|
|
3867
5143
|
* @example
|
|
3868
5144
|
* ```typescript
|
|
5145
|
+
* // 传统方式
|
|
3869
5146
|
* class MovementSystem extends EntitySystem {
|
|
3870
5147
|
* constructor() {
|
|
3871
|
-
* super(Transform, Velocity);
|
|
5148
|
+
* super(Matcher.of(Transform, Velocity));
|
|
3872
5149
|
* }
|
|
3873
5150
|
*
|
|
3874
5151
|
* protected process(entities: readonly Entity[]): void {
|
|
@@ -3879,9 +5156,24 @@ declare class Scene implements IScene {
|
|
|
3879
5156
|
* }
|
|
3880
5157
|
* }
|
|
3881
5158
|
* }
|
|
5159
|
+
*
|
|
5160
|
+
* // 类型安全方式
|
|
5161
|
+
* class MovementSystem extends EntitySystem<[typeof Transform, typeof Velocity]> {
|
|
5162
|
+
* constructor() {
|
|
5163
|
+
* super(Matcher.of(Transform, Velocity));
|
|
5164
|
+
* }
|
|
5165
|
+
*
|
|
5166
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5167
|
+
* for (const entity of entities) {
|
|
5168
|
+
* // 类型安全的组件访问
|
|
5169
|
+
* const [transform, velocity] = this.getComponents(entity);
|
|
5170
|
+
* transform.position.add(velocity.value);
|
|
5171
|
+
* }
|
|
5172
|
+
* }
|
|
5173
|
+
* }
|
|
3882
5174
|
* ```
|
|
3883
5175
|
*/
|
|
3884
|
-
declare abstract class EntitySystem implements ISystemBase {
|
|
5176
|
+
declare abstract class EntitySystem<TComponents extends readonly ComponentConstructor[] = []> implements ISystemBase {
|
|
3885
5177
|
private _updateOrder;
|
|
3886
5178
|
private _enabled;
|
|
3887
5179
|
private _performanceMonitor;
|
|
@@ -4132,6 +5424,162 @@ declare abstract class EntitySystem implements ISystemBase {
|
|
|
4132
5424
|
* 注意:事件监听器会被框架自动清理,无需手动处理。
|
|
4133
5425
|
*/
|
|
4134
5426
|
protected onDestroy(): void;
|
|
5427
|
+
/**
|
|
5428
|
+
* 类型安全地获取单个组件
|
|
5429
|
+
*
|
|
5430
|
+
* 相比Entity.getComponent,此方法保证返回非空值,
|
|
5431
|
+
* 如果组件不存在会抛出错误而不是返回null
|
|
5432
|
+
*
|
|
5433
|
+
* @param entity 实体
|
|
5434
|
+
* @param componentType 组件类型
|
|
5435
|
+
* @returns 组件实例(保证非空)
|
|
5436
|
+
* @throws 如果组件不存在则抛出错误
|
|
5437
|
+
*
|
|
5438
|
+
* @example
|
|
5439
|
+
* ```typescript
|
|
5440
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5441
|
+
* for (const entity of entities) {
|
|
5442
|
+
* const transform = this.requireComponent(entity, Transform);
|
|
5443
|
+
* // transform 保证非空,类型为 Transform
|
|
5444
|
+
* }
|
|
5445
|
+
* }
|
|
5446
|
+
* ```
|
|
5447
|
+
*/
|
|
5448
|
+
protected requireComponent<T extends ComponentConstructor>(entity: Entity, componentType: T): ComponentInstance<T>;
|
|
5449
|
+
/**
|
|
5450
|
+
* 批量获取实体的所有必需组件
|
|
5451
|
+
*
|
|
5452
|
+
* 根据泛型参数TComponents推断返回类型,
|
|
5453
|
+
* 返回一个元组,包含所有组件实例
|
|
5454
|
+
*
|
|
5455
|
+
* @param entity 实体
|
|
5456
|
+
* @param components 组件类型数组
|
|
5457
|
+
* @returns 组件实例元组
|
|
5458
|
+
*
|
|
5459
|
+
* @example
|
|
5460
|
+
* ```typescript
|
|
5461
|
+
* class MySystem extends EntitySystem<[typeof Position, typeof Velocity]> {
|
|
5462
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5463
|
+
* for (const entity of entities) {
|
|
5464
|
+
* const [pos, vel] = this.getComponents(entity, Position, Velocity);
|
|
5465
|
+
* // pos: Position, vel: Velocity (自动类型推断)
|
|
5466
|
+
* pos.x += vel.x;
|
|
5467
|
+
* }
|
|
5468
|
+
* }
|
|
5469
|
+
* }
|
|
5470
|
+
* ```
|
|
5471
|
+
*/
|
|
5472
|
+
protected getComponents<T extends readonly ComponentConstructor[]>(entity: Entity, ...components: T): {
|
|
5473
|
+
[K in keyof T]: ComponentInstance<T[K]>;
|
|
5474
|
+
};
|
|
5475
|
+
/**
|
|
5476
|
+
* 遍历实体并处理每个实体
|
|
5477
|
+
*
|
|
5478
|
+
* 提供更简洁的语法糖,避免手动遍历
|
|
5479
|
+
*
|
|
5480
|
+
* @param entities 实体列表
|
|
5481
|
+
* @param processor 处理函数
|
|
5482
|
+
*
|
|
5483
|
+
* @example
|
|
5484
|
+
* ```typescript
|
|
5485
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5486
|
+
* this.forEach(entities, (entity) => {
|
|
5487
|
+
* const transform = this.requireComponent(entity, Transform);
|
|
5488
|
+
* transform.position.y -= 9.8 * Time.deltaTime;
|
|
5489
|
+
* });
|
|
5490
|
+
* }
|
|
5491
|
+
* ```
|
|
5492
|
+
*/
|
|
5493
|
+
protected forEach(entities: readonly Entity[], processor: (entity: Entity, index: number) => void): void;
|
|
5494
|
+
/**
|
|
5495
|
+
* 过滤实体
|
|
5496
|
+
*
|
|
5497
|
+
* @param entities 实体列表
|
|
5498
|
+
* @param predicate 过滤条件
|
|
5499
|
+
* @returns 过滤后的实体数组
|
|
5500
|
+
*
|
|
5501
|
+
* @example
|
|
5502
|
+
* ```typescript
|
|
5503
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5504
|
+
* const activeEntities = this.filterEntities(entities, (entity) => {
|
|
5505
|
+
* const health = this.requireComponent(entity, Health);
|
|
5506
|
+
* return health.value > 0;
|
|
5507
|
+
* });
|
|
5508
|
+
* }
|
|
5509
|
+
* ```
|
|
5510
|
+
*/
|
|
5511
|
+
protected filterEntities(entities: readonly Entity[], predicate: (entity: Entity, index: number) => boolean): Entity[];
|
|
5512
|
+
/**
|
|
5513
|
+
* 映射实体到另一种类型
|
|
5514
|
+
*
|
|
5515
|
+
* @param entities 实体列表
|
|
5516
|
+
* @param mapper 映射函数
|
|
5517
|
+
* @returns 映射后的结果数组
|
|
5518
|
+
*
|
|
5519
|
+
* @example
|
|
5520
|
+
* ```typescript
|
|
5521
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5522
|
+
* const positions = this.mapEntities(entities, (entity) => {
|
|
5523
|
+
* const transform = this.requireComponent(entity, Transform);
|
|
5524
|
+
* return transform.position;
|
|
5525
|
+
* });
|
|
5526
|
+
* }
|
|
5527
|
+
* ```
|
|
5528
|
+
*/
|
|
5529
|
+
protected mapEntities<R>(entities: readonly Entity[], mapper: (entity: Entity, index: number) => R): R[];
|
|
5530
|
+
/**
|
|
5531
|
+
* 查找第一个满足条件的实体
|
|
5532
|
+
*
|
|
5533
|
+
* @param entities 实体列表
|
|
5534
|
+
* @param predicate 查找条件
|
|
5535
|
+
* @returns 第一个满足条件的实体,或undefined
|
|
5536
|
+
*
|
|
5537
|
+
* @example
|
|
5538
|
+
* ```typescript
|
|
5539
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5540
|
+
* const player = this.findEntity(entities, (entity) =>
|
|
5541
|
+
* entity.hasComponent(PlayerTag)
|
|
5542
|
+
* );
|
|
5543
|
+
* }
|
|
5544
|
+
* ```
|
|
5545
|
+
*/
|
|
5546
|
+
protected findEntity(entities: readonly Entity[], predicate: (entity: Entity, index: number) => boolean): Entity | undefined;
|
|
5547
|
+
/**
|
|
5548
|
+
* 检查是否存在满足条件的实体
|
|
5549
|
+
*
|
|
5550
|
+
* @param entities 实体列表
|
|
5551
|
+
* @param predicate 检查条件
|
|
5552
|
+
* @returns 是否存在满足条件的实体
|
|
5553
|
+
*
|
|
5554
|
+
* @example
|
|
5555
|
+
* ```typescript
|
|
5556
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5557
|
+
* const hasLowHealth = this.someEntity(entities, (entity) => {
|
|
5558
|
+
* const health = this.requireComponent(entity, Health);
|
|
5559
|
+
* return health.value < 20;
|
|
5560
|
+
* });
|
|
5561
|
+
* }
|
|
5562
|
+
* ```
|
|
5563
|
+
*/
|
|
5564
|
+
protected someEntity(entities: readonly Entity[], predicate: (entity: Entity, index: number) => boolean): boolean;
|
|
5565
|
+
/**
|
|
5566
|
+
* 检查是否所有实体都满足条件
|
|
5567
|
+
*
|
|
5568
|
+
* @param entities 实体列表
|
|
5569
|
+
* @param predicate 检查条件
|
|
5570
|
+
* @returns 是否所有实体都满足条件
|
|
5571
|
+
*
|
|
5572
|
+
* @example
|
|
5573
|
+
* ```typescript
|
|
5574
|
+
* protected process(entities: readonly Entity[]): void {
|
|
5575
|
+
* const allHealthy = this.everyEntity(entities, (entity) => {
|
|
5576
|
+
* const health = this.requireComponent(entity, Health);
|
|
5577
|
+
* return health.value > 50;
|
|
5578
|
+
* });
|
|
5579
|
+
* }
|
|
5580
|
+
* ```
|
|
5581
|
+
*/
|
|
5582
|
+
protected everyEntity(entities: readonly Entity[], predicate: (entity: Entity, index: number) => boolean): boolean;
|
|
4135
5583
|
}
|
|
4136
5584
|
|
|
4137
5585
|
/**
|
|
@@ -4184,7 +5632,7 @@ declare class EntityProcessorList {
|
|
|
4184
5632
|
*/
|
|
4185
5633
|
private sortProcessors;
|
|
4186
5634
|
/** 获取处理器列表 */
|
|
4187
|
-
get processors(): EntitySystem[];
|
|
5635
|
+
get processors(): EntitySystem<[]>[];
|
|
4188
5636
|
/** 获取处理器数量 */
|
|
4189
5637
|
get count(): number;
|
|
4190
5638
|
}
|
|
@@ -4199,6 +5647,24 @@ interface IScene {
|
|
|
4199
5647
|
* 场景名称
|
|
4200
5648
|
*/
|
|
4201
5649
|
name: string;
|
|
5650
|
+
/**
|
|
5651
|
+
* 场景自定义数据
|
|
5652
|
+
*
|
|
5653
|
+
* 用于存储场景级别的配置和状态数据,例如:
|
|
5654
|
+
* - 天气状态
|
|
5655
|
+
* - 时间设置
|
|
5656
|
+
* - 游戏难度
|
|
5657
|
+
* - 音频配置
|
|
5658
|
+
* - 关卡检查点
|
|
5659
|
+
*
|
|
5660
|
+
* @example
|
|
5661
|
+
* ```typescript
|
|
5662
|
+
* scene.sceneData.set('weather', 'rainy');
|
|
5663
|
+
* scene.sceneData.set('timeOfDay', 14.5);
|
|
5664
|
+
* scene.sceneData.set('checkpoint', { x: 100, y: 200 });
|
|
5665
|
+
* ```
|
|
5666
|
+
*/
|
|
5667
|
+
readonly sceneData: Map<string, any>;
|
|
4202
5668
|
/**
|
|
4203
5669
|
* 场景中的实体集合
|
|
4204
5670
|
*/
|
|
@@ -4530,9 +5996,15 @@ declare class Entity {
|
|
|
4530
5996
|
/**
|
|
4531
5997
|
* 创建并添加组件
|
|
4532
5998
|
*
|
|
4533
|
-
* @param componentType -
|
|
5999
|
+
* @param componentType - 组件类型构造函数
|
|
4534
6000
|
* @param args - 组件构造函数参数
|
|
4535
6001
|
* @returns 创建的组件实例
|
|
6002
|
+
*
|
|
6003
|
+
* @example
|
|
6004
|
+
* ```typescript
|
|
6005
|
+
* const position = entity.createComponent(Position, 100, 200);
|
|
6006
|
+
* const health = entity.createComponent(Health, 100);
|
|
6007
|
+
* ```
|
|
4536
6008
|
*/
|
|
4537
6009
|
createComponent<T extends Component>(componentType: ComponentType<T>, ...args: any[]): T;
|
|
4538
6010
|
/**
|
|
@@ -4547,29 +6019,61 @@ declare class Entity {
|
|
|
4547
6019
|
*
|
|
4548
6020
|
* @param component - 要添加的组件实例
|
|
4549
6021
|
* @returns 添加的组件实例
|
|
4550
|
-
* @throws {Error}
|
|
6022
|
+
* @throws {Error} 如果实体已存在该类型的组件
|
|
6023
|
+
*
|
|
6024
|
+
* @example
|
|
6025
|
+
* ```typescript
|
|
6026
|
+
* const position = new Position(100, 200);
|
|
6027
|
+
* entity.addComponent(position);
|
|
6028
|
+
* ```
|
|
4551
6029
|
*/
|
|
4552
6030
|
addComponent<T extends Component>(component: T): T;
|
|
4553
6031
|
/**
|
|
4554
6032
|
* 获取指定类型的组件
|
|
4555
6033
|
*
|
|
4556
|
-
* @param type -
|
|
4557
|
-
* @returns
|
|
6034
|
+
* @param type - 组件类型构造函数
|
|
6035
|
+
* @returns 组件实例,如果不存在则返回null
|
|
6036
|
+
*
|
|
6037
|
+
* @example
|
|
6038
|
+
* ```typescript
|
|
6039
|
+
* const position = entity.getComponent(Position);
|
|
6040
|
+
* if (position) {
|
|
6041
|
+
* position.x += 10;
|
|
6042
|
+
* position.y += 20;
|
|
6043
|
+
* }
|
|
6044
|
+
* ```
|
|
4558
6045
|
*/
|
|
4559
6046
|
getComponent<T extends Component>(type: ComponentType<T>): T | null;
|
|
4560
6047
|
/**
|
|
4561
|
-
*
|
|
6048
|
+
* 检查实体是否拥有指定类型的组件
|
|
4562
6049
|
*
|
|
4563
|
-
* @param type -
|
|
4564
|
-
* @returns
|
|
6050
|
+
* @param type - 组件类型构造函数
|
|
6051
|
+
* @returns 如果实体拥有该组件返回true,否则返回false
|
|
6052
|
+
*
|
|
6053
|
+
* @example
|
|
6054
|
+
* ```typescript
|
|
6055
|
+
* if (entity.hasComponent(Position)) {
|
|
6056
|
+
* const position = entity.getComponent(Position)!;
|
|
6057
|
+
* position.x += 10;
|
|
6058
|
+
* }
|
|
6059
|
+
* ```
|
|
4565
6060
|
*/
|
|
4566
6061
|
hasComponent<T extends Component>(type: ComponentType<T>): boolean;
|
|
4567
6062
|
/**
|
|
4568
6063
|
* 获取或创建指定类型的组件
|
|
4569
6064
|
*
|
|
4570
|
-
*
|
|
4571
|
-
*
|
|
6065
|
+
* 如果组件已存在则返回现有组件,否则创建新组件并添加到实体
|
|
6066
|
+
*
|
|
6067
|
+
* @param type - 组件类型构造函数
|
|
6068
|
+
* @param args - 组件构造函数参数(仅在创建新组件时使用)
|
|
4572
6069
|
* @returns 组件实例
|
|
6070
|
+
*
|
|
6071
|
+
* @example
|
|
6072
|
+
* ```typescript
|
|
6073
|
+
* // 确保实体拥有Position组件
|
|
6074
|
+
* const position = entity.getOrCreateComponent(Position, 0, 0);
|
|
6075
|
+
* position.x = 100;
|
|
6076
|
+
* ```
|
|
4573
6077
|
*/
|
|
4574
6078
|
getOrCreateComponent<T extends Component>(type: ComponentType<T>, ...args: any[]): T;
|
|
4575
6079
|
/**
|
|
@@ -6606,6 +8110,7 @@ declare abstract class WorkerEntitySystem<TEntityData = any> extends EntitySyste
|
|
|
6606
8110
|
protected sharedBuffer: SharedArrayBuffer | null;
|
|
6607
8111
|
protected sharedFloatArray: Float32Array | null;
|
|
6608
8112
|
private platformAdapter;
|
|
8113
|
+
private hasLoggedSyncMode;
|
|
6609
8114
|
constructor(matcher?: Matcher, config?: WorkerSystemConfig);
|
|
6610
8115
|
/**
|
|
6611
8116
|
* 检查是否支持Worker
|
|
@@ -6893,6 +8398,487 @@ declare class ComponentPoolManager {
|
|
|
6893
8398
|
getComponentUtilization(componentName: string): number;
|
|
6894
8399
|
}
|
|
6895
8400
|
|
|
8401
|
+
/**
|
|
8402
|
+
* 序列化装饰器
|
|
8403
|
+
*
|
|
8404
|
+
* 提供组件级别的序列化支持,包括字段级装饰器和类级装饰器
|
|
8405
|
+
*/
|
|
8406
|
+
|
|
8407
|
+
/**
|
|
8408
|
+
* 序列化元数据的Symbol键
|
|
8409
|
+
*/
|
|
8410
|
+
declare const SERIALIZABLE_METADATA: unique symbol;
|
|
8411
|
+
declare const SERIALIZE_FIELD: unique symbol;
|
|
8412
|
+
declare const SERIALIZE_OPTIONS: unique symbol;
|
|
8413
|
+
/**
|
|
8414
|
+
* 可序列化配置选项
|
|
8415
|
+
*/
|
|
8416
|
+
interface SerializableOptions {
|
|
8417
|
+
/**
|
|
8418
|
+
* 序列化版本号,用于数据迁移
|
|
8419
|
+
*/
|
|
8420
|
+
version: number;
|
|
8421
|
+
/**
|
|
8422
|
+
* 组件类型标识符(可选,默认使用类名)
|
|
8423
|
+
*/
|
|
8424
|
+
typeId?: string;
|
|
8425
|
+
}
|
|
8426
|
+
/**
|
|
8427
|
+
* 字段序列化配置
|
|
8428
|
+
*/
|
|
8429
|
+
interface FieldSerializeOptions {
|
|
8430
|
+
/**
|
|
8431
|
+
* 自定义序列化器
|
|
8432
|
+
*/
|
|
8433
|
+
serializer?: (value: any) => any;
|
|
8434
|
+
/**
|
|
8435
|
+
* 自定义反序列化器
|
|
8436
|
+
*/
|
|
8437
|
+
deserializer?: (value: any) => any;
|
|
8438
|
+
/**
|
|
8439
|
+
* 字段别名(用于序列化后的键名)
|
|
8440
|
+
*/
|
|
8441
|
+
alias?: string;
|
|
8442
|
+
}
|
|
8443
|
+
/**
|
|
8444
|
+
* 序列化元数据
|
|
8445
|
+
*/
|
|
8446
|
+
interface SerializationMetadata {
|
|
8447
|
+
options: SerializableOptions;
|
|
8448
|
+
fields: Map<string | symbol, FieldSerializeOptions>;
|
|
8449
|
+
ignoredFields: Set<string | symbol>;
|
|
8450
|
+
}
|
|
8451
|
+
/**
|
|
8452
|
+
* 组件可序列化装饰器
|
|
8453
|
+
*
|
|
8454
|
+
* 标记组件类为可序列化,必须与字段装饰器配合使用
|
|
8455
|
+
*
|
|
8456
|
+
* @param options 序列化配置选项
|
|
8457
|
+
*
|
|
8458
|
+
* @example
|
|
8459
|
+
* ```typescript
|
|
8460
|
+
* @ECSComponent('Player')
|
|
8461
|
+
* @Serializable({ version: 1 })
|
|
8462
|
+
* class PlayerComponent extends Component {
|
|
8463
|
+
* @Serialize() name: string = 'Player';
|
|
8464
|
+
* @Serialize() level: number = 1;
|
|
8465
|
+
* }
|
|
8466
|
+
* ```
|
|
8467
|
+
*/
|
|
8468
|
+
declare function Serializable(options: SerializableOptions): <T extends new (...args: any[]) => Component>(target: T) => T;
|
|
8469
|
+
/**
|
|
8470
|
+
* 字段序列化装饰器
|
|
8471
|
+
*
|
|
8472
|
+
* 标记字段为可序列化
|
|
8473
|
+
*
|
|
8474
|
+
* @param options 字段序列化选项(可选)
|
|
8475
|
+
*
|
|
8476
|
+
* @example
|
|
8477
|
+
* ```typescript
|
|
8478
|
+
* @Serialize()
|
|
8479
|
+
* name: string = 'Player';
|
|
8480
|
+
*
|
|
8481
|
+
* @Serialize({ alias: 'hp' })
|
|
8482
|
+
* health: number = 100;
|
|
8483
|
+
* ```
|
|
8484
|
+
*/
|
|
8485
|
+
declare function Serialize(options?: FieldSerializeOptions): (target: any, propertyKey: string | symbol) => void;
|
|
8486
|
+
/**
|
|
8487
|
+
* Map序列化装饰器
|
|
8488
|
+
*
|
|
8489
|
+
* 专门用于序列化Map类型字段
|
|
8490
|
+
*
|
|
8491
|
+
* @example
|
|
8492
|
+
* ```typescript
|
|
8493
|
+
* @SerializeAsMap()
|
|
8494
|
+
* inventory: Map<string, number> = new Map();
|
|
8495
|
+
* ```
|
|
8496
|
+
*/
|
|
8497
|
+
declare function SerializeAsMap(): (target: any, propertyKey: string | symbol) => void;
|
|
8498
|
+
/**
|
|
8499
|
+
* Set序列化装饰器
|
|
8500
|
+
*
|
|
8501
|
+
* 专门用于序列化Set类型字段
|
|
8502
|
+
*
|
|
8503
|
+
* @example
|
|
8504
|
+
* ```typescript
|
|
8505
|
+
* @SerializeAsSet()
|
|
8506
|
+
* tags: Set<string> = new Set();
|
|
8507
|
+
* ```
|
|
8508
|
+
*/
|
|
8509
|
+
declare function SerializeAsSet(): (target: any, propertyKey: string | symbol) => void;
|
|
8510
|
+
/**
|
|
8511
|
+
* 忽略序列化装饰器
|
|
8512
|
+
*
|
|
8513
|
+
* 标记字段不参与序列化
|
|
8514
|
+
*
|
|
8515
|
+
* @example
|
|
8516
|
+
* ```typescript
|
|
8517
|
+
* @IgnoreSerialization()
|
|
8518
|
+
* tempCache: any = null;
|
|
8519
|
+
* ```
|
|
8520
|
+
*/
|
|
8521
|
+
declare function IgnoreSerialization(): (target: any, propertyKey: string | symbol) => void;
|
|
8522
|
+
/**
|
|
8523
|
+
* 获取组件的序列化元数据
|
|
8524
|
+
*
|
|
8525
|
+
* @param componentClass 组件类或组件实例
|
|
8526
|
+
* @returns 序列化元数据,如果组件不可序列化则返回null
|
|
8527
|
+
*/
|
|
8528
|
+
declare function getSerializationMetadata(componentClass: any): SerializationMetadata | null;
|
|
8529
|
+
/**
|
|
8530
|
+
* 检查组件是否可序列化
|
|
8531
|
+
*
|
|
8532
|
+
* @param component 组件类或组件实例
|
|
8533
|
+
* @returns 如果组件可序列化返回true
|
|
8534
|
+
*/
|
|
8535
|
+
declare function isSerializable(component: any): boolean;
|
|
8536
|
+
|
|
8537
|
+
/**
|
|
8538
|
+
* 版本迁移系统
|
|
8539
|
+
*
|
|
8540
|
+
* 提供组件和场景数据的版本迁移支持
|
|
8541
|
+
*/
|
|
8542
|
+
|
|
8543
|
+
/**
|
|
8544
|
+
* 组件迁移函数
|
|
8545
|
+
*/
|
|
8546
|
+
type ComponentMigrationFunction = (data: any, fromVersion: number, toVersion: number) => any;
|
|
8547
|
+
/**
|
|
8548
|
+
* 场景迁移函数
|
|
8549
|
+
*/
|
|
8550
|
+
type SceneMigrationFunction = (scene: SerializedScene, fromVersion: number, toVersion: number) => SerializedScene;
|
|
8551
|
+
/**
|
|
8552
|
+
* 版本迁移管理器
|
|
8553
|
+
*/
|
|
8554
|
+
declare class VersionMigrationManager {
|
|
8555
|
+
/**
|
|
8556
|
+
* 组件迁移函数注册表
|
|
8557
|
+
* Map<组件类型名, Map<版本号, 迁移函数>>
|
|
8558
|
+
*/
|
|
8559
|
+
private static componentMigrations;
|
|
8560
|
+
/**
|
|
8561
|
+
* 场景迁移函数注册表
|
|
8562
|
+
* Map<版本号, 迁移函数>
|
|
8563
|
+
*/
|
|
8564
|
+
private static sceneMigrations;
|
|
8565
|
+
/**
|
|
8566
|
+
* 注册组件迁移函数
|
|
8567
|
+
*
|
|
8568
|
+
* @param componentType 组件类型名称
|
|
8569
|
+
* @param fromVersion 源版本号
|
|
8570
|
+
* @param toVersion 目标版本号
|
|
8571
|
+
* @param migration 迁移函数
|
|
8572
|
+
*
|
|
8573
|
+
* @example
|
|
8574
|
+
* ```typescript
|
|
8575
|
+
* // 从版本1迁移到版本2
|
|
8576
|
+
* VersionMigrationManager.registerComponentMigration(
|
|
8577
|
+
* 'PlayerComponent',
|
|
8578
|
+
* 1,
|
|
8579
|
+
* 2,
|
|
8580
|
+
* (data) => {
|
|
8581
|
+
* // 添加新字段
|
|
8582
|
+
* data.experience = 0;
|
|
8583
|
+
* return data;
|
|
8584
|
+
* }
|
|
8585
|
+
* );
|
|
8586
|
+
* ```
|
|
8587
|
+
*/
|
|
8588
|
+
static registerComponentMigration(componentType: string, fromVersion: number, toVersion: number, migration: ComponentMigrationFunction): void;
|
|
8589
|
+
/**
|
|
8590
|
+
* 注册场景迁移函数
|
|
8591
|
+
*
|
|
8592
|
+
* @param fromVersion 源版本号
|
|
8593
|
+
* @param toVersion 目标版本号
|
|
8594
|
+
* @param migration 迁移函数
|
|
8595
|
+
*
|
|
8596
|
+
* @example
|
|
8597
|
+
* ```typescript
|
|
8598
|
+
* VersionMigrationManager.registerSceneMigration(
|
|
8599
|
+
* 1,
|
|
8600
|
+
* 2,
|
|
8601
|
+
* (scene) => {
|
|
8602
|
+
* // 迁移场景结构
|
|
8603
|
+
* scene.metadata = { ...scene.metadata, migratedFrom: 1 };
|
|
8604
|
+
* return scene;
|
|
8605
|
+
* }
|
|
8606
|
+
* );
|
|
8607
|
+
* ```
|
|
8608
|
+
*/
|
|
8609
|
+
static registerSceneMigration(fromVersion: number, toVersion: number, migration: SceneMigrationFunction): void;
|
|
8610
|
+
/**
|
|
8611
|
+
* 迁移组件数据
|
|
8612
|
+
*
|
|
8613
|
+
* @param component 序列化的组件数据
|
|
8614
|
+
* @param targetVersion 目标版本号
|
|
8615
|
+
* @returns 迁移后的组件数据
|
|
8616
|
+
*/
|
|
8617
|
+
static migrateComponent(component: SerializedComponent, targetVersion: number): SerializedComponent;
|
|
8618
|
+
/**
|
|
8619
|
+
* 迁移场景数据
|
|
8620
|
+
*
|
|
8621
|
+
* @param scene 序列化的场景数据
|
|
8622
|
+
* @param targetVersion 目标版本号
|
|
8623
|
+
* @returns 迁移后的场景数据
|
|
8624
|
+
*/
|
|
8625
|
+
static migrateScene(scene: SerializedScene, targetVersion: number): SerializedScene;
|
|
8626
|
+
/**
|
|
8627
|
+
* 迁移场景中所有组件的版本
|
|
8628
|
+
*/
|
|
8629
|
+
private static migrateSceneComponents;
|
|
8630
|
+
/**
|
|
8631
|
+
* 递归迁移实体的组件
|
|
8632
|
+
*/
|
|
8633
|
+
private static migrateEntitiesComponents;
|
|
8634
|
+
/**
|
|
8635
|
+
* 清除所有迁移函数
|
|
8636
|
+
*/
|
|
8637
|
+
static clearMigrations(): void;
|
|
8638
|
+
/**
|
|
8639
|
+
* 获取组件的迁移路径
|
|
8640
|
+
*
|
|
8641
|
+
* @param componentType 组件类型名称
|
|
8642
|
+
* @returns 可用的迁移版本列表
|
|
8643
|
+
*/
|
|
8644
|
+
static getComponentMigrationPath(componentType: string): number[];
|
|
8645
|
+
/**
|
|
8646
|
+
* 获取场景的迁移路径
|
|
8647
|
+
*
|
|
8648
|
+
* @returns 可用的场景迁移版本列表
|
|
8649
|
+
*/
|
|
8650
|
+
static getSceneMigrationPath(): number[];
|
|
8651
|
+
/**
|
|
8652
|
+
* 检查是否可以迁移组件
|
|
8653
|
+
*
|
|
8654
|
+
* @param componentType 组件类型名称
|
|
8655
|
+
* @param fromVersion 源版本
|
|
8656
|
+
* @param toVersion 目标版本
|
|
8657
|
+
* @returns 是否存在完整的迁移路径
|
|
8658
|
+
*/
|
|
8659
|
+
static canMigrateComponent(componentType: string, fromVersion: number, toVersion: number): boolean;
|
|
8660
|
+
/**
|
|
8661
|
+
* 检查是否可以迁移场景
|
|
8662
|
+
*
|
|
8663
|
+
* @param fromVersion 源版本
|
|
8664
|
+
* @param toVersion 目标版本
|
|
8665
|
+
* @returns 是否存在完整的迁移路径
|
|
8666
|
+
*/
|
|
8667
|
+
static canMigrateScene(fromVersion: number, toVersion: number): boolean;
|
|
8668
|
+
}
|
|
8669
|
+
/**
|
|
8670
|
+
* 便捷的迁移构建器
|
|
8671
|
+
*
|
|
8672
|
+
* 提供链式API来定义迁移
|
|
8673
|
+
*/
|
|
8674
|
+
declare class MigrationBuilder {
|
|
8675
|
+
private componentType?;
|
|
8676
|
+
private fromVersion;
|
|
8677
|
+
private toVersion;
|
|
8678
|
+
/**
|
|
8679
|
+
* 设置组件类型
|
|
8680
|
+
*/
|
|
8681
|
+
forComponent(componentType: string): this;
|
|
8682
|
+
/**
|
|
8683
|
+
* 设置版本范围
|
|
8684
|
+
*/
|
|
8685
|
+
fromVersionToVersion(from: number, to: number): this;
|
|
8686
|
+
/**
|
|
8687
|
+
* 注册迁移函数
|
|
8688
|
+
*/
|
|
8689
|
+
migrate(migration: ComponentMigrationFunction | SceneMigrationFunction): void;
|
|
8690
|
+
}
|
|
8691
|
+
|
|
8692
|
+
/**
|
|
8693
|
+
* Entity类型安全工具函数
|
|
8694
|
+
*
|
|
8695
|
+
* 提供类型安全的组件操作工具函数,无需修改Entity类
|
|
8696
|
+
*/
|
|
8697
|
+
|
|
8698
|
+
/**
|
|
8699
|
+
* 获取组件,如果不存在则抛出错误
|
|
8700
|
+
*
|
|
8701
|
+
* @param entity - 实体实例
|
|
8702
|
+
* @param componentType - 组件类型构造函数
|
|
8703
|
+
* @returns 组件实例(保证非空)
|
|
8704
|
+
* @throws {Error} 如果组件不存在
|
|
8705
|
+
*
|
|
8706
|
+
* @example
|
|
8707
|
+
* ```typescript
|
|
8708
|
+
* const position = requireComponent(entity, Position);
|
|
8709
|
+
* position.x += 10;
|
|
8710
|
+
* ```
|
|
8711
|
+
*/
|
|
8712
|
+
declare function requireComponent<T extends ComponentConstructor>(entity: Entity, componentType: T): ComponentInstance<T>;
|
|
8713
|
+
/**
|
|
8714
|
+
* 尝试获取组件
|
|
8715
|
+
*
|
|
8716
|
+
* @param entity - 实体实例
|
|
8717
|
+
* @param componentType - 组件类型构造函数
|
|
8718
|
+
* @returns 组件实例或undefined
|
|
8719
|
+
*
|
|
8720
|
+
* @example
|
|
8721
|
+
* ```typescript
|
|
8722
|
+
* const health = tryGetComponent(entity, Health);
|
|
8723
|
+
* if (health) {
|
|
8724
|
+
* health.value -= 10;
|
|
8725
|
+
* }
|
|
8726
|
+
* ```
|
|
8727
|
+
*/
|
|
8728
|
+
declare function tryGetComponent<T extends ComponentConstructor>(entity: Entity, componentType: T): ComponentInstance<T> | undefined;
|
|
8729
|
+
/**
|
|
8730
|
+
* 批量获取组件
|
|
8731
|
+
*
|
|
8732
|
+
* @param entity - 实体实例
|
|
8733
|
+
* @param types - 组件类型构造函数数组
|
|
8734
|
+
* @returns 组件实例元组,每个元素可能为null
|
|
8735
|
+
*
|
|
8736
|
+
* @example
|
|
8737
|
+
* ```typescript
|
|
8738
|
+
* const [pos, vel, health] = getComponents(entity, Position, Velocity, Health);
|
|
8739
|
+
* if (pos && vel && health) {
|
|
8740
|
+
* pos.x += vel.dx;
|
|
8741
|
+
* }
|
|
8742
|
+
* ```
|
|
8743
|
+
*/
|
|
8744
|
+
declare function getComponents<T extends readonly ComponentConstructor[]>(entity: Entity, ...types: T): {
|
|
8745
|
+
[K in keyof T]: ComponentInstance<T[K]> | null;
|
|
8746
|
+
};
|
|
8747
|
+
/**
|
|
8748
|
+
* 检查实体是否拥有所有指定的组件
|
|
8749
|
+
*
|
|
8750
|
+
* @param entity - 实体实例
|
|
8751
|
+
* @param types - 组件类型构造函数数组
|
|
8752
|
+
* @returns 如果拥有所有组件返回true,否则返回false
|
|
8753
|
+
*
|
|
8754
|
+
* @example
|
|
8755
|
+
* ```typescript
|
|
8756
|
+
* if (hasComponents(entity, Position, Velocity)) {
|
|
8757
|
+
* const pos = entity.getComponent(Position)!;
|
|
8758
|
+
* const vel = entity.getComponent(Velocity)!;
|
|
8759
|
+
* }
|
|
8760
|
+
* ```
|
|
8761
|
+
*/
|
|
8762
|
+
declare function hasComponents(entity: Entity, ...types: ComponentConstructor[]): boolean;
|
|
8763
|
+
/**
|
|
8764
|
+
* 检查实体是否拥有至少一个指定的组件
|
|
8765
|
+
*
|
|
8766
|
+
* @param entity - 实体实例
|
|
8767
|
+
* @param types - 组件类型构造函数数组
|
|
8768
|
+
* @returns 如果拥有任意一个组件返回true,否则返回false
|
|
8769
|
+
*/
|
|
8770
|
+
declare function hasAnyComponent(entity: Entity, ...types: ComponentConstructor[]): boolean;
|
|
8771
|
+
/**
|
|
8772
|
+
* 添加组件并立即配置
|
|
8773
|
+
*
|
|
8774
|
+
* @param entity - 实体实例
|
|
8775
|
+
* @param component - 组件实例
|
|
8776
|
+
* @param configure - 配置回调函数
|
|
8777
|
+
* @returns 实体实例(支持链式调用)
|
|
8778
|
+
*
|
|
8779
|
+
* @example
|
|
8780
|
+
* ```typescript
|
|
8781
|
+
* addAndConfigure(entity, new Health(), health => {
|
|
8782
|
+
* health.maxValue = 100;
|
|
8783
|
+
* health.value = 50;
|
|
8784
|
+
* });
|
|
8785
|
+
* ```
|
|
8786
|
+
*/
|
|
8787
|
+
declare function addAndConfigure<T extends Component>(entity: Entity, component: T, configure: (component: T) => void): Entity;
|
|
8788
|
+
/**
|
|
8789
|
+
* 获取或添加组件
|
|
8790
|
+
*
|
|
8791
|
+
* 如果组件已存在则返回现有组件,否则通过工厂函数创建并添加
|
|
8792
|
+
*
|
|
8793
|
+
* @param entity - 实体实例
|
|
8794
|
+
* @param componentType - 组件类型构造函数
|
|
8795
|
+
* @param factory - 组件工厂函数(仅在组件不存在时调用)
|
|
8796
|
+
* @returns 组件实例
|
|
8797
|
+
*
|
|
8798
|
+
* @example
|
|
8799
|
+
* ```typescript
|
|
8800
|
+
* const health = getOrAddComponent(entity, Health, () => new Health(100));
|
|
8801
|
+
* ```
|
|
8802
|
+
*/
|
|
8803
|
+
declare function getOrAddComponent<T extends ComponentConstructor>(entity: Entity, componentType: T, factory: () => ComponentInstance<T>): ComponentInstance<T>;
|
|
8804
|
+
/**
|
|
8805
|
+
* 更新组件的部分字段
|
|
8806
|
+
*
|
|
8807
|
+
* @param entity - 实体实例
|
|
8808
|
+
* @param componentType - 组件类型构造函数
|
|
8809
|
+
* @param data - 要更新的部分数据
|
|
8810
|
+
* @returns 如果更新成功返回true,组件不存在返回false
|
|
8811
|
+
*
|
|
8812
|
+
* @example
|
|
8813
|
+
* ```typescript
|
|
8814
|
+
* updateComponent(entity, Position, { x: 100 });
|
|
8815
|
+
* ```
|
|
8816
|
+
*/
|
|
8817
|
+
declare function updateComponent<T extends ComponentConstructor>(entity: Entity, componentType: T, data: Partial<ComponentInstance<T>>): boolean;
|
|
8818
|
+
/**
|
|
8819
|
+
* 类型安全的实体构建器
|
|
8820
|
+
*
|
|
8821
|
+
* @example
|
|
8822
|
+
* ```typescript
|
|
8823
|
+
* const player = buildEntity(scene.createEntity("Player"))
|
|
8824
|
+
* .with(new Position(100, 100))
|
|
8825
|
+
* .with(new Velocity(0, 0))
|
|
8826
|
+
* .withTag(1)
|
|
8827
|
+
* .build();
|
|
8828
|
+
* ```
|
|
8829
|
+
*/
|
|
8830
|
+
declare class TypedEntityBuilder {
|
|
8831
|
+
private _entity;
|
|
8832
|
+
constructor(entity: Entity);
|
|
8833
|
+
/**
|
|
8834
|
+
* 添加组件
|
|
8835
|
+
*/
|
|
8836
|
+
with<T extends Component>(component: T): this;
|
|
8837
|
+
/**
|
|
8838
|
+
* 添加并配置组件
|
|
8839
|
+
*/
|
|
8840
|
+
withConfigured<T extends Component>(component: T, configure: (component: T) => void): this;
|
|
8841
|
+
/**
|
|
8842
|
+
* 设置标签
|
|
8843
|
+
*/
|
|
8844
|
+
withTag(tag: number): this;
|
|
8845
|
+
/**
|
|
8846
|
+
* 设置名称
|
|
8847
|
+
*/
|
|
8848
|
+
withName(name: string): this;
|
|
8849
|
+
/**
|
|
8850
|
+
* 设置激活状态
|
|
8851
|
+
*/
|
|
8852
|
+
withActive(active: boolean): this;
|
|
8853
|
+
/**
|
|
8854
|
+
* 设置启用状态
|
|
8855
|
+
*/
|
|
8856
|
+
withEnabled(enabled: boolean): this;
|
|
8857
|
+
/**
|
|
8858
|
+
* 设置更新顺序
|
|
8859
|
+
*/
|
|
8860
|
+
withUpdateOrder(order: number): this;
|
|
8861
|
+
/**
|
|
8862
|
+
* 添加子实体
|
|
8863
|
+
*/
|
|
8864
|
+
withChild(child: Entity): this;
|
|
8865
|
+
/**
|
|
8866
|
+
* 完成构建
|
|
8867
|
+
*/
|
|
8868
|
+
build(): Entity;
|
|
8869
|
+
/**
|
|
8870
|
+
* 获取正在构建的实体
|
|
8871
|
+
*/
|
|
8872
|
+
get entity(): Entity;
|
|
8873
|
+
}
|
|
8874
|
+
/**
|
|
8875
|
+
* 创建类型安全的实体构建器
|
|
8876
|
+
*
|
|
8877
|
+
* @param entity - 要包装的实体
|
|
8878
|
+
* @returns 实体构建器
|
|
8879
|
+
*/
|
|
8880
|
+
declare function buildEntity(entity: Entity): TypedEntityBuilder;
|
|
8881
|
+
|
|
6896
8882
|
/**
|
|
6897
8883
|
* 类型工具类
|
|
6898
8884
|
* 提供类型相关的实用方法
|
|
@@ -7239,5 +9225,5 @@ declare function getFullPlatformConfig(): Promise<any>;
|
|
|
7239
9225
|
declare function supportsFeature(feature: 'worker' | 'shared-array-buffer' | 'transferable-objects' | 'module-worker'): boolean;
|
|
7240
9226
|
declare function hasAdapter(): boolean;
|
|
7241
9227
|
|
|
7242
|
-
export { AutoTyped, BitMask64Utils, Bits, COMPONENT_TYPE_NAME, Colors, Component, ComponentDataCollector, ComponentPool, ComponentPoolManager, ComponentRegistry, ComponentSparseSet, ComponentStorage, ComponentTypeManager, ConsoleLogger, Core, DebugManager, DeepCopy, ECSComponent, ECSEventType, ECSFluentAPI, ECSSystem, EVENT_TYPES, Emitter, EnableSoA, Entity, EntityDataCollector, EntityList, EntityProcessorList, EntitySystem, EventBus, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, HighPrecision, IdentifierPool, Int16, Int32, Int8, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, NumberExtension, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, PlatformDetector, PlatformManager, Pool, PoolManager, ProcessingSystem, QuerySystem, SYSTEM_TYPE_NAME, Scene, SceneDataCollector, SerializeArray, SerializeMap, SerializeSet, SoAStorage, SparseSet, SystemDataCollector, Time, Timer, TimerManager, TypeInference, TypeSafeEventSystem, TypeUtils, Uint16, Uint32, Uint8, Uint8Clamped, WebSocketManager, WorkerEntitySystem, World, WorldManager, createECSAPI, createLogger, getBasicWorkerConfig, getComponentInstanceTypeName, getComponentTypeName, getCurrentAdapter, getFullPlatformConfig, getSystemInstanceTypeName, getSystemTypeName, hasAdapter, registerPlatformAdapter, resetLoggerColors, setGlobalLogLevel, setLoggerColors, supportsFeature };
|
|
7243
|
-
export type { BitMask64Data, ComponentType$1 as ComponentType, EventListenerConfig, EventStats, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPlatformAdapter, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IWorldConfig, IWorldManagerConfig, LoggerColorConfig, LoggerConfig, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PlatformConfig, PlatformDetectionResult, PlatformWorker, PoolStats, SharedArrayBufferProcessFunction, SupportedTypedArray, WorkerCreationOptions, WorkerProcessFunction, WorkerSystemConfig };
|
|
9228
|
+
export { AutoTyped, BitMask64Utils, Bits, COMPONENT_TYPE_NAME, ChangeOperation, Colors, Component, ComponentDataCollector, ComponentPool, ComponentPoolManager, ComponentRegistry, ComponentSerializer, ComponentSparseSet, ComponentStorage, ComponentTypeManager, ConsoleLogger, Core, DebugManager, DeepCopy, ECSComponent, ECSEventType, ECSFluentAPI, ECSSystem, EVENT_TYPES, Emitter, EnableSoA, Entity, EntityDataCollector, EntityList, EntityProcessorList, EntitySerializer, EntitySystem, EventBus, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, HighPrecision, IdentifierPool, IgnoreSerialization, IncrementalSerializer, Int16, Int32, Int8, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, MigrationBuilder, NumberExtension, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, PlatformDetector, PlatformManager, Pool, PoolManager, ProcessingSystem, QuerySystem, SERIALIZABLE_METADATA, SERIALIZE_FIELD, SERIALIZE_OPTIONS, SYSTEM_TYPE_NAME, Scene, SceneDataCollector, SceneSerializer, Serializable, Serialize, SerializeArray, SerializeAsMap, SerializeAsSet, SerializeMap, SerializeSet, SoAStorage, SparseSet, SystemDataCollector, Time, Timer, TimerManager, TypeInference, TypeSafeEventSystem, TypeUtils, TypedEntityBuilder, TypedQueryBuilder, TypedQueryResult, Uint16, Uint32, Uint8, Uint8Clamped, VersionMigrationManager, WebSocketManager, WorkerEntitySystem, World, WorldManager, addAndConfigure, buildEntity, createECSAPI, createLogger, createQuery, getBasicWorkerConfig, getComponentInstanceTypeName, getComponentTypeName, getComponents, getCurrentAdapter, getFullPlatformConfig, getOrAddComponent, getSerializationMetadata, getSystemInstanceTypeName, getSystemTypeName, hasAdapter, hasAnyComponent, hasComponents, isComponentArray, isComponentType, isSerializable, queryFor, queryForAll, registerPlatformAdapter, requireComponent, resetLoggerColors, setGlobalLogLevel, setLoggerColors, supportsFeature, tryGetComponent, updateComponent };
|
|
9229
|
+
export type { AnyComponentConstructor, BitMask64Data, ComponentChange, ComponentConstructor, ComponentInstance, ComponentMigrationFunction, ComponentType$1 as ComponentType, ComponentTypeMap, ComponentTypeName, ComponentTypeNames, DataOnly, DeepPartial, DeepReadonly, DeserializationStrategy, EntityChange, EntityWithComponents, EventListenerConfig, EventStats, ExtractComponents, FieldSerializeOptions, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPlatformAdapter, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IWorldConfig, IWorldManagerConfig, IncrementalSerializationFormat, IncrementalSerializationOptions, IncrementalSnapshot, LoggerColorConfig, LoggerConfig, MigrationFunction, PartialComponent, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PlatformConfig, PlatformDetectionResult, PlatformWorker, PoolStats, QueryResult$1 as QueryResult, ReadonlyComponent, SceneDataChange, SceneDeserializationOptions, SceneMigrationFunction, SceneSerializationOptions, SerializableComponent, SerializableFields, SerializableOptions, SerializationFormat, SerializationMetadata, SerializedComponent, SerializedEntity, SerializedScene, SharedArrayBufferProcessFunction, SupportedTypedArray, SystemEntityType, SystemLifecycleHooks, TypeSafeBuilder, TypedEventHandler, TypedQueryCondition, ValidComponent, ValidComponentArray, WorkerCreationOptions, WorkerProcessFunction, WorkerSystemConfig };
|