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 { ToolMode } from "../core/tool-mode";
import type { SceneDocument } from "../document/scene-document"; import type { SceneDocument } from "../document/scene-document";
import type { WorldSettings } from "../document/world-settings"; import type { WorldSettings } from "../document/world-settings";
import type { RuntimeClockState } from "../runtime-three/runtime-project-time"; import type { EditorSimulationController } from "../runtime-three/editor-simulation-controller";
import type { RuntimeSceneDefinition } from "../runtime-three/runtime-scene-build";
interface ViewportPanelProps { interface ViewportPanelProps {
panelId: ViewportPanelId; panelId: ViewportPanelId;
@@ -54,8 +53,7 @@ interface ViewportPanelProps {
style?: CSSProperties; style?: CSSProperties;
world: WorldSettings; world: WorldSettings;
sceneDocument: SceneDocument; sceneDocument: SceneDocument;
editorSimulationScene: RuntimeSceneDefinition | null; editorSimulationController: EditorSimulationController;
editorSimulationClock: RuntimeClockState | null;
projectAssets: Record<string, ProjectAssetRecord>; projectAssets: Record<string, ProjectAssetRecord>;
loadedModelAssets: Record<string, LoadedModelAsset>; loadedModelAssets: Record<string, LoadedModelAsset>;
loadedImageAssets: Record<string, LoadedImageAsset>; loadedImageAssets: Record<string, LoadedImageAsset>;
@@ -131,8 +129,7 @@ export function ViewportPanel({
style, style,
world, world,
sceneDocument, sceneDocument,
editorSimulationScene, editorSimulationController,
editorSimulationClock,
projectAssets, projectAssets,
loadedModelAssets, loadedModelAssets,
loadedImageAssets, loadedImageAssets,
@@ -197,8 +194,7 @@ export function ViewportPanel({
panelId={panelId} panelId={panelId}
world={world} world={world}
sceneDocument={sceneDocument} sceneDocument={sceneDocument}
editorSimulationScene={editorSimulationScene} editorSimulationController={editorSimulationController}
editorSimulationClock={editorSimulationClock}
projectAssets={projectAssets} projectAssets={projectAssets}
loadedModelAssets={loadedModelAssets} loadedModelAssets={loadedModelAssets}
loadedImageAssets={loadedImageAssets} loadedImageAssets={loadedImageAssets}

View File

@@ -1,7 +1,10 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { createPlayerStartInputBindings } from "../../src/entities/entity-instances"; 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 { function createMockGamepad(pressedButtons: number[] = []): Gamepad {
return { return {
@@ -51,3 +54,34 @@ describe("player-input-bindings pause input", () => {
).toBe(1); ).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);
});
});