Improve pointer lock handling and context usage across runtime components
This commit is contained in:
@@ -705,6 +705,7 @@ describe("validateSceneDocument", () => {
|
||||
interactionAngleDegrees: Number.NaN,
|
||||
allowLookInputTargetSwitch: "yes" as unknown as boolean,
|
||||
targetButtonCyclesActiveTarget: 1 as unknown as boolean,
|
||||
invertMouseCameraHorizontal: "yes" as unknown as boolean,
|
||||
movementTemplate: {
|
||||
kind: "invalidTemplate",
|
||||
moveSpeed: 0,
|
||||
|
||||
@@ -191,7 +191,7 @@ describe("RuntimeHost", () => {
|
||||
message: null
|
||||
});
|
||||
expect(runtimeMessages).toContain(
|
||||
"Third Person active. Drag to orbit the camera, use the right stick for gamepad camera look, move with your authored bindings, and scroll to zoom."
|
||||
"Third Person active. Click inside the runner viewport to capture mouse look, or drag to orbit if pointer lock is unavailable. Scroll to zoom and use the right stick for gamepad camera look."
|
||||
);
|
||||
});
|
||||
|
||||
@@ -3889,6 +3889,66 @@ describe("RuntimeHost", () => {
|
||||
host.dispose();
|
||||
});
|
||||
|
||||
it("clears active target when third-person Escape releases pointer lock", () => {
|
||||
const host = new RuntimeHost({
|
||||
enableRendering: false
|
||||
});
|
||||
const hostInternals = host as unknown as {
|
||||
runtimeScene: unknown;
|
||||
activeController: unknown;
|
||||
thirdPersonController: unknown;
|
||||
activeRuntimeTargetReference: {
|
||||
kind: "npc" | "interactable";
|
||||
entityId: string;
|
||||
} | null;
|
||||
domElement: HTMLCanvasElement;
|
||||
controllerContext: {
|
||||
setPlayerControllerTelemetry(telemetry: unknown): void;
|
||||
};
|
||||
};
|
||||
const requestPointerLock = vi.fn();
|
||||
|
||||
Object.defineProperty(hostInternals.domElement, "requestPointerLock", {
|
||||
configurable: true,
|
||||
value: requestPointerLock
|
||||
});
|
||||
|
||||
hostInternals.runtimeScene = {
|
||||
playerInputBindings: {
|
||||
keyboard: {
|
||||
clearTarget: "Escape"
|
||||
}
|
||||
},
|
||||
entities: {
|
||||
cameraRigs: [],
|
||||
interactables: [],
|
||||
npcs: []
|
||||
}
|
||||
} as never;
|
||||
hostInternals.activeController = hostInternals.thirdPersonController;
|
||||
hostInternals.activeRuntimeTargetReference = {
|
||||
kind: "npc",
|
||||
entityId: "npc-active"
|
||||
};
|
||||
|
||||
hostInternals.controllerContext.setPlayerControllerTelemetry({
|
||||
pointerLocked: true,
|
||||
hooks: {
|
||||
audio: null
|
||||
}
|
||||
});
|
||||
hostInternals.controllerContext.setPlayerControllerTelemetry({
|
||||
pointerLocked: false,
|
||||
hooks: {
|
||||
audio: null
|
||||
}
|
||||
});
|
||||
|
||||
expect(hostInternals.activeRuntimeTargetReference).toBeNull();
|
||||
expect(requestPointerLock).toHaveBeenCalledTimes(1);
|
||||
host.dispose();
|
||||
});
|
||||
|
||||
it("switches an active target once from directional screen-space look input", () => {
|
||||
const host = new RuntimeHost({
|
||||
enableRendering: false
|
||||
|
||||
Reference in New Issue
Block a user