From 2fbe69f243449ff49f3d8b18ec2feb7a5fa5b16e Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 27 Apr 2026 15:43:26 +0200 Subject: [PATCH] Refactor ViewportPanel to use EditorSimulationController and add unit tests for player interact input bindings --- src/viewport-three/ViewportPanel.tsx | 12 +++----- tests/unit/player-input-bindings.test.ts | 36 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/viewport-three/ViewportPanel.tsx b/src/viewport-three/ViewportPanel.tsx index 47bc44cd..bfc583ea 100644 --- a/src/viewport-three/ViewportPanel.tsx +++ b/src/viewport-three/ViewportPanel.tsx @@ -42,8 +42,7 @@ import type { import type { ToolMode } from "../core/tool-mode"; import type { SceneDocument } from "../document/scene-document"; import type { WorldSettings } from "../document/world-settings"; -import type { RuntimeClockState } from "../runtime-three/runtime-project-time"; -import type { RuntimeSceneDefinition } from "../runtime-three/runtime-scene-build"; +import type { EditorSimulationController } from "../runtime-three/editor-simulation-controller"; interface ViewportPanelProps { panelId: ViewportPanelId; @@ -54,8 +53,7 @@ interface ViewportPanelProps { style?: CSSProperties; world: WorldSettings; sceneDocument: SceneDocument; - editorSimulationScene: RuntimeSceneDefinition | null; - editorSimulationClock: RuntimeClockState | null; + editorSimulationController: EditorSimulationController; projectAssets: Record; loadedModelAssets: Record; loadedImageAssets: Record; @@ -131,8 +129,7 @@ export function ViewportPanel({ style, world, sceneDocument, - editorSimulationScene, - editorSimulationClock, + editorSimulationController, projectAssets, loadedModelAssets, loadedImageAssets, @@ -197,8 +194,7 @@ export function ViewportPanel({ panelId={panelId} world={world} sceneDocument={sceneDocument} - editorSimulationScene={editorSimulationScene} - editorSimulationClock={editorSimulationClock} + editorSimulationController={editorSimulationController} projectAssets={projectAssets} loadedModelAssets={loadedModelAssets} loadedImageAssets={loadedImageAssets} diff --git a/tests/unit/player-input-bindings.test.ts b/tests/unit/player-input-bindings.test.ts index 8f0ec3ba..b08f295a 100644 --- a/tests/unit/player-input-bindings.test.ts +++ b/tests/unit/player-input-bindings.test.ts @@ -1,7 +1,10 @@ import { describe, expect, it } from "vitest"; import { createPlayerStartInputBindings } from "../../src/entities/entity-instances"; -import { resolvePlayerStartPauseInput } from "../../src/runtime-three/player-input-bindings"; +import { + resolvePlayerStartInteractInput, + resolvePlayerStartPauseInput +} from "../../src/runtime-three/player-input-bindings"; function createMockGamepad(pressedButtons: number[] = []): Gamepad { return { @@ -51,3 +54,34 @@ describe("player-input-bindings pause input", () => { ).toBe(1); }); }); + +describe("player-input-bindings interact input", () => { + it("resolves authored keyboard interact bindings", () => { + const bindings = createPlayerStartInputBindings({ + keyboard: { + interact: "KeyE" + } + }); + + expect(resolvePlayerStartInteractInput(new Set(["MouseLeft"]), bindings, [])).toBe( + 0 + ); + expect(resolvePlayerStartInteractInput(new Set(["KeyE"]), bindings, [])).toBe( + 1 + ); + }); + + it("resolves the authored gamepad interact binding from the standard west button", () => { + const bindings = createPlayerStartInputBindings({ + gamepad: { + interact: "buttonWest" + } + }); + + expect( + resolvePlayerStartInteractInput(new Set(), bindings, [ + createMockGamepad([2]) + ]) + ).toBe(1); + }); +});