Skip to content

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.

refactor: replace 11 independent registries with unified EditorContainer IoC

esengine4430af6eb09d
diff --git a/editor/src/Editor.ts b/editor/src/Editor.ts
index c8b18d7e1..3be71d01b 100644
--- a/editor/src/Editor.ts
+++ b/editor/src/Editor.ts
@@ -11,15 +11,13 @@ import { EditorBridge } from './bridge/EditorBridge';
import { PanelManager } from './PanelManager';
import { MenuManager } from './MenuManager';
import { PreviewManager } from './PreviewManager';
+import { getAllPanels } from './panels/PanelRegistry';
+import { exposeRegistrationAPI } from './schemas/ComponentSchemas';
import {
- registerPanel,
- getAllPanels,
- isBuiltinPanel,
- isSaveable,
-} from './panels/PanelRegistry';
-import { lockBuiltinPropertyEditors, clearExtensionPropertyEditors } from './property/PropertyEditor';
-import { lockBuiltinComponentSchemas, clearExtensionComponentSchemas, exposeRegistrationAPI } from './schemas/ComponentSchemas';
-import { registerBoundsProvider, lockBuiltinBoundsProviders, clearExtensionBoundsProviders } from './bounds';
+ EditorContainer, setEditorContainer, getEditorContainer,
+ PANEL,
+} from './container';
+import * as containerTokens from './container/tokens';
import { saveSceneToFile, saveSceneToPath, loadSceneFromFile, loadSceneFromPath, hasFileHandle, clearFileHandle } from './io/SceneSerializer';
import { isAbsolutePath, joinPath, getProjectDir } from './utils/path';
import { icons } from './utils/icons';
@@ -31,26 +29,12 @@ import { getSharedRenderContext } from './renderer/SharedRenderContext';
import type { EditorAssetServer } from './asset/EditorAssetServer';
import { getAssetLibrary } from './asset/AssetLibrary';
import { setEditorInstance, getEditorContext, getEditorInstance } from './context/EditorContext';
-import { registerGizmo, lockBuiltinGizmos, clearExtensionGizmos } from './gizmos';
import { ExtensionLoader } from './extension';
import { setEditorAPI, clearEditorAPI } from './extension/editorAPI';
-import {
- registerMenu, registerMenuItem, registerStatusbarItem,
- lockBuiltinMenus, clearExtensionMenus,
-} from './menus/MenuRegistry';
-import { registerPropertyEditor } from './property';
-import { registerComponentSchema } from './schemas';
import { showToast, showSuccessToast, showErrorToast } from './ui/Toast';
import { showContextMenu } from './ui/ContextMenu';
-import { registerContextMenuItem, lockBuiltinContextMenuItems, clearExtensionContextMenuItems } from './ui/ContextMenuRegistry';
import { installGlobalErrorHandler } from './error/GlobalErrorHandler';
import { EditorLogger, createConsoleHandler, createToastHandler } from './logging';
-import {
- registerInspectorSection,
- registerComponentInspector,
- lockBuiltinInspectorExtensions,
- clearExtensionInspectorExtensions,
-} from './panels/inspector/InspectorRegistry';
import type { EditorPlugin, EditorPluginContext } from './plugins/EditorPlugin';
import { builtinPlugins, coreStatusbarPlugin } from './plugins';
@@ -58,11 +42,7 @@ import { showConfirmDialog, showInputDialog, showDialog } from './ui/dialog';
import { getEditorStore } from './store';
import { generateUniqueName } from './utils/naming';
import {
- lockBuiltinSettings,
- clearExtensionSettings,
showSettingsDialog,
- registerSettingsSection,
- registerSettingsItem,
getSettingsValue,
setSettingsValue,
onSettingsChange,
@@ -71,9 +51,6 @@ import {
import { loadEditorLocalSettings, saveEditorLocalSetting } from './launcher/ProjectService';
import { DockLayoutManager } from './DockLayoutManager';
import { ContentDrawer } from './ui/ContentDrawer';
-import {
- lockBuiltinPanels, clearExtensionPanels,
-} from './panels/PanelRegistry';
import { MainWindowBridge } from './multiwindow/MainWindowBridge';
import { WindowManager } from './multiwindow/WindowManager';
import { emit } from '@tauri-apps/api/event';
@@ -128,7 +105,11 @@ export class Editor {
this.menuManager_.setStore(this.store_);
this.previewManager_ = new PreviewManager(this.projectPath_);
+ const iocContainer = new EditorContainer();
+ setEditorContainer(iocContainer);
+
this.pluginContext_ = {
+ registrar: iocContainer,
editor: this,
projectPath: this.projectPath_,
onOpenScene: (path: string) => this.openSceneFromPath(path),
@@ -147,15 +128,7 @@ export class Editor {
this.addPlugin(plugin);
}
exposeRegistrationAPI();
- lockBuiltinPanels();
- lockBuiltinMenus();
- lockBuiltinGizmos();
- lockBuiltinPropertyEditors();
- lockBuiltinComponentSchemas();
- lockBuiltinBoundsProviders();
- lockBuiltinSettings();
- lockBuiltinContextMenuItems();
- lockBuiltinInspectorExtensions();
+ iocContainer.lockBuiltins();
this.setupLayout();
@@ -322,11 +295,7 @@ export class Editor {
}
private async saveDirtyPanels(): Promise<void> {
- for (const panel of this.panelManager_.panelInstances.values()) {
- if (isSaveable(panel) && panel.isDirty) {
- await panel.saveAsset();
- }
- }
+ await this.panelManager_.saveDirtyPanels();
}
async saveSceneAs(): Promise<void> {
@@ -741,28 +710,24 @@ export class Editor {
// =========================================================================
private setupEditorGlobals(): void {
+ const container = getEditorContainer();
+ const registrar = container as import('./container').PluginRegistrar;
+
this.baseAPI_ = {
...esengine,
- registerPanel,
- registerMenuItem,
- registerMenu,
- registerGizmo,
- registerStatusbarItem,
- registerPropertyEditor,
- registerComponentSchema,
- registerBoundsProvider,
+ registrar,
+ tokens: containerTokens,
icons,
showToast,
showSuccessToast,
showErrorToast,
showContextMenu,
- registerContextMenuItem,
- registerInspectorSection,
- registerComponentInspector,
showConfirmDialog,
showInputDialog,
getEditorInstance,
getEditorStore,
+ getSettingsValue,
+ setSettingsValue,
Draw,
Geometry,
Material,
@@ -775,10 +740,6 @@ export class Editor {
registerDrawCallback,
unregisterDrawCallback,
clearDrawCallbacks,
- registerSettingsSection,
- registerSettingsItem,
- getSettingsValue,
- setSettingsValue,
};
setEditorAPI(this.baseAPI_);
}
@@ -809,9 +770,10 @@ export class Editor {
}
private cleanupExtensionUI(): void {
+ const c = getEditorContainer();
if (this.dockLayout_) {
for (const [id] of this.panelManager_.panelInstances) {
- if (!isBuiltinPanel(id)) {
+ if (!c.isBuiltin(PANEL, id)) {
this.dockLayout_.removePanel(id);
}
}
@@ -820,24 +782,17 @@ export class Editor {
this.container_.querySelectorAll('[data-statusbar-id^="toggle-"]').forEach(el => {
const panelId = el.getAttribute('data-statusbar-id')?.replace('toggle-', '');
- if (panelId && !isBuiltinPanel(panelId)) el.remove();
+ if (panelId && !c.isBuiltin(PANEL, panelId)) el.remove();
});
- clearExtensionPanels();
- clearExtensionMenus();
- clearExtensionGizmos();
- clearExtensionPropertyEditors();
- clearExtensionComponentSchemas();
- clearExtensionBoundsProviders();
- clearExtensionSettings();
- clearExtensionContextMenuItems();
- clearExtensionInspectorExtensions();
+ c.clearExtensions();
}
private applyExtensionUI(): void {
+ const c = getEditorContainer();
if (this.dockLayout_) {
for (const desc of getAllPanels()) {
- if (isBuiltinPanel(desc.id)) continue;
+ if (c.isBuiltin(PANEL, desc.id)) continue;
this.dockLayout_.addPanel(desc);
}
}
diff --git a/editor/src/PanelManager.ts b/editor/src/PanelManager.ts
index 5859a21ea..87445e135 100644
--- a/editor/src/PanelManager.ts
+++ b/editor/src/PanelManager.ts
@@ -1,26 +1,19 @@
import type { App } from 'esengine';
-import type { SpineModuleController, SpineWasmModule } from 'esengine/spine';
-import { wrapSpineModule, SpineModuleController as SpineModuleControllerClass } from 'esengine/spine';
+import type { SpineWasmModule } from 'esengine/spine';
+import { SpineModuleController as SpineModuleControllerClass, wrapSpineModule } from 'esengine/spine';
import type { EditorStore } from './store/EditorStore';
import type { EditorBridge } from './bridge/EditorBridge';
-import type { PanelInstance, PanelDescriptor } from './panels/PanelRegistry';
-import {
- isBridgeAware,
- isAppAware,
- isAssetServerProvider,
- isAssetNavigable,
- isOutputAppendable,
- isSpineControllerAware,
- isSpineInfoProvider,
- isBuiltinPanel,
- getPanel,
-} from './panels/PanelRegistry';
+import type { PanelInstance, PanelDescriptor, PanelHooks } from './panels/PanelRegistry';
+import { getPanel } from './panels/PanelRegistry';
import type { EditorAssetServer } from './asset/EditorAssetServer';
+import { getEditorContainer } from './container';
+import { PANEL } from './container/tokens';
import { icons } from './utils/icons';
import { escapeHtml } from './utils/html';
export class PanelManager {
private panelInstances_ = new Map<string, PanelInstance>();
+ private panelHooks_ = new Map<string, PanelHooks>();
private bridge_: EditorBridge | null = null;
private app_: App | null = null;
@@ -29,8 +22,8 @@ export class PanelManager {
}
get assetServer(): EditorAssetServer | null {
- for (const panel of this.panelInstances_.values()) {
- if (isAssetServerProvider(panel)) return panel.assetServer as EditorAssetServer;
+ for (const hooks of this.panelHooks_.values()) {
+ if (hooks.getAssetServer) return hooks.getAssetServer();
}
return null;
}
@@ -50,9 +43,13 @@ export class PanelManager {
app?: App | null,
): void {
try {
- const instance = desc.factory(container, store);
- if (bridge && isBridgeAware(instance)) instance.setBridge(bridge);
- if (app && isAppAware(instance)) instance.setApp(app);
+ const result = desc.factory(container, store);
+ const { instance, hooks } = result;
+ if (hooks) {
+ this.panelHooks_.set(desc.id, hooks);
+ if (bridge) hooks.setBridge?.(bridge);
+ if (app) hooks.setApp?.(app);
+ }
this.panelInstances_.set(desc.id, instance);
} catch (err) {
console.error(`Panel "${desc.id}" failed to initialize:`, err);
@@ -100,44 +97,42 @@ export class PanelManager {
setApp(app: App, bridge: EditorBridge): void {
this.app_ = app;
this.bridge_ = bridge;
- for (const panel of this.panelInstances_.values()) {
- if (isBridgeAware(panel)) panel.setBridge(bridge);
- if (isAppAware(panel)) panel.setApp(app);
+ for (const hooks of this.panelHooks_.values()) {
+ hooks.setBridge?.(bridge);
+ hooks.setApp?.(app);
}
}
setSpineModule(module: unknown): void {
const raw = module as SpineWasmModule;
const controller = module ? new SpineModuleControllerClass(raw, wrapSpineModule(raw)) : null;
- for (const panel of this.panelInstances_.values()) {
- if (isSpineControllerAware(panel)) {
- panel.setSpineController(controller);
- }
+ for (const hooks of this.panelHooks_.values()) {
+ hooks.setSpineController?.(controller);
}
}
getSpineSkeletonInfo(entityId: number): { animations: string[]; skins: string[] } | null {
- for (const panel of this.panelInstances_.values()) {
- if (isSpineInfoProvider(panel)) {
- return panel.getSpineSkeletonInfo(entityId);
+ for (const hooks of this.panelHooks_.values()) {
+ if (hooks.getSpineSkeletonInfo) {
+ return hooks.getSpineSkeletonInfo(entityId);
}
}
return null;
}
onSpineInstanceReady(listener: (entityId: number) => void): () => void {
- for (const panel of this.panelInstances_.values()) {
- if (isSpineInfoProvider(panel)) {
- return panel.onSpineInstanceReady(listener);
+ for (const hooks of this.panelHooks_.values()) {
+ if (hooks.onSpineInstanceReady) {
+ return hooks.onSpineInstanceReady(listener);
}
}
return () => {};
}
async navigateToAsset(assetPath: string): Promise<void> {
- for (const panel of this.panelInstances_.values()) {
- if (isAssetNavigable(panel)) {
- await panel.navigateToAsset(assetPath);
+ for (const hooks of this.panelHooks_.values()) {
+ if (hooks.navigateToAsset) {
+ await hooks.navigateToAsset(assetPath);
return;
}
}
@@ -160,10 +155,20 @@ export class PanelManager {
}
appendOutput(text: string, type: 'command' | 'stdout' | 'stderr' | 'error' | 'success'): void {
- const outputPanel = this.panelInstances_.get('output');
- if (outputPanel && isOutputAppendable(outputPanel)) {
- outputPanel.appendOutput(text, type);
+ const hooks = this.panelHooks_.get('output');
+ if (hooks?.appendOutput) {
+ hooks.appendOutput(text, type);
+ }
+ }
+
+ saveDirtyPanels(): Promise<void> {
+ const promises: Promise<boolean>[] = [];
+ for (const hooks of this.panelHooks_.values()) {
+ if (hooks.isDirty?.() && hooks.saveAsset) {
+ promises.push(hooks.saveAsset());
+ }
}
+ return Promise.all(promises).then(() => {});
}
removePanelInstance(panelId: string): void {
@@ -171,14 +176,17 @@ export class PanelManager {
if (instance) {
instance.dispose();
this.panelInstances_.delete(panelId);
+ this.panelHooks_.delete(panelId);
}
}
cleanupExtensionPanels(): void {
+ const c = getEditorContainer();
for (const [id, instance] of this.panelInstances_) {
- if (isBuiltinPanel(id)) continue;
+ if (c.isBuiltin(PANEL, id)) continue;
instance.dispose();
this.panelInstances_.delete(id);
+ this.panelHooks_.delete(id);
}
}
@@ -187,6 +195,6 @@ export class PanelManager {
panel.dispose();
}
this.panelInstances_.clear();
+ this.panelHooks_.clear();
}
}
-
diff --git a/editor/src/asset/AssetTypeRegistry.ts b/editor/src/asset/AssetTypeRegistry.ts
index 068d7a955..064391133 100644
--- a/editor/src/asset/AssetTypeRegistry.ts
+++ b/editor/src/asset/AssetTypeRegistry.ts
@@ -17,6 +17,8 @@ import { getPlatformAdapter } from '../platform/PlatformAdapter';
import { getEditorContext } from '../context/EditorContext';
import { getAssetDatabase } from './AssetDatabase';
import { AssetType } from '../constants/AssetTypes';
+import { getEditorContainer } from '../container';
+import { ASSET_TYPE, ASSET_EDITOR_TYPE } from '../container/tokens';
export type AssetPayload = { type: string; path: string; name: string };
@@ -33,33 +35,31 @@ export interface AssetTypeDescriptor {
onCreateEntity?: (state: HierarchyState, asset: AssetPayload, parent: Entity | null) => Promise<void>;
}
-const registry_ = new Map<string, AssetTypeDescriptor>();
-const editorTypeIndex_ = new Map<string, string>();
-
export function registerAssetType(displayType: string, descriptor: AssetTypeDescriptor): void {
- if (registry_.has(displayType)) {
+ const c = getEditorContainer();
+ if (c.has(ASSET_TYPE, displayType)) {
throw new Error(`Asset type '${displayType}' is already registered`);
}
- registry_.set(displayType, descriptor);
+ c.provide(ASSET_TYPE, displayType, descriptor);
const editorTypes = Array.isArray(descriptor.editorType)
? descriptor.editorType
: [descriptor.editorType];
for (const et of editorTypes) {
- editorTypeIndex_.set(et, displayType);
+ c.provide(ASSET_EDITOR_TYPE, et, displayType);
}
}
export function getAssetTypeDescriptor(displayType: string): AssetTypeDescriptor | undefined {
- return registry_.get(displayType);
+ return getEditorContainer().get(ASSET_TYPE, displayType);
}
export function getAllAssetTypes(): string[] {
- return [...registry_.keys()];
+ return [...getEditorContainer().getAll(ASSET_TYPE).keys()];
}
export function getDroppableTypes(): Set<string> {
const result = new Set<string>();
- for (const [type, desc] of registry_) {
+ for (const [type, desc] of getEditorContainer().getAll(ASSET_TYPE)) {
if (desc.droppable) {
result.add(type);
}
@@ -68,11 +68,11 @@ export function getDroppableTypes(): Set<string> {
}
export function getDisplayType(editorType: string): string {
- return editorTypeIndex_.get(editorType) ?? editorType;
+ return getEditorContainer().get(ASSET_EDITOR_TYPE, editorType) ?? editorType;
}
export function getAssetTypeIcon(displayType: string, size: number = 16): string {
- const desc = registry_.get(displayType);
+ const desc = getEditorContainer().get(ASSET_TYPE, displayType);
if (desc) {
return desc.icon(size);
}
@@ -80,7 +80,7 @@ export function getAssetTypeIcon(displayType: string, size: number = 16): string
}
export function getAssetTypeDisplayName(displayType: string): string {
- const desc = registry_.get(displayType);
+ const desc = getEditorContainer().get(ASSET_TYPE, displayType);
if (desc) {
return desc.displayName;
}
@@ -88,7 +88,7 @@ export function getAssetTypeDisplayName(displayType: string): string {
}
export function getInspectorRenderer(displayType: string): AssetTypeDescriptor['inspectorRenderer'] {
- return registry_.get(displayType)?.inspectorRenderer ?? null;
+ return getEditorContainer().get(ASSET_TYPE, displayType)?.inspectorRenderer ?? null;
}
// =========================================================================
@@ -188,8 +188,21 @@ async function createSpineEntityFromAsset(
// Builtin registration
// =========================================================================
-export function registerBuiltinAssetTypes(): void {
- registerAssetType(AssetType.IMAGE, {
+export function registerBuiltinAssetTypes(registrar?: import('../container').PluginRegistrar): void {
+ const reg = (displayType: string, descriptor: AssetTypeDescriptor) => {
+ const r = registrar ?? getEditorContainer();
+ if (r.has(ASSET_TYPE, displayType)) {
+ throw new Error(`Asset type '${displayType}' is already registered`);
+ }
+ r.provide(ASSET_TYPE, displayType, descriptor);
+ const editorTypes = Array.isArray(descriptor.editorType)
+ ? descriptor.editorType
+ : [descriptor.editorType];
+ for (const et of editorTypes) {
+ r.provide(ASSET_EDITOR_TYPE, et, displayType);
+ }
+ };
+ reg(AssetType.IMAGE, {
editorType: 'texture',
displayType: AssetType.IMAGE,
displayName: 'Image',
@@ -237,7 +250,7 @@ export function registerBuiltinAssetTypes(): void {
},
});
- registerAssetType(AssetType.MATERIAL, {
+ reg(AssetType.MATERIAL, {
editorType: 'material',
displayType: AssetType.MATERIAL,
displayName: 'Material',
@@ -248,7 +261,7 @@ export function registerBuiltinAssetTypes(): void {
createMenuEntry: null,
});
- registerAssetType(AssetType.SHADER, {
+ reg(AssetType.SHADER, {
editorType: 'shader',
displayType: AssetType.SHADER,
displayName: 'Shader',
@@ -259,7 +272,7 @@ export function registerBuiltinAssetTypes(): void {
createMenuEntry: null,
});
- registerAssetType(AssetType.FONT, {
+ reg(AssetType.FONT, {
editorType: 'bitmap-font',
displayType: AssetType.FONT,
displayName: 'BitmapFont',
@@ -270,7 +283,7 @@ export function registerBuiltinAssetTypes(): void {
createMenuEntry: null,
});
- registerAssetType(AssetType.SPINE, {
+ reg(AssetType.SPINE, {
editorType: ['spine-atlas', 'spine-skeleton'],
displayType: AssetType.SPINE,
displayName: 'Spine',
@@ -282,7 +295,7 @@ export function registerBuiltinAssetTypes(): void {
onCreateEntity: createSpineEntityFromAsset,
});
- registerAssetType(AssetType.ANIMCLIP, {
+ reg(AssetType.ANIMCLIP, {
editorType: 'anim-clip',
displayType: AssetType.ANIMCLIP,
displayName: 'Animation Clip',
@@ -320,7 +333,7 @@ export function registerBuiltinAssetTypes(): void {
},
});
- registerAssetType(AssetType.TIMELINE, {
+ reg(AssetType.TIMELINE, {
editorType: 'timeline',
displayType: AssetType.TIMELINE,
displayName: 'Timeline',
@@ -331,7 +344,7 @@ export function registerBuiltinAssetTypes(): void {
createMenuEntry: null,
});
- registerAssetType(AssetType.SCENE, {
+ reg(AssetType.SCENE, {
editorType: 'scene',
displayType: AssetType.SCENE,
displayName: 'Scene',
@@ -342,7 +355,7 @@ export function registerBuiltinAssetTypes(): void {
createMenuEntry: null,
});
- registerAssetType(AssetType.PREFAB, {
+ reg(AssetType.PREFAB, {
editorType: 'prefab',
displayType: AssetType.PREFAB,
displayName: 'Prefab',
@@ -358,7 +371,7 @@ export function registerBuiltinAssetTypes(): void {
},
});
- registerAssetType(AssetType.AUDIO, {
+ reg(AssetType.AUDIO, {
editorType: 'audio',
displayType: AssetType.AUDIO,
displayName: 'Audio',
@@ -392,7 +405,7 @@ export function registerBuiltinAssetTypes(): void {
},
});
- registerAssetType(AssetType.SCRIPT, {
+ reg(AssetType.SCRIPT, {
editorType: 'script',
displayType: AssetType.SCRIPT,
displayName: 'Script',
@@ -403,7 +416,7 @@ export function registerBuiltinAssetTypes(): void {
createMenuEntry: null,
});
- registerAssetType(AssetType.JSON, {
+ reg(AssetType.JSON, {
editorType: 'json',
displayType: AssetType.JSON,
displayName: 'JSON',
@@ -415,7 +428,7 @@ export function registerBuiltinAssetTypes(): void {
onCreateEntity: createSpineEntityFromAsset,
});
- registerAssetType(AssetType.FOLDER, {
+ reg(AssetType.FOLDER, {
editorType: 'folder',
displayType: AssetType.FOLDER,
displayName: 'Folder',
@@ -426,7 +439,7 @@ export function registerBuiltinAssetTypes(): void {
createMenuEntry: null,
});
- registerAssetType(AssetType.FILE, {
+ reg(AssetType.FILE, {
editorType: 'file',
displayType: AssetType.FILE,
displayName: 'File',
@@ -439,6 +452,7 @@ export function registerBuiltinAssetTypes(): void {
}
export function resetAssetTypeRegistry(): void {
- registry_.clear();
- editorTypeIndex_.clear();
+ const c = getEditorContainer();
+ c.removeWhere(ASSET_TYPE, () => true);
+ c.removeWhere(ASSET_EDITOR_TYPE, () => true);
}
diff --git a/editor/src/bounds/BoundsRegistry.ts b/editor/src/bounds/BoundsRegistry.ts
index 1a894de4f..4c1ee7fd1 100644
--- a/editor/src/bounds/BoundsRegistry.ts
+++ b/editor/src/bounds/BoundsRegistry.ts
@@ -1,31 +1,15 @@
-/**
- * @file BoundsRegistry.ts
- * @brief Registry for component bounds providers
- */
-
import type { Bounds, BoundsProvider } from './BoundsProvider';
-
-const providers = new Map<string, BoundsProvider>();
+import { getEditorContainer } from '../container';
+import { BOUNDS_PROVIDER } from '../container/tokens';
export function registerBoundsProvider(componentType: string, provider: BoundsProvider): void {
- providers.set(componentType, provider);
-}
-
-const builtinProviderTypes = new Set<string>();
-
-export function lockBuiltinBoundsProviders(): void {
- for (const type of providers.keys()) builtinProviderTypes.add(type);
-}
-
-export function clearExtensionBoundsProviders(): void {
- for (const type of providers.keys()) {
- if (!builtinProviderTypes.has(type)) providers.delete(type);
- }
+ getEditorContainer().provide(BOUNDS_PROVIDER, componentType, provider);
}
export function getEntityBounds(components: { type: string; data: any }[]): Bounds {
+ const container = getEditorContainer();
for (const comp of components) {
- const provider = providers.get(comp.type);
+ const provider = container.get(BOUNDS_PROVIDER, comp.type);
if (provider) {
const bounds = provider.getBounds(comp.data);
if (bounds) return bounds;
diff --git a/editor/src/bounds/index.ts b/editor/src/bounds/index.ts
index 3068e4b5d..a53021529 100644
--- a/editor/src/bounds/index.ts
+++ b/editor/src/bounds/index.ts
@@ -4,4 +4,4 @@
*/
export * from './BoundsProvider';
-export { registerBoundsProvider, getEntityBounds, lockBuiltinBoundsProviders, clearExtensionBoundsProviders } from './BoundsRegistry';
+export { registerBoundsProvider, getEntityBounds } from './BoundsRegistry';
diff --git a/editor/src/container/EditorContainer.ts b/editor/src/container/EditorContainer.ts
new file mode 100644
index 000000000..0aab69294
--- /dev/null
+++ b/editor/src/container/EditorContainer.ts
@@ -0,0 +1,85 @@
+import { ServiceToken } from './ServiceToken';
+
+export interface PluginRegistrar {
+ provide<V>(token: ServiceToken<V>, key: string, value: V): void;
+ get<V>(token: ServiceToken<V>, key: string): V | undefined;
+ has<V>(token: ServiceToken<V>, key: string): boolean;
+ getAll<V>(token: ServiceToken<V>): ReadonlyMap<string, V>;
+}
+
+export class EditorContainer implements PluginRegistrar {
+ private stores_ = new Map<ServiceToken<any>, Map<string, any>>();
+ private builtinKeys_ = new Map<ServiceToken<any>, Set<string>>();
+ private locked_ = false;
+
+ provide<V>(token: ServiceToken<V>, key: string, value: V): void {
+ let map = this.stores_.get(token);
+ if (!map) {
+ map = new Map();
+ this.stores_.set(token, map);
+ }
+ map.set(key, value);
+ }
+
+ get<V>(token: ServiceToken<V>, key: string): V | undefined {
+ return this.stores_.get(token)?.get(key) as V | undefined;
+ }
+
+ has<V>(token: ServiceToken<V>, key: string): boolean {
+ return this.stores_.get(token)?.has(key) ?? false;
+ }
+
+ getAll<V>(token: ServiceToken<V>): ReadonlyMap<string, V> {
+ return (this.stores_.get(token) as ReadonlyMap<string, V>) ?? new Map<string, V>();
+ }
+
+ remove<V>(token: ServiceToken<V>, key: string): boolean {
+ return this.stores_.get(token)?.delete(key) ?? false;
+ }
+
+ removeWhere<V>(token: ServiceToken<V>, pred: (key: string, value: V) => boolean): void {
+ const map = this.stores_.get(token);
+ if (!map) return;
+ for (const [key, value] of map) {
+ if (pred(key, value)) map.delete(key);
+ }
+ }
+
+ isBuiltin<V>(token: ServiceToken<V>, key: string): boolean {
+ return this.builtinKeys_.get(token)?.has(key) ?? false;
+ }
+
+ lockBuiltins(): void {
+ if (this.locked_) return;
+ this.locked_ = true;
+ for (const [token, map] of this.stores_) {
+ this.builtinKeys_.set(token, new Set(map.keys()));
+ }
+ }
+
+ clearExtensions(): void {
+ for (const [token, map] of this.stores_) {
+ const builtin = this.builtinKeys_.get(token);
+ if (!builtin) {
+ map.clear();
+ continue;
+ }
+ for (const key of map.keys()) {
+ if (!builtin.has(key)) map.delete(key);
+ }
+ }
+ }
+}
+
+let editorContainer_: EditorContainer | null = null;
+
+export function setEditorContainer(container: EditorContainer): void {
+ editorContainer_ = container;
+}
+
+export function getEditorContainer(): EditorContainer {
+ if (!editorContainer_) {
+ throw new Error('EditorContainer not initialized');
+ }
+ return editorContainer_;
+}
diff --git a/editor/src/container/ServiceToken.ts b/editor/src/container/ServiceToken.ts
new file mode 100644
index 000000000..23ff4787d
--- /dev/null
+++ b/editor/src/container/ServiceToken.ts
@@ -0,0 +1,3 @@
+export class ServiceToken<V> {
+ constructor(public readonly name: string) {}
+}
diff --git a/editor/src/container/index.ts b/editor/src/container/index.ts
new file mode 100644
index 000000000..79d4e045f
--- /dev/null
+++ b/editor/src/container/index.ts
@@ -0,0 +1,21 @@
+export { ServiceToken } from './ServiceToken';
+export { EditorContainer, setEditorContainer, getEditorContainer } from './EditorContainer';
+export type { PluginRegistrar } from './EditorContainer';
+export {
+ COMPONENT_SCHEMA,
+ PROPERTY_EDITOR,
+ BOUNDS_PROVIDER,
+ GIZMO,
+ PANEL,
+ MENU,
+ MENU_ITEM,
+ STATUSBAR_ITEM,
+ SETTINGS_SECTION,
+ SETTINGS_GROUP,
+ SETTINGS_ITEM,
+ CONTEXT_MENU_ITEM,
+ INSPECTOR_SECTION,
+ COMPONENT_INSPECTOR,
+ ASSET_TYPE,
+ ASSET_EDITOR_TYPE,
+} from './tokens';
diff --git a/editor/src/container/tokens.ts b/editor/src/container/tokens.ts
new file mode 100644
index 000000000..49a191d55
--- /dev/null
+++ b/editor/src/container/tokens.ts
@@ -0,0 +1,28 @@
+import { ServiceToken } from './ServiceToken';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import type { PropertyEditorFactory } from '../property/PropertyEditor';
+import type { BoundsProvider } from '../bounds/BoundsProvider';
+import type { GizmoDescriptor } from '../gizmos/GizmoRegistry';
+import type { PanelDescriptor } from '../panels/PanelRegistry';
+import type { MenuDescriptor, MenuItemDescriptor, StatusbarItemDescriptor } from '../menus/MenuRegistry';
+import type { SettingsSectionDescriptor, SettingsGroupDescriptor, SettingsItemDescriptor } from '../settings/SettingsRegistry';
+import type { ContextMenuContribution } from '../ui/ContextMenuRegistry';
+import type { InspectorSectionDescriptor, ComponentInspectorDescriptor } from '../panels/inspector/InspectorRegistry';
+import type { AssetTypeDescriptor } from '../asset/AssetTypeRegistry';
+
+export const COMPONENT_SCHEMA = new ServiceToken<ComponentSchema>('COMPONENT_SCHEMA');
+export const PROPERTY_EDITOR = new ServiceToken<PropertyEditorFactory>('PROPERTY_EDITOR');
+export const BOUNDS_PROVIDER = new ServiceToken<BoundsProvider>('BOUNDS_PROVIDER');
+export const GIZMO = new ServiceToken<GizmoDescriptor>('GIZMO');
+export const PANEL = new ServiceToken<PanelDescriptor>('PANEL');
+export const MENU = new ServiceToken<MenuDescriptor>('MENU');
+export const MENU_ITEM = new ServiceToken<MenuItemDescriptor>('MENU_ITEM');
+export const STATUSBAR_ITEM = new ServiceToken<StatusbarItemDescriptor>('STATUSBAR_ITEM');
+export const SETTINGS_SECTION = new ServiceToken<SettingsSectionDescriptor>('SETTINGS_SECTION');
+export const SETTINGS_GROUP = new ServiceToken<SettingsGroupDescriptor>('SETTINGS_GROUP');
+export const SETTINGS_ITEM = new ServiceToken<SettingsItemDescriptor>('SETTINGS_ITEM');
+export const CONTEXT_MENU_ITEM = new ServiceToken<ContextMenuContribution>('CONTEXT_MENU_ITEM');
+export const INSPECTOR_SECTION = new ServiceToken<InspectorSectionDescriptor>('INSPECTOR_SECTION');
+export const COMPONENT_INSPECTOR = new ServiceToken<ComponentInspectorDescriptor>('COMPONENT_INSPECTOR');
+export const ASSET_TYPE = new ServiceToken<AssetTypeDescriptor>('ASSET_TYPE');
+export const ASSET_EDITOR_TYPE = new ServiceToken<string>('ASSET_EDITOR_TYPE');
diff --git a/editor/src/gizmos/GizmoRegistry.ts b/editor/src/gizmos/GizmoRegistry.ts
index 786533938..e44c15f4b 100644
--- a/editor/src/gizmos/GizmoRegistry.ts
+++ b/editor/src/gizmos/GizmoRegistry.ts
@@ -1,6 +1,8 @@
import type { EditorStore } from '../store/EditorStore';
import type { EntityData } from '../types/SceneTypes';
import type { TransformValue } from '../math/Transform';
+import { getEditorContainer } from '../container';
+import { GIZMO } from '../container/tokens';
export interface GizmoContext {
store: EditorStore;
@@ -28,27 +30,15 @@ export interface GizmoDescriptor {
getCursor?(hitData: unknown): string;
}
-const gizmos = new Map<string, GizmoDescriptor>();
-const builtinGizmoIds = new Set<string>();
-
export function registerGizmo(descriptor: GizmoDescriptor): void {
- gizmos.set(descriptor.id, descriptor);
-}
-
-export function lockBuiltinGizmos(): void {
- for (const id of gizmos.keys()) builtinGizmoIds.add(id);
-}
-
-export function clearExtensionGizmos(): void {
- for (const id of gizmos.keys()) {
- if (!builtinGizmoIds.has(id)) gizmos.delete(id);
- }
+ getEditorContainer().provide(GIZMO, descriptor.id, descriptor);
}
export function getGizmo(id: string): GizmoDescriptor | undefined {
- return gizmos.get(id);
+ return getEditorContainer().get(GIZMO, id);
}
export function getAllGizmos(): GizmoDescriptor[] {
- return Array.from(gizmos.values()).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
+ return Array.from(getEditorContainer().getAll(GIZMO).values())
+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
diff --git a/editor/src/gizmos/builtinGizmos.ts b/editor/src/gizmos/builtinGizmos.ts
index d7528dfb9..633411687 100644
--- a/editor/src/gizmos/builtinGizmos.ts
+++ b/editor/src/gizmos/builtinGizmos.ts
@@ -1,4 +1,6 @@
-import { registerGizmo, type GizmoContext, type GizmoDescriptor } from './GizmoRegistry';
+import type { GizmoContext, GizmoDescriptor } from './GizmoRegistry';
+import type { PluginRegistrar } from '../container';
+import { GIZMO } from '../container/tokens';
import { icons } from '../utils/icons';
import { quatToEuler, eulerToQuat } from '../math/Transform';
import { getSettingsValue } from '../settings/SettingsRegistry';
@@ -800,7 +802,8 @@ export function createRectGizmo(): GizmoDescriptor {
// Registration
// =============================================================================
-export function registerBuiltinGizmos(): void {
+export function registerBuiltinGizmos(registrar: PluginRegistrar): void {
+ const registerGizmo = (d: GizmoDescriptor) => registrar.provide(GIZMO, d.id, d);
registerGizmo(createSelectGizmo());
registerGizmo(createMoveGizmo());
registerGizmo(createRotateGizmo());
diff --git a/editor/src/gizmos/index.ts b/editor/src/gizmos/index.ts
index 9a928ec29..041917c42 100644
--- a/editor/src/gizmos/index.ts
+++ b/editor/src/gizmos/index.ts
@@ -4,8 +4,6 @@ export {
registerGizmo,
getGizmo,
getAllGizmos,
- lockBuiltinGizmos,
- clearExtensionGizmos,
} from './GizmoRegistry';
export { GizmoManager } from './GizmoManager';
diff --git a/editor/src/index.ts b/editor/src/index.ts
index 5aac466f1..6268f59a6 100644
--- a/editor/src/index.ts
+++ b/editor/src/index.ts
@@ -87,22 +87,11 @@ export {
type PanelDescriptor,
type PanelFactory,
type PanelInstance,
- type Resizable,
- type BridgeAware,
- type AppAware,
- type AssetServerProvider,
- type AssetNavigable,
- type OutputAppendable,
+ type PanelHooks,
+ type PanelFactoryResult,
registerPanel,
getPanel,
getAllPanels,
- isResizable,
- isBridgeAware,
- isAppAware,
- isAssetServerProvider,
- isAssetNavigable,
- isOutputAppendable,
- isSpineControllerAware,
} from './panels/PanelRegistry';
// =============================================================================
@@ -163,7 +152,6 @@ export {
registerComponentSchema,
getComponentSchema,
getAllComponentSchemas,
- registerBuiltinSchemas,
} from './schemas';
// =============================================================================
@@ -392,6 +380,24 @@ export {
showSettingsDialog,
} from './settings';
+// =============================================================================
+// IoC Container
+// =============================================================================
+
+export {
+ type PluginRegistrar,
+ EditorContainer,
+ getEditorContainer,
+} from './container';
+
+export * as tokens from './container/tokens';
+
+// =============================================================================
+// Plugins
+// =============================================================================
+
+export type { EditorPlugin, EditorPluginContext } from './plugins/EditorPlugin';
+
// =============================================================================
// SDK Re-exports
// =============================================================================
diff --git a/editor/src/menus/MenuRegistry.ts b/editor/src/menus/MenuRegistry.ts
index 56aed8dab..8a986d540 100644
--- a/editor/src/menus/MenuRegistry.ts
+++ b/editor/src/menus/MenuRegistry.ts
@@ -1,3 +1,6 @@
+import { getEditorContainer } from '../container';
+import { MENU, MENU_ITEM, STATUSBAR_ITEM } from '../container/tokens';
+
export interface MenuDescriptor {
id: string;
label: string;
@@ -24,70 +27,38 @@ export interface StatusbarItemDescriptor {
render: (container: HTMLElement) => { dispose(): void; update?(): void };
}
-const menus = new Map<string, MenuDescriptor>();
-const menuItems = new Map<string, MenuItemDescriptor[]>();
-const statusbarItems = new Map<string, StatusbarItemDescriptor>();
-const builtinMenuIds = new Set<string>();
-const builtinMenuItemIds = new Set<string>();
-const builtinStatusbarIds = new Set<string>();
-
export function registerMenu(descriptor: MenuDescriptor): void {
- menus.set(descriptor.id, descriptor);
- if (!menuItems.has(descriptor.id)) {
- menuItems.set(descriptor.id, []);
- }
+ getEditorContainer().provide(MENU, descriptor.id, descriptor);
}
export function registerMenuItem(item: MenuItemDescriptor): void {
- const items = menuItems.get(item.menu);
- if (items) {
- if (items.some(i => i.id === item.id)) return;
- items.push(item);
- } else {
- menuItems.set(item.menu, [item]);
- }
+ const c = getEditorContainer();
+ if (c.has(MENU_ITEM, item.id)) return;
+ c.provide(MENU_ITEM, item.id, item);
}
export function registerStatusbarItem(item: StatusbarItemDescriptor): void {
- statusbarItems.set(item.id, item);
-}
-
-export function lockBuiltinMenus(): void {
- for (const id of menus.keys()) builtinMenuIds.add(id);
- for (const items of menuItems.values()) {
- for (const item of items) builtinMenuItemIds.add(item.id);
- }
- for (const id of statusbarItems.keys()) builtinStatusbarIds.add(id);
-}
-
-export function clearExtensionMenus(): void {
- for (const id of menus.keys()) {
- if (!builtinMenuIds.has(id)) menus.delete(id);
- }
- for (const [menuId, items] of menuItems.entries()) {
- menuItems.set(menuId, items.filter(i => builtinMenuItemIds.has(i.id)));
- }
- for (const id of statusbarItems.keys()) {
- if (!builtinStatusbarIds.has(id)) statusbarItems.delete(id);
- }
+ getEditorContainer().provide(STATUSBAR_ITEM, item.id, item);
}
export function getAllMenus(): MenuDescriptor[] {
- return Array.from(menus.values()).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
+ return Array.from(getEditorContainer().getAll(MENU).values())
+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function getMenuItems(menuId: string): MenuItemDescriptor[] {
- return (menuItems.get(menuId) ?? []).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
+ const result: MenuItemDescriptor[] = [];
+ for (const item of getEditorContainer().getAll(MENU_ITEM).values()) {
+ if (item.menu === menuId) result.push(item);
+ }
+ return result.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function getAllStatusbarItems(): StatusbarItemDescriptor[] {
- return Array.from(statusbarItems.values()).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
+ return Array.from(getEditorContainer().getAll(STATUSBAR_ITEM).values())
+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function getMenuItem(id: string): MenuItemDescriptor | undefined {
- for (const items of menuItems.values()) {
- const found = items.find(i => i.id === id);
- if (found) return found;
- }
- return undefined;
+ return getEditorContainer().get(MENU_ITEM, id);
}
diff --git a/editor/src/menus/builtinMenus.ts b/editor/src/menus/builtinMenus.ts
index fec225cd7..7dab06492 100644
--- a/editor/src/menus/builtinMenus.ts
+++ b/editor/src/menus/builtinMenus.ts
@@ -1,11 +1,15 @@
-import { registerMenu, registerMenuItem } from './MenuRegistry';
+import type { MenuDescriptor, MenuItemDescriptor } from './MenuRegistry';
import type { Editor } from '../Editor';
+import type { PluginRegistrar } from '../container';
+import { MENU, MENU_ITEM } from '../container/tokens';
import { getEditorContext } from '../context/EditorContext';
import { showStatusBarMessage } from './builtinStatusbar';
import { showConfirmDialog } from '../ui/dialog';
import type { Entity } from 'esengine';
-export function registerBuiltinMenus(editor: Editor): void {
+export function registerBuiltinMenus(registrar: PluginRegistrar, editor: Editor): void {
+ const registerMenu = (d: MenuDescriptor) => registrar.provide(MENU, d.id, d);
+ const registerMenuItem = (d: MenuItemDescriptor) => registrar.provide(MENU_ITEM, d.id, d);
registerMenu({ id: 'file', label: 'File', order: 0 });
registerMenu({ id: 'edit', label: 'Edit', order: 1 });
registerMenu({ id: 'view', label: 'View', order: 2 });
diff --git a/editor/src/menus/builtinStatusbar.ts b/editor/src/menus/builtinStatusbar.ts
index 325b746f7..674c86edd 100644
--- a/editor/src/menus/builtinStatusbar.ts
+++ b/editor/src/menus/builtinStatusbar.ts
@@ -1,7 +1,9 @@
-import { registerStatusbarItem } from './MenuRegistry';
+import type { StatusbarItemDescriptor } from './MenuRegistry';
import { getPanelsByPosition } from '../panels/PanelRegistry';
import { icons } from '../utils/icons';
import type { Editor } from '../Editor';
+import type { PluginRegistrar } from '../container';
+import { STATUSBAR_ITEM } from '../container/tokens';
let statusMessageTimer_: ReturnType<typeof setTimeout> | null = null;
let statusMessageEl_: HTMLElement | null = null;
@@ -16,7 +18,8 @@ export function showStatusBarMessage(text: string, durationMs = 2000): void {
}, durationMs);
}
-export function registerBuiltinStatusbarItems(editor: Editor): void {
+export function registerBuiltinStatusbarItems(registrar: PluginRegistrar, editor: Editor): void {
+ const registerStatusbarItem = (d: StatusbarItemDescriptor) => registrar.provide(STATUSBAR_ITEM, d.id, d);
const bottomPanels = getPanelsByPosition('bottom');
for (const panel of bottomPanels) {
diff --git a/editor/src/panels/PanelRegistry.ts b/editor/src/panels/PanelRegistry.ts
index 13ff2afdc..2f7dfc316 100644
--- a/editor/src/panels/PanelRegistry.ts
+++ b/editor/src/panels/PanelRegistry.ts
@@ -2,6 +2,9 @@ import type { App } from 'esengine';
import type { SpineModuleController } from 'esengine/spine';
import type { EditorStore } from '../store/EditorStore';
import type { EditorBridge } from '../bridge/EditorBridge';
+import type { EditorAssetServer } from '../asset/EditorAssetServer';
+import { getEditorContainer } from '../container';
+import { PANEL } from '../container/tokens';
export type PanelPosition = 'left' | 'right' | 'center' | 'bottom';
@@ -16,116 +19,44 @@ export interface PanelDescriptor {
factory: PanelFactory;
}
-export type PanelFactory = (container: HTMLElement, store: EditorStore) => PanelInstance;
-
-export interface PanelInstance {
- dispose(): void;
- onShow?(): void;
- onHide?(): void;
-}
-
-export interface Resizable {
- resize(): void;
-}
-
-export interface BridgeAware {
- setBridge(bridge: EditorBridge): void;
-}
-
-export interface AppAware {
- setApp(app: App): void;
-}
-
-export interface AssetServerProvider {
- readonly assetServer: unknown;
-}
-
-export interface AssetNavigable {
- navigateToAsset(path: string): Promise<void>;
-}
-
-export interface OutputAppendable {
- appendOutput(text: string, type: 'command' | 'stdout' | 'stderr' | 'error' | 'success'): void;
- clear(): void;
-}
-
-export interface SpineControllerAware {
- setSpineController(controller: SpineModuleController | null): void;
-}
-
-export interface SpineInfoProvider {
- getSpineSkeletonInfo(entityId: number): { animations: string[]; skins: string[] } | null;
- onSpineInstanceReady(listener: (entityId: number) => void): () => void;
+export interface PanelHooks {
+ setBridge?: (bridge: EditorBridge) => void;
+ setApp?: (app: App | null) => void;
+ resize?: () => void;
+ getAssetServer?: () => EditorAssetServer | null;
+ navigateToAsset?: (path: string) => Promise<void>;
+ appendOutput?: (text: string, type: string) => void;
+ setSpineController?: (ctrl: SpineModuleController | null) => void;
+ getSpineSkeletonInfo?: (entityId: number) => { animations: string[]; skins: string[] } | null;
+ onSpineInstanceReady?: (listener: (entityId: number) => void) => () => void;
+ saveAsset?: () => Promise<boolean>;
+ isDirty?: () => boolean;
}
-export interface Saveable {
- readonly isDirty: boolean;
- saveAsset(): Promise<boolean>;
+export interface PanelFactoryResult {
+ instance: PanelInstance;
+ hooks?: PanelHooks;
}
-export function isResizable(p: PanelInstance): p is PanelInstance & Resizable {
- return typeof (p as any).resize === 'function';
-}
-
-export function isBridgeAware(p: PanelInstance): p is PanelInstance & BridgeAware {
- return typeof (p as any).setBridge === 'function';
-}
+export type PanelFactory = (container: HTMLElement, store: EditorStore) => PanelFactoryResult;
-export function isAppAware(p: PanelInstance): p is PanelInstance & AppAware {
- return typeof (p as any).setApp === 'function';
-}
-
-export function isAssetServerProvider(p: PanelInstance): p is PanelInstance & AssetServerProvider {
- return 'assetServer' in p;
-}
-
-export function isAssetNavigable(p: PanelInstance): p is PanelInstance & AssetNavigable {
- return typeof (p as any).navigateToAsset === 'function';
-}
-
-export function isSpineControllerAware(p: PanelInstance): p is PanelInstance & SpineControllerAware {
- return typeof (p as any).setSpineController === 'function';
-}
-
-export function isOutputAppendable(p: PanelInstance): p is PanelInstance & OutputAppendable {
- return typeof (p as any).appendOutput === 'function';
-}
-
-export function isSpineInfoProvider(p: PanelInstance): p is PanelInstance & SpineInfoProvider {
- return typeof (p as any).getSpineSkeletonInfo === 'function';
-}
-
-export function isSaveable(p: PanelInstance): p is PanelInstance & Saveable {
- return typeof (p as any).saveAsset === 'function' && 'isDirty' in p;
+export interface PanelInstance {
+ dispose(): void;
+ onShow?(): void;
+ onHide?(): void;
}
-const panels = new Map<string, PanelDescriptor>();
-const builtinPanelIds = new Set<string>();
-
export function registerPanel(descriptor: PanelDescriptor): void {
- panels.set(descriptor.id, descriptor);
-}
-
-export function lockBuiltinPanels(): void {
- for (const id of panels.keys()) builtinPanelIds.add(id);
-}
-
-export function clearExtensionPanels(): void {
- for (const id of panels.keys()) {
- if (!builtinPanelIds.has(id)) panels.delete(id);
- }
-}
-
-export function isBuiltinPanel(id: string): boolean {
- return builtinPanelIds.has(id);
+ getEditorContainer().provide(PANEL, descriptor.id, descriptor);
}
export function getPanel(id: string): PanelDescriptor | undefined {
- return panels.get(id);
+ return getEditorContainer().get(PANEL, id);
}
export function getAllPanels(): PanelDescriptor[] {
- return Array.from(panels.values()).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
+ return Array.from(getEditorContainer().getAll(PANEL).values())
+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function getPanelsByPosition(position: PanelPosition): PanelDescriptor[] {
diff --git a/editor/src/panels/builtinPanels.ts b/editor/src/panels/builtinPanels.ts
index 53da95062..0799a190b 100644
--- a/editor/src/panels/builtinPanels.ts
+++ b/editor/src/panels/builtinPanels.ts
@@ -1,4 +1,6 @@
-import { registerPanel } from './PanelRegistry';
+import type { PanelHooks, PanelDescriptor } from './PanelRegistry';
+import type { PluginRegistrar } from '../container';
+import { PANEL } from '../container/tokens';
import { HierarchyPanel } from './hierarchy/HierarchyPanel';
import { InspectorPanel } from './InspectorPanel';
import { SceneViewPanel } from './scene-view/SceneViewPanel';
@@ -16,7 +18,8 @@ export interface BuiltinPanelOptions {
onOpenScene?: (path: string) => void;
}
-export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
+export function registerBuiltinPanels(registrar: PluginRegistrar, options: BuiltinPanelOptions): void {
+ const registerPanel = (d: PanelDescriptor) => registrar.provide(PANEL, d.id, d);
registerPanel({
id: 'hierarchy',
title: 'Hierarchy',
@@ -24,7 +27,7 @@ export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
position: 'left',
order: 0,
defaultVisible: true,
- factory: (c, s) => new HierarchyPanel(c, s),
+ factory: (c, s) => ({ instance: new HierarchyPanel(c, s) }),
});
registerPanel({
@@ -33,7 +36,19 @@ export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
position: 'center',
order: 0,
defaultVisible: true,
- factory: (c, s) => new SceneViewPanel(c, s, { projectPath: options.projectPath }),
+ factory: (c, s) => {
+ const panel = new SceneViewPanel(c, s, { projectPath: options.projectPath });
+ const hooks: PanelHooks = {
+ setBridge: (b) => panel.setBridge(b),
+ setApp: (a) => panel.setApp(a!),
+ resize: () => panel.resize(),
+ getAssetServer: () => panel.assetServer,
+ setSpineController: (ctrl) => panel.setSpineController(ctrl),
+ getSpineSkeletonInfo: (id) => panel.getSpineSkeletonInfo(id),
+ onSpineInstanceReady: (listener) => panel.onSpineInstanceReady(listener),
+ };
+ return { instance: panel, hooks };
+ },
});
registerPanel({
@@ -43,7 +58,13 @@ export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
position: 'center',
order: 2,
defaultVisible: true,
- factory: (c, s) => new GameViewPanel(c, s, { projectPath: options.projectPath }),
+ factory: (c, s) => {
+ const panel = new GameViewPanel(c, s, { projectPath: options.projectPath });
+ const hooks: PanelHooks = {
+ resize: () => panel.resize(),
+ };
+ return { instance: panel, hooks };
+ },
});
registerPanel({
@@ -53,7 +74,7 @@ export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
position: 'right',
order: 0,
defaultVisible: true,
- factory: (c, s) => new InspectorPanel(c, s),
+ factory: (c, s) => ({ instance: new InspectorPanel(c, s) }),
});
registerPanel({
@@ -63,10 +84,16 @@ export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
position: 'bottom',
order: 0,
defaultVisible: true,
- factory: (c, s) => new ContentBrowserPanel(c, s, {
- projectPath: options.projectPath,
- onOpenScene: options.onOpenScene,
- }),
+ factory: (c, s) => {
+ const panel = new ContentBrowserPanel(c, s, {
+ projectPath: options.projectPath,
+ onOpenScene: options.onOpenScene,
+ });
+ const hooks: PanelHooks = {
+ navigateToAsset: (path) => panel.navigateToAsset(path),
+ };
+ return { instance: panel, hooks };
+ },
});
registerPanel({
@@ -76,7 +103,13 @@ export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
position: 'bottom',
order: 1,
defaultVisible: false,
- factory: (c) => new OutputPanel(c),
+ factory: (c) => {
+ const panel = new OutputPanel(c);
+ const hooks: PanelHooks = {
+ appendOutput: (text, type) => panel.appendOutput(text, type as any),
+ };
+ return { instance: panel, hooks };
+ },
});
registerPanel({
@@ -86,7 +119,15 @@ export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
position: 'bottom',
order: 2,
defaultVisible: false,
- factory: (c, s) => new TimelinePanel(c, s),
+ factory: (c, s) => {
+ const panel = new TimelinePanel(c, s);
+ const hooks: PanelHooks = {
+ resize: () => panel.resize(),
+ saveAsset: () => panel.saveAsset(),
+ isDirty: () => panel.isDirty,
+ };
+ return { instance: panel, hooks };
+ },
});
registerPanel({
@@ -96,7 +137,6 @@ export function registerBuiltinPanels(options: BuiltinPanelOptions): void {
position: 'bottom',
detachOnly: true,
order: 99,
- factory: (c) => new ProfilerPanel(c),
+ factory: (c) => ({ instance: new ProfilerPanel(c) }),
});
-
}
diff --git a/editor/src/panels/game-view/GameViewPanel.ts b/editor/src/panels/game-view/GameViewPanel.ts
index 882cd28d3..64de64af1 100644
--- a/editor/src/panels/game-view/GameViewPanel.ts
+++ b/editor/src/panels/game-view/GameViewPanel.ts
@@ -1,5 +1,5 @@
import type { EditorStore } from '../../store/EditorStore';
-import type { PanelInstance, Resizable } from '../PanelRegistry';
+import type { PanelInstance } from '../PanelRegistry';
import { GameInstanceManager, type GameState } from './GameInstanceManager';
import { GameViewToolbar } from './GameViewToolbar';
import { GameViewRenderer } from '../../renderer/GameViewRenderer';
@@ -11,7 +11,7 @@ export interface GameViewPanelOptions {
projectPath?: string;
}
-export class GameViewPanel implements PanelInstance, Resizable {
+export class GameViewPanel implements PanelInstance {
private container_: HTMLElement;
private toolbar_: GameViewToolbar;
private gameManager_: GameInstanceManager;
diff --git a/editor/src/panels/index.ts b/editor/src/panels/index.ts
index 91c94620a..967023413 100644
--- a/editor/src/panels/index.ts
+++ b/editor/src/panels/index.ts
@@ -14,21 +14,11 @@ export {
type PanelDescriptor,
type PanelFactory,
type PanelInstance,
- type Resizable,
- type BridgeAware,
- type AppAware,
- type AssetServerProvider,
- type AssetNavigable,
- type OutputAppendable,
+ type PanelHooks,
+ type PanelFactoryResult,
registerPanel,
getPanel,
getAllPanels,
getPanelsByPosition,
- isResizable,
- isBridgeAware,
- isAppAware,
- isAssetServerProvider,
- isAssetNavigable,
- isOutputAppendable,
} from './PanelRegistry';
export { registerBuiltinPanels } from './builtinPanels';
diff --git a/editor/src/panels/inspector/InspectorRegistry.ts b/editor/src/panels/inspector/InspectorRegistry.ts
index d52c79de9..609982fcc 100644
--- a/editor/src/panels/inspector/InspectorRegistry.ts
+++ b/editor/src/panels/inspector/InspectorRegistry.ts
@@ -1,15 +1,8 @@
-/**
- * @file InspectorRegistry.ts
- * @brief Registry for custom inspector sections and component inspectors
- */
-
import type { Entity } from 'esengine';
import type { EditorStore } from '../../store/EditorStore';
import type { AssetType } from '../../store/EditorStore';
-
-// =============================================================================
-// Types
-// =============================================================================
+import { getEditorContainer } from '../../container';
+import { INSPECTOR_SECTION, COMPONENT_INSPECTOR } from '../../container/tokens';
export interface InspectorContext {
store: EditorStore;
@@ -52,56 +45,22 @@ export interface ComponentInspectorDescriptor {
render: (container: HTMLElement, ctx: ComponentInspectorContext) => ComponentInspectorInstance;
}
-// =============================================================================
-// Section Registry
-// =============================================================================
-
-const sectionRegistry: InspectorSectionDescriptor[] = [];
-const builtinSectionIds = new Set<string>();
-
export function registerInspectorSection(descriptor: InspectorSectionDescriptor): void {
- sectionRegistry.push(descriptor);
+ getEditorContainer().provide(INSPECTOR_SECTION, descriptor.id, descriptor);
}
export function getInspectorSections(target: 'entity' | 'asset'): InspectorSectionDescriptor[] {
- return sectionRegistry
- .filter(s => s.target === target || s.target === 'both')
- .sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
-}
-
-export function lockBuiltinInspectorExtensions(): void {
- for (const s of sectionRegistry) {
- builtinSectionIds.add(s.id);
- }
- for (const c of componentRegistry.values()) {
- builtinComponentTypes.add(c.componentType);
+ const result: InspectorSectionDescriptor[] = [];
+ for (const s of getEditorContainer().getAll(INSPECTOR_SECTION).values()) {
+ if (s.target === target || s.target === 'both') result.push(s);
}
+ return result.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
-export function clearExtensionInspectorExtensions(): void {
- for (let i = sectionRegistry.length - 1; i >= 0; i--) {
- if (!builtinSectionIds.has(sectionRegistry[i].id)) {
- sectionRegistry.splice(i, 1);
- }
- }
- for (const [key, desc] of componentRegistry) {
- if (!builtinComponentTypes.has(desc.componentType)) {
- componentRegistry.delete(key);
- }
- }
-}
-
-// =============================================================================
-// Component Inspector Registry
-// =============================================================================
-
-const componentRegistry = new Map<string, ComponentInspectorDescriptor>();
-const builtinComponentTypes = new Set<string>();
-
export function registerComponentInspector(descriptor: ComponentInspectorDescriptor): void {
- componentRegistry.set(descriptor.componentType, descriptor);
+ getEditorContainer().provide(COMPONENT_INSPECTOR, descriptor.componentType, descriptor);
}
export function getComponentInspector(componentType: string): ComponentInspectorDescriptor | undefined {
- return componentRegistry.get(componentType);
+ return getEditorContainer().get(COMPONENT_INSPECTOR, componentType);
}
diff --git a/editor/src/panels/inspector/PostProcessVolumeInspector.ts b/editor/src/panels/inspector/PostProcessVolumeInspector.ts
index 21c908f9b..115ec0e1d 100644
--- a/editor/src/panels/inspector/PostProcessVolumeInspector.ts
+++ b/editor/src/panels/inspector/PostProcessVolumeInspector.ts
@@ -11,9 +11,10 @@ import {
type PostProcessVolumeData,
} from 'esengine';
import type { ComponentInspectorContext, ComponentInspectorInstance } from './InspectorRegistry';
-import { registerComponentInspector } from './InspectorRegistry';
import { createFloatEditor, createIntEditor, createVec2Editor } from './SharedEditors';
import { icons } from '../../utils/icons';
+import type { PluginRegistrar } from '../../container';
+import { COMPONENT_INSPECTOR } from '../../container/tokens';
function cloneEffects(effects: PostProcessEffectData[]): PostProcessEffectData[] {
return effects.map(e => ({
@@ -349,8 +350,8 @@ function renderAddButton(
container.appendChild(wrapper);
}
-export function registerPostProcessVolumeInspector(): void {
- registerComponentInspector({
+export function registerPostProcessVolumeInspector(registrar: PluginRegistrar): void {
+ registrar.provide(COMPONENT_INSPECTOR, 'postprocess-volume', {
id: 'postprocess-volume',
componentType: 'PostProcessVolume',
render: renderInspector,
diff --git a/editor/src/panels/timeline/TimelinePanel.ts b/editor/src/panels/timeline/TimelinePanel.ts
index 381bf2f0c..d083e8909 100644
--- a/editor/src/panels/timeline/TimelinePanel.ts
+++ b/editor/src/panels/timeline/TimelinePanel.ts
@@ -1,4 +1,4 @@
-import type { PanelInstance, Resizable } from '../PanelRegistry';
+import type { PanelInstance } from '../PanelRegistry';
import type { EditorStore } from '../../store/EditorStore';
import type { PropertyChangeEvent } from '../../store/EditorStore';
import type { Command } from '../../commands/Command';
@@ -13,7 +13,7 @@ import { getAssetDatabase as getAssetLibrary, isUUID } from '../../asset';
const PLAYBACK_INTERVAL_MS = 16;
-export class TimelinePanel implements PanelInstance, Resizable {
+export class TimelinePanel implements PanelInstance {
private container_: HTMLElement;
private store_: EditorStore;
private state_: TimelineState;
diff --git a/editor/src/plugins/EditorPlugin.ts b/editor/src/plugins/EditorPlugin.ts
index ab7eb5f61..79e449051 100644
--- a/editor/src/plugins/EditorPlugin.ts
+++ b/editor/src/plugins/EditorPlugin.ts
@@ -1,6 +1,8 @@
import type { Editor } from '../Editor';
+import type { PluginRegistrar } from '../container';
export interface EditorPluginContext {
+ registrar: PluginRegistrar;
editor: Editor;
projectPath: string | null;
onOpenScene: (path: string) => void;
diff --git a/editor/src/plugins/animation.ts b/editor/src/plugins/animation.ts
index 534912b80..31049832d 100644
--- a/editor/src/plugins/animation.ts
+++ b/editor/src/plugins/animation.ts
@@ -1,5 +1,6 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import { COMPONENT_SCHEMA } from '../container/tokens';
import { TIME_SCALE_MAX } from '../schemas/schemaConstants';
const SpriteAnimatorSchema: ComponentSchema = {
@@ -16,7 +17,7 @@ const SpriteAnimatorSchema: ComponentSchema = {
export const animationPlugin: EditorPlugin = {
name: 'animation',
- register() {
- registerComponentSchema(SpriteAnimatorSchema);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, SpriteAnimatorSchema.name, SpriteAnimatorSchema);
},
};
diff --git a/editor/src/plugins/assetInfra.ts b/editor/src/plugins/assetInfra.ts
index 8aa4b0d8d..3f7a214dc 100644
--- a/editor/src/plugins/assetInfra.ts
+++ b/editor/src/plugins/assetInfra.ts
@@ -1,9 +1,9 @@
-import type { EditorPlugin } from './EditorPlugin';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
import { registerBuiltinAssetTypes } from '../asset/AssetTypeRegistry';
export const assetInfraPlugin: EditorPlugin = {
name: 'asset-infra',
- register() {
- registerBuiltinAssetTypes();
+ register(ctx: EditorPluginContext) {
+ registerBuiltinAssetTypes(ctx.registrar);
},
};
diff --git a/editor/src/plugins/audio.ts b/editor/src/plugins/audio.ts
index 1fc3b84c1..4456f6fc2 100644
--- a/editor/src/plugins/audio.ts
+++ b/editor/src/plugins/audio.ts
@@ -1,5 +1,6 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import { COMPONENT_SCHEMA } from '../container/tokens';
const AudioSourceSchema: ComponentSchema = {
name: 'AudioSource',
@@ -29,8 +30,8 @@ const AudioListenerSchema: ComponentSchema = {
export const audioPlugin: EditorPlugin = {
name: 'audio',
- register() {
- registerComponentSchema(AudioSourceSchema);
- registerComponentSchema(AudioListenerSchema);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, AudioSourceSchema.name, AudioSourceSchema);
+ ctx.registrar.provide(COMPONENT_SCHEMA, AudioListenerSchema.name, AudioListenerSchema);
},
};
diff --git a/editor/src/plugins/coreComponents.ts b/editor/src/plugins/coreComponents.ts
index bd50fcb9a..c8d9e0cbf 100644
--- a/editor/src/plugins/coreComponents.ts
+++ b/editor/src/plugins/coreComponents.ts
@@ -1,5 +1,6 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import { COMPONENT_SCHEMA } from '../container/tokens';
const NameSchema: ComponentSchema = {
name: 'Name',
@@ -121,9 +122,9 @@ const CORE_SCHEMAS: ComponentSchema[] = [
export const coreComponentsPlugin: EditorPlugin = {
name: 'core-components',
- register() {
+ register(ctx: EditorPluginContext) {
for (const schema of CORE_SCHEMAS) {
- registerComponentSchema(schema);
+ ctx.registrar.provide(COMPONENT_SCHEMA, schema.name, schema);
}
},
};
diff --git a/editor/src/plugins/coreGizmos.ts b/editor/src/plugins/coreGizmos.ts
index 123fcad28..53f15abbe 100644
--- a/editor/src/plugins/coreGizmos.ts
+++ b/editor/src/plugins/coreGizmos.ts
@@ -1,9 +1,9 @@
-import type { EditorPlugin } from './EditorPlugin';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
import { registerBuiltinGizmos } from '../gizmos/builtinGizmos';
export const coreGizmosPlugin: EditorPlugin = {
name: 'core-gizmos',
- register() {
- registerBuiltinGizmos();
+ register(ctx: EditorPluginContext) {
+ registerBuiltinGizmos(ctx.registrar);
},
};
diff --git a/editor/src/plugins/coreMenus.ts b/editor/src/plugins/coreMenus.ts
index 5349765e8..e8f542682 100644
--- a/editor/src/plugins/coreMenus.ts
+++ b/editor/src/plugins/coreMenus.ts
@@ -5,7 +5,7 @@ import { registerBuiltinStatusbarItems } from '../menus/builtinStatusbar';
export const coreMenusPlugin: EditorPlugin = {
name: 'core-menus',
register(ctx: EditorPluginContext) {
- registerBuiltinMenus(ctx.editor);
+ registerBuiltinMenus(ctx.registrar, ctx.editor);
},
};
@@ -13,6 +13,6 @@ export const coreStatusbarPlugin: EditorPlugin = {
name: 'core-statusbar',
dependencies: ['core-menus', 'core-panels'],
register(ctx: EditorPluginContext) {
- registerBuiltinStatusbarItems(ctx.editor);
+ registerBuiltinStatusbarItems(ctx.registrar, ctx.editor);
},
};
diff --git a/editor/src/plugins/corePanels.ts b/editor/src/plugins/corePanels.ts
index 11f80799e..c5b0c7d64 100644
--- a/editor/src/plugins/corePanels.ts
+++ b/editor/src/plugins/corePanels.ts
@@ -4,7 +4,7 @@ import { registerBuiltinPanels } from '../panels/builtinPanels';
export const corePanelsPlugin: EditorPlugin = {
name: 'core-panels',
register(ctx: EditorPluginContext) {
- registerBuiltinPanels({
+ registerBuiltinPanels(ctx.registrar, {
projectPath: ctx.projectPath ?? undefined,
onOpenScene: ctx.onOpenScene,
});
diff --git a/editor/src/plugins/corePropertyEditors.ts b/editor/src/plugins/corePropertyEditors.ts
index 1d0919c0a..b267561e0 100644
--- a/editor/src/plugins/corePropertyEditors.ts
+++ b/editor/src/plugins/corePropertyEditors.ts
@@ -1,9 +1,9 @@
-import type { EditorPlugin } from './EditorPlugin';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
import { registerBuiltinEditors } from '../property/editors';
export const corePropertyEditorsPlugin: EditorPlugin = {
name: 'core-property-editors',
- register() {
- registerBuiltinEditors();
+ register(ctx: EditorPluginContext) {
+ registerBuiltinEditors(ctx.registrar);
},
};
diff --git a/editor/src/plugins/coreSettings.ts b/editor/src/plugins/coreSettings.ts
index a4272a6da..8e4156880 100644
--- a/editor/src/plugins/coreSettings.ts
+++ b/editor/src/plugins/coreSettings.ts
@@ -1,17 +1,17 @@
-import type { EditorPlugin } from './EditorPlugin';
-import {
- registerSettingsSection,
- registerSettingsGroup,
- registerSettingsItem,
- type SettingsItemType,
-} from '../settings/SettingsRegistry';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { SettingsItemType, SettingsSectionDescriptor, SettingsGroupDescriptor, SettingsItemDescriptor } from '../settings/SettingsRegistry';
+import { SETTINGS_SECTION, SETTINGS_GROUP, SETTINGS_ITEM } from '../container/tokens';
import { DEFAULT_DESIGN_WIDTH, DEFAULT_DESIGN_HEIGHT } from 'esengine';
import { renderCollisionMatrix } from '../settings/CollisionMatrixWidget';
import { MAX_COLLISION_LAYERS } from '../settings/collisionLayers';
export const coreSettingsPlugin: EditorPlugin = {
name: 'core-settings',
- register() {
+ register(ctx: EditorPluginContext) {
+ const registerSettingsSection = (d: SettingsSectionDescriptor) => ctx.registrar.provide(SETTINGS_SECTION, d.id, d);
+ const registerSettingsGroup = (d: SettingsGroupDescriptor) => ctx.registrar.provide(SETTINGS_GROUP, d.id, d);
+ const registerSettingsItem = (d: SettingsItemDescriptor) => ctx.registrar.provide(SETTINGS_ITEM, d.id, d);
+
registerSettingsSection({ id: 'general', title: 'General', icon: 'settings', order: 0 });
registerSettingsSection({ id: 'project', title: 'Project', icon: 'folder', order: 2 });
registerSettingsSection({ id: 'rendering', title: 'Rendering', icon: 'image', order: 2.5 });
diff --git a/editor/src/plugins/importers.ts b/editor/src/plugins/importers.ts
index 15d664ff6..5e6e68d65 100644
--- a/editor/src/plugins/importers.ts
+++ b/editor/src/plugins/importers.ts
@@ -1,10 +1,10 @@
-import type { EditorPlugin } from './EditorPlugin';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
import { getImporterRegistry } from '../asset/ImporterRegistry';
export const importersPlugin: EditorPlugin = {
name: 'importers',
dependencies: ['asset-infra'],
- register() {
+ register(_ctx: EditorPluginContext) {
getImporterRegistry();
},
};
diff --git a/editor/src/plugins/materialEditors.ts b/editor/src/plugins/materialEditors.ts
index d6d5883e3..7c3d5004a 100644
--- a/editor/src/plugins/materialEditors.ts
+++ b/editor/src/plugins/materialEditors.ts
@@ -1,10 +1,10 @@
-import type { EditorPlugin } from './EditorPlugin';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
import { registerMaterialEditors } from '../property/materialEditors';
export const materialEditorsPlugin: EditorPlugin = {
name: 'material-editors',
dependencies: ['core-property-editors'],
- register() {
- registerMaterialEditors();
+ register(ctx: EditorPluginContext) {
+ registerMaterialEditors(ctx.registrar);
},
};
diff --git a/editor/src/plugins/particle.ts b/editor/src/plugins/particle.ts
index ec11746a6..64ac4c31e 100644
--- a/editor/src/plugins/particle.ts
+++ b/editor/src/plugins/particle.ts
@@ -1,5 +1,6 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import { COMPONENT_SCHEMA } from '../container/tokens';
import { LAYER_MIN, LAYER_MAX } from '../schemas/schemaConstants';
const ParticleEmitterSchema: ComponentSchema = {
@@ -52,7 +53,7 @@ const ParticleEmitterSchema: ComponentSchema = {
export const particlePlugin: EditorPlugin = {
name: 'particle',
- register() {
- registerComponentSchema(ParticleEmitterSchema);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, ParticleEmitterSchema.name, ParticleEmitterSchema);
},
};
diff --git a/editor/src/plugins/physics.ts b/editor/src/plugins/physics.ts
index 438b81bca..a30ada8d3 100644
--- a/editor/src/plugins/physics.ts
+++ b/editor/src/plugins/physics.ts
@@ -1,5 +1,6 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import { COMPONENT_SCHEMA } from '../container/tokens';
const RigidBodySchema: ComponentSchema = {
name: 'RigidBody',
@@ -125,9 +126,9 @@ const PHYSICS_SCHEMAS: ComponentSchema[] = [
export const physicsPlugin: EditorPlugin = {
name: 'physics',
- register() {
+ register(ctx: EditorPluginContext) {
for (const schema of PHYSICS_SCHEMAS) {
- registerComponentSchema(schema);
+ ctx.registrar.provide(COMPONENT_SCHEMA, schema.name, schema);
}
},
};
diff --git a/editor/src/plugins/postProcess.ts b/editor/src/plugins/postProcess.ts
index 0e1d85f9e..a51392b41 100644
--- a/editor/src/plugins/postProcess.ts
+++ b/editor/src/plugins/postProcess.ts
@@ -1,6 +1,7 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
import { registerPostProcessVolumeInspector } from '../panels/inspector/PostProcessVolumeInspector';
+import { COMPONENT_SCHEMA } from '../container/tokens';
const PostProcessVolumeSchema: ComponentSchema = {
name: 'PostProcessVolume',
@@ -10,8 +11,8 @@ const PostProcessVolumeSchema: ComponentSchema = {
export const postProcessPlugin: EditorPlugin = {
name: 'post-process',
- register() {
- registerComponentSchema(PostProcessVolumeSchema);
- registerPostProcessVolumeInspector();
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, PostProcessVolumeSchema.name, PostProcessVolumeSchema);
+ registerPostProcessVolumeInspector(ctx.registrar);
},
};
diff --git a/editor/src/plugins/runtimeSettings.ts b/editor/src/plugins/runtimeSettings.ts
index e6ef1b103..92ae7bccb 100644
--- a/editor/src/plugins/runtimeSettings.ts
+++ b/editor/src/plugins/runtimeSettings.ts
@@ -1,14 +1,15 @@
-import type { EditorPlugin } from './EditorPlugin';
-import {
- registerSettingsSection,
- registerSettingsGroup,
- registerSettingsItem,
-} from '../settings/SettingsRegistry';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { SettingsSectionDescriptor, SettingsGroupDescriptor, SettingsItemDescriptor } from '../settings/SettingsRegistry';
+import { SETTINGS_SECTION, SETTINGS_GROUP, SETTINGS_ITEM } from '../container/tokens';
export const runtimeSettingsPlugin: EditorPlugin = {
name: 'runtime-settings',
dependencies: ['core-settings'],
- register() {
+ register(ctx: EditorPluginContext) {
+ const registerSettingsSection = (d: SettingsSectionDescriptor) => ctx.registrar.provide(SETTINGS_SECTION, d.id, d);
+ const registerSettingsGroup = (d: SettingsGroupDescriptor) => ctx.registrar.provide(SETTINGS_GROUP, d.id, d);
+ const registerSettingsItem = (d: SettingsItemDescriptor) => ctx.registrar.provide(SETTINGS_ITEM, d.id, d);
+
registerSettingsSection({ id: 'runtime', title: 'Runtime', icon: 'play', order: 5 });
registerSettingsGroup({ id: 'runtime.canvas', section: 'runtime', label: 'Canvas', order: 0 });
diff --git a/editor/src/plugins/sceneViewSettings.ts b/editor/src/plugins/sceneViewSettings.ts
index aeeeaa62e..b14ec7581 100644
--- a/editor/src/plugins/sceneViewSettings.ts
+++ b/editor/src/plugins/sceneViewSettings.ts
@@ -1,14 +1,15 @@
-import type { EditorPlugin } from './EditorPlugin';
-import {
- registerSettingsSection,
- registerSettingsGroup,
- registerSettingsItem,
-} from '../settings/SettingsRegistry';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { SettingsSectionDescriptor, SettingsGroupDescriptor, SettingsItemDescriptor } from '../settings/SettingsRegistry';
+import { SETTINGS_SECTION, SETTINGS_GROUP, SETTINGS_ITEM } from '../container/tokens';
export const sceneViewSettingsPlugin: EditorPlugin = {
name: 'scene-view-settings',
dependencies: ['core-settings'],
- register() {
+ register(ctx: EditorPluginContext) {
+ const registerSettingsSection = (d: SettingsSectionDescriptor) => ctx.registrar.provide(SETTINGS_SECTION, d.id, d);
+ const registerSettingsGroup = (d: SettingsGroupDescriptor) => ctx.registrar.provide(SETTINGS_GROUP, d.id, d);
+ const registerSettingsItem = (d: SettingsItemDescriptor) => ctx.registrar.provide(SETTINGS_ITEM, d.id, d);
+
registerSettingsSection({ id: 'scene-view', title: 'Scene View', icon: 'eye', order: 1 });
registerSettingsGroup({ id: 'scene-view.grid', section: 'scene-view', label: 'Grid', order: 0 });
diff --git a/editor/src/plugins/shapeRenderer.ts b/editor/src/plugins/shapeRenderer.ts
index e846a5d61..1f84d0b1b 100644
--- a/editor/src/plugins/shapeRenderer.ts
+++ b/editor/src/plugins/shapeRenderer.ts
@@ -1,5 +1,6 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import { COMPONENT_SCHEMA } from '../container/tokens';
import { LAYER_MIN, LAYER_MAX } from '../schemas/schemaConstants';
const ShapeRendererSchema: ComponentSchema = {
@@ -24,7 +25,7 @@ const ShapeRendererSchema: ComponentSchema = {
export const shapeRendererPlugin: EditorPlugin = {
name: 'shape-renderer',
- register() {
- registerComponentSchema(ShapeRendererSchema);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, ShapeRendererSchema.name, ShapeRendererSchema);
},
};
diff --git a/editor/src/plugins/spine.ts b/editor/src/plugins/spine.ts
index ee513b046..590bfe8df 100644
--- a/editor/src/plugins/spine.ts
+++ b/editor/src/plugins/spine.ts
@@ -1,7 +1,7 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
-import { registerBoundsProvider } from '../bounds/BoundsRegistry';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
import { spineAnimationBoundsProvider } from '../bounds/SpineAnimationBoundsProvider';
+import { COMPONENT_SCHEMA, BOUNDS_PROVIDER } from '../container/tokens';
import {
LAYER_MIN, LAYER_MAX,
TIME_SCALE_MAX,
@@ -30,8 +30,8 @@ const SpineAnimationSchema: ComponentSchema = {
export const spinePlugin: EditorPlugin = {
name: 'spine',
- register() {
- registerComponentSchema(SpineAnimationSchema);
- registerBoundsProvider('SpineAnimation', spineAnimationBoundsProvider);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, SpineAnimationSchema.name, SpineAnimationSchema);
+ ctx.registrar.provide(BOUNDS_PROVIDER, 'SpineAnimation', spineAnimationBoundsProvider);
},
};
diff --git a/editor/src/plugins/sprite.ts b/editor/src/plugins/sprite.ts
index d333b9cce..3cb950036 100644
--- a/editor/src/plugins/sprite.ts
+++ b/editor/src/plugins/sprite.ts
@@ -1,7 +1,7 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
-import { registerBoundsProvider } from '../bounds/BoundsRegistry';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
import { spriteBoundsProvider } from '../bounds/SpriteBoundsProvider';
+import { COMPONENT_SCHEMA, BOUNDS_PROVIDER } from '../container/tokens';
import { LAYER_MIN, LAYER_MAX } from '../schemas/schemaConstants';
const SpriteSchema: ComponentSchema = {
@@ -23,9 +23,9 @@ const SpriteSchema: ComponentSchema = {
export const spritePlugin: EditorPlugin = {
name: 'sprite',
dependencies: ['core-components'],
- register() {
- registerComponentSchema(SpriteSchema);
- registerBoundsProvider('Sprite', spriteBoundsProvider);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, SpriteSchema.name, SpriteSchema);
+ ctx.registrar.provide(BOUNDS_PROVIDER, 'Sprite', spriteBoundsProvider);
},
};
diff --git a/editor/src/plugins/text.ts b/editor/src/plugins/text.ts
index 11569e077..98794bb5a 100644
--- a/editor/src/plugins/text.ts
+++ b/editor/src/plugins/text.ts
@@ -1,7 +1,7 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
-import { registerBoundsProvider } from '../bounds/BoundsRegistry';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
import { textBoundsProvider } from '../bounds/TextBoundsProvider';
+import { COMPONENT_SCHEMA, BOUNDS_PROVIDER } from '../container/tokens';
import { LAYER_MIN, LAYER_MAX, FONT_SIZE_MIN, FONT_SIZE_MAX } from '../schemas/schemaConstants';
const TextSchema: ComponentSchema = {
@@ -69,10 +69,10 @@ const BitmapTextSchema: ComponentSchema = {
export const textPlugin: EditorPlugin = {
name: 'text',
dependencies: ['core-components'],
- register() {
- registerComponentSchema(TextSchema);
- registerComponentSchema(BitmapTextSchema);
- registerBoundsProvider('Text', textBoundsProvider);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, TextSchema.name, TextSchema);
+ ctx.registrar.provide(COMPONENT_SCHEMA, BitmapTextSchema.name, BitmapTextSchema);
+ ctx.registrar.provide(BOUNDS_PROVIDER, 'Text', textBoundsProvider);
},
};
diff --git a/editor/src/plugins/tilemap.ts b/editor/src/plugins/tilemap.ts
index bb7b8a1b7..cf63cbe91 100644
--- a/editor/src/plugins/tilemap.ts
+++ b/editor/src/plugins/tilemap.ts
@@ -1,5 +1,6 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import { COMPONENT_SCHEMA } from '../container/tokens';
import { LAYER_MIN, LAYER_MAX } from '../schemas/schemaConstants';
const TilemapSchema: ComponentSchema = {
@@ -27,8 +28,8 @@ const TilemapLayerSchema: ComponentSchema = {
export const tilemapPlugin: EditorPlugin = {
name: 'tilemap',
- register() {
- registerComponentSchema(TilemapSchema);
- registerComponentSchema(TilemapLayerSchema);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, TilemapSchema.name, TilemapSchema);
+ ctx.registrar.provide(COMPONENT_SCHEMA, TilemapLayerSchema.name, TilemapLayerSchema);
},
};
diff --git a/editor/src/plugins/timeline.ts b/editor/src/plugins/timeline.ts
index 38bc03eec..d9bbd78c1 100644
--- a/editor/src/plugins/timeline.ts
+++ b/editor/src/plugins/timeline.ts
@@ -1,5 +1,6 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
+import { COMPONENT_SCHEMA } from '../container/tokens';
import { TIME_SCALE_MAX } from '../schemas/schemaConstants';
const TimelinePlayerSchema: ComponentSchema = {
@@ -15,7 +16,7 @@ const TimelinePlayerSchema: ComponentSchema = {
export const timelinePlugin: EditorPlugin = {
name: 'timeline',
- register() {
- registerComponentSchema(TimelinePlayerSchema);
+ register(ctx: EditorPluginContext) {
+ ctx.registrar.provide(COMPONENT_SCHEMA, TimelinePlayerSchema.name, TimelinePlayerSchema);
},
};
diff --git a/editor/src/plugins/ui.ts b/editor/src/plugins/ui.ts
index d49975320..db6bd8b1a 100644
--- a/editor/src/plugins/ui.ts
+++ b/editor/src/plugins/ui.ts
@@ -1,7 +1,7 @@
-import type { EditorPlugin } from './EditorPlugin';
-import { registerComponentSchema, type ComponentSchema } from '../schemas/ComponentSchemas';
-import { registerBoundsProvider } from '../bounds/BoundsRegistry';
+import type { EditorPlugin, EditorPluginContext } from './EditorPlugin';
+import type { ComponentSchema } from '../schemas/ComponentSchemas';
import { uiRectBoundsProvider } from '../bounds/UIRectBoundsProvider';
+import { COMPONENT_SCHEMA, BOUNDS_PROVIDER } from '../container/tokens';
const UIRectSchema: ComponentSchema = {
name: 'UIRect',
@@ -234,10 +234,10 @@ const UI_SCHEMAS: ComponentSchema[] = [
export const uiPlugin: EditorPlugin = {
name: 'ui',
dependencies: ['core-components'],
- register() {
+ register(ctx: EditorPluginContext) {
for (const schema of UI_SCHEMAS) {
- registerComponentSchema(schema);
+ ctx.registrar.provide(COMPONENT_SCHEMA, schema.name, schema);
}
- registerBoundsProvider('UIRect', uiRectBoundsProvider);
+ ctx.registrar.provide(BOUNDS_PROVIDER, 'UIRect', uiRectBoundsProvider);
},
};
diff --git a/editor/src/property/PropertyEditor.ts b/editor/src/property/PropertyEditor.ts
index c922b5b04..ee94b6b42 100644
--- a/editor/src/property/PropertyEditor.ts
+++ b/editor/src/property/PropertyEditor.ts
@@ -1,11 +1,5 @@
-/**
- * @file PropertyEditor.ts
- * @brief Base property editor interface and registry
- */
-
-// =============================================================================
-// Types
-// =============================================================================
+import { getEditorContainer } from '../container';
+import { PROPERTY_EDITOR } from '../container/tokens';
export interface PropertyMeta {
name: string;
@@ -38,37 +32,19 @@ export interface PropertyEditorInstance {
dispose(): void;
}
-// =============================================================================
-// Registry
-// =============================================================================
-
-const editorRegistry = new Map<string, PropertyEditorFactory>();
-
export function registerPropertyEditor(type: string, factory: PropertyEditorFactory): void {
- editorRegistry.set(type, factory);
+ getEditorContainer().provide(PROPERTY_EDITOR, type, factory);
}
export function getPropertyEditor(type: string): PropertyEditorFactory | undefined {
- return editorRegistry.get(type);
-}
-
-const builtinEditorTypes = new Set<string>();
-
-export function lockBuiltinPropertyEditors(): void {
- for (const type of editorRegistry.keys()) builtinEditorTypes.add(type);
-}
-
-export function clearExtensionPropertyEditors(): void {
- for (const type of editorRegistry.keys()) {
- if (!builtinEditorTypes.has(type)) editorRegistry.delete(type);
- }
+ return getEditorContainer().get(PROPERTY_EDITOR, type);
}
export function createPropertyEditor(
container: HTMLElement,
ctx: PropertyEditorContext
): PropertyEditorInstance | null {
- const factory = editorRegistry.get(ctx.meta.type);
+ const factory = getEditorContainer().get(PROPERTY_EDITOR, ctx.meta.type);
if (!factory) {
console.warn(`[PropertyEditor] No editor registered for type "${ctx.meta.type}"`);
return null;
diff --git a/editor/src/property/editors.ts b/editor/src/property/editors.ts
index 3f743f75a..eb5c58718 100644
--- a/editor/src/property/editors.ts
+++ b/editor/src/property/editors.ts
@@ -4,10 +4,12 @@
*/
import {
- registerPropertyEditor,
type PropertyEditorContext,
type PropertyEditorInstance,
+ type PropertyEditorFactory,
} from './PropertyEditor';
+import type { PluginRegistrar } from '../container';
+import { PROPERTY_EDITOR } from '../container/tokens';
import { getEditorContext, getEditorInstance } from '../context/EditorContext';
import { getPlatformAdapter } from '../platform/PlatformAdapter';
import { getAssetLibrary, isUUID } from '../asset/AssetLibrary';
@@ -1827,7 +1829,8 @@ function createCollisionLayerEditor(
// Register All Editors
// =============================================================================
-export function registerBuiltinEditors(): void {
+export function registerBuiltinEditors(registrar: PluginRegistrar): void {
+ const registerPropertyEditor = (type: string, factory: PropertyEditorFactory) => registrar.provide(PROPERTY_EDITOR, type, factory);
console.log('[PropertyEditor] registerBuiltinEditors called');
registerPropertyEditor('number', createNumberEditor);
registerPropertyEditor('string', createStringEditor);
diff --git a/editor/src/property/index.ts b/editor/src/property/index.ts
index f23348c40..c8a3eda82 100644
--- a/editor/src/property/index.ts
+++ b/editor/src/property/index.ts
@@ -11,8 +11,6 @@ export {
registerPropertyEditor,
getPropertyEditor,
createPropertyEditor,
- lockBuiltinPropertyEditors,
- clearExtensionPropertyEditors,
} from './PropertyEditor';
export { registerBuiltinEditors } from './editors';
diff --git a/editor/src/property/materialEditors.ts b/editor/src/property/materialEditors.ts
index 28a59e0ad..cd9c517f1 100644
--- a/editor/src/property/materialEditors.ts
+++ b/editor/src/property/materialEditors.ts
@@ -4,10 +4,12 @@
*/
import {
- registerPropertyEditor,
type PropertyEditorContext,
type PropertyEditorInstance,
+ type PropertyEditorFactory,
} from './PropertyEditor';
+import type { PluginRegistrar } from '../container';
+import { PROPERTY_EDITOR } from '../container/tokens';
import { BLEND_MODE_OPTIONS } from '../types/MaterialMetadata';
import {
getProjectDir,
@@ -242,7 +244,8 @@ function createMaterialTextureEditor(
// Register Material Editors
// =============================================================================
-export function registerMaterialEditors(): void {
+export function registerMaterialEditors(registrar: PluginRegistrar): void {
+ const registerPropertyEditor = (type: string, factory: PropertyEditorFactory) => registrar.provide(PROPERTY_EDITOR, type, factory);
registerPropertyEditor('blend-mode', createBlendModeEditor);
registerPropertyEditor('shader-file', createShaderFileEditor);
registerPropertyEditor('material-texture', createMaterialTextureEditor);
diff --git a/editor/src/schemas/ComponentSchemas.ts b/editor/src/schemas/ComponentSchemas.ts
index a19ce1eb9..a5660c0f9 100644
--- a/editor/src/schemas/ComponentSchemas.ts
+++ b/editor/src/schemas/ComponentSchemas.ts
@@ -1,10 +1,8 @@
import type { PropertyMeta } from '../property/PropertyEditor';
import { getComponentDefaults } from 'esengine';
import { getSettingsValue } from '../settings/SettingsRegistry';
-
-// =============================================================================
-// Types
-// =============================================================================
+import { getEditorContainer } from '../container';
+import { COMPONENT_SCHEMA } from '../container/tokens';
export type ComponentCategory = 'builtin' | 'ui' | 'physics' | 'script' | 'tag';
@@ -17,10 +15,6 @@ export interface ComponentSchema {
displayName?: string;
}
-// =============================================================================
-// Type Inference
-// =============================================================================
-
function isVec2(v: unknown): boolean {
return typeof v === 'object' && v !== null &&
'x' in v && 'y' in v && !('z' in v);
@@ -44,26 +38,20 @@ export function inferPropertyType(value: unknown): string {
return 'string';
}
-// =============================================================================
-// Registry
-// =============================================================================
-
-const schemaRegistry = new Map<string, ComponentSchema>();
-
export function registerComponentSchema(schema: ComponentSchema): void {
- schemaRegistry.set(schema.name, schema);
+ getEditorContainer().provide(COMPONENT_SCHEMA, schema.name, schema);
}
export function getComponentSchema(name: string): ComponentSchema | undefined {
- return schemaRegistry.get(name);
+ return getEditorContainer().get(COMPONENT_SCHEMA, name);
}
export function getAllComponentSchemas(): ComponentSchema[] {
- return Array.from(schemaRegistry.values());
+ return Array.from(getEditorContainer().getAll(COMPONENT_SCHEMA).values());
}
export function isComponentRemovable(name: string): boolean {
- const schema = schemaRegistry.get(name);
+ const schema = getEditorContainer().get(COMPONENT_SCHEMA, name);
return schema?.removable !== false;
}
@@ -77,7 +65,7 @@ export interface ComponentsByCategory {
export function getComponentsByCategory(): ComponentsByCategory {
const result: ComponentsByCategory = { builtin: [], ui: [], physics: [], script: [], tag: [] };
- for (const schema of schemaRegistry.values()) {
+ for (const schema of getEditorContainer().getAll(COMPONENT_SCHEMA).values()) {
result[schema.category].push(schema);
}
result.builtin.sort((a, b) => a.name.localeCompare(b.name));
@@ -88,37 +76,19 @@ export function getComponentsByCategory(): ComponentsByCategory {
return result;
}
-const builtinSchemaNames = new Set<string>();
-
-export function lockBuiltinComponentSchemas(): void {
- for (const name of schemaRegistry.keys()) builtinSchemaNames.add(name);
-}
-
-export function clearExtensionComponentSchemas(): void {
- for (const name of schemaRegistry.keys()) {
- if (!builtinSchemaNames.has(name)) schemaRegistry.delete(name);
- }
-}
-
export function clearScriptComponents(): void {
- for (const [name, schema] of schemaRegistry.entries()) {
- if (builtinSchemaNames.has(name)) continue;
- if (schema.category === 'script' || schema.category === 'tag') {
- schemaRegistry.delete(name);
- }
- }
+ const c = getEditorContainer();
+ c.removeWhere(COMPONENT_SCHEMA,
+ (k, s) => !c.isBuiltin(COMPONENT_SCHEMA, k) && (s.category === 'script' || s.category === 'tag'));
}
-// =============================================================================
-// User Component Registration
-// =============================================================================
-
function registerUserComponent(
name: string,
defaults: Record<string, unknown>,
isTag: boolean
): void {
- const existing = schemaRegistry.get(name);
+ const c = getEditorContainer();
+ const existing = c.get(COMPONENT_SCHEMA, name);
if (existing?.category === 'builtin') {
return;
}
@@ -131,7 +101,7 @@ function registerUserComponent(
type: inferPropertyType(value),
})),
};
- schemaRegistry.set(name, schema);
+ c.provide(COMPONENT_SCHEMA, name, schema);
}
export function exposeRegistrationAPI(): void {
@@ -140,36 +110,10 @@ export function exposeRegistrationAPI(): void {
}
}
-// =============================================================================
-// Backward-compatible re-exports from plugins
-// =============================================================================
-
export { TransformSchema, CameraSchema } from '../plugins/coreComponents';
export { SpriteSchema } from '../plugins/sprite';
export { TextSchema } from '../plugins/text';
-// =============================================================================
-// Legacy registration (kept for backward compat)
-// =============================================================================
-
-export interface BuiltinSchemaOptions {
- enableSpine?: boolean;
-}
-
-export function registerBuiltinSchemas(_options?: BuiltinSchemaOptions): void {
- // Schemas are now registered via EditorPlugin system.
- // This function is kept for backward compatibility.
- exposeRegistrationAPI();
-}
-
-export function registerSpineSchema(): void {
- // Spine schema is now registered via the spine plugin.
-}
-
-// =============================================================================
-// Default Component Data
-// =============================================================================
-
export function getDefaultComponentData(typeName: string): Record<string, unknown> {
return getComponentDefaults(typeName) ?? {};
}
diff --git a/editor/src/schemas/index.ts b/editor/src/schemas/index.ts
index 32bd68901..2e001c303 100644
--- a/editor/src/schemas/index.ts
+++ b/editor/src/schemas/index.ts
@@ -12,9 +12,4 @@ export {
registerComponentSchema,
getComponentSchema,
getAllComponentSchemas,
- registerBuiltinSchemas,
- registerSpineSchema,
- lockBuiltinComponentSchemas,
- clearExtensionComponentSchemas,
- type BuiltinSchemaOptions,
} from './ComponentSchemas';
diff --git a/editor/src/settings/SettingsRegistry.ts b/editor/src/settings/SettingsRegistry.ts
index 3abf98f01..3a860772b 100644
--- a/editor/src/settings/SettingsRegistry.ts
+++ b/editor/src/settings/SettingsRegistry.ts
@@ -1,3 +1,6 @@
+import { getEditorContainer } from '../container';
+import { SETTINGS_SECTION, SETTINGS_GROUP, SETTINGS_ITEM } from '../container/tokens';
+
export type SettingsItemType = 'boolean' | 'number' | 'string' | 'color' | 'select' | 'range' | 'custom';
export interface SettingsSectionDescriptor {
@@ -40,13 +43,8 @@ type SettingsChangeListener = (id: string, value: unknown) => void;
const STORAGE_KEY = 'esengine_settings';
-const sections_ = new Map<string, SettingsSectionDescriptor>();
-const groups_ = new Map<string, SettingsGroupDescriptor>();
-const items_ = new Map<string, SettingsItemDescriptor>();
const values_ = new Map<string, unknown>();
const listeners_: SettingsChangeListener[] = [];
-let builtinSectionIds_: Set<string> | null = null;
-let builtinItemIds_: Set<string> | null = null;
const LEGACY_GIZMO_KEY = 'esengine_gizmo_settings';
@@ -99,15 +97,15 @@ loadFromStorage();
migrateLegacySettings();
export function registerSettingsSection(descriptor: SettingsSectionDescriptor): void {
- sections_.set(descriptor.id, descriptor);
+ getEditorContainer().provide(SETTINGS_SECTION, descriptor.id, descriptor);
}
export function registerSettingsGroup(descriptor: SettingsGroupDescriptor): void {
- groups_.set(descriptor.id, descriptor);
+ getEditorContainer().provide(SETTINGS_GROUP, descriptor.id, descriptor);
}
export function registerSettingsItem(descriptor: SettingsItemDescriptor): void {
- items_.set(descriptor.id, descriptor);
+ getEditorContainer().provide(SETTINGS_ITEM, descriptor.id, descriptor);
if (!values_.has(descriptor.id)) {
values_.set(descriptor.id, descriptor.defaultValue);
}
@@ -115,7 +113,7 @@ export function registerSettingsItem(descriptor: SettingsItemDescriptor): void {
export function getSettingsValue<T = unknown>(id: string): T {
if (values_.has(id)) return values_.get(id) as T;
- const item = items_.get(id);
+ const item = getEditorContainer().get(SETTINGS_ITEM, id);
return (item?.defaultValue ?? undefined) as T;
}
@@ -126,7 +124,7 @@ export function setSettingsValue(id: string, value: unknown): void {
values_.set(id, value);
saveToStorage();
- const item = items_.get(id);
+ const item = getEditorContainer().get(SETTINGS_ITEM, id);
item?.onChange?.(value);
for (const listener of listeners_) {
@@ -143,41 +141,42 @@ export function onSettingsChange(listener: SettingsChangeListener): () => void {
}
export function getAllSections(): SettingsSectionDescriptor[] {
- return [...sections_.values()].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
+ return [...getEditorContainer().getAll(SETTINGS_SECTION).values()]
+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function getSectionItems(sectionId: string): SettingsItemDescriptor[] {
- return [...items_.values()]
+ return [...getEditorContainer().getAll(SETTINGS_ITEM).values()]
.filter(item => item.section === sectionId)
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function getSectionGroups(sectionId: string): SettingsGroupDescriptor[] {
- return [...groups_.values()]
+ return [...getEditorContainer().getAll(SETTINGS_GROUP).values()]
.filter(g => g.section === sectionId)
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function getGroupItems(groupId: string): SettingsItemDescriptor[] {
- return [...items_.values()]
+ return [...getEditorContainer().getAll(SETTINGS_ITEM).values()]
.filter(item => item.group === groupId)
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function getUngroupedSectionItems(sectionId: string): SettingsItemDescriptor[] {
- return [...items_.values()]
+ return [...getEditorContainer().getAll(SETTINGS_ITEM).values()]
.filter(item => item.section === sectionId && !item.group)
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
export function searchSettings(query: string): SettingsItemDescriptor[] {
const q = query.toLowerCase();
- return [...items_.values()].filter(item => {
+ return [...getEditorContainer().getAll(SETTINGS_ITEM).values()].filter(item => {
if (item.hidden) return false;
if (item.label.toLowerCase().includes(q)) return true;
if (item.description?.toLowerCase().includes(q)) return true;
if (item.tags?.some(t => t.toLowerCase().includes(q))) return true;
- const section = sections_.get(item.section);
+ const section = getEditorContainer().get(SETTINGS_SECTION, item.section);
if (section?.title.toLowerCase().includes(q)) return true;
return false;
});
@@ -200,7 +199,7 @@ export function resetSection(sectionId: string): void {
export function exportSettings(): Record<string, unknown> {
const result: Record<string, unknown> = {};
- for (const item of items_.values()) {
+ for (const item of getEditorContainer().getAll(SETTINGS_ITEM).values()) {
const value = getSettingsValue(item.id);
if (value !== item.defaultValue) {
result[item.id] = value;
@@ -210,32 +209,18 @@ export function exportSettings(): Record<string, unknown> {
}
export function importSettings(data: Record<string, unknown>): void {
+ const c = getEditorContainer();
for (const [id, value] of Object.entries(data)) {
- if (items_.has(id)) {
+ if (c.has(SETTINGS_ITEM, id)) {
setSettingsValue(id, value);
}
}
}
export function getItemDescriptor(id: string): SettingsItemDescriptor | undefined {
- return items_.get(id);
+ return getEditorContainer().get(SETTINGS_ITEM, id);
}
export function getGroupDescriptor(id: string): SettingsGroupDescriptor | undefined {
- return groups_.get(id);
-}
-
-export function lockBuiltinSettings(): void {
- builtinSectionIds_ = new Set(sections_.keys());
- builtinItemIds_ = new Set(items_.keys());
-}
-
-export function clearExtensionSettings(): void {
- if (!builtinSectionIds_ || !builtinItemIds_) return;
- for (const id of sections_.keys()) {
- if (!builtinSectionIds_.has(id)) sections_.delete(id);
- }
- for (const id of items_.keys()) {
- if (!builtinItemIds_.has(id)) items_.delete(id);
- }
+ return getEditorContainer().get(SETTINGS_GROUP, id);
}
diff --git a/editor/src/settings/builtinSettings.ts b/editor/src/settings/builtinSettings.ts
deleted file mode 100644
index 5ec6c0b68..000000000
--- a/editor/src/settings/builtinSettings.ts
+++ /dev/null
@@ -1,827 +0,0 @@
-import { registerSettingsSection, registerSettingsGroup, registerSettingsItem, type SettingsItemType } from './SettingsRegistry';
-import { DEFAULT_DESIGN_WIDTH, DEFAULT_DESIGN_HEIGHT } from 'esengine';
-import { renderCollisionMatrix } from './CollisionMatrixWidget';
-import { MAX_COLLISION_LAYERS } from './collisionLayers';
-
-export function registerBuiltinSettings(): void {
- // =========================================================================
- // Sections
- // =========================================================================
-
- registerSettingsSection({
- id: 'general',
- title: 'General',
- icon: 'settings',
- order: 0,
- });
-
- registerSettingsSection({
- id: 'scene-view',
- title: 'Scene View',
- icon: 'eye',
- order: 1,
- });
-
- registerSettingsSection({
- id: 'project',
- title: 'Project',
- icon: 'folder',
- order: 2,
- });
-
- registerSettingsSection({
- id: 'rendering',
- title: 'Rendering',
- icon: 'image',
- order: 2.5,
- });
-
- registerSettingsSection({
- id: 'physics',
- title: 'Physics',
- icon: 'zap',
- order: 3,
- });
-
- registerSettingsSection({
- id: 'build',
- title: 'Build',
- icon: 'package',
- order: 4,
- });
-
- registerSettingsSection({
- id: 'runtime',
- title: 'Runtime',
- icon: 'play',
- order: 5,
- });
-
- registerSettingsSection({
- id: 'asset-loading',
- title: 'Asset Loading',
- icon: 'download',
- order: 6.5,
- });
-
- registerSettingsSection({
- id: 'network',
- title: 'Network',
- icon: 'globe',
- order: 7,
- });
-
- // =========================================================================
- // Groups
- // =========================================================================
-
- registerSettingsGroup({
- id: 'scene-view.grid',
- section: 'scene-view',
- label: 'Grid',
- order: 0,
- });
-
- registerSettingsGroup({
- id: 'scene-view.overlays',
- section: 'scene-view',
- label: 'Overlays',
- order: 1,
- });
-
- registerSettingsGroup({
- id: 'scene-view.gizmo-appearance',
- section: 'scene-view',
- label: 'Gizmo Appearance',
- order: 2,
- collapsed: true,
- });
-
- registerSettingsGroup({
- id: 'runtime.canvas',
- section: 'runtime',
- label: 'Canvas',
- order: 0,
- });
-
- registerSettingsGroup({
- id: 'runtime.timing',
- section: 'runtime',
- label: 'Timing',
- order: 1,
- });
-
- registerSettingsGroup({
- id: 'runtime.scene-transitions',
- section: 'runtime',
- label: 'Scene Transitions',
- order: 2,
- });
-
- // =========================================================================
- // General
- // =========================================================================
-
- registerSettingsItem({
- id: 'general.language',
- section: 'general',
- label: 'Language',
- type: 'select',
- defaultValue: 'en',
- order: 0,
- options: [
- { label: 'English', value: 'en' },
- ],
- });
-
- registerSettingsItem({
- id: 'general.previewPort',
- section: 'general',
- label: 'Preview Port',
- type: 'number',
- defaultValue: 3456,
- min: 1024,
- max: 65535,
- step: 1,
- order: 1,
- });
-
- // =========================================================================
- // Scene View — Grid group
- // =========================================================================
-
- registerSettingsItem({
- id: 'scene.showGrid',
- section: 'scene-view',
- group: 'scene-view.grid',
- label: 'Show Grid',
- type: 'boolean',
- defaultValue: true,
- order: 0,
- });
-
- registerSettingsItem({
- id: 'scene.gridColor',
- section: 'scene-view',
- group: 'scene-view.grid',
- label: 'Grid Color',
- type: 'color',
- defaultValue: '#333333',
- order: 1,
- });
-
- registerSettingsItem({
- id: 'scene.gridOpacity',
- section: 'scene-view',
- group: 'scene-view.grid',
- label: 'Grid Opacity',
- type: 'range',
- defaultValue: 1.0,
- min: 0,
- max: 1,
- step: 0.1,
- order: 2,
- });
-
- registerSettingsItem({
- id: 'scene.gridSize',
- section: 'scene-view',
- group: 'scene-view.grid',
- label: 'Grid Size',
- type: 'number',
- defaultValue: 50,
- min: 5,
- max: 500,
- step: 5,
- order: 3,
- });
-
- // =========================================================================
- // Scene View — Overlays group
- // =========================================================================
-
- registerSettingsItem({
- id: 'scene.showGizmos',
- section: 'scene-view',
- group: 'scene-view.overlays',
- label: 'Show Gizmos',
- type: 'boolean',
- defaultValue: true,
- order: 0,
- });
-
- registerSettingsItem({
- id: 'scene.showSelectionBox',
- section: 'scene-view',
- group: 'scene-view.overlays',
- label: 'Show Selection Box',
- type: 'boolean',
- defaultValue: true,
- order: 1,
- });
-
- registerSettingsItem({
- id: 'scene.showColliders',
- section: 'scene-view',
- group: 'scene-view.overlays',
- label: 'Show Colliders',
- type: 'boolean',
- defaultValue: true,
- order: 2,
- });
-
- registerSettingsItem({
- id: 'scene.showStats',
- section: 'scene-view',
- group: 'scene-view.overlays',
- label: 'Show Stats',
- type: 'boolean',
- defaultValue: false,
- order: 3,
- });
-
- // =========================================================================
- // Scene View — Gizmo Appearance group
- // =========================================================================
-
- registerSettingsItem({
- id: 'scene.gizmoColorX',
- section: 'scene-view',
- group: 'scene-view.gizmo-appearance',
- label: 'Gizmo Color X',
- type: 'color',
- defaultValue: '#e74c3c',
- order: 0,
- tags: ['gizmo', 'color'],
- });
-
- registerSettingsItem({
- id: 'scene.gizmoColorY',
- section: 'scene-view',
- group: 'scene-view.gizmo-appearance',
- label: 'Gizmo Color Y',
- type: 'color',
- defaultValue: '#2ecc71',
- order: 1,
- tags: ['gizmo', 'color'],
- });
-
- registerSettingsItem({
- id: 'scene.gizmoColorXY',
- section: 'scene-view',
- group: 'scene-view.gizmo-appearance',
- label: 'Gizmo Color XY',
- type: 'color',
- defaultValue: '#f1c40f',
- order: 2,
- tags: ['gizmo', 'color'],
- });
-
- registerSettingsItem({
- id: 'scene.gizmoColorHover',
- section: 'scene-view',
- group: 'scene-view.gizmo-appearance',
- label: 'Gizmo Color Hover',
- type: 'color',
- defaultValue: '#ffffff',
- order: 3,
- tags: ['gizmo', 'color'],
- });
-
- registerSettingsItem({
- id: 'scene.selectionColor',
- section: 'scene-view',
- group: 'scene-view.gizmo-appearance',
- label: 'Selection Color',
- type: 'color',
- defaultValue: '#00aaff',
- order: 4,
- tags: ['gizmo', 'selection'],
- });
-
- registerSettingsItem({
- id: 'scene.gizmoHandleSize',
- section: 'scene-view',
- group: 'scene-view.gizmo-appearance',
- label: 'Gizmo Handle Size',
- type: 'number',
- defaultValue: 10,
- min: 4,
- max: 24,
- step: 1,
- order: 5,
- tags: ['gizmo'],
- });
-
- registerSettingsItem({
- id: 'scene.gizmoSize',
- section: 'scene-view',
- group: 'scene-view.gizmo-appearance',
- label: 'Gizmo Size',
- type: 'number',
- defaultValue: 80,
- min: 40,
- max: 200,
- step: 5,
- order: 6,
- tags: ['gizmo'],
- });
-
- // =========================================================================
- // Project
- // =========================================================================
-
- registerSettingsItem({
- id: 'project.spineVersion',
- section: 'project',
- label: 'Spine Version',
- type: 'select',
- defaultValue: 'none',
- order: 0,
- projectSync: true,
- options: [
- { label: 'None', value: 'none' },
- { label: 'Spine 4.2', value: '4.2' },
- { label: 'Spine 4.1', value: '4.1' },
- { label: 'Spine 3.8', value: '3.8' },
- ],
- });
-
- registerSettingsItem({
- id: 'project.name',
- section: 'project',
- label: 'Project Name',
- type: 'string',
- defaultValue: '',
- order: 1,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'project.version',
- section: 'project',
- label: 'Version',
- type: 'string',
- defaultValue: '',
- order: 2,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'project.defaultScene',
- section: 'project',
- label: 'Default Scene',
- type: 'string',
- defaultValue: '',
- order: 3,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'project.designWidth',
- section: 'project',
- label: 'Design Width',
- type: 'number',
- defaultValue: DEFAULT_DESIGN_WIDTH,
- min: 1,
- step: 1,
- order: 4,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'project.designHeight',
- section: 'project',
- label: 'Design Height',
- type: 'number',
- defaultValue: DEFAULT_DESIGN_HEIGHT,
- min: 1,
- step: 1,
- order: 5,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'project.enablePhysics',
- section: 'physics',
- label: 'Enable Physics',
- type: 'boolean',
- defaultValue: false,
- order: 0,
- projectSync: true,
- });
-
- // =========================================================================
- // Rendering
- // =========================================================================
-
- registerSettingsItem({
- id: 'rendering.defaultSpriteWidth',
- section: 'rendering',
- label: 'Default Sprite Width',
- description: 'Default width for new sprites in pixels',
- type: 'number',
- defaultValue: 100,
- min: 1,
- max: 4096,
- step: 1,
- order: 0,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'rendering.defaultSpriteHeight',
- section: 'rendering',
- label: 'Default Sprite Height',
- description: 'Default height for new sprites in pixels',
- type: 'number',
- defaultValue: 100,
- min: 1,
- max: 4096,
- step: 1,
- order: 1,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'rendering.pixelsPerUnit',
- section: 'rendering',
- label: 'Pixels Per Unit',
- description: 'Number of pixels per world unit',
- type: 'number',
- defaultValue: 100,
- min: 1,
- max: 1000,
- step: 1,
- order: 2,
- projectSync: true,
- });
-
- // =========================================================================
- // Physics
- // =========================================================================
-
- // =========================================================================
- // Physics — Collision Layers group
- // =========================================================================
-
- registerSettingsGroup({
- id: 'physics.collision-layers',
- section: 'physics',
- label: 'Collision Layers',
- order: 10,
- collapsed: true,
- });
-
- registerSettingsGroup({
- id: 'physics.collision-matrix',
- section: 'physics',
- label: 'Collision Matrix',
- order: 11,
- });
-
- const COLLISION_LAYER_DEFAULTS = [
- 'Default', '', '', '', '', '', '', '',
- '', '', '', '', '', '', '', '',
- ];
-
- for (let i = 0; i < MAX_COLLISION_LAYERS; i++) {
- registerSettingsItem({
- id: `physics.layerName${i}`,
- section: 'physics',
- group: 'physics.collision-layers',
- label: `Layer ${i}`,
- type: 'string',
- defaultValue: COLLISION_LAYER_DEFAULTS[i],
- order: i,
- projectSync: true,
- tags: ['collision', 'layer'],
- });
-
- registerSettingsItem({
- id: `physics.layerMask${i}`,
- section: 'physics',
- label: `Layer ${i} Mask`,
- type: 'number',
- defaultValue: 0xFFFF,
- hidden: true,
- projectSync: true,
- });
- }
-
- registerSettingsItem({
- id: 'physics.collisionMatrix',
- section: 'physics',
- group: 'physics.collision-matrix',
- label: 'Collision Matrix',
- type: 'custom' as SettingsItemType,
- defaultValue: null,
- render: renderCollisionMatrix,
- tags: ['collision', 'matrix', 'layer'],
- });
-
- registerSettingsItem({
- id: 'physics.gravityX',
- section: 'physics',
- label: 'Gravity X',
- type: 'number',
- defaultValue: 0,
- step: 0.1,
- order: 1,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'physics.gravityY',
- section: 'physics',
- label: 'Gravity Y',
- type: 'number',
- defaultValue: -9.81,
- step: 0.1,
- order: 2,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'physics.fixedTimestep',
- section: 'physics',
- label: 'Fixed Timestep',
- description: 'Maximum simulation time step in seconds',
- type: 'number',
- defaultValue: 1 / 60,
- step: 0.001,
- min: 0.001,
- order: 3,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'physics.subStepCount',
- section: 'physics',
- label: 'Sub-Step Count',
- description: 'Maximum physics sub-steps per frame',
- type: 'number',
- defaultValue: 4,
- step: 1,
- min: 1,
- max: 16,
- order: 4,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'physics.contactHertz',
- section: 'physics',
- label: 'Contact Hertz',
- description: 'Contact stiffness (cycles/sec). Higher = less overlap but more jitter',
- type: 'number',
- defaultValue: 30,
- step: 10,
- min: 1,
- max: 500,
- order: 5,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'physics.contactDampingRatio',
- section: 'physics',
- label: 'Contact Damping Ratio',
- description: 'Contact bounciness damping. Lower = faster overlap recovery but more energetic',
- type: 'number',
- defaultValue: 10,
- step: 1,
- min: 0.1,
- max: 100,
- order: 6,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'physics.contactSpeed',
- section: 'physics',
- label: 'Contact Speed',
- description: 'Max overlap resolution speed (m/s)',
- type: 'number',
- defaultValue: 3,
- step: 1,
- min: 1,
- max: 100,
- order: 7,
- projectSync: true,
- });
-
- // =========================================================================
- // Build
- // =========================================================================
-
- registerSettingsItem({
- id: 'build.atlasMaxSize',
- section: 'build',
- label: 'Atlas Max Size',
- type: 'select',
- defaultValue: '2048',
- order: 0,
- projectSync: true,
- options: [
- { label: '512', value: '512' },
- { label: '1024', value: '1024' },
- { label: '2048', value: '2048' },
- { label: '4096', value: '4096' },
- ],
- });
-
- registerSettingsItem({
- id: 'build.atlasPadding',
- section: 'build',
- label: 'Atlas Padding',
- type: 'number',
- defaultValue: 2,
- min: 0,
- max: 16,
- step: 1,
- order: 1,
- projectSync: true,
- });
-
- // =========================================================================
- // Runtime — Scene Transitions group
- // =========================================================================
-
- registerSettingsItem({
- id: 'runtime.sceneTransitionDuration',
- section: 'runtime',
- group: 'runtime.scene-transitions',
- label: 'Scene Transition Duration',
- description: 'Fade duration when switching scenes, in seconds',
- type: 'number',
- defaultValue: 0.3,
- min: 0,
- max: 5,
- step: 0.1,
- order: 0,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'runtime.sceneTransitionColor',
- section: 'runtime',
- group: 'runtime.scene-transitions',
- label: 'Scene Transition Color',
- description: 'Background color during scene transitions',
- type: 'color',
- defaultValue: '#000000',
- order: 1,
- projectSync: true,
- });
-
- // =========================================================================
- // Runtime — ungrouped
- // =========================================================================
-
- registerSettingsItem({
- id: 'runtime.defaultFontFamily',
- section: 'runtime',
- label: 'Default Font Family',
- description: 'Fallback font used for text rendering',
- type: 'string',
- defaultValue: 'Arial',
- order: 2,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'runtime.textCanvasSize',
- section: 'runtime',
- label: 'Text Canvas Size',
- type: 'select',
- defaultValue: '512',
- order: 3,
- projectSync: true,
- options: [
- { label: '256', value: '256' },
- { label: '512', value: '512' },
- { label: '1024', value: '1024' },
- { label: '2048', value: '2048' },
- ],
- });
-
- // =========================================================================
- // Runtime — Canvas group
- // =========================================================================
-
- registerSettingsItem({
- id: 'runtime.canvasScaleMode',
- section: 'runtime',
- group: 'runtime.canvas',
- label: 'Canvas Scale Mode',
- description: 'How the canvas adapts to different screen sizes',
- type: 'select',
- defaultValue: 'FixedHeight',
- order: 0,
- projectSync: true,
- options: [
- { label: 'Fixed Width', value: 'FixedWidth' },
- { label: 'Fixed Height', value: 'FixedHeight' },
- { label: 'Expand', value: 'Expand' },
- { label: 'Shrink', value: 'Shrink' },
- { label: 'Match', value: 'Match' },
- ],
- });
-
- registerSettingsItem({
- id: 'runtime.canvasMatchWidthOrHeight',
- section: 'runtime',
- group: 'runtime.canvas',
- label: 'Canvas Match W/H',
- description: 'Blend between matching width (0) and height (1)',
- type: 'range',
- defaultValue: 0.5,
- min: 0,
- max: 1,
- step: 0.1,
- order: 1,
- projectSync: true,
- visibleWhen: { settingId: 'runtime.canvasScaleMode', value: 'Match' },
- });
-
- // =========================================================================
- // Runtime — Timing group
- // =========================================================================
-
- registerSettingsItem({
- id: 'runtime.maxDeltaTime',
- section: 'runtime',
- group: 'runtime.timing',
- label: 'Max Delta Time',
- description: 'Maximum allowed frame delta time in seconds',
- type: 'number',
- defaultValue: 0.25,
- min: 0.01,
- max: 1,
- step: 0.01,
- order: 0,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'runtime.maxFixedSteps',
- section: 'runtime',
- group: 'runtime.timing',
- label: 'Max Fixed Steps',
- description: 'Maximum fixed update iterations per frame',
- type: 'number',
- defaultValue: 8,
- min: 1,
- max: 64,
- step: 1,
- order: 1,
- projectSync: true,
- });
-
- // =========================================================================
- // Asset Loading
- // =========================================================================
-
- registerSettingsItem({
- id: 'asset.timeout',
- section: 'asset-loading',
- label: 'Load Timeout',
- description: 'Maximum time to wait for an asset load in milliseconds',
- type: 'number',
- defaultValue: 30000,
- min: 1000,
- max: 120000,
- step: 1000,
- order: 0,
- projectSync: true,
- });
-
- registerSettingsItem({
- id: 'asset.failureCooldown',
- section: 'asset-loading',
- label: 'Failure Cooldown',
- description: 'Time to wait before retrying a failed asset load in milliseconds',
- type: 'number',
- defaultValue: 5000,
- min: 0,
- max: 60000,
- step: 1000,
- order: 1,
- projectSync: true,
- });
-
- // =========================================================================
- // Network
- // =========================================================================
-
- registerSettingsItem({
- id: 'network.proxy',
- section: 'network',
- label: 'HTTP Proxy',
- description: 'Proxy for update downloads (e.g. http://127.0.0.1:7890)',
- type: 'string',
- defaultValue: '',
- order: 0,
- });
-}
diff --git a/editor/src/settings/index.ts b/editor/src/settings/index.ts
index 62568f5c1..fee1ed380 100644
--- a/editor/src/settings/index.ts
+++ b/editor/src/settings/index.ts
@@ -21,12 +21,9 @@ export {
importSettings,
getItemDescriptor,
getGroupDescriptor,
- lockBuiltinSettings,
- clearExtensionSettings,
} from './SettingsRegistry';
export { showSettingsDialog } from './SettingsDialog';
-export { registerBuiltinSettings } from './builtinSettings';
export { ProjectSettingsSync } from './ProjectSettingsSync';
export {
MAX_COLLISION_LAYERS,
diff --git a/editor/src/ui/ContextMenuRegistry.ts b/editor/src/ui/ContextMenuRegistry.ts
index 6dfb79c78..39765bdd0 100644
--- a/editor/src/ui/ContextMenuRegistry.ts
+++ b/editor/src/ui/ContextMenuRegistry.ts
@@ -1,15 +1,8 @@
-/**
- * @file ContextMenuRegistry.ts
- * @brief Context menu contribution registry for extension-provided menu items
- */
-
import type { Entity } from 'esengine';
import type { EntityData } from '../types/SceneTypes';
import type { ContextMenuItem } from './ContextMenu';
-
-// =============================================================================
-// Types
-// =============================================================================
+import { getEditorContainer } from '../container';
+import { CONTEXT_MENU_ITEM } from '../container/tokens';
export type ContextMenuLocation =
| 'hierarchy.entity'
@@ -43,37 +36,17 @@ export interface ContextMenuContribution {
children?: ContextMenuContribution[];
}
-// =============================================================================
-// Registry
-// =============================================================================
-
-const registry: ContextMenuContribution[] = [];
-const builtinIds = new Set<string>();
-
export function registerContextMenuItem(contribution: ContextMenuContribution): void {
- registry.push(contribution);
-}
-
-export function lockBuiltinContextMenuItems(): void {
- for (const item of registry) {
- builtinIds.add(item.id);
- }
-}
-
-export function clearExtensionContextMenuItems(): void {
- for (let i = registry.length - 1; i >= 0; i--) {
- if (!builtinIds.has(registry[i].id)) {
- registry.splice(i, 1);
- }
- }
+ getEditorContainer().provide(CONTEXT_MENU_ITEM, contribution.id, contribution);
}
export function getContextMenuItems(location: ContextMenuLocation, ctx: ContextMenuContext): ContextMenuItem[] {
- const contributions = registry.filter(c => {
- if (c.location !== location) return false;
- if (c.visible && !c.visible(ctx)) return false;
- return true;
- });
+ const contributions: ContextMenuContribution[] = [];
+ for (const c of getEditorContainer().getAll(CONTEXT_MENU_ITEM).values()) {
+ if (c.location !== location) continue;
+ if (c.visible && !c.visible(ctx)) continue;
+ contributions.push(c);
+ }
if (contributions.length === 0) return [];