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: move editor schema definitions into plugin register() for lazy initialization
esengine5fa8da84408a
diff --git a/editor/src/plugins/animation.ts b/editor/src/plugins/animation.tsindex 296e94e2d..3d44c89f1 100644--- a/editor/src/plugins/animation.ts+++ b/editor/src/plugins/animation.ts@@ -2,13 +2,13 @@ import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';import { defineSchema } from '../schemas/ComponentSchemas';import { TIME_SCALE_MAX } from '../schemas/schemaConstants';-const SpriteAnimatorSchema = defineSchema('SpriteAnimator', {- overrides: {- speed: { min: 0, max: TIME_SCALE_MAX, step: 0.1 },- },-});-export const animationPlugin: EditorPlugin = {name: 'animation',- register(_ctx: EditorPluginContext) {},+ register(_ctx: EditorPluginContext) {+ defineSchema('SpriteAnimator', {+ overrides: {+ speed: { min: 0, max: TIME_SCALE_MAX, step: 0.1 },+ },+ });+ },};diff --git a/editor/src/plugins/audio.ts b/editor/src/plugins/audio.tsindex ee448b8fe..38e5c471e 100644--- a/editor/src/plugins/audio.ts+++ b/editor/src/plugins/audio.ts@@ -2,51 +2,51 @@ import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';import { defineSchema } from '../schemas/ComponentSchemas';import { Constraints } from '../schemas/schemaConstants';-const spatialVisible = { field: 'spatial', equals: true } as const;--const AudioSourceSchema = defineSchema('AudioSource', {- overrides: {- bus: {- type: 'enum',- options: [- { label: 'SFX', value: 'sfx' },- { label: 'Music', value: 'music' },- { label: 'UI', value: 'ui' },- { label: 'Voice', value: 'voice' },- ],- },- volume: { ...Constraints.opacity },- pitch: { ...Constraints.pitch },- playOnAwake: { displayName: 'Play On Awake' },- priority: { ...Constraints.positiveInt },- spatial: { group: 'Spatial' },- minDistance: {- min: 0, step: 10, displayName: 'Min Distance', group: 'Spatial',- visibleWhen: spatialVisible,- },- maxDistance: {- min: 0, step: 10, displayName: 'Max Distance', group: 'Spatial',- visibleWhen: spatialVisible,- },- attenuationModel: {- type: 'enum', displayName: 'Attenuation', group: 'Spatial',- visibleWhen: spatialVisible,- options: [- { label: 'Linear', value: 0 },- { label: 'Inverse', value: 1 },- { label: 'Exponential', value: 2 },- ],- },- rolloff: {- min: 0, max: 5, step: 0.1, group: 'Spatial',- visibleWhen: spatialVisible,- },- },-});--const AudioListenerSchema = defineSchema('AudioListener');-export const audioPlugin: EditorPlugin = {name: 'audio',- register(_ctx: EditorPluginContext) {},+ register(_ctx: EditorPluginContext) {+ const spatialVisible = { field: 'spatial', equals: true } as const;++ defineSchema('AudioSource', {+ overrides: {+ bus: {+ type: 'enum',+ options: [+ { label: 'SFX', value: 'sfx' },+ { label: 'Music', value: 'music' },+ { label: 'UI', value: 'ui' },+ { label: 'Voice', value: 'voice' },+ ],+ },+ volume: { ...Constraints.opacity },+ pitch: { ...Constraints.pitch },+ playOnAwake: { displayName: 'Play On Awake' },+ priority: { ...Constraints.positiveInt },+ spatial: { group: 'Spatial' },+ minDistance: {+ min: 0, step: 10, displayName: 'Min Distance', group: 'Spatial',+ visibleWhen: spatialVisible,+ },+ maxDistance: {+ min: 0, step: 10, displayName: 'Max Distance', group: 'Spatial',+ visibleWhen: spatialVisible,+ },+ attenuationModel: {+ type: 'enum', displayName: 'Attenuation', group: 'Spatial',+ visibleWhen: spatialVisible,+ options: [+ { label: 'Linear', value: 0 },+ { label: 'Inverse', value: 1 },+ { label: 'Exponential', value: 2 },+ ],+ },+ rolloff: {+ min: 0, max: 5, step: 0.1, group: 'Spatial',+ visibleWhen: spatialVisible,+ },+ },+ });++ defineSchema('AudioListener');+ },};diff --git a/editor/src/plugins/coreComponents.ts b/editor/src/plugins/coreComponents.tsindex 3fd6acc66..068dc38d8 100644--- a/editor/src/plugins/coreComponents.ts+++ b/editor/src/plugins/coreComponents.ts@@ -1,108 +1,111 @@import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';-import { defineSchema } from '../schemas/ComponentSchemas';+import { defineSchema, type ComponentSchema } from '../schemas/ComponentSchemas';import { getSettingsValue } from '../settings/SettingsRegistry';import { Constraints } from '../schemas/schemaConstants';-const NameSchema = defineSchema('Name', {- removable: false,-});+let TransformSchema: ComponentSchema;+let CameraSchema: ComponentSchema;-const ParentSchema = defineSchema('Parent', {- removable: false,- hidden: true,- overrides: {- entity: { type: 'entity' },- },-});+export const coreComponentsPlugin: EditorPlugin = {+ name: 'core-components',+ register(_ctx: EditorPluginContext) {+ defineSchema('Name', {+ removable: false,+ });-const ChildrenSchema = defineSchema('Children', {- category: 'tag',- removable: false,- hidden: true,-});+ defineSchema('Parent', {+ removable: false,+ hidden: true,+ overrides: {+ entity: { type: 'entity' },+ },+ });-const TransformSchema = defineSchema('Transform', {- removable: false,- overrides: {- rotation: { type: 'euler' },- },-});+ defineSchema('Children', {+ category: 'tag',+ removable: false,+ hidden: true,+ });-const VelocitySchema = defineSchema('Velocity', {-});+ TransformSchema = defineSchema('Transform', {+ removable: false,+ overrides: {+ rotation: { type: 'euler' },+ },+ });-const SceneOwnerSchema = defineSchema('SceneOwner', {- removable: false,-});+ defineSchema('Velocity', {+ });-const CanvasSchema = defineSchema('Canvas', {- editorDefaults: () => {- const ppu = getSettingsValue<number>('rendering.pixelsPerUnit');- if (ppu != null) {- return { pixelsPerUnit: ppu };- }- return null;- },- overrides: {- pixelsPerUnit: { min: 1, step: 1 },- scaleMode: {- type: 'enum',- options: [- { label: 'FixedWidth', value: 0 },- { label: 'FixedHeight', value: 1 },- { label: 'Expand', value: 2 },- { label: 'Shrink', value: 3 },- { label: 'Match', value: 4 },- ],- },- matchWidthOrHeight: { min: 0, max: 1, step: 0.1 },- },-});+ defineSchema('SceneOwner', {+ removable: false,+ });-const CameraSchema = defineSchema('Camera', {- overrides: {- priority: { ...Constraints.positiveInt },- projectionType: {- type: 'enum',- displayName: 'Projection',- options: [- { label: 'Perspective', value: 0 },- { label: 'Orthographic', value: 1 },- ],- },- fov: {- ...Constraints.fov,- displayName: 'Field of View',- visibleWhen: { field: 'projectionType', equals: 0 },- },- orthoSize: {- min: 0.1,- displayName: 'Size',- visibleWhen: { field: 'projectionType', equals: 1 },- },- nearPlane: { step: 0.1, displayName: 'Near', group: 'Clipping' },- farPlane: { step: 1, displayName: 'Far', group: 'Clipping' },- viewportX: { ...Constraints.percentage, group: 'Viewport' },- viewportY: { ...Constraints.percentage, group: 'Viewport' },- viewportW: { ...Constraints.percentage, group: 'Viewport' },- viewportH: { ...Constraints.percentage, group: 'Viewport' },- clearFlags: {- type: 'enum',- group: 'Viewport',- options: [- { label: 'None', value: 0 },- { label: 'Color Only', value: 1 },- { label: 'Depth Only', value: 2 },- { label: 'Color + Depth', value: 3 },- ],- },- showFrustum: { group: 'Debug' },- },-});+ defineSchema('Canvas', {+ editorDefaults: () => {+ const ppu = getSettingsValue<number>('rendering.pixelsPerUnit');+ if (ppu != null) {+ return { pixelsPerUnit: ppu };+ }+ return null;+ },+ overrides: {+ pixelsPerUnit: { min: 1, step: 1 },+ scaleMode: {+ type: 'enum',+ options: [+ { label: 'FixedWidth', value: 0 },+ { label: 'FixedHeight', value: 1 },+ { label: 'Expand', value: 2 },+ { label: 'Shrink', value: 3 },+ { label: 'Match', value: 4 },+ ],+ },+ matchWidthOrHeight: { min: 0, max: 1, step: 0.1 },+ },+ });-export const coreComponentsPlugin: EditorPlugin = {- name: 'core-components',- register(_ctx: EditorPluginContext) {},+ CameraSchema = defineSchema('Camera', {+ overrides: {+ priority: { ...Constraints.positiveInt },+ projectionType: {+ type: 'enum',+ displayName: 'Projection',+ options: [+ { label: 'Perspective', value: 0 },+ { label: 'Orthographic', value: 1 },+ ],+ },+ fov: {+ ...Constraints.fov,+ displayName: 'Field of View',+ visibleWhen: { field: 'projectionType', equals: 0 },+ },+ orthoSize: {+ min: 0.1,+ displayName: 'Size',+ visibleWhen: { field: 'projectionType', equals: 1 },+ },+ nearPlane: { step: 0.1, displayName: 'Near', group: 'Clipping' },+ farPlane: { step: 1, displayName: 'Far', group: 'Clipping' },+ viewportX: { ...Constraints.percentage, group: 'Viewport' },+ viewportY: { ...Constraints.percentage, group: 'Viewport' },+ viewportW: { ...Constraints.percentage, group: 'Viewport' },+ viewportH: { ...Constraints.percentage, group: 'Viewport' },+ clearFlags: {+ type: 'enum',+ group: 'Viewport',+ options: [+ { label: 'None', value: 0 },+ { label: 'Color Only', value: 1 },+ { label: 'Depth Only', value: 2 },+ { label: 'Color + Depth', value: 3 },+ ],+ },+ showFrustum: { group: 'Debug' },+ },+ });+ },};export { TransformSchema, CameraSchema };diff --git a/editor/src/plugins/particle.ts b/editor/src/plugins/particle.tsindex aa52cc4c2..bbcf0dd61 100644--- a/editor/src/plugins/particle.ts+++ b/editor/src/plugins/particle.ts@@ -9,70 +9,70 @@ const EASING_OPTIONS = [{ label: 'EaseInOut', value: 3 },];-const ParticleEmitterSchema = defineSchema('ParticleEmitter', {- overrides: {- duration: { min: 0, step: 0.1 },- rate: { min: 0, step: 1, group: 'Emission' },- burstCount: { min: 0, step: 1, group: 'Emission' },- burstInterval: { min: 0, step: 0.1, group: 'Emission' },- maxParticles: { min: 1, step: 1, group: 'Emission' },- lifetimeMin: { min: 0, step: 0.1, group: 'Lifetime' },- lifetimeMax: { min: 0, step: 0.1, group: 'Lifetime' },- shape: {- type: 'enum', group: 'Shape',- options: [- { label: 'Point', value: 0 },- { label: 'Circle', value: 1 },- { label: 'Rectangle', value: 2 },- { label: 'Cone', value: 3 },- ],- },- shapeRadius: { min: 0, step: 0.1, group: 'Shape' },- shapeSize: { group: 'Shape' },- shapeAngle: { min: 0, max: 360, step: 1, group: 'Shape' },- speedMin: { min: 0, step: 0.1, group: 'Velocity' },- speedMax: { min: 0, step: 0.1, group: 'Velocity' },- angleSpreadMin: { min: 0, max: 360, step: 1, group: 'Velocity' },- angleSpreadMax: { min: 0, max: 360, step: 1, group: 'Velocity' },- startSizeMin: { min: 0, step: 0.1, group: 'Size' },- startSizeMax: { min: 0, step: 0.1, group: 'Size' },- endSizeMin: { min: 0, step: 0.1, group: 'Size' },- endSizeMax: { min: 0, step: 0.1, group: 'Size' },- sizeEasing: { type: 'enum', group: 'Size', options: EASING_OPTIONS },- startColor: { group: 'Color' },- endColor: { group: 'Color' },- colorEasing: { type: 'enum', group: 'Color', options: EASING_OPTIONS },- rotationMin: { step: 1, group: 'Rotation' },- rotationMax: { step: 1, group: 'Rotation' },- angularVelocityMin: { step: 1, group: 'Rotation' },- angularVelocityMax: { step: 1, group: 'Rotation' },- gravity: { group: 'Forces' },- damping: { min: 0, step: 0.01, group: 'Forces' },- texture: { group: 'Texture' },- spriteColumns: { min: 1, step: 1, group: 'Texture' },- spriteRows: { min: 1, step: 1, group: 'Texture' },- spriteFPS: { min: 1, step: 1, group: 'Texture' },- spriteLoop: { group: 'Texture' },- blendMode: {- type: 'enum', group: 'Rendering',- options: [- { label: 'Normal', value: 0 },- { label: 'Additive', value: 1 },- ],- },- layer: { min: LAYER_MIN, max: LAYER_MAX, group: 'Rendering' },- material: { group: 'Rendering' },- simulationSpace: {- type: 'enum', group: 'Rendering',- options: [- { label: 'World', value: 0 },- { label: 'Local', value: 1 },- ],- },- },-});-export const particlePlugin: EditorPlugin = {name: 'particle',- register(_ctx: EditorPluginContext) {},+ register(_ctx: EditorPluginContext) {+ defineSchema('ParticleEmitter', {+ overrides: {+ duration: { min: 0, step: 0.1 },+ rate: { min: 0, step: 1, group: 'Emission' },+ burstCount: { min: 0, step: 1, group: 'Emission' },+ burstInterval: { min: 0, step: 0.1, group: 'Emission' },+ maxParticles: { min: 1, step: 1, group: 'Emission' },+ lifetimeMin: { min: 0, step: 0.1, group: 'Lifetime' },+ lifetimeMax: { min: 0, step: 0.1, group: 'Lifetime' },+ shape: {+ type: 'enum', group: 'Shape',+ options: [+ { label: 'Point', value: 0 },+ { label: 'Circle', value: 1 },+ { label: 'Rectangle', value: 2 },+ { label: 'Cone', value: 3 },+ ],+ },+ shapeRadius: { min: 0, step: 0.1, group: 'Shape' },+ shapeSize: { group: 'Shape' },+ shapeAngle: { min: 0, max: 360, step: 1, group: 'Shape' },+ speedMin: { min: 0, step: 0.1, group: 'Velocity' },+ speedMax: { min: 0, step: 0.1, group: 'Velocity' },+ angleSpreadMin: { min: 0, max: 360, step: 1, group: 'Velocity' },+ angleSpreadMax: { min: 0, max: 360, step: 1, group: 'Velocity' },+ startSizeMin: { min: 0, step: 0.1, group: 'Size' },+ startSizeMax: { min: 0, step: 0.1, group: 'Size' },+ endSizeMin: { min: 0, step: 0.1, group: 'Size' },+ endSizeMax: { min: 0, step: 0.1, group: 'Size' },+ sizeEasing: { type: 'enum', group: 'Size', options: EASING_OPTIONS },+ startColor: { group: 'Color' },+ endColor: { group: 'Color' },+ colorEasing: { type: 'enum', group: 'Color', options: EASING_OPTIONS },+ rotationMin: { step: 1, group: 'Rotation' },+ rotationMax: { step: 1, group: 'Rotation' },+ angularVelocityMin: { step: 1, group: 'Rotation' },+ angularVelocityMax: { step: 1, group: 'Rotation' },+ gravity: { group: 'Forces' },+ damping: { min: 0, step: 0.01, group: 'Forces' },+ texture: { group: 'Texture' },+ spriteColumns: { min: 1, step: 1, group: 'Texture' },+ spriteRows: { min: 1, step: 1, group: 'Texture' },+ spriteFPS: { min: 1, step: 1, group: 'Texture' },+ spriteLoop: { group: 'Texture' },+ blendMode: {+ type: 'enum', group: 'Rendering',+ options: [+ { label: 'Normal', value: 0 },+ { label: 'Additive', value: 1 },+ ],+ },+ layer: { min: LAYER_MIN, max: LAYER_MAX, group: 'Rendering' },+ material: { group: 'Rendering' },+ simulationSpace: {+ type: 'enum', group: 'Rendering',+ options: [+ { label: 'World', value: 0 },+ { label: 'Local', value: 1 },+ ],+ },+ },+ });+ },};diff --git a/editor/src/plugins/sprite.ts b/editor/src/plugins/sprite.tsindex 18bfa5cfa..6c15d52d6 100644--- a/editor/src/plugins/sprite.ts+++ b/editor/src/plugins/sprite.ts@@ -1,29 +1,31 @@import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';-import { defineSchema } from '../schemas/ComponentSchemas';+import { defineSchema, type ComponentSchema } from '../schemas/ComponentSchemas';import { spriteBoundsProvider } from '../bounds/SpriteBoundsProvider';import { BOUNDS_PROVIDER } from '../container/tokens';import { LAYER_MIN, LAYER_MAX } from '../schemas/schemaConstants';import { getSettingsValue } from '../settings/SettingsRegistry';-const SpriteSchema = defineSchema('Sprite', {- editorDefaults: () => {- const w = getSettingsValue<number>('rendering.defaultSpriteWidth');- const h = getSettingsValue<number>('rendering.defaultSpriteHeight');- if (w != null || h != null) {- return { size: { x: w ?? 100, y: h ?? 100 } };- }- return null;- },- overrides: {- size: { hiddenWhen: { hasComponent: 'UIRect' } },- layer: { min: LAYER_MIN, max: LAYER_MAX },- },-});+let SpriteSchema: ComponentSchema;export const spritePlugin: EditorPlugin = {name: 'sprite',dependencies: ['core-components'],register(ctx: EditorPluginContext) {+ SpriteSchema = defineSchema('Sprite', {+ editorDefaults: () => {+ const w = getSettingsValue<number>('rendering.defaultSpriteWidth');+ const h = getSettingsValue<number>('rendering.defaultSpriteHeight');+ if (w != null || h != null) {+ return { size: { x: w ?? 100, y: h ?? 100 } };+ }+ return null;+ },+ overrides: {+ size: { hiddenWhen: { hasComponent: 'UIRect' } },+ layer: { min: LAYER_MIN, max: LAYER_MAX },+ },+ });+ctx.registrar.provide(BOUNDS_PROVIDER, 'Sprite', spriteBoundsProvider);},};diff --git a/sdk/wasm.generated.ts b/sdk/wasm.generated.tsindex 66c2fcd7a..92eb25811 100644--- a/sdk/wasm.generated.ts+++ b/sdk/wasm.generated.ts@@ -22,6 +22,14 @@ export interface VectorEntity {// Enums+export enum AlignSelf {+ Auto = 0,+ Start = 1,+ Center = 2,+ End = 3,+ Stretch = 4,+}+export enum EmitterShape {Point = 0,Circle = 1,@@ -86,6 +94,15 @@ export enum AlignItems {Stretch = 3,}+export enum AlignContent {+ Start = 0,+ Center = 1,+ End = 2,+ Stretch = 3,+ SpaceBetween = 4,+ SpaceAround = 5,+}+export enum LayoutDirection {Horizontal = 0,Vertical = 1,@@ -126,6 +143,14 @@ export interface FlexItem {flexShrink: number;flexBasis: number;order: number;+ alignSelf: number;+ margin: Padding;+ minWidth: number;+ minHeight: number;+ maxWidth: number;+ maxHeight: number;+ widthPercent: number;+ heightPercent: number;}export interface BoxCollider {@@ -177,6 +202,15 @@ export interface SegmentCollider {maskBits: number;}+export interface FanLayout {+ radius: number;+ maxSpreadAngle: number;+ maxCardAngle: number;+ tiltFactor: number;+ cardSpacing: number;+ direction: number;+}+export interface ParticleEmitter {rate: number;burstCount: number;@@ -241,6 +275,13 @@ export interface UIRenderer {enabled: boolean;}+export interface GridLayout {+ direction: number;+ crossAxisCount: number;+ itemSize: Vec2;+ spacing: Vec2;+}+export interface Velocity {linear: Vec3;angular: Vec3;@@ -301,6 +342,7 @@ export interface Sprite {texture: number;color: Vec4;size: Vec2;+ pivot: Vec2;uvOffset: Vec2;uvScale: Vec2;layer: number;@@ -320,6 +362,7 @@ export interface FlexContainer {wrap: number;justifyContent: number;alignItems: number;+ alignContent: number;gap: Vec2;padding: Padding;}@@ -341,6 +384,11 @@ export interface ShapeRenderer {enabled: boolean;}+export interface Selectable {+ selected: boolean;+ group: number;+}+export interface LayoutGroup {direction: number;spacing: number;@@ -407,6 +455,10 @@ export interface Registry {getSegmentCollider(entity: Entity): SegmentCollider;addSegmentCollider(entity: Entity, component: SegmentCollider): void;removeSegmentCollider(entity: Entity): void;+ hasFanLayout(entity: Entity): boolean;+ getFanLayout(entity: Entity): FanLayout;+ addFanLayout(entity: Entity, component: FanLayout): void;+ removeFanLayout(entity: Entity): void;hasParticleEmitter(entity: Entity): boolean;getParticleEmitter(entity: Entity): ParticleEmitter;addParticleEmitter(entity: Entity, component: ParticleEmitter): void;@@ -419,6 +471,10 @@ export interface Registry {getUIRenderer(entity: Entity): UIRenderer;addUIRenderer(entity: Entity, component: UIRenderer): void;removeUIRenderer(entity: Entity): void;+ hasGridLayout(entity: Entity): boolean;+ getGridLayout(entity: Entity): GridLayout;+ addGridLayout(entity: Entity, component: GridLayout): void;+ removeGridLayout(entity: Entity): void;hasVelocity(entity: Entity): boolean;getVelocity(entity: Entity): Velocity;addVelocity(entity: Entity, component: Velocity): void;@@ -467,6 +523,10 @@ export interface Registry {getShapeRenderer(entity: Entity): ShapeRenderer;addShapeRenderer(entity: Entity, component: ShapeRenderer): void;removeShapeRenderer(entity: Entity): void;+ hasSelectable(entity: Entity): boolean;+ getSelectable(entity: Entity): Selectable;+ addSelectable(entity: Entity, component: Selectable): void;+ removeSelectable(entity: Entity): void;hasLayoutGroup(entity: Entity): boolean;getLayoutGroup(entity: Entity): LayoutGroup;addLayoutGroup(entity: Entity, component: LayoutGroup): void;@@ -497,9 +557,11 @@ export interface ESEngineModule {CircleCollider: new () => CircleCollider;CapsuleCollider: new () => CapsuleCollider;SegmentCollider: new () => SegmentCollider;+ FanLayout: new () => FanLayout;ParticleEmitter: new () => ParticleEmitter;Transform: new () => Transform;UIRenderer: new () => UIRenderer;+ GridLayout: new () => GridLayout;Velocity: new () => Velocity;SpineAnimation: new () => SpineAnimation;Interactable: new () => Interactable;@@ -512,6 +574,7 @@ export interface ESEngineModule {Parent: new () => Parent;Children: new () => Children;ShapeRenderer: new () => ShapeRenderer;+ Selectable: new () => Selectable;LayoutGroup: new () => LayoutGroup;ScreenSpace: new () => ScreenSpace;Canvas: new () => Canvas;