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
feat: complete StateMachine graph panel with detail editing and Rive-style UI
esengine082aeeac1aaa
diff --git a/editor/src/menus/ShortcutManager.ts b/editor/src/menus/ShortcutManager.tsindex 8d79dae07..e279c961a 100644--- a/editor/src/menus/ShortcutManager.ts+++ b/editor/src/menus/ShortcutManager.ts@@ -33,6 +33,7 @@ export class ShortcutManager {}handleKeyDown(e: KeyboardEvent): boolean {+ if (e.defaultPrevented) return false;const ctrl = e.ctrlKey || e.metaKey;const shift = e.shiftKey;const alt = e.altKey;diff --git a/editor/src/panels/state-machine-graph/GraphCanvas.ts b/editor/src/panels/state-machine-graph/GraphCanvas.tsindex 58969dc7c..cb27c7bf7 100644--- a/editor/src/panels/state-machine-graph/GraphCanvas.ts+++ b/editor/src/panels/state-machine-graph/GraphCanvas.ts@@ -8,7 +8,6 @@ import {MAX_ZOOM,ZOOM_SPEED,NODE_BORDER_RADIUS,- NODE_HEADER_HEIGHT,NODE_FONT_SIZE,NODE_SUBTITLE_FONT_SIZE,CONNECTION_HIT_TOLERANCE,@@ -24,6 +23,8 @@ export interface GraphCanvasCallbacks {onDeleteSelection?(): void;onAddState?(worldX: number, worldY: number): void;onRenameNode?(name: string): void;+ onSetInitialState?(name: string): void;+ onAddAnyState?(worldX: number, worldY: number): void;}const MULTI_TRANSITION_OFFSET = 8;@@ -117,6 +118,7 @@ export class GraphCanvas {draw(): void {if (this.disposed_) return;+ this.resizeCanvas();const ctx = this.ctx_;const w = this.canvas_.clientWidth;@@ -331,12 +333,18 @@ export class GraphCanvas {const layout = this.state_.nodeLayouts.get(this.hoveredConnector_);if (!layout) return;- const cx = (layout.x + layout.width) * vt.zoom + vt.x;+ const rightX = (layout.x + layout.width) * vt.zoom + vt.x;+ const leftX = layout.x * vt.zoom + vt.x;const cy = (layout.y + layout.height / 2) * vt.zoom + vt.y;+ this.drawConnectorDot(ctx, rightX, cy, COLORS.connectorFill);+ this.drawConnectorDot(ctx, leftX, cy, COLORS.connectorFill);+ }++ private drawConnectorDot(ctx: CanvasRenderingContext2D, cx: number, cy: number, color: string): void {ctx.beginPath();ctx.arc(cx, cy, CONNECTOR_RADIUS, 0, Math.PI * 2);- ctx.fillStyle = COLORS.connectorFill;+ ctx.fillStyle = color;ctx.fill();ctx.strokeStyle = COLORS.connectorStroke;ctx.lineWidth = 1.5;@@ -379,62 +387,55 @@ export class GraphCanvas {const sh = layout.height * vt.zoom;const isEntry = name === '__entry__';+ const isAny = name === '__any__';+ const isSpecial = isEntry || isAny;const isSelected = this.state_.selectedNodes.has(name);const isActive = this.state_.isPlayMode && this.state_.activeStateName === name;- const fillColor = isEntry ? COLORS.entryFill : COLORS.nodeFill;- const headerColor = isEntry ? COLORS.entryHeader : COLORS.nodeHeader;+ const fillColor = isEntry ? COLORS.entryFill : isAny ? COLORS.anyFill : COLORS.nodeFill;const borderColor = isActive? COLORS.playModeActive: isSelected? COLORS.nodeSelectedBorder- : isEntry ? COLORS.entryBorder : COLORS.nodeBorder;- const textColor = isEntry ? COLORS.entryText : COLORS.nodeText;+ : isEntry ? COLORS.entryBorder : isAny ? COLORS.anyBorder : COLORS.nodeBorder;+ const textColor = isEntry ? COLORS.entryText : isAny ? COLORS.anyText : COLORS.nodeText;- const r = NODE_BORDER_RADIUS * vt.zoom;+ const r = Math.min(NODE_BORDER_RADIUS * vt.zoom, sh / 2);+ ctx.save();+ ctx.shadowColor = 'rgba(0,0,0,0.3)';+ ctx.shadowBlur = 4 * vt.zoom;+ ctx.shadowOffsetY = 2 * vt.zoom;ctx.beginPath();this.roundRect(ctx, sx, sy, sw, sh, r);ctx.fillStyle = fillColor;ctx.fill();+ ctx.restore();++ ctx.beginPath();+ this.roundRect(ctx, sx, sy, sw, sh, r);ctx.strokeStyle = borderColor;ctx.lineWidth = isActive ? 2.5 : isSelected ? 2 : 1;ctx.stroke();- const headerH = isEntry ? sh : NODE_HEADER_HEIGHT * vt.zoom;- if (!isEntry) {- ctx.beginPath();- ctx.moveTo(sx, sy + headerH);- ctx.lineTo(sx + sw, sy + headerH);- ctx.strokeStyle = COLORS.nodeBorder;- ctx.lineWidth = 1;- ctx.stroke();-- ctx.save();- ctx.beginPath();- this.roundRectTop(ctx, sx, sy, sw, headerH, r);- ctx.clip();- ctx.fillStyle = headerColor;- ctx.fillRect(sx, sy, sw, headerH);- ctx.restore();- }+ const subtitle = isSpecial ? '' : (this.nodeSubtitles_.get(name) ?? '');+ const hasSubtitle = subtitle.length > 0;- const fontSize = (isEntry ? NODE_SUBTITLE_FONT_SIZE : NODE_FONT_SIZE) * vt.zoom;- ctx.font = `bold ${fontSize}px -apple-system, BlinkMacSystemFont, sans-serif`;+ const fontSize = (isSpecial ? NODE_SUBTITLE_FONT_SIZE : NODE_FONT_SIZE) * vt.zoom;+ ctx.font = `600 ${fontSize}px -apple-system, BlinkMacSystemFont, sans-serif`;ctx.fillStyle = textColor;ctx.textAlign = 'center';ctx.textBaseline = 'middle';- const displayName = isEntry ? 'Entry' : name;- const textY = isEntry ? sy + sh / 2 : sy + headerH / 2;- ctx.fillText(displayName, sx + sw / 2, textY, sw - 8 * vt.zoom);+ const displayName = isEntry ? 'Entry' : isAny ? 'Any' : name;+ const nameY = hasSubtitle ? sy + sh * 0.38 : sy + sh / 2;+ ctx.fillText(displayName, sx + sw / 2, nameY, sw - 12 * vt.zoom);- if (!isEntry) {- const subtitle = this.nodeSubtitles_.get(name) ?? '';+ if (hasSubtitle) {const subFontSize = NODE_SUBTITLE_FONT_SIZE * vt.zoom;ctx.font = `${subFontSize}px -apple-system, BlinkMacSystemFont, sans-serif`;ctx.fillStyle = COLORS.nodeSubtext;- ctx.fillText(subtitle, sx + sw / 2, sy + headerH + (sh - headerH) / 2, sw - 8 * vt.zoom);+ ctx.fillText(subtitle, sx + sw / 2, sy + sh * 0.66, sw - 12 * vt.zoom);}}}@@ -452,17 +453,6 @@ export class GraphCanvas {ctx.closePath();}- private roundRectTop(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number): void {- ctx.moveTo(x + r, y);- ctx.lineTo(x + w - r, y);- ctx.arcTo(x + w, y, x + w, y + r, r);- ctx.lineTo(x + w, y + h);- ctx.lineTo(x, y + h);- ctx.lineTo(x, y + r);- ctx.arcTo(x, y, x + r, y, r);- ctx.closePath();- }-// =========================================================================// Hit Testing// =========================================================================@@ -528,14 +518,17 @@ export class GraphCanvas {private isNearNodeEdge(worldX: number, worldY: number): string | null {for (const [name, layout] of this.state_.nodeLayouts) {if (name === '__entry__') continue;- const rightEdge = layout.x + layout.width;const cy = layout.y + layout.height / 2;- const dx = worldX - rightEdge;const dy = worldY - cy;- if (Math.abs(dx) < CONNECTOR_HOVER_MARGIN && Math.abs(dy) < layout.height / 2 + CONNECTOR_HOVER_MARGIN) {- if (dx >= -CONNECTOR_HOVER_MARGIN && dx <= CONNECTOR_HOVER_MARGIN) {- return name;- }+ if (Math.abs(dy) > layout.height / 2 + CONNECTOR_HOVER_MARGIN) continue;++ const rightEdge = layout.x + layout.width;+ const leftEdge = layout.x;+ const dxRight = Math.abs(worldX - rightEdge);+ const dxLeft = Math.abs(worldX - leftEdge);++ if (dxRight <= CONNECTOR_HOVER_MARGIN || dxLeft <= CONNECTOR_HOVER_MARGIN) {+ return name;}}return null;@@ -686,7 +679,7 @@ export class GraphCanvas {const world = this.screenToWorld(sx, sy);const targetNode = this.hitTestNode(world.x, world.y);- if (targetNode && targetNode !== this.state_.pendingConnection.from && targetNode !== '__entry__') {+ if (targetNode && targetNode !== this.state_.pendingConnection.from && targetNode !== '__entry__' && targetNode !== '__any__') {this.callbacks_.onConnectionCreated?.(this.state_.pendingConnection.from, targetNode);}@@ -745,26 +738,32 @@ export class GraphCanvas {const world = this.screenToWorld(sx, sy);const hitNode = this.hitTestNode(world.x, world.y);- if (hitNode && hitNode !== '__entry__') {+ if (hitNode && hitNode !== '__entry__' && hitNode !== '__any__') {+ const isInitial = this.state_.initialStateName === hitNode;+ const items = [+ { label: 'Rename', onClick: () => this.callbacks_.onRenameNode?.(hitNode) },+ ...(!isInitial ? [{ label: 'Set as Initial State', onClick: () => this.callbacks_.onSetInitialState?.(hitNode) }] : []),+ { label: 'Delete', onClick: () => {+ this.state_.selectedNodes.clear();+ this.state_.selectedNodes.add(hitNode);+ this.callbacks_.onDeleteSelection?.();+ }},+ ];showContextMenu({x: e.clientX,y: e.clientY,- items: [- { label: 'Rename', onClick: () => this.callbacks_.onRenameNode?.(hitNode) },- { label: 'Delete', onClick: () => {- this.state_.selectedNodes.clear();- this.state_.selectedNodes.add(hitNode);- this.callbacks_.onDeleteSelection?.();- }},- ],+ items,});- } else {+ } else if (!hitNode || hitNode === '__entry__' || hitNode === '__any__') {+ const hasAny = this.state_.nodeLayouts.has('__any__');+ const items = [+ { label: 'Add State', onClick: () => this.callbacks_.onAddState?.(world.x, world.y) },+ ...(!hasAny ? [{ label: 'Add Any State', onClick: () => this.callbacks_.onAddAnyState?.(world.x, world.y) }] : []),+ ];showContextMenu({x: e.clientX,y: e.clientY,- items: [- { label: 'Add State', onClick: () => this.callbacks_.onAddState?.(world.x, world.y) },- ],+ items,});}}@@ -781,6 +780,7 @@ export class GraphCanvas {if (this.state_.selectedNodes.size > 0 || this.state_.selectedTransition) {this.callbacks_.onDeleteSelection?.();e.preventDefault();+ e.stopPropagation();}}}diff --git a/editor/src/panels/state-machine-graph/GraphDetailPanel.ts b/editor/src/panels/state-machine-graph/GraphDetailPanel.tsnew file mode 100644index 000000000..47de62e89--- /dev/null+++ b/editor/src/panels/state-machine-graph/GraphDetailPanel.ts@@ -0,0 +1,541 @@+const CHEVRON_RIGHT_SVG = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 6 15 12 9 18"></polyline></svg>`;+const CHEVRON_DOWN_SVG = `<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"></polyline></svg>`;+const CLOSE_SVG = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 6 9 12 15 18"></polyline></svg>`;+const REMOVE_SVG = `<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>`;++const EASING_OPTIONS = ['linear', 'easeInQuad', 'easeOutQuad', 'easeInOutQuad', 'easeInCubic', 'easeOutCubic', 'easeInOutCubic', 'easeInBack', 'easeOutBack', 'easeInOutBack', 'easeOutBounce'];+const COMPARATOR_OPTIONS = ['eq', 'neq', 'gt', 'lt', 'gte', 'lte'];+const COMPARATOR_LABELS: Record<string, string> = { eq: '=', neq: '\u2260', gt: '>', lt: '<', gte: '\u2265', lte: '\u2264' };+const WRAP_MODE_OPTIONS = ['loop', 'once'];++const DETAIL_WIDTH = 260;+const COLLAPSED_WIDTH = 24;++interface Condition {+ inputName: string;+ comparator: string;+ value: boolean | number;+}++interface Transition {+ target: string;+ conditions: Condition[];+ duration: number;+ exitTime?: number;+ easing?: string;+}++interface StateNode {+ timeline?: string;+ timelineWrapMode?: 'once' | 'loop';+ properties?: Record<string, unknown>;+ transitions: Transition[];+}++interface InputDef {+ name: string;+ type: 'bool' | 'number' | 'trigger';+ defaultValue?: boolean | number;+}++export interface DetailPanelCallbacks {+ onStateChanged(stateName: string, field: string, value: unknown): void;+ onTransitionChanged(fromState: string, transitionIndex: number, field: string, value: unknown): void;+ onSelectTransition(fromState: string, index: number): void;+ onAddTransitionCondition(fromState: string, transitionIndex: number): void;+ onRemoveTransitionCondition(fromState: string, transitionIndex: number, conditionIndex: number): void;+ onAddProperty(stateName: string, key: string): void;+ onRemoveProperty(stateName: string, key: string): void;+ onRenameProperty(stateName: string, oldKey: string, newKey: string): void;+ onPropertyValueChanged(stateName: string, key: string, value: unknown): void;+}++export class GraphDetailPanel {+ private el_: HTMLElement;+ private expandedContent_: HTMLElement;+ private collapsedBar_: HTMLElement;+ private callbacks_: DetailPanelCallbacks;+ private visible_ = false;+ private collapsed_ = false;+ private collapsedSections_ = new Set<string>();++ private pendingState_: { name: string; state: StateNode; inputs: InputDef[] } | null = null;+ private pendingTransition_: { from: string; target: string; index: number; transition: Transition; inputs: InputDef[] } | null = null;++ constructor(parent: HTMLElement, callbacks: DetailPanelCallbacks) {+ this.callbacks_ = callbacks;++ this.el_ = document.createElement('div');+ this.el_.className = 'es-graph-detail';+ this.el_.style.cssText = 'display:none;height:100%;flex-shrink:0;';+ parent.appendChild(this.el_);++ this.collapsedBar_ = document.createElement('div');+ this.collapsedBar_.style.cssText = `display:none;flex-direction:column;align-items:center;width:${COLLAPSED_WIDTH}px;height:100%;background:var(--es-bg-secondary, #252526);border-left:1px solid var(--es-border, #333);cursor:pointer;font-size:11px;color:var(--es-text-muted, #888);padding:6px 0;box-sizing:border-box;user-select:none;overflow:hidden;`;+ this.collapsedBar_.addEventListener('click', () => this.setCollapsed(false));+ this.el_.appendChild(this.collapsedBar_);++ this.expandedContent_ = document.createElement('div');+ this.expandedContent_.style.cssText = `display:flex;flex-direction:column;width:${DETAIL_WIDTH}px;height:100%;background:var(--es-bg-secondary, #252526);border-left:1px solid var(--es-border, #333);overflow:hidden;`;+ this.el_.appendChild(this.expandedContent_);+ }++ get visible(): boolean {+ return this.visible_;+ }++ hide(): void {+ if (!this.visible_) return;+ this.visible_ = false;+ this.el_.style.display = 'none';+ this.pendingState_ = null;+ this.pendingTransition_ = null;+ }++ showState(name: string, state: StateNode, inputs: InputDef[]): void {+ this.visible_ = true;+ this.el_.style.display = 'flex';+ this.pendingState_ = { name, state, inputs };+ this.pendingTransition_ = null;+ this.renderCurrent();+ }++ showTransition(fromState: string, targetState: string, index: number, transition: Transition, inputs: InputDef[]): void {+ this.visible_ = true;+ this.el_.style.display = 'flex';+ this.pendingState_ = null;+ this.pendingTransition_ = { from: fromState, target: targetState, index, transition, inputs };+ this.renderCurrent();+ }++ dispose(): void {+ this.el_.remove();+ }++ private setCollapsed(collapsed: boolean): void {+ this.collapsed_ = collapsed;+ this.renderCurrent();+ }++ private renderCurrent(): void {+ if (this.collapsed_) {+ this.collapsedBar_.style.display = 'flex';+ this.expandedContent_.style.display = 'none';+ let label = 'Details';+ if (this.pendingState_) label = this.pendingState_.name;+ else if (this.pendingTransition_) label = `${this.pendingTransition_.from} \u2192 ${this.pendingTransition_.target}`;+ this.collapsedBar_.innerHTML = '';+ const chevron = document.createElement('span');+ chevron.innerHTML = CHEVRON_RIGHT_SVG;+ chevron.style.cssText = 'display:flex;align-items:center;justify-content:center;flex-shrink:0;transform:rotate(180deg);margin-bottom:4px;';+ this.collapsedBar_.appendChild(chevron);+ const text = document.createElement('span');+ text.textContent = label;+ text.style.cssText = 'writing-mode:vertical-rl;text-orientation:mixed;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-height:calc(100% - 24px);';+ this.collapsedBar_.appendChild(text);+ return;+ }++ this.collapsedBar_.style.display = 'none';+ this.expandedContent_.style.display = 'flex';+ this.expandedContent_.innerHTML = '';++ this.renderToolbar();++ const body = document.createElement('div');+ body.style.cssText = 'flex:1;overflow-y:auto;overflow-x:hidden;padding:10px 12px;';+ this.expandedContent_.appendChild(body);++ if (this.pendingState_) {+ this.renderStateView(body, this.pendingState_.name, this.pendingState_.state, this.pendingState_.inputs);+ } else if (this.pendingTransition_) {+ const p = this.pendingTransition_;+ this.renderTransitionView(body, p.from, p.target, p.index, p.transition, p.inputs);+ }+ }++ private renderToolbar(): void {+ const bar = document.createElement('div');+ bar.style.cssText = 'display:flex;align-items:center;height:28px;min-height:28px;padding:0 4px 0 10px;background:var(--es-bg-tertiary, #2d2d2d);border-bottom:1px solid var(--es-border, #333);gap:4px;';++ const title = document.createElement('span');+ title.style.cssText = 'flex:1;font-size:11px;font-weight:600;color:var(--es-text-secondary, #ccc);text-transform:uppercase;letter-spacing:0.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';+ if (this.pendingState_) title.textContent = this.pendingState_.name;+ else if (this.pendingTransition_) title.textContent = `${this.pendingTransition_.from} \u2192 ${this.pendingTransition_.target}`;+ bar.appendChild(title);++ const collapseBtn = document.createElement('button');+ collapseBtn.className = 'es-btn es-btn-icon es-btn-clear';+ collapseBtn.style.cssText = 'width:22px;height:22px;padding:0;display:flex;align-items:center;justify-content:center;flex-shrink:0;';+ collapseBtn.title = 'Collapse panel';+ collapseBtn.innerHTML = CLOSE_SVG;+ collapseBtn.addEventListener('click', () => this.setCollapsed(true));+ bar.appendChild(collapseBtn);++ this.expandedContent_.appendChild(bar);+ }++ // =========================================================================+ // State View+ // =========================================================================++ private renderStateView(container: HTMLElement, name: string, state: StateNode, inputs: InputDef[]): void {+ this.appendFieldRow(container, 'Timeline', () => {+ const input = this.createTextInput(state.timeline ?? '', (val) => {+ this.callbacks_.onStateChanged(name, 'timeline', val || undefined);+ });+ input.placeholder = 'path/to/timeline';+ return input;+ });++ this.appendFieldRow(container, 'Wrap Mode', () => {+ return this.createSelect(WRAP_MODE_OPTIONS, state.timelineWrapMode ?? 'loop', (val) => {+ this.callbacks_.onStateChanged(name, 'timelineWrapMode', val);+ });+ });++ this.renderCollapsibleSection(container, 'properties', 'Properties', state.properties ? Object.keys(state.properties).length : 0, (body) => {+ this.renderPropertiesContent(body, name, state.properties ?? {});+ }, () => {+ const existing = state.properties ?? {};+ let key = 'newProperty';+ let i = 1;+ while (key in existing) { key = `newProperty${i++}`; }+ this.callbacks_.onAddProperty(name, key);+ });++ this.renderCollapsibleSection(container, 'transitions', 'Transitions', state.transitions?.length ?? 0, (body) => {+ this.renderTransitionsListContent(body, name, state.transitions ?? []);+ });+ }++ private renderPropertiesContent(container: HTMLElement, stateName: string, properties: Record<string, unknown>): void {+ for (const [key, value] of Object.entries(properties)) {+ const row = document.createElement('div');+ row.style.cssText = 'display:flex;align-items:center;gap:4px;padding:2px 0;';++ const keyInput = document.createElement('input');+ keyInput.className = 'es-input';+ keyInput.style.cssText = 'flex:1;min-width:0;font-size:11px;padding:2px 4px;height:20px;';+ keyInput.value = key;+ keyInput.addEventListener('change', () => {+ const newKey = keyInput.value.trim();+ if (newKey && newKey !== key && !(newKey in properties)) {+ this.callbacks_.onRenameProperty(stateName, key, newKey);+ } else {+ keyInput.value = key;+ }+ });++ const valInput = document.createElement('input');+ valInput.className = 'es-input';+ valInput.style.cssText = 'width:64px;flex-shrink:0;font-size:11px;padding:2px 4px;height:20px;';+ valInput.value = String(value ?? '');+ valInput.addEventListener('change', () => {+ this.callbacks_.onPropertyValueChanged(stateName, key, parsePropertyValue(valInput.value));+ });++ const removeBtn = this.createRemoveBtn();+ removeBtn.addEventListener('click', () => {+ this.callbacks_.onRemoveProperty(stateName, key);+ });++ row.appendChild(keyInput);+ row.appendChild(valInput);+ row.appendChild(removeBtn);+ container.appendChild(row);+ }++ if (Object.keys(properties).length === 0) {+ this.appendEmptyHint(container, 'No properties');+ }+ }++ private renderTransitionsListContent(container: HTMLElement, stateName: string, transitions: Transition[]): void {+ for (let i = 0; i < transitions.length; i++) {+ const t = transitions[i];+ const row = document.createElement('div');+ row.style.cssText = 'display:flex;align-items:center;gap:4px;padding:3px 4px;border-radius:3px;cursor:pointer;font-size:11px;color:var(--es-text-primary, #ddd);';+ row.addEventListener('mouseenter', () => { row.style.background = 'var(--es-bg-hover, #333)'; });+ row.addEventListener('mouseleave', () => { row.style.background = ''; });++ const arrow = document.createElement('span');+ arrow.style.cssText = 'color:var(--es-text-muted, #888);flex-shrink:0;';+ arrow.textContent = '\u2192';++ const label = document.createElement('span');+ label.style.cssText = 'flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';+ const parts = [t.target];+ if (t.duration > 0) parts.push(`${t.duration}s`);+ if (t.conditions?.length > 0) parts.push(`${t.conditions.length} cond`);+ label.textContent = parts.join(' ');++ row.appendChild(arrow);+ row.appendChild(label);++ const idx = i;+ row.addEventListener('click', () => this.callbacks_.onSelectTransition(stateName, idx));+ container.appendChild(row);+ }++ if (transitions.length === 0) {+ this.appendEmptyHint(container, 'No transitions');+ }+ }++ // =========================================================================+ // Transition View+ // =========================================================================++ private renderTransitionView(container: HTMLElement, fromState: string, targetState: string, index: number, transition: Transition, inputs: InputDef[]): void {+ this.appendFieldRow(container, 'Duration', () => {+ return this.createNumberInput(transition.duration, (val) => {+ this.callbacks_.onTransitionChanged(fromState, index, 'duration', val);+ }, 's');+ });++ this.appendFieldRow(container, 'Exit Time', () => {+ return this.createNumberInput(transition.exitTime ?? 0, (val) => {+ this.callbacks_.onTransitionChanged(fromState, index, 'exitTime', val > 0 ? val : undefined);+ }, 'none');+ });++ this.appendFieldRow(container, 'Easing', () => {+ return this.createSelect(EASING_OPTIONS, transition.easing ?? 'linear', (val) => {+ this.callbacks_.onTransitionChanged(fromState, index, 'easing', val === 'linear' ? undefined : val);+ });+ });++ this.renderCollapsibleSection(container, 'conditions', 'Conditions', transition.conditions?.length ?? 0, (body) => {+ this.renderConditionsContent(body, fromState, index, transition.conditions ?? [], inputs);+ }, () => {+ this.callbacks_.onAddTransitionCondition(fromState, index);+ });+ }++ private renderConditionsContent(container: HTMLElement, fromState: string, transitionIndex: number, conditions: Condition[], inputs: InputDef[]): void {+ const inputNames = inputs.map(i => i.name);++ for (let i = 0; i < conditions.length; i++) {+ const c = conditions[i];+ const row = document.createElement('div');+ row.style.cssText = 'display:flex;align-items:center;gap:3px;padding:2px 0;';++ const nameSelect = this.createMiniSelect(+ inputNames.length > 0 ? inputNames : [c.inputName || ''],+ c.inputName || '',+ );+ nameSelect.style.cssText += 'flex:1;min-width:0;';+ nameSelect.addEventListener('change', () => {+ this.callbacks_.onTransitionChanged(fromState, transitionIndex, `conditions.${i}.inputName`, nameSelect.value);+ });++ const compSelect = this.createMiniSelect(+ COMPARATOR_OPTIONS,+ c.comparator || 'eq',+ COMPARATOR_LABELS,+ );+ compSelect.style.cssText += 'width:40px;flex-shrink:0;text-align:center;';+ compSelect.addEventListener('change', () => {+ this.callbacks_.onTransitionChanged(fromState, transitionIndex, `conditions.${i}.comparator`, compSelect.value);+ });++ const valInput = document.createElement('input');+ valInput.className = 'es-input';+ valInput.style.cssText = 'width:40px;flex-shrink:0;font-size:11px;padding:2px 4px;height:20px;';+ valInput.value = String(c.value ?? '');+ valInput.addEventListener('change', () => {+ this.callbacks_.onTransitionChanged(fromState, transitionIndex, `conditions.${i}.value`, parsePropertyValue(valInput.value));+ });++ const removeBtn = this.createRemoveBtn();+ const ci = i;+ removeBtn.addEventListener('click', () => {+ this.callbacks_.onRemoveTransitionCondition(fromState, transitionIndex, ci);+ });++ row.appendChild(nameSelect);+ row.appendChild(compSelect);+ row.appendChild(valInput);+ row.appendChild(removeBtn);+ container.appendChild(row);+ }++ if (conditions.length === 0) {+ this.appendEmptyHint(container, 'No conditions (always fires)');+ }+ }++ // =========================================================================+ // Reusable Layout Components+ // =========================================================================++ private appendFieldRow(container: HTMLElement, label: string, createControl: () => HTMLElement): void {+ const row = document.createElement('div');+ row.style.cssText = 'display:flex;align-items:center;gap:8px;margin-bottom:6px;';++ const labelEl = document.createElement('span');+ labelEl.style.cssText = 'width:72px;flex-shrink:0;font-size:11px;color:var(--es-text-secondary, #aaa);';+ labelEl.textContent = label;++ const control = createControl();+ control.style.cssText += ';flex:1;min-width:0;';++ row.appendChild(labelEl);+ row.appendChild(control);+ container.appendChild(row);+ }++ private renderCollapsibleSection(+ container: HTMLElement,+ id: string,+ title: string,+ count: number,+ renderBody: (body: HTMLElement) => void,+ onAdd?: () => void,+ ): void {+ const expanded = !this.collapsedSections_.has(id);++ const section = document.createElement('div');+ section.style.cssText = 'margin-top:8px;';++ const header = document.createElement('div');+ header.style.cssText = 'display:flex;align-items:center;gap:4px;padding:4px 0;cursor:pointer;user-select:none;';+ header.addEventListener('mouseenter', () => { header.style.background = 'var(--es-bg-hover, #333)'; });+ header.addEventListener('mouseleave', () => { header.style.background = ''; });++ const chevron = document.createElement('span');+ chevron.style.cssText = `display:flex;align-items:center;transition:transform 0.15s;transform:rotate(${expanded ? '90deg' : '0deg'});color:var(--es-text-muted, #888);`;+ chevron.innerHTML = CHEVRON_RIGHT_SVG;++ const labelEl = document.createElement('span');+ labelEl.style.cssText = 'flex:1;font-size:11px;font-weight:600;color:var(--es-text-secondary, #ccc);';+ labelEl.textContent = title;++ const badge = document.createElement('span');+ badge.style.cssText = 'font-size:10px;color:var(--es-text-muted, #888);margin-right:2px;';+ badge.textContent = count > 0 ? String(count) : '';++ header.appendChild(chevron);+ header.appendChild(labelEl);+ header.appendChild(badge);++ if (onAdd) {+ const addBtn = document.createElement('button');+ addBtn.className = 'es-btn es-btn-icon es-btn-clear';+ addBtn.style.cssText = 'font-size:13px;width:18px;height:18px;line-height:18px;padding:0;flex-shrink:0;';+ addBtn.textContent = '+';+ addBtn.title = `Add`;+ addBtn.addEventListener('click', (e) => { e.stopPropagation(); onAdd(); });+ header.appendChild(addBtn);+ }++ const body = document.createElement('div');+ body.style.cssText = `padding:2px 0 2px 18px;${expanded ? '' : 'display:none;'}`;++ header.addEventListener('click', () => {+ const isExpanded = body.style.display !== 'none';+ body.style.display = isExpanded ? 'none' : 'block';+ chevron.style.transform = isExpanded ? 'rotate(0deg)' : 'rotate(90deg)';+ if (isExpanded) this.collapsedSections_.add(id);+ else this.collapsedSections_.delete(id);+ });++ if (expanded) renderBody(body);+ else renderBody(body);++ section.appendChild(header);+ section.appendChild(body);+ container.appendChild(section);+ }++ // =========================================================================+ // DOM Helpers+ // =========================================================================++ private appendEmptyHint(container: HTMLElement, text: string): void {+ const el = document.createElement('div');+ el.style.cssText = 'color:var(--es-text-muted, #666);font-size:10px;font-style:italic;padding:2px 0;';+ el.textContent = text;+ container.appendChild(el);+ }++ private createTextInput(value: string, onChange: (val: string) => void): HTMLInputElement {+ const input = document.createElement('input');+ input.className = 'es-input';+ input.style.cssText = 'font-size:11px;padding:2px 6px;height:22px;box-sizing:border-box;';+ input.value = value;+ input.addEventListener('change', () => onChange(input.value));+ return input;+ }++ private createNumberInput(value: number, onChange: (val: number) => void, suffix?: string): HTMLElement {+ const wrap = document.createElement('div');+ wrap.style.cssText = 'display:flex;align-items:center;gap:4px;';++ const input = document.createElement('input');+ input.className = 'es-input es-input-number';+ input.type = 'number';+ input.step = '0.01';+ input.style.cssText = 'font-size:11px;padding:2px 6px;height:22px;box-sizing:border-box;flex:1;min-width:0;';+ input.value = value ? String(value) : '';+ if (suffix === 'none') input.placeholder = 'none';+ input.addEventListener('change', () => onChange(parseFloat(input.value) || 0));+ wrap.appendChild(input);++ if (suffix && suffix !== 'none') {+ const s = document.createElement('span');+ s.style.cssText = 'font-size:10px;color:var(--es-text-muted, #888);flex-shrink:0;';+ s.textContent = suffix;+ wrap.appendChild(s);+ }++ return wrap;+ }++ private createSelect(options: string[], value: string, onChange: (val: string) => void): HTMLSelectElement {+ const sel = document.createElement('select');+ sel.className = 'es-input es-input-select';+ sel.style.cssText = 'font-size:11px;padding:2px 4px;height:22px;box-sizing:border-box;';+ for (const opt of options) {+ const o = document.createElement('option');+ o.value = opt;+ o.textContent = opt;+ sel.appendChild(o);+ }+ sel.value = value;+ sel.addEventListener('change', () => onChange(sel.value));+ return sel;+ }++ private createMiniSelect(options: string[], value: string, labels?: Record<string, string>): HTMLSelectElement {+ const sel = document.createElement('select');+ sel.className = 'es-input es-input-select';+ sel.style.cssText = 'font-size:11px;padding:1px 2px;height:20px;box-sizing:border-box;';+ for (const opt of options) {+ const o = document.createElement('option');+ o.value = opt;+ o.textContent = labels?.[opt] ?? opt;+ sel.appendChild(o);+ }+ sel.value = value;+ return sel;+ }++ private createRemoveBtn(): HTMLButtonElement {+ const btn = document.createElement('button');+ btn.className = 'es-btn es-btn-icon es-btn-clear';+ btn.title = 'Remove';+ btn.innerHTML = REMOVE_SVG;+ btn.style.cssText = 'flex-shrink:0;width:16px;height:16px;padding:0;';+ return btn;+ }+}++function parsePropertyValue(raw: string): unknown {+ if (raw === 'true') return true;+ if (raw === 'false') return false;+ const num = Number(raw);+ if (!isNaN(num) && raw.trim() !== '') return num;+ return raw;+}diff --git a/editor/src/panels/state-machine-graph/GraphSidePanel.ts b/editor/src/panels/state-machine-graph/GraphSidePanel.tsnew file mode 100644index 000000000..86280bff5--- /dev/null+++ b/editor/src/panels/state-machine-graph/GraphSidePanel.ts@@ -0,0 +1,342 @@+import { showContextMenu } from '../../ui/ContextMenu';++const REMOVE_SVG = `<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>`;++const SIDE_WIDTH = 200;++const EVENT_OPTIONS = ['pointerEnter', 'pointerExit', 'pointerDown', 'pointerUp'];+const ACTION_OPTIONS = ['set', 'reset', 'toggle'];++interface InputDef {+ name: string;+ type: 'bool' | 'number' | 'trigger';+ defaultValue?: boolean | number;+}++interface ListenerDef {+ event: string;+ inputName: string;+ action: string;+ value?: boolean | number;+}++export interface SidePanelCallbacks {+ onAddInput(type: 'bool' | 'number' | 'trigger'): void;+ onRemoveInput(index: number): void;+ onUpdateInput(index: number, field: 'name' | 'type' | 'defaultValue', value: unknown): void;+ onAddListener(): void;+ onRemoveListener(index: number): void;+ onUpdateListener(index: number, field: 'event' | 'inputName' | 'action', value: string): void;+}++type TabId = 'inputs' | 'listeners';++export class GraphSidePanel {+ private el_: HTMLElement;+ private contentEl_: HTMLElement;+ private callbacks_: SidePanelCallbacks;+ private activeTab_: TabId | null = null;+ private inputsTabBtn_: HTMLButtonElement;+ private listenersTabBtn_: HTMLButtonElement;++ private inputs_: InputDef[] = [];+ private listeners_: ListenerDef[] = [];++ constructor(+ tabBar: HTMLElement,+ bodyRow: HTMLElement,+ callbacks: SidePanelCallbacks,+ ) {+ this.callbacks_ = callbacks;++ this.inputsTabBtn_ = this.createTabButton(tabBar, 'Inputs', 'inputs');+ this.listenersTabBtn_ = this.createTabButton(tabBar, 'Listeners', 'listeners');++ this.el_ = document.createElement('div');+ this.el_.style.cssText = `display:none;width:${SIDE_WIDTH}px;height:100%;flex-shrink:0;background:var(--es-bg-secondary, #252526);border-right:1px solid var(--es-border, #333);overflow:hidden;`;+ bodyRow.insertBefore(this.el_, bodyRow.firstChild);++ this.contentEl_ = document.createElement('div');+ this.contentEl_.style.cssText = 'height:100%;overflow-y:auto;overflow-x:hidden;padding:8px;';+ this.el_.appendChild(this.contentEl_);+ }++ get visible(): boolean {+ return this.activeTab_ !== null;+ }++ dispose(): void {+ this.el_.remove();+ this.inputsTabBtn_.remove();+ this.listenersTabBtn_.remove();+ }++ update(inputs: InputDef[], listeners: ListenerDef[]): void {+ this.inputs_ = inputs;+ this.listeners_ = listeners;+ this.updateBadges();+ if (this.activeTab_) this.renderContent();+ }++ private createTabButton(tabBar: HTMLElement, label: string, tab: TabId): HTMLButtonElement {+ const btn = document.createElement('button');+ btn.className = 'es-btn es-btn-clear';+ btn.style.cssText = 'font-size:11px;padding:2px 10px;height:24px;border-radius:3px;color:var(--es-text-muted, #888);position:relative;';++ const textSpan = document.createElement('span');+ textSpan.textContent = label;+ btn.appendChild(textSpan);++ const badge = document.createElement('span');+ badge.className = 'es-side-tab-badge';+ badge.style.cssText = 'font-size:9px;color:var(--es-text-muted, #666);margin-left:3px;';+ btn.appendChild(badge);++ btn.addEventListener('click', () => this.toggleTab(tab));+ tabBar.appendChild(btn);+ return btn;+ }++ private updateBadges(): void {+ const iBadge = this.inputsTabBtn_.querySelector('.es-side-tab-badge') as HTMLElement;+ const lBadge = this.listenersTabBtn_.querySelector('.es-side-tab-badge') as HTMLElement;+ if (iBadge) iBadge.textContent = this.inputs_.length > 0 ? String(this.inputs_.length) : '';+ if (lBadge) lBadge.textContent = this.listeners_.length > 0 ? String(this.listeners_.length) : '';+ }++ private toggleTab(tab: TabId): void {+ if (this.activeTab_ === tab) {+ this.activeTab_ = null;+ this.el_.style.display = 'none';+ this.inputsTabBtn_.style.color = 'var(--es-text-muted, #888)';+ this.listenersTabBtn_.style.color = 'var(--es-text-muted, #888)';+ } else {+ this.activeTab_ = tab;+ this.el_.style.display = 'block';+ this.inputsTabBtn_.style.color = tab === 'inputs' ? 'var(--es-text-primary, #ddd)' : 'var(--es-text-muted, #888)';+ this.listenersTabBtn_.style.color = tab === 'listeners' ? 'var(--es-text-primary, #ddd)' : 'var(--es-text-muted, #888)';+ this.renderContent();+ }+ }++ private renderContent(): void {+ this.contentEl_.innerHTML = '';+ if (this.activeTab_ === 'inputs') {+ this.renderInputs();+ } else if (this.activeTab_ === 'listeners') {+ this.renderListeners();+ }+ }++ // =========================================================================+ // Inputs+ // =========================================================================++ private renderInputs(): void {+ const header = this.createSectionHeader('Inputs', (e) => {+ showContextMenu({+ x: e.clientX,+ y: e.clientY,+ items: [+ { label: 'Bool', onClick: () => this.callbacks_.onAddInput('bool') },+ { label: 'Number', onClick: () => this.callbacks_.onAddInput('number') },+ { label: 'Trigger', onClick: () => this.callbacks_.onAddInput('trigger') },+ ],+ });+ });+ this.contentEl_.appendChild(header);++ if (this.inputs_.length === 0) {+ this.appendEmptyHint('No inputs defined');+ return;+ }++ for (let i = 0; i < this.inputs_.length; i++) {+ this.renderInputRow(i, this.inputs_[i]);+ }+ }++ private renderInputRow(index: number, input: InputDef): void {+ const row = document.createElement('div');+ row.style.cssText = 'display:flex;align-items:center;gap:4px;padding:3px 0;';++ if (input.type === 'bool') {+ const cb = document.createElement('input');+ cb.type = 'checkbox';+ cb.checked = !!input.defaultValue;+ cb.style.cssText = 'flex-shrink:0;margin:0;';+ cb.addEventListener('change', () => {+ this.callbacks_.onUpdateInput(index, 'defaultValue', cb.checked);+ });+ row.appendChild(cb);+ } else if (input.type === 'number') {+ const num = document.createElement('input');+ num.className = 'es-input es-input-number';+ num.type = 'number';+ num.step = '0.1';+ num.style.cssText = 'width:40px;flex-shrink:0;font-size:10px;padding:1px 3px;height:18px;';+ num.value = String(input.defaultValue ?? 0);+ num.addEventListener('change', () => {+ this.callbacks_.onUpdateInput(index, 'defaultValue', parseFloat(num.value) || 0);+ });+ row.appendChild(num);+ } else {+ const trigBtn = document.createElement('button');+ trigBtn.className = 'es-btn es-btn-clear';+ trigBtn.style.cssText = 'width:18px;height:18px;padding:0;flex-shrink:0;font-size:10px;line-height:18px;';+ trigBtn.textContent = '\u25B6';+ trigBtn.title = 'Fire trigger';+ row.appendChild(trigBtn);+ }++ const nameInput = document.createElement('input');+ nameInput.className = 'es-input';+ nameInput.style.cssText = 'flex:1;min-width:0;font-size:11px;padding:1px 4px;height:18px;';+ nameInput.value = input.name;+ nameInput.addEventListener('change', () => {+ const newName = nameInput.value.trim();+ if (newName && newName !== input.name) {+ this.callbacks_.onUpdateInput(index, 'name', newName);+ } else {+ nameInput.value = input.name;+ }+ });+ row.appendChild(nameInput);++ const badge = document.createElement('span');+ badge.style.cssText = 'font-size:9px;color:var(--es-text-muted, #666);flex-shrink:0;padding:1px 4px;border-radius:2px;background:var(--es-bg-tertiary, #2d2d2d);';+ badge.textContent = input.type;+ row.appendChild(badge);++ const removeBtn = this.createRemoveBtn(() => {+ this.callbacks_.onRemoveInput(index);+ });+ row.appendChild(removeBtn);++ this.contentEl_.appendChild(row);+ }++ // =========================================================================+ // Listeners+ // =========================================================================++ private renderListeners(): void {+ const header = this.createSectionHeader('Listeners', () => {+ this.callbacks_.onAddListener();+ });+ this.contentEl_.appendChild(header);++ if (this.listeners_.length === 0) {+ this.appendEmptyHint('No listeners defined');+ return;+ }++ for (let i = 0; i < this.listeners_.length; i++) {+ this.renderListenerRow(i, this.listeners_[i]);+ }+ }++ private renderListenerRow(index: number, listener: ListenerDef): void {+ const row = document.createElement('div');+ row.style.cssText = 'padding:4px 0;border-bottom:1px solid var(--es-border, #333);';++ const eventSel = this.createSmallSelect(EVENT_OPTIONS, listener.event, (val) => {+ this.callbacks_.onUpdateListener(index, 'event', val);+ });+ eventSel.style.width = '100%';+ eventSel.style.marginBottom = '3px';+ row.appendChild(eventSel);++ const actionRow = document.createElement('div');+ actionRow.style.cssText = 'display:flex;align-items:center;gap:3px;';++ const arrow = document.createElement('span');+ arrow.style.cssText = 'color:var(--es-text-muted, #888);font-size:10px;flex-shrink:0;';+ arrow.textContent = '\u2192';+ actionRow.appendChild(arrow);++ const inputNames = this.inputs_.map(i => i.name);+ const inputSel = this.createSmallSelect(+ inputNames.length > 0 ? inputNames : ['(no inputs)'],+ listener.inputName,+ (val) => { this.callbacks_.onUpdateListener(index, 'inputName', val); },+ );+ inputSel.style.cssText += 'flex:1;min-width:0;';+ actionRow.appendChild(inputSel);++ const eq = document.createElement('span');+ eq.style.cssText = 'color:var(--es-text-muted, #888);font-size:10px;flex-shrink:0;';+ eq.textContent = '=';+ actionRow.appendChild(eq);++ const actionSel = this.createSmallSelect(ACTION_OPTIONS, listener.action, (val) => {+ this.callbacks_.onUpdateListener(index, 'action', val);+ });+ actionSel.style.cssText += 'width:56px;flex-shrink:0;';+ actionRow.appendChild(actionSel);++ const removeBtn = this.createRemoveBtn(() => {+ this.callbacks_.onRemoveListener(index);+ });+ actionRow.appendChild(removeBtn);++ row.appendChild(actionRow);+ this.contentEl_.appendChild(row);+ }++ // =========================================================================+ // DOM Helpers+ // =========================================================================++ private createSectionHeader(title: string, onAdd: (e: MouseEvent) => void): HTMLElement {+ const header = document.createElement('div');+ header.style.cssText = 'display:flex;align-items:center;margin-bottom:6px;';++ const label = document.createElement('span');+ label.style.cssText = 'flex:1;font-size:11px;font-weight:600;color:var(--es-text-secondary, #ccc);text-transform:uppercase;letter-spacing:0.5px;';+ label.textContent = title;+ header.appendChild(label);++ const addBtn = document.createElement('button');+ addBtn.className = 'es-btn es-btn-clear';+ addBtn.style.cssText = 'font-size:14px;width:20px;height:20px;padding:0;line-height:20px;flex-shrink:0;';+ addBtn.textContent = '+';+ addBtn.addEventListener('click', onAdd);+ header.appendChild(addBtn);++ return header;+ }++ private createSmallSelect(options: string[], value: string, onChange: (val: string) => void): HTMLSelectElement {+ const sel = document.createElement('select');+ sel.className = 'es-input es-input-select';+ sel.style.cssText = 'font-size:10px;padding:1px 2px;height:18px;box-sizing:border-box;';+ for (const opt of options) {+ const o = document.createElement('option');+ o.value = opt;+ o.textContent = opt;+ sel.appendChild(o);+ }+ sel.value = value;+ sel.addEventListener('change', () => onChange(sel.value));+ return sel;+ }++ private createRemoveBtn(onClick: () => void): HTMLButtonElement {+ const btn = document.createElement('button');+ btn.className = 'es-btn es-btn-icon es-btn-clear';+ btn.style.cssText = 'width:16px;height:16px;padding:0;display:flex;align-items:center;justify-content:center;flex-shrink:0;opacity:0.5;';+ btn.innerHTML = REMOVE_SVG;+ btn.addEventListener('mouseenter', () => { btn.style.opacity = '1'; });+ btn.addEventListener('mouseleave', () => { btn.style.opacity = '0.5'; });+ btn.addEventListener('click', onClick);+ return btn;+ }++ private appendEmptyHint(text: string): void {+ const el = document.createElement('div');+ el.style.cssText = 'color:var(--es-text-muted, #666);font-size:10px;font-style:italic;padding:4px 0;';+ el.textContent = text;+ this.contentEl_.appendChild(el);+ }+}diff --git a/editor/src/panels/state-machine-graph/StateMachineGraphPanel.ts b/editor/src/panels/state-machine-graph/StateMachineGraphPanel.tsindex 9f040366a..a5ce5d232 100644--- a/editor/src/panels/state-machine-graph/StateMachineGraphPanel.ts+++ b/editor/src/panels/state-machine-graph/StateMachineGraphPanel.ts@@ -2,6 +2,8 @@ import type { PanelInstance } from '../PanelRegistry';import type { EditorStore } from '../../store/EditorStore';import { getPlayModeService } from '../../services/PlayModeService';import { GraphCanvas } from './GraphCanvas';+import { GraphDetailPanel } from './GraphDetailPanel';+import { GraphSidePanel } from './GraphSidePanel';import { createGraphState } from './GraphState';import {NODE_WIDTH,@@ -14,16 +16,44 @@ import {AUTO_LAYOUT_START_Y,} from './graphConstants';-interface StateMachineStates {- [name: string]: {- timeline?: string;- properties?: Record<string, unknown>;- transitions: Array<{ target: string; conditions: unknown[]; duration: number }>;- };+interface Condition {+ inputName: string;+ comparator: string;+ value: boolean | number;+}++interface Transition {+ target: string;+ conditions: Condition[];+ duration: number;+ exitTime?: number;+ easing?: string;+}++interface StateNode {+ timeline?: string;+ timelineWrapMode?: 'once' | 'loop';+ properties?: Record<string, unknown>;+ transitions: Transition[];+}++interface InputDef {+ name: string;+ type: 'bool' | 'number' | 'trigger';+ defaultValue?: boolean | number;+}++interface ListenerDef {+ event: string;+ inputName: string;+ action: string;+ value?: boolean | number;}interface StateMachineComponentData {- states: StateMachineStates;+ states: Record<string, StateNode>;+ inputs: InputDef[];+ listeners: ListenerDef[];initialState: string;_editorLayout?: Record<string, { x: number; y: number }>;}@@ -34,8 +64,12 @@ export class StateMachineGraphPanel implements PanelInstance {private graphCanvas_: GraphCanvas | null = null;private graphState_ = createGraphState();private wrapper_: HTMLElement;+ private tabBar_: HTMLElement;+ private bodyRow_: HTMLElement;private canvasContainer_: HTMLElement;private emptyEl_: HTMLElement;+ private sidePanel_: GraphSidePanel;+ private detailPanel_: GraphDetailPanel;private unsubscribe_: (() => void) | null = null;private disposePlayMode_: (() => void) | null = null;private currentEntityId_: number | null = null;@@ -49,14 +83,48 @@ export class StateMachineGraphPanel implements PanelInstance {this.wrapper_.style.cssText = 'display:flex;flex-direction:column;width:100%;height:100%;overflow:hidden;background:#1e1e1e;';container.appendChild(this.wrapper_);+ this.tabBar_ = document.createElement('div');+ this.tabBar_.style.cssText = 'display:none;align-items:center;height:28px;min-height:28px;padding:0 8px;gap:4px;background:var(--es-bg-tertiary, #2d2d2d);border-bottom:1px solid var(--es-border, #333);';+ this.wrapper_.appendChild(this.tabBar_);++ this.bodyRow_ = document.createElement('div');+ this.bodyRow_.style.cssText = 'display:flex;flex:1;min-height:0;overflow:hidden;';+ this.wrapper_.appendChild(this.bodyRow_);+this.emptyEl_ = document.createElement('div');- this.emptyEl_.style.cssText = 'display:flex;align-items:center;justify-content:center;height:100%;color:#666;font-size:13px;';+ this.emptyEl_.style.cssText = 'display:none;position:absolute;inset:0;align-items:center;justify-content:center;color:#666;font-size:13px;z-index:1;';this.emptyEl_.textContent = 'Select an entity with a StateMachine component';- this.wrapper_.appendChild(this.emptyEl_);+ this.bodyRow_.appendChild(this.emptyEl_);++ this.sidePanel_ = new GraphSidePanel(this.tabBar_, this.bodyRow_, {+ onAddInput: (type) => this.addInput(type),+ onRemoveInput: (index) => this.removeInput(index),+ onUpdateInput: (index, field, value) => this.updateInput(index, field, value),+ onAddListener: () => this.addListener(),+ onRemoveListener: (index) => this.removeListener(index),+ onUpdateListener: (index, field, value) => this.updateListener(index, field, value),+ });this.canvasContainer_ = document.createElement('div');- this.canvasContainer_.style.cssText = 'flex:1;min-height:0;position:relative;display:none;overflow:hidden;';- this.wrapper_.appendChild(this.canvasContainer_);+ this.canvasContainer_.style.cssText = 'flex:1;min-width:0;min-height:0;position:relative;display:none;overflow:hidden;';+ this.bodyRow_.appendChild(this.canvasContainer_);++ this.detailPanel_ = new GraphDetailPanel(this.bodyRow_, {+ onStateChanged: (name, field, value) => this.updateStateField(name, field, value),+ onTransitionChanged: (from, idx, field, value) => this.updateTransitionField(from, idx, field, value),+ onSelectTransition: (from, idx) => {+ this.graphState_.selectedNodes.clear();+ this.graphState_.selectedTransition = { from, index: idx };+ this.graphCanvas_?.draw();+ this.updateDetailPanel();+ },+ onAddTransitionCondition: (from, idx) => this.addTransitionCondition(from, idx),+ onRemoveTransitionCondition: (from, idx, ci) => this.removeTransitionCondition(from, idx, ci),+ onAddProperty: (name, key) => this.addStateProperty(name, key),+ onRemoveProperty: (name, key) => this.removeStateProperty(name, key),+ onRenameProperty: (name, oldKey, newKey) => this.renameStateProperty(name, oldKey, newKey),+ onPropertyValueChanged: (name, key, value) => this.updateStateProperty(name, key, value),+ });this.unsubscribe_ = store.subscribe((_state, dirtyFlags) => {if (!dirtyFlags || dirtyFlags.has('selection') || dirtyFlags.has('scene')) {@@ -79,6 +147,8 @@ export class StateMachineGraphPanel implements PanelInstance {this.unsubscribe_?.();this.disposePlayMode_?.();this.graphCanvas_?.dispose();+ this.detailPanel_.dispose();+ this.sidePanel_.dispose();this.container_.innerHTML = '';}@@ -92,12 +162,16 @@ export class StateMachineGraphPanel implements PanelInstance {if (!smData) {this.emptyEl_.style.display = 'flex';this.canvasContainer_.style.display = 'none';+ this.tabBar_.style.display = 'none';+ this.detailPanel_.hide();this.currentEntityId_ = null;return;}this.emptyEl_.style.display = 'none';this.canvasContainer_.style.display = 'block';+ this.tabBar_.style.display = 'flex';+ this.sidePanel_.update(smData.inputs ?? [], smData.listeners ?? []);if (!this.graphCanvas_) {this.graphCanvas_ = new GraphCanvas(this.canvasContainer_, this.graphState_, {@@ -125,12 +199,19 @@ export class StateMachineGraphPanel implements PanelInstance {onRenameNode: (name) => {this.promptRename(name);},- onSelectionChanged: () => {},+ onSetInitialState: (name) => {+ this.setInitialState(name);+ },+ onAddAnyState: (worldX, worldY) => {+ this.addAnyState(worldX, worldY);+ },+ onSelectionChanged: () => this.updateDetailPanel(),});}this.syncGraphState(smData);this.graphCanvas_.draw();+ this.updateDetailPanel();}private findStateMachineData(): StateMachineComponentData | null {@@ -180,15 +261,18 @@ export class StateMachineGraphPanel implements PanelInstance {this.graphState_.transitions = [];let autoIdx = 0;for (const name of stateNames) {+ const isAny = name === '__any__';if (!layouts.has(name)) {const saved = editorLayout[name];+ const w = isAny ? ENTRY_NODE_WIDTH : NODE_WIDTH;+ const h = isAny ? ENTRY_NODE_HEIGHT : NODE_HEIGHT;layouts.set(name, {- x: saved?.x ?? AUTO_LAYOUT_START_X + autoIdx * AUTO_LAYOUT_SPACING_X,- y: saved?.y ?? AUTO_LAYOUT_START_Y + (autoIdx % 2) * AUTO_LAYOUT_SPACING_Y,- width: NODE_WIDTH,- height: NODE_HEIGHT,+ x: saved?.x ?? (isAny ? 20 : AUTO_LAYOUT_START_X + autoIdx * AUTO_LAYOUT_SPACING_X),+ y: saved?.y ?? (isAny ? AUTO_LAYOUT_START_Y + ENTRY_NODE_HEIGHT + 20 : AUTO_LAYOUT_START_Y + (autoIdx % 2) * AUTO_LAYOUT_SPACING_Y),+ width: w,+ height: h,});- autoIdx++;+ if (!isAny) autoIdx++;}const stateData = data.states[name];@@ -357,6 +441,36 @@ export class StateMachineGraphPanel implements PanelInstance {}}+ private addAnyState(worldX: number, worldY: number): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || smData.states['__any__']) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ newStates['__any__'] = { transitions: [] };++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);++ const oldLayout = smData._editorLayout ?? {};+ const newLayout = { ...oldLayout, __any__: { x: Math.round(worldX), y: Math.round(worldY) } };+ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', '_editorLayout', oldLayout, newLayout);+ }++ private setInitialState(name: string): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[name]) return;++ this.store_.updateProperty(+ this.currentEntityId_,+ 'StateMachine',+ 'initialState',+ smData.initialState,+ name,+ );+ }+private promptRename(oldName: string): void {const newName = prompt('Rename state:', oldName);if (!newName || newName === oldName) return;@@ -422,6 +536,240 @@ export class StateMachineGraphPanel implements PanelInstance {}}+ // =========================================================================+ // Detail Panel+ // =========================================================================++ private updateDetailPanel(): void {+ const smData = this.findStateMachineData();+ if (!smData) {+ this.detailPanel_.hide();+ return;+ }++ const sel = this.graphState_;++ if (sel.selectedTransition) {+ const { from, index } = sel.selectedTransition;+ const state = smData.states[from];+ const t = state?.transitions?.[index];+ if (t) {+ this.detailPanel_.showTransition(from, t.target, index, t, smData.inputs ?? []);+ return;+ }+ }++ if (sel.selectedNodes.size === 1) {+ const name = sel.selectedNodes.values().next().value as string;+ if (name !== '__entry__' && smData.states[name]) {+ this.detailPanel_.showState(name, smData.states[name], smData.inputs ?? []);+ return;+ }+ }++ this.detailPanel_.hide();+ }++ private updateStateField(stateName: string, field: string, value: unknown): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[stateName]) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ (newStates[stateName] as Record<string, unknown>)[field] = value;++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);+ }++ private updateTransitionField(fromState: string, transitionIndex: number, field: string, value: unknown): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[fromState]?.transitions?.[transitionIndex]) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ const t = newStates[fromState].transitions[transitionIndex];++ if (field.startsWith('conditions.')) {+ const parts = field.split('.');+ const ci = parseInt(parts[1], 10);+ const prop = parts[2];+ if (t.conditions?.[ci]) {+ (t.conditions[ci] as Record<string, unknown>)[prop] = value;+ }+ } else {+ (t as Record<string, unknown>)[field] = value;+ }++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);+ }++ private addTransitionCondition(fromState: string, transitionIndex: number): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[fromState]?.transitions?.[transitionIndex]) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ const t = newStates[fromState].transitions[transitionIndex];+ if (!t.conditions) t.conditions = [];+ const inputName = smData.inputs?.[0]?.name ?? '';+ t.conditions.push({ inputName, comparator: 'eq', value: true });++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);+ }++ private removeTransitionCondition(fromState: string, transitionIndex: number, conditionIndex: number): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[fromState]?.transitions?.[transitionIndex]) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ newStates[fromState].transitions[transitionIndex].conditions.splice(conditionIndex, 1);++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);+ }++ private addStateProperty(stateName: string, key: string): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[stateName]) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ if (!newStates[stateName].properties) newStates[stateName].properties = {};+ newStates[stateName].properties[key] = 0;++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);+ }++ private renameStateProperty(stateName: string, oldKey: string, newKey: string): void {+ if (this.currentEntityId_ === null || oldKey === newKey) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[stateName]) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ const props = newStates[stateName].properties;+ if (!props || !(oldKey in props)) return;+ props[newKey] = props[oldKey];+ delete props[oldKey];++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);+ }++ private removeStateProperty(stateName: string, key: string): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[stateName]) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ delete newStates[stateName].properties?.[key];++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);+ }++ private updateStateProperty(stateName: string, key: string, value: unknown): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData || !smData.states[stateName]) return;++ const oldStates = JSON.parse(JSON.stringify(smData.states));+ const newStates = JSON.parse(JSON.stringify(smData.states));+ if (!newStates[stateName].properties) newStates[stateName].properties = {};+ newStates[stateName].properties[key] = value;++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'states', oldStates, newStates);+ }++ // =========================================================================+ // Inputs / Listeners+ // =========================================================================++ private addInput(type: 'bool' | 'number' | 'trigger'): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData) return;++ const oldInputs = JSON.parse(JSON.stringify(smData.inputs ?? []));+ const newInputs = JSON.parse(JSON.stringify(smData.inputs ?? [])) as InputDef[];+ let name = 'newInput';+ let i = 1;+ while (newInputs.some(inp => inp.name === name)) { name = `newInput${i++}`; }+ const defaultValue = type === 'bool' ? false : 0;+ newInputs.push({ name, type, defaultValue });++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'inputs', oldInputs, newInputs);+ }++ private removeInput(index: number): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData) return;++ const oldInputs = JSON.parse(JSON.stringify(smData.inputs ?? []));+ const newInputs = JSON.parse(JSON.stringify(smData.inputs ?? [])) as InputDef[];+ newInputs.splice(index, 1);++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'inputs', oldInputs, newInputs);+ }++ private updateInput(index: number, field: 'name' | 'type' | 'defaultValue', value: unknown): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData) return;++ const oldInputs = JSON.parse(JSON.stringify(smData.inputs ?? []));+ const newInputs = JSON.parse(JSON.stringify(smData.inputs ?? [])) as InputDef[];+ if (!newInputs[index]) return;+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ (newInputs[index] as any)[field] = value;++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'inputs', oldInputs, newInputs);+ }++ private addListener(): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData) return;++ const oldListeners = JSON.parse(JSON.stringify(smData.listeners ?? []));+ const newListeners = JSON.parse(JSON.stringify(smData.listeners ?? [])) as ListenerDef[];+ const firstInput = (smData.inputs ?? [])[0]?.name ?? '';+ newListeners.push({ event: 'pointerDown', inputName: firstInput, action: 'set' });++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'listeners', oldListeners, newListeners);+ }++ private removeListener(index: number): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData) return;++ const oldListeners = JSON.parse(JSON.stringify(smData.listeners ?? []));+ const newListeners = JSON.parse(JSON.stringify(smData.listeners ?? [])) as ListenerDef[];+ newListeners.splice(index, 1);++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'listeners', oldListeners, newListeners);+ }++ private updateListener(index: number, field: 'event' | 'inputName' | 'action', value: string): void {+ if (this.currentEntityId_ === null) return;+ const smData = this.findStateMachineData();+ if (!smData) return;++ const oldListeners = JSON.parse(JSON.stringify(smData.listeners ?? []));+ const newListeners = JSON.parse(JSON.stringify(smData.listeners ?? [])) as ListenerDef[];+ if (!newListeners[index]) return;+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ (newListeners[index] as any)[field] = value;++ this.store_.updateProperty(this.currentEntityId_, 'StateMachine', 'listeners', oldListeners, newListeners);+ }+private saveEditorLayout(updates: Record<string, { x: number; y: number }>): void {if (this.currentEntityId_ === null) return;diff --git a/editor/src/panels/state-machine-graph/graphConstants.ts b/editor/src/panels/state-machine-graph/graphConstants.tsindex 594a3bd70..7a7b031e4 100644--- a/editor/src/panels/state-machine-graph/graphConstants.ts+++ b/editor/src/panels/state-machine-graph/graphConstants.ts@@ -1,12 +1,12 @@-export const NODE_WIDTH = 160;-export const NODE_HEIGHT = 48;-export const NODE_HEADER_HEIGHT = 24;-export const NODE_BORDER_RADIUS = 6;+export const NODE_WIDTH = 150;+export const NODE_HEIGHT = 44;+export const NODE_HEADER_HEIGHT = 22;+export const NODE_BORDER_RADIUS = 10;export const NODE_FONT_SIZE = 12;export const NODE_SUBTITLE_FONT_SIZE = 10;-export const ENTRY_NODE_WIDTH = 80;-export const ENTRY_NODE_HEIGHT = 32;+export const ENTRY_NODE_WIDTH = 72;+export const ENTRY_NODE_HEIGHT = 30;export const GRID_SIZE = 20;export const GRID_DOT_RADIUS = 1;@@ -21,26 +21,30 @@ export const MAX_ZOOM = 3;export const ZOOM_SPEED = 0.001;export const COLORS = {- background: '#1e1e1e',- gridDot: '#333333',+ background: '#1a1a1a',+ gridDot: '#2a2a2a',- nodeFill: '#2d2d2d',- nodeHeader: '#3c3c3c',- nodeText: '#cccccc',- nodeSubtext: '#888888',- nodeBorder: '#444444',- nodeSelectedBorder: '#4a9eff',+ nodeFill: '#3d3d3d',+ nodeHeader: '#4a4a4a',+ nodeText: '#e0e0e0',+ nodeSubtext: '#999999',+ nodeBorder: '#555555',+ nodeSelectedBorder: '#57a5ff',- entryFill: '#1b3a2a',+ entryFill: '#2a5a3a',entryHeader: '#2a5a3a',- entryBorder: '#3a7a4a',- entryText: '#88cc88',+ entryBorder: '#4a9a5a',+ entryText: '#a0dda0',- connectionLine: '#666666',- connectionSelected: '#4a9eff',- connectionPending: '#4a9eff',+ anyFill: '#3a2a5a',+ anyBorder: '#6a4a9a',+ anyText: '#b0a0dd',- connectorFill: '#4a9eff',+ connectionLine: '#777777',+ connectionSelected: '#57a5ff',+ connectionPending: '#57a5ff',++ connectorFill: '#57a5ff',connectorStroke: '#ffffff',playModeActive: '#ff8833',diff --git a/sdk/src/ui/StateMachinePlugin.ts b/sdk/src/ui/StateMachinePlugin.tsindex d37e9734a..bddeaa1ab 100644--- a/sdk/src/ui/StateMachinePlugin.ts+++ b/sdk/src/ui/StateMachinePlugin.ts@@ -262,11 +262,16 @@ export class StateMachinePlugin implements Plugin {}}- // Evaluate transitions+ // Evaluate transitions (current state first, then __any__)const currentState = data.states[runtime.currentState];if (!currentState) continue;- for (const transition of currentState.transitions) {+ const anyState = data.states['__any__'];+ const allTransitions = anyState+ ? [...currentState.transitions, ...anyState.transitions]+ : currentState.transitions;++ for (const transition of allTransitions) {// exitTime gating (for timeline states)if (transition.exitTime !== undefined && transition.exitTime > 0) {if (runtime.timelineHandle && module && runtime.timelineDuration > 0) {