fix(sync): use GlobalComponentRegistry for network sync decoding (#392)
- Decoder.ts now uses GlobalComponentRegistry.getComponentType() instead of local registry - @sync decorator uses getComponentTypeName() to get @ECSComponent decorator name - @ECSComponent decorator updates SYNC_METADATA.typeId when defined - Removed deprecated registerSyncComponent/autoRegisterSyncComponent functions - Updated ComponentSync.ts in network package to use GlobalComponentRegistry - Updated tests to use correct @ECSComponent type names This ensures that components decorated with @ECSComponent are automatically available for network sync decoding without any manual registration.
This commit is contained in:
@@ -53,7 +53,7 @@ describe('@sync 装饰器测试', () => {
|
||||
const metadata = getSyncMetadata(PlayerComponent);
|
||||
|
||||
expect(metadata).not.toBeNull();
|
||||
expect(metadata!.typeId).toBe('PlayerComponent');
|
||||
expect(metadata!.typeId).toBe('SyncTest_PlayerComponent');
|
||||
expect(metadata!.fields.length).toBe(4);
|
||||
});
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ import {
|
||||
import {
|
||||
decodeSnapshot,
|
||||
decodeSpawn,
|
||||
processDespawn,
|
||||
registerSyncComponent
|
||||
processDespawn
|
||||
} from '../../../src/ECS/Sync/encoding/Decoder';
|
||||
import { SyncOperation } from '../../../src/ECS/Sync/types';
|
||||
|
||||
@@ -320,10 +319,7 @@ describe('BinaryWriter/BinaryReader - 二进制读写器测试', () => {
|
||||
describe('Encoder/Decoder - 实体编解码测试', () => {
|
||||
let scene: Scene;
|
||||
|
||||
beforeAll(() => {
|
||||
registerSyncComponent('PlayerComponent', PlayerComponent);
|
||||
registerSyncComponent('AllTypesComponent', AllTypesComponent);
|
||||
});
|
||||
// Components are auto-registered via @ECSComponent decorator
|
||||
|
||||
beforeEach(() => {
|
||||
scene = new Scene();
|
||||
@@ -414,7 +410,7 @@ describe('Encoder/Decoder - 实体编解码测试', () => {
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.prefabType).toBe('Player');
|
||||
expect(result!.componentTypes).toContain('PlayerComponent');
|
||||
expect(result!.componentTypes).toContain('EncodingTest_PlayerComponent');
|
||||
|
||||
const decodedComp = result!.entity.getComponent(PlayerComponent);
|
||||
expect(decodedComp!.name).toBe("SpawnedPlayer");
|
||||
@@ -470,10 +466,6 @@ describe('Encoder/Decoder - 实体编解码测试', () => {
|
||||
});
|
||||
|
||||
describe('所有同步类型编解码', () => {
|
||||
beforeAll(() => {
|
||||
registerSyncComponent('AllTypesComponent', AllTypesComponent);
|
||||
});
|
||||
|
||||
test('应该正确编解码所有类型', () => {
|
||||
const entity = scene.createEntity('AllTypes');
|
||||
const comp = entity.addComponent(new AllTypesComponent());
|
||||
|
||||
Reference in New Issue
Block a user