A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
refactor: export loadComponent and add getComponentDefaults for editor unification
esengine7bb955b9be06
diff --git a/sdk/src/component.ts b/sdk/src/component.tsindex 0da916c48..94712b5f2 100644--- a/sdk/src/component.ts+++ b/sdk/src/component.ts@@ -151,6 +151,21 @@ export interface ChildrenData {entities: Entity[];}+export interface SpineAnimationData {+ skeletonPath: string;+ atlasPath: string;+ skin: string;+ animation: string;+ timeScale: number;+ loop: boolean;+ playing: boolean;+ flipX: boolean;+ flipY: boolean;+ color: Vec4;+ layer: number;+ skeletonScale: number;+}+// =============================================================================// Builtin Component Instances// =============================================================================@@ -210,6 +225,21 @@ export const Children = defineBuiltin<ChildrenData>('Children', {entities: []});+export const SpineAnimation = defineBuiltin<SpineAnimationData>('SpineAnimation', {+ skeletonPath: '',+ atlasPath: '',+ skin: '',+ animation: '',+ timeScale: 1.0,+ loop: true,+ playing: true,+ flipX: false,+ flipY: false,+ color: { x: 1, y: 1, z: 1, w: 1 },+ layer: 0,+ skeletonScale: 1.0+});+// =============================================================================// Type Helpers// =============================================================================@@ -218,3 +248,27 @@ export type ComponentData<C> =C extends BuiltinComponentDef<infer T> ? T :C extends ComponentDef<infer T> ? T :never;++// =============================================================================+// Component Defaults Registry+// =============================================================================++const builtinComponents: Record<string, BuiltinComponentDef<any>> = {+ LocalTransform,+ WorldTransform,+ Sprite,+ Camera,+ Canvas,+ Velocity,+ Parent,+ Children,+ SpineAnimation,+};++export function getComponentDefaults(typeName: string): Record<string, unknown> | null {+ const component = builtinComponents[typeName];+ if (component) {+ return { ...component._default };+ }+ return null;+}diff --git a/sdk/src/scene.ts b/sdk/src/scene.tsindex ad5d144f8..249888654 100644--- a/sdk/src/scene.ts+++ b/sdk/src/scene.ts@@ -10,10 +10,12 @@ import {Sprite,Camera,Canvas,+ SpineAnimation,type LocalTransformData,type SpriteData,type CameraData,type CanvasData,+ type SpineAnimationData,} from './component';import { Text, type TextData } from './ui/text';import type { AssetServer } from './asset/AssetServer';@@ -125,6 +127,22 @@ export async function loadSceneWithAssets(}}+ if (compData.type === 'SpineAnimation' && assetServer) {+ const data = compData.data as Record<string, unknown>;+ const skeletonPath = data.skeletonPath as string;+ const atlasPath = data.atlasPath as string;+ if (skeletonPath && atlasPath) {+ const result = await assetServer.loadSpine(+ skeletonPath,+ atlasPath,+ options?.assetBaseUrl+ );+ if (!result.success) {+ console.warn(`Failed to load Spine: ${result.error}`);+ }+ }+ }+loadComponent(world, entity, compData);}}@@ -151,7 +169,7 @@ export async function loadSceneWithAssets(return entityMap;}-function loadComponent(world: World, entity: Entity, compData: SceneComponentData): void {+export function loadComponent(world: World, entity: Entity, compData: SceneComponentData): void {const data = compData.data as unknown;switch (compData.type) {case 'LocalTransform':@@ -169,6 +187,9 @@ function loadComponent(world: World, entity: Entity, compData: SceneComponentDatcase 'Text':world.insert(entity, Text, data as TextData);break;+ case 'SpineAnimation':+ world.insert(entity, SpineAnimation, data as SpineAnimationData);+ break;default:console.warn(`Unknown component type: ${compData.type}`);}