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:
YHH
2025-12-30 09:39:17 +08:00
committed by GitHub
parent 449bd420a6
commit a08a84b7db
10 changed files with 63 additions and 59 deletions

View File

@@ -23,7 +23,7 @@ import {
decodeSnapshot,
decodeSpawn,
processDespawn,
registerSyncComponent,
GlobalComponentRegistry,
type DecodeSnapshotResult,
type DecodeSpawnResult,
} from '@esengine/ecs-framework';
@@ -166,10 +166,7 @@ export class ComponentSyncSystem extends EntitySystem {
* @en Client needs to call this to register all component types to be synced
*/
public registerComponent<T extends new () => any>(componentClass: T): void {
const metadata: SyncMetadata | undefined = (componentClass as any)[SYNC_METADATA];
if (metadata) {
registerSyncComponent(metadata.typeId, componentClass as any);
}
GlobalComponentRegistry.register(componentClass as any);
}
// =========================================================================