Refactor ViewportPanel to use EditorSimulationController and add unit tests for player interact input bindings

This commit is contained in:
2026-04-27 15:43:26 +02:00
parent 775cbbb976
commit 2fbe69f243
2 changed files with 39 additions and 9 deletions

View File

@@ -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<string, ProjectAssetRecord>;
loadedModelAssets: Record<string, LoadedModelAsset>;
loadedImageAssets: Record<string, LoadedImageAsset>;
@@ -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}

View File

@@ -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<string>(), bindings, [
createMockGamepad([2])
])
).toBe(1);
});
});