Enhance unit tests for player climbing logic, including movement detection and planar input resolution

This commit is contained in:
2026-04-30 00:33:32 +02:00
parent c6091cb31c
commit 02575c8d0f

View File

@@ -5,7 +5,9 @@ import { createEmptySceneDocument } from "../../src/document/scene-document";
import { FIRST_PERSON_PLAYER_SHAPE } from "../../src/runtime-three/player-collision";
import {
computeClimbPlaneMovement,
isClimbMovementIntoSurface,
isClimbableWallNormal,
resolveClimbPlanarInputDirection,
resolvePlayerClimbSurface,
shouldEnterClimbing,
shouldExitClimbing
@@ -79,6 +81,7 @@ describe("player climbing helpers", () => {
expect(
shouldEnterClimbing({
climbInput: 1,
movementIntoSurface: false,
surface,
jumpPressed: false
})
@@ -86,26 +89,72 @@ describe("player climbing helpers", () => {
expect(
shouldEnterClimbing({
climbInput: 0,
movementIntoSurface: true,
surface,
jumpPressed: false
})
).toBe(true);
expect(
shouldEnterClimbing({
climbInput: 0,
movementIntoSurface: false,
surface,
jumpPressed: false
})
).toBe(false);
expect(
shouldExitClimbing({
climbInput: 1,
surface,
jumpPressed: true
})
).toBe(true);
expect(
shouldExitClimbing({
climbInput: 0,
surface,
jumpPressed: false
})
).toBe(false);
expect(
shouldExitClimbing({
surface: null,
jumpPressed: false
})
).toBe(true);
});
it("treats movement into a climbable face as climb intent", () => {
const surface = {
brushId: "brush-wall",
faceId: "negZ",
point: { x: 0, y: 1, z: 0.75 },
normal: { x: 0, y: 0, z: -1 },
distance: 0.75
};
expect(
resolveClimbPlanarInputDirection(createInputState({ moveForward: 1 }), 0)
.direction
).toMatchObject({
x: 0,
y: 0,
z: 1
});
expect(
isClimbMovementIntoSurface({
input: createInputState({ moveForward: 1 }),
movementYawRadians: 0,
surface,
})
).toBe(true);
expect(
isClimbMovementIntoSurface({
input: createInputState({ moveBackward: 1 }),
movementYawRadians: 0,
surface
})
).toBe(false);
});
it("resolves only authored climbable whitebox faces in front of the player", () => {
const brush = createBoxBrush({
id: "brush-climbable-wall",