A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
refactor: remove GameViewBridge and add bidirectional play mode inspector sync
esengine8090479a6882
diff --git a/editor/src/panels/InspectorPanel.ts b/editor/src/panels/InspectorPanel.tsindex 9d79bb8ef..98e28c4b5 100644--- a/editor/src/panels/InspectorPanel.ts+++ b/editor/src/panels/InspectorPanel.ts@@ -21,7 +21,6 @@ import { renderFolderInspector } from './inspector/FolderInspector';import { renderScriptInspector, renderSceneInspector, renderFileInspector } from './inspector/FileInspector';import { getPlayModeService } from '../services/PlayModeService';import { RuntimeStoreProxy } from '../services/RuntimeStoreProxy';-import { renderRuntimeEntity } from './inspector/RuntimeEntityRenderer';// =============================================================================// InspectorPanel@@ -86,9 +85,7 @@ export class InspectorPanel {if (isPlaying) {this.container_.classList.add('es-play-mode');hideMaterialPreview(this.materialPreviewState_);- this.runtimeProxy_ = new RuntimeStoreProxy(- pms.bridge, this.store_- );+ this.runtimeProxy_ = new RuntimeStoreProxy(this.store_);} else {this.container_.classList.remove('es-play-mode');this.stopRuntimeRefresh();@@ -378,7 +375,7 @@ export class InspectorPanel {// Play Mode (Runtime Inspector)// =========================================================================- private async renderPlayModeEntity(runtimeEntityId: number): Promise<void> {+ private renderPlayModeEntity(runtimeEntityId: number): void {this.stopRuntimeRefresh();this.disposeEditors();this.cleanupImageUrl();@@ -386,26 +383,8 @@ export class InspectorPanel {this.currentAssetPath_ = null;hideMaterialPreview(this.materialPreviewState_);- const pms = getPlayModeService();-- if (pms.isSharedMode) {- this.rebuildPlayModeEntity(runtimeEntityId as Entity);- this.startSharedRefreshLoop(runtimeEntityId);- } else if (this.runtimeProxy_) {- const freshData = await pms.queryEntityByRuntimeId(runtimeEntityId);- if (!freshData || this.runtimeEntityId_ !== runtimeEntityId) return;-- this.runtimeProxy_.applyRuntimeData(runtimeEntityId, freshData);- this.rebuildPlayModeEntity(runtimeEntityId as Entity);- this.startRuntimeRefreshLoop(runtimeEntityId);- } else {- const freshData = await pms.queryEntityByRuntimeId(runtimeEntityId);- if (!freshData || this.runtimeEntityId_ !== runtimeEntityId) return;-- this.contentContainer_.innerHTML = '';- renderRuntimeEntity(this.contentContainer_, freshData, pms.bridge);- this.updateFooter(`${freshData.components.length} components (Runtime)`);- }+ this.rebuildPlayModeEntity(runtimeEntityId as Entity);+ this.startSharedRefreshLoop(runtimeEntityId);}private rebuildPlayModeEntity(entity: Entity): void {@@ -475,40 +454,6 @@ export class InspectorPanel {this.updateFooter('Live mode');}- private startRuntimeRefreshLoop(runtimeEntityId: number): void {- const pms = getPlayModeService();- const tick = async () => {- if (this.runtimeEntityId_ !== runtimeEntityId) return;- if (this.runtimeRefreshPending_) {- this.runtimeRefreshRafId_ = requestAnimationFrame(tick);- return;- }- this.runtimeRefreshPending_ = true;- try {- if (this.runtimeProxy_) {- this.runtimeProxy_.prepareForQuery(runtimeEntityId);- }- const fresh = await pms.queryEntityByRuntimeId(runtimeEntityId);- if (this.runtimeEntityId_ !== runtimeEntityId) return;- if (!fresh) {- this.contentContainer_.innerHTML = '<div class="es-inspector-empty">Entity despawned</div>';- this.updateFooter('Runtime mode');- return;- }- if (this.runtimeProxy_) {- this.runtimeProxy_.applyRuntimeData(runtimeEntityId, fresh);- this.updatePlayModeEditors(runtimeEntityId);- }- } finally {- this.runtimeRefreshPending_ = false;- }- if (this.runtimeEntityId_ === runtimeEntityId) {- this.runtimeRefreshRafId_ = requestAnimationFrame(tick);- }- };- this.runtimeRefreshRafId_ = requestAnimationFrame(tick);- }-private startSharedRefreshLoop(entityId: number): void {const pms = getPlayModeService();const tick = () => {@@ -520,6 +465,7 @@ export class InspectorPanel {return;}if (this.runtimeProxy_) {+ this.runtimeProxy_.prepareForQuery(entityId);this.runtimeProxy_.applyRuntimeData(entityId, fresh);this.updatePlayModeEditors(entityId);}diff --git a/editor/src/panels/game-view/GameViewBridge.ts b/editor/src/panels/game-view/GameViewBridge.tsdeleted file mode 100644index cb2eab420..000000000--- a/editor/src/panels/game-view/GameViewBridge.ts+++ /dev/null@@ -1,167 +0,0 @@-export interface EntityComponentData {- type: string;- data: Record<string, unknown>;-}--export interface RuntimeEntityData {- entityId: number;- name: string;- parentId: number | null;- children: number[];- components: EntityComponentData[];-}--export interface RuntimeStats {- fps: number;- entityCount: number;-}--type EventHandler = (data: any) => void;--export class GameViewBridge {- private iframe_: HTMLIFrameElement;- private messageId_ = 0;- private pendingRequests_ = new Map<number, { resolve: (v: any) => void; timer: ReturnType<typeof setTimeout> }>();- private listeners_ = new Map<string, Set<EventHandler>>();- private boundHandler_: (e: MessageEvent) => void;- private ready_ = false;-- constructor(iframe: HTMLIFrameElement) {- this.iframe_ = iframe;- this.boundHandler_ = (e: MessageEvent) => this.handleMessage(e);- window.addEventListener('message', this.boundHandler_);- }-- get isReady(): boolean {- return this.ready_;- }-- request<T = any>(type: string, payload?: Record<string, unknown>, timeout = 5000): Promise<T> {- return new Promise((resolve, reject) => {- const requestId = ++this.messageId_;- const timer = setTimeout(() => {- this.pendingRequests_.delete(requestId);- reject(new Error(`GameViewBridge: '${type}' timed out`));- }, timeout);- this.pendingRequests_.set(requestId, { resolve, timer });- this.postCommand({ type, requestId, ...payload });- });- }-- send(type: string, payload?: Record<string, unknown>): void {- this.postCommand({ type, ...payload });- }-- async pause(): Promise<void> {- await this.request('pause');- }-- async resume(): Promise<void> {- await this.request('resume');- }-- async step(): Promise<void> {- await this.request('step');- }-- setSpeed(speed: number): void {- this.send('set-speed', { speed });- }-- async queryEntityList(): Promise<RuntimeEntityData[]> {- return this.request('query-entity-list');- }-- async queryEntity(entityId: number): Promise<RuntimeEntityData> {- return this.request('query-entity', { entityId });- }-- async setEntityProperty(- entityId: number,- component: string,- property: string,- value: unknown,- ): Promise<void> {- return this.request('set-entity-property', { entityId, component, property, value });- }-- async queryStats(): Promise<RuntimeStats> {- return this.request('query-stats');- }-- async spawnEntity(name?: string, parentId?: number | null): Promise<RuntimeEntityData> {- return this.request('spawn-entity', { name, parentId });- }-- async despawnEntity(entityId: number): Promise<void> {- await this.request('despawn-entity', { entityId });- }-- async addComponent(entityId: number, componentType: string, data?: Record<string, unknown>): Promise<void> {- await this.request('add-component', { entityId, componentType, data });- }-- async removeComponent(entityId: number, componentType: string): Promise<void> {- await this.request('remove-component', { entityId, componentType });- }-- async renameEntity(entityId: number, name: string): Promise<void> {- await this.request('rename-entity', { entityId, name });- }-- async reparentEntity(entityId: number, newParentId: number | null): Promise<void> {- await this.request('reparent-entity', { entityId, newParentId });- }-- on(event: string, handler: EventHandler): () => void {- if (!this.listeners_.has(event)) {- this.listeners_.set(event, new Set());- }- this.listeners_.get(event)!.add(handler);- return () => {- this.listeners_.get(event)?.delete(handler);- };- }-- dispose(): void {- window.removeEventListener('message', this.boundHandler_);- for (const { timer } of this.pendingRequests_.values()) {- clearTimeout(timer);- }- this.pendingRequests_.clear();- this.listeners_.clear();- this.ready_ = false;- }-- private postCommand(data: Record<string, unknown>): void {- this.iframe_.contentWindow?.postMessage(data, '*');- }-- private handleMessage(e: MessageEvent): void {- if (e.source !== this.iframe_.contentWindow) return;-- const msg = e.data;- if (!msg || typeof msg !== 'object' || !msg.type) return;-- if (msg.type === 'ready') {- this.ready_ = true;- }-- if (msg.requestId !== undefined) {- const pending = this.pendingRequests_.get(msg.requestId);- if (pending) {- clearTimeout(pending.timer);- pending.resolve(msg.data);- this.pendingRequests_.delete(msg.requestId);- return;- }- }-- const handlers = this.listeners_.get(msg.type);- if (handlers) {- for (const handler of handlers) {- handler(msg.data);- }- }- }-}diff --git a/editor/src/panels/game-view/GameViewPanel.ts b/editor/src/panels/game-view/GameViewPanel.tsindex d54d15c28..9a6014bf4 100644--- a/editor/src/panels/game-view/GameViewPanel.ts+++ b/editor/src/panels/game-view/GameViewPanel.ts@@ -125,7 +125,7 @@ export class GameViewPanel implements PanelInstance, Resizable {private async play(): Promise<void> {const service = getPlayModeService();- await service.enterShared();+ await service.enter();this.gameManager_.setState('playing');if (this.gameRenderer_) {this.gameRenderer_.setVisible(true);@@ -157,7 +157,7 @@ export class GameViewPanel implements PanelInstance, Resizable {if (this.gameRenderer_) {this.gameRenderer_.setVisible(false);}- await getPlayModeService().exitShared();+ await getPlayModeService().exit();await this.gameManager_.stop();}diff --git a/editor/src/panels/game-view/index.ts b/editor/src/panels/game-view/index.tsindex 467634ea6..21f8e0446 100644--- a/editor/src/panels/game-view/index.ts+++ b/editor/src/panels/game-view/index.ts@@ -1,4 +1,3 @@export { GameViewPanel, type GameViewPanelOptions } from './GameViewPanel';export { GameInstanceManager, type GameState } from './GameInstanceManager';export { GameViewToolbar, type ResolutionPreset, type GameViewToolbarCallbacks } from './GameViewToolbar';-export { GameViewBridge, type RuntimeEntityData, type RuntimeStats, type EntityComponentData } from './GameViewBridge';diff --git a/editor/src/panels/inspector/RuntimeEntityRenderer.ts b/editor/src/panels/inspector/RuntimeEntityRenderer.tsindex d78e9d4c5..7cf9902cc 100644--- a/editor/src/panels/inspector/RuntimeEntityRenderer.ts+++ b/editor/src/panels/inspector/RuntimeEntityRenderer.ts@@ -1,10 +1,10 @@-import type { RuntimeEntityData, GameViewBridge } from '../game-view/GameViewBridge';+import type { RuntimeEntityData } from '../../services/PlayModeService';+import { getPlayModeService } from '../../services/PlayModeService';import { icons } from '../../utils/icons';export function renderRuntimeEntity(container: HTMLElement,data: RuntimeEntityData,- bridge: GameViewBridge | null,): void {container.innerHTML = '';@@ -61,7 +61,7 @@ export function renderRuntimeEntity(const editor = document.createElement('div');editor.className = 'es-property-editor';- createRuntimePropertyEditor(editor, data.entityId, comp.type, key, value, bridge);+ createRuntimePropertyEditor(editor, data.entityId, comp.type, key, value);row.appendChild(label);row.appendChild(editor);@@ -114,8 +114,9 @@ function createRuntimePropertyEditor(componentType: string,property: string,value: unknown,- bridge: GameViewBridge | null,): void {+ const pms = getPlayModeService();+if (typeof value === 'number') {const input = document.createElement('input');input.type = 'number';@@ -125,7 +126,7 @@ function createRuntimePropertyEditor(input.dataset.rtComp = componentType;input.dataset.rtProp = property;input.addEventListener('change', () => {- bridge?.setEntityProperty(entityId, componentType, property, parseFloat(input.value));+ pms.setEntityProperty(entityId, componentType, property, parseFloat(input.value));});container.appendChild(input);} else if (typeof value === 'boolean') {@@ -135,7 +136,7 @@ function createRuntimePropertyEditor(input.dataset.rtComp = componentType;input.dataset.rtProp = property;input.addEventListener('change', () => {- bridge?.setEntityProperty(entityId, componentType, property, input.checked);+ pms.setEntityProperty(entityId, componentType, property, input.checked);});container.appendChild(input);} else if (typeof value === 'string') {@@ -146,7 +147,7 @@ function createRuntimePropertyEditor(input.dataset.rtComp = componentType;input.dataset.rtProp = property;input.addEventListener('change', () => {- bridge?.setEntityProperty(entityId, componentType, property, input.value);+ pms.setEntityProperty(entityId, componentType, property, input.value);});container.appendChild(input);} else if (value && typeof value === 'object' && !Array.isArray(value)) {@@ -170,7 +171,7 @@ function createRuntimePropertyEditor(inp.dataset.rtKey = k;inp.addEventListener('change', () => {const newObj = { ...obj, [k]: parseFloat(inp.value) };- bridge?.setEntityProperty(entityId, componentType, property, newObj);+ pms.setEntityProperty(entityId, componentType, property, newObj);});field.appendChild(lbl);field.appendChild(inp);diff --git a/editor/src/services/PlayModeService.ts b/editor/src/services/PlayModeService.tsindex ec8387fd0..ac22b0f06 100644--- a/editor/src/services/PlayModeService.ts+++ b/editor/src/services/PlayModeService.ts@@ -1,4 +1,3 @@-import type { GameViewBridge, RuntimeEntityData } from '../panels/game-view/GameViewBridge';import type { EntityData } from '../types/SceneTypes';import { Assets, Name, Parent, Children, getComponent, getComponentAssetFields } from 'esengine';import type { Entity, World } from 'esengine';@@ -8,12 +7,29 @@ import { ScriptInjector } from './ScriptInjector';import { getEditorInstance, getEditorContext } from '../context/EditorContext';import { getAssetDatabase, isUUID } from '../asset';+export interface EntityComponentData {+ type: string;+ data: Record<string, unknown>;+}++export interface RuntimeEntityData {+ entityId: number;+ name: string;+ parentId: number | null;+ children: number[];+ components: EntityComponentData[];+}+export type PlayState = 'stopped' | 'playing';type StateChangeCallback = (state: PlayState) => void;type EntityListCallback = (entities: RuntimeEntityData[]) => void;type SelectionCallback = (entityId: number | null) => void;+function isBuiltinComponent(comp: ReturnType<typeof getComponent>): boolean {+ return !!(comp && (comp as any)._builtin);+}+export function runtimeToEntityData(re: RuntimeEntityData): EntityData {return {id: re.entityId,@@ -27,13 +43,8 @@ export function runtimeToEntityData(re: RuntimeEntityData): EntityData {class PlayModeService {private state_: PlayState = 'stopped';- private bridge_: GameViewBridge | null = null;- private sharedMode_ = false;private selectedEntityId_: number | null = null;private cachedEntities_: RuntimeEntityData[] = [];- private pollTimer_: ReturnType<typeof setTimeout> | null = null;- private isRefreshing_ = false;- private consecutiveFailures_ = 0;private stateListeners_ = new Set<StateChangeCallback>();private entityListListeners_ = new Set<EntityListCallback>();private selectionListeners_ = new Set<SelectionCallback>();@@ -45,10 +56,8 @@ class PlayModeService {private entitySceneDataMap_: Map<number, { type: string; data: Record<string, unknown> }[]> | null = null;get state(): PlayState { return this.state_; }- get bridge(): GameViewBridge | null { return this.bridge_; }get runtimeEntities(): RuntimeEntityData[] { return this.cachedEntities_; }get selectedEntityId(): number | null { return this.selectedEntityId_; }- get isSharedMode(): boolean { return this.sharedMode_; }getRuntimeEntityData(entityId: number): EntityData | null {const re = this.cachedEntities_.find(e => e.entityId === entityId);@@ -61,10 +70,8 @@ class PlayModeService {return this.entityToRuntimeData(this.sharedWorld_, entityId as Entity);}- async enterShared(): Promise<void> {+ async enter(): Promise<void> {this.snapshot_ = getEditorStore().takeSnapshot();- this.sharedMode_ = true;- this.bridge_ = null;this.state_ = 'playing';this.cachedEntities_ = [];this.selectedEntityId_ = null;@@ -78,15 +85,14 @@ class PlayModeService {this.emitStateChange();}- async exitShared(): Promise<void> {- if (!this.sharedMode_) return;+ async exit(): Promise<void> {+ if (this.state_ !== 'playing') return;for (const cleanup of this.sharedCleanups_) cleanup();this.sharedCleanups_ = [];const snapshot = this.snapshot_;this.snapshot_ = null;- this.sharedMode_ = false;this.state_ = 'stopped';this.cachedEntities_ = [];this.selectedEntityId_ = null;@@ -105,44 +111,6 @@ class PlayModeService {this.emitSelectionChange();}- enter(bridge: GameViewBridge): void {- if (this.state_ === 'playing') {- this.stopPolling();- this.bridge_ = bridge;- this.cachedEntities_ = [];- this.selectedEntityId_ = null;- this.startPolling();- this.emitSelectionChange();- return;- }- this.snapshot_ = getEditorStore().takeSnapshot();- this.bridge_ = bridge;- this.sharedMode_ = false;- this.state_ = 'playing';- this.cachedEntities_ = [];- this.selectedEntityId_ = null;- this.startPolling();- this.emitStateChange();- }-- exit(): void {- if (this.sharedMode_) {- this.exitShared();- return;- }- this.stopPolling();- this.bridge_ = null;- this.state_ = 'stopped';- this.cachedEntities_ = [];- this.selectedEntityId_ = null;- if (this.snapshot_) {- getEditorStore().restoreSnapshot(this.snapshot_);- this.snapshot_ = null;- }- this.emitStateChange();- this.emitSelectionChange();- }-selectEntity(id: number | null): void {this.selectedEntityId_ = id;this.emitSelectionChange();@@ -163,106 +131,71 @@ class PlayModeService {return () => { this.selectionListeners_.delete(cb); };}- async queryEntityByRuntimeId(runtimeId: number): Promise<RuntimeEntityData | null> {- if (!this.bridge_?.isReady) return null;- try {- return await this.bridge_.queryEntity(runtimeId);- } catch (e) {- console.warn('[PlayModeService] queryEntityByRuntimeId failed:', e);- return null;+ setEntityProperty(entityId: number, componentType: string, property: string, value: unknown): void {+ if (!this.sharedWorld_ || !this.sharedWorld_.valid(entityId as Entity)) return;++ const compDef = getComponent(componentType);+ if (!compDef) return;++ if (isBuiltinComponent(compDef)) {+ const current = this.sharedWorld_.tryGet(entityId as Entity, compDef);+ if (!current) return;+ const snapshot = { ...current, [property]: value };+ this.sharedWorld_.insert(entityId as Entity, compDef, snapshot);+ } else {+ const current = this.sharedWorld_.tryGet(entityId as Entity, compDef);+ if (!current) return;+ (current as Record<string, unknown>)[property] = value;}}- async refreshEntityList(): Promise<void> {- if (this.isRefreshing_ || !this.bridge_?.isReady) return;- this.isRefreshing_ = true;- try {- this.cachedEntities_ = await this.bridge_.queryEntityList();- this.consecutiveFailures_ = 0;- this.emitEntityListUpdate();- } catch (e) {- this.consecutiveFailures_++;- if (this.consecutiveFailures_ <= 3) {- console.warn('[PlayModeService] refresh failed:', e);- }- } finally {- this.isRefreshing_ = false;+ spawnEntity(name?: string, parentId?: number | null): number | null {+ if (!this.sharedWorld_) return null;+ const world = this.sharedWorld_;+ const entity = world.spawn();+ if (name) {+ world.insert(entity, Name, { value: name });}- }-- async querySelectedEntity(): Promise<RuntimeEntityData | null> {- if (this.selectedEntityId_ === null || !this.bridge_?.isReady) return null;- try {- return await this.bridge_.queryEntity(this.selectedEntityId_);- } catch (e) {- console.warn('[PlayModeService] querySelectedEntity failed:', e);- return null;+ if (parentId != null && world.valid(parentId as Entity)) {+ world.insert(entity, Parent, { entity: parentId as Entity });}+ return entity as number;}- async spawnEntity(name?: string, parentId?: number | null): Promise<number | null> {- if (!this.bridge_?.isReady) return null;- try {- const result = await this.bridge_.spawnEntity(name, parentId);- await this.refreshEntityList();- return result.entityId;- } catch (e) {- console.warn('[PlayModeService] spawnEntity failed:', e);- return null;- }- }-- async despawnEntity(entityId: number): Promise<void> {- if (!this.bridge_?.isReady) return;- try {- await this.bridge_.despawnEntity(entityId);- if (this.selectedEntityId_ === entityId) {- this.selectedEntityId_ = null;- this.emitSelectionChange();- }- await this.refreshEntityList();- } catch (e) {- console.warn('[PlayModeService] despawnEntity failed:', e);+ despawnEntity(entityId: number): void {+ if (!this.sharedWorld_ || !this.sharedWorld_.valid(entityId as Entity)) return;+ this.sharedWorld_.despawn(entityId as Entity);+ if (this.selectedEntityId_ === entityId) {+ this.selectedEntityId_ = null;+ this.emitSelectionChange();}}- async addComponent(entityId: number, componentType: string, data?: Record<string, unknown>): Promise<void> {- if (!this.bridge_?.isReady) return;- try {- await this.bridge_.addComponent(entityId, componentType, data);- await this.refreshEntityList();- } catch (e) {- console.warn('[PlayModeService] addComponent failed:', e);- }+ addComponent(entityId: number, componentType: string, data?: Record<string, unknown>): void {+ if (!this.sharedWorld_ || !this.sharedWorld_.valid(entityId as Entity)) return;+ const compDef = getComponent(componentType);+ if (!compDef) return;+ this.sharedWorld_.insert(entityId as Entity, compDef, data ?? {});}- async removeComponent(entityId: number, componentType: string): Promise<void> {- if (!this.bridge_?.isReady) return;- try {- await this.bridge_.removeComponent(entityId, componentType);- await this.refreshEntityList();- } catch (e) {- console.warn('[PlayModeService] removeComponent failed:', e);- }+ removeComponent(entityId: number, componentType: string): void {+ if (!this.sharedWorld_ || !this.sharedWorld_.valid(entityId as Entity)) return;+ const compDef = getComponent(componentType);+ if (!compDef) return;+ this.sharedWorld_.remove(entityId as Entity, compDef);}- async renameEntity(entityId: number, name: string): Promise<void> {- if (!this.bridge_?.isReady) return;- try {- await this.bridge_.renameEntity(entityId, name);- await this.refreshEntityList();- } catch (e) {- console.warn('[PlayModeService] renameEntity failed:', e);- }+ renameEntity(entityId: number, name: string): void {+ if (!this.sharedWorld_ || !this.sharedWorld_.valid(entityId as Entity)) return;+ this.sharedWorld_.insert(entityId as Entity, Name, { value: name });}- async reparentEntity(entityId: number, newParentId: number | null): Promise<void> {- if (!this.bridge_?.isReady) return;- try {- await this.bridge_.reparentEntity(entityId, newParentId);- await this.refreshEntityList();- } catch (e) {- console.warn('[PlayModeService] reparentEntity failed:', e);+ reparentEntity(entityId: number, newParentId: number | null): void {+ if (!this.sharedWorld_ || !this.sharedWorld_.valid(entityId as Entity)) return;+ if (newParentId != null) {+ this.sharedWorld_.insert(entityId as Entity, Parent, { entity: newParentId as Entity });+ } else {+ this.sharedWorld_.remove(entityId as Entity, Parent);}}@@ -400,29 +333,6 @@ class PlayModeService {this.sharedCleanups_.push(unsubSpawn, unsubDespawn);}- private startPolling(): void {- this.stopPolling();- this.consecutiveFailures_ = 0;- this.refreshEntityList();- this.schedulePoll();- }-- private schedulePoll(): void {- if (this.state_ !== 'playing') return;- const delay = this.consecutiveFailures_ > 2 ? 5000 : 500;- this.pollTimer_ = setTimeout(async () => {- await this.refreshEntityList();- this.schedulePoll();- }, delay);- }-- private stopPolling(): void {- if (this.pollTimer_) {- clearTimeout(this.pollTimer_);- this.pollTimer_ = null;- }- }-private emitStateChange(): void {for (const cb of this.stateListeners_) cb(this.state_);}diff --git a/editor/src/services/RuntimeStoreProxy.ts b/editor/src/services/RuntimeStoreProxy.tsindex e9c888227..d75b4d3e3 100644--- a/editor/src/services/RuntimeStoreProxy.ts+++ b/editor/src/services/RuntimeStoreProxy.ts@@ -1,17 +1,14 @@import type { Entity } from 'esengine';-import type { GameViewBridge, RuntimeEntityData } from '../panels/game-view/GameViewBridge';import type { EditorStore } from '../store/EditorStore';import type { SceneData, EntityData, ComponentData } from '../types/SceneTypes';-import { getPlayModeService } from './PlayModeService';+import { getPlayModeService, type RuntimeEntityData } from './PlayModeService';export class RuntimeStoreProxy {- private bridge_: GameViewBridge | null;private editorStore_: EditorStore;private runtimeCache_ = new Map<number, Record<string, Record<string, unknown>>>();private pendingWrites_ = new Map<string, { value: unknown; stale: boolean }>();- constructor(bridge: GameViewBridge | null, editorStore: EditorStore) {- this.bridge_ = bridge;+ constructor(editorStore: EditorStore) {this.editorStore_ = editorStore;}@@ -105,7 +102,7 @@ export class RuntimeStoreProxy {newValue: unknown,): void {this.recordPendingWrite(entity as number, componentType, propertyName, newValue);- this.bridge_?.setEntityProperty(entity as number, componentType, propertyName, newValue);+ getPlayModeService().setEntityProperty(entity as number, componentType, propertyName, newValue);}updateProperties(@@ -113,9 +110,10 @@ export class RuntimeStoreProxy {componentType: string,changes: { property: string; oldValue: unknown; newValue: unknown }[],): void {+ const pms = getPlayModeService();for (const change of changes) {this.recordPendingWrite(entity as number, componentType, change.property, change.newValue);- this.bridge_?.setEntityProperty(entity as number, componentType, change.property, change.newValue);+ pms.setEntityProperty(entity as number, componentType, change.property, change.newValue);}}@@ -126,42 +124,33 @@ export class RuntimeStoreProxy {newValue: unknown,): void {this.recordPendingWrite(entity as number, componentType, propertyName, newValue);- this.bridge_?.setEntityProperty(entity as number, componentType, propertyName, newValue);+ getPlayModeService().setEntityProperty(entity as number, componentType, propertyName, newValue);}renameEntity(entity: Entity, name: string): void {- const pms = getPlayModeService();- pms.renameEntity(entity as number, name);+ getPlayModeService().renameEntity(entity as number, name);}- toggleVisibility(_entityId: number): void {- // visibility toggle not applicable in play mode- }+ toggleVisibility(_entityId: number): void {}removeComponent(entity: Entity, type: string): void {- const pms = getPlayModeService();- pms.removeComponent(entity as number, type);+ getPlayModeService().removeComponent(entity as number, type);}- reorderComponent(_entity: Entity, _fromIndex: number, _toIndex: number): void {- // reorder not supported via bridge- }+ reorderComponent(_entity: Entity, _fromIndex: number, _toIndex: number): void {}addComponent(entity: Entity, type: string, data: Record<string, unknown>): void {- const pms = getPlayModeService();- pms.addComponent(entity as number, type, data);+ getPlayModeService().addComponent(entity as number, type, data);}deleteEntity(entity: Entity): void {- const pms = getPlayModeService();- pms.despawnEntity(entity as number);+ getPlayModeService().despawnEntity(entity as number);}createEntity(name?: string, parent?: Entity | null): Entity {- const pms = getPlayModeService();const parentId = parent != null ? Number(parent) : null;- pms.spawnEntity(name, parentId);- return 0 as Entity;+ const id = getPlayModeService().spawnEntity(name, parentId);+ return (id ?? 0) as Entity;}selectEntity(entity: Entity | null, _mode?: 'replace' | 'add' | 'toggle'): void {