Simplify interaction prompt display and handling in various components
This commit is contained in:
@@ -346,6 +346,11 @@ describe("RuntimeInteractionSystem", () => {
|
||||
y: 1.6,
|
||||
z: 0
|
||||
},
|
||||
{
|
||||
x: 0,
|
||||
y: 1.6,
|
||||
z: 0
|
||||
},
|
||||
{
|
||||
x: 0,
|
||||
y: 0,
|
||||
@@ -362,6 +367,11 @@ describe("RuntimeInteractionSystem", () => {
|
||||
|
||||
expect(
|
||||
interactionSystem.resolveClickInteractionPrompt(
|
||||
{
|
||||
x: 0,
|
||||
y: 1.6,
|
||||
z: 0
|
||||
},
|
||||
{
|
||||
x: 0,
|
||||
y: 1.6,
|
||||
@@ -377,6 +387,46 @@ describe("RuntimeInteractionSystem", () => {
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("uses the player eye for interaction range while aiming with a third-person camera ray", () => {
|
||||
const runtimeScene = createRuntimeSceneFixture();
|
||||
runtimeScene.interactionLinks = [
|
||||
createTeleportPlayerInteractionLink({
|
||||
id: "link-click-teleport",
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
trigger: "click",
|
||||
targetEntityId: "entity-teleport-main"
|
||||
})
|
||||
];
|
||||
|
||||
const interactionSystem = new RuntimeInteractionSystem();
|
||||
|
||||
expect(
|
||||
interactionSystem.resolveClickInteractionPrompt(
|
||||
{
|
||||
x: 0,
|
||||
y: 1.6,
|
||||
z: 0
|
||||
},
|
||||
{
|
||||
x: 0,
|
||||
y: 1.6,
|
||||
z: -2
|
||||
},
|
||||
{
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 1
|
||||
},
|
||||
runtimeScene
|
||||
)
|
||||
).toEqual({
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
prompt: "Use Console",
|
||||
distance: expect.any(Number),
|
||||
range: 2
|
||||
});
|
||||
});
|
||||
|
||||
it("dispatches click actions for the targeted Interactable", () => {
|
||||
const runtimeScene = createRuntimeSceneFixture();
|
||||
runtimeScene.interactionLinks = [
|
||||
@@ -483,6 +533,11 @@ describe("RuntimeInteractionSystem", () => {
|
||||
y: 1.6,
|
||||
z: 0
|
||||
},
|
||||
{
|
||||
x: 0,
|
||||
y: 1.6,
|
||||
z: 0
|
||||
},
|
||||
{
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
||||
@@ -2,70 +2,84 @@ import { expect, test } from "@playwright/test";
|
||||
|
||||
import { clickViewport, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
|
||||
test("Interactable click prompt can teleport the player in run mode", async ({ page }) => {
|
||||
const pageErrors: string[] = [];
|
||||
const consoleErrors: string[] = [];
|
||||
for (const navigationMode of [
|
||||
{
|
||||
buttonLabel: "First Person",
|
||||
name: "first-person"
|
||||
},
|
||||
{
|
||||
buttonLabel: "Third Person",
|
||||
name: "third-person"
|
||||
}
|
||||
] as const) {
|
||||
test(`Interactable click prompt can teleport the player in ${navigationMode.name} run mode`, async ({ page }) => {
|
||||
const pageErrors: string[] = [];
|
||||
const consoleErrors: string[] = [];
|
||||
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-player-start").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "playerStart", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-interactable").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "interactable", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("interactable-position-y").fill("1");
|
||||
await page.getByTestId("interactable-position-y").press("Tab");
|
||||
await page.getByTestId("interactable-position-z").fill("1");
|
||||
await page.getByTestId("interactable-position-z").press("Tab");
|
||||
await page.getByTestId("interactable-radius").fill("4");
|
||||
await page.getByTestId("interactable-radius").press("Tab");
|
||||
await page.getByTestId("interactable-prompt").fill("Use Console");
|
||||
await page.getByTestId("interactable-prompt").press("Tab");
|
||||
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-teleport-target").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "teleportTarget", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("teleportTarget-position-x").fill("6");
|
||||
await page.getByTestId("teleportTarget-position-x").press("Tab");
|
||||
|
||||
await page
|
||||
.locator('[data-testid^="outliner-entity-"]')
|
||||
.filter({ hasText: "Interactable" })
|
||||
.first()
|
||||
.click();
|
||||
|
||||
await page.getByTestId("add-interactable-teleport-link").click();
|
||||
await page.getByRole("button", { name: navigationMode.buttonLabel }).first().click();
|
||||
await page.getByTestId("enter-run-mode").click();
|
||||
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-interaction-state")).toContainText(
|
||||
"Ready"
|
||||
);
|
||||
await expect(page.getByTestId("runner-interaction-prompt")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-interaction-prompt-text")).toContainText("Use Console");
|
||||
|
||||
await page.locator('[data-testid="runner-shell"] canvas').click();
|
||||
await expect(page.getByTestId("runner-player-position")).toContainText("6.00,");
|
||||
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-player-start").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "playerStart", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-interactable").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "interactable", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("interactable-position-y").fill("1");
|
||||
await page.getByTestId("interactable-position-y").press("Tab");
|
||||
await page.getByTestId("interactable-position-z").fill("1");
|
||||
await page.getByTestId("interactable-position-z").press("Tab");
|
||||
await page.getByTestId("interactable-radius").fill("4");
|
||||
await page.getByTestId("interactable-radius").press("Tab");
|
||||
await page.getByTestId("interactable-prompt").fill("Use Console");
|
||||
await page.getByTestId("interactable-prompt").press("Tab");
|
||||
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-teleport-target").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "teleportTarget", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("teleportTarget-position-x").fill("6");
|
||||
await page.getByTestId("teleportTarget-position-x").press("Tab");
|
||||
|
||||
await page
|
||||
.locator('[data-testid^="outliner-entity-"]')
|
||||
.filter({ hasText: "Interactable" })
|
||||
.first()
|
||||
.click();
|
||||
|
||||
await page.getByTestId("add-interactable-teleport-link").click();
|
||||
await page.getByRole("button", { name: "First Person" }).first().click();
|
||||
await page.getByTestId("enter-run-mode").click();
|
||||
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-interaction-prompt")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-interaction-prompt-text")).toContainText("Use Console");
|
||||
|
||||
await page.locator('[data-testid="runner-shell"] canvas').click();
|
||||
await expect(page.getByTestId("runner-player-position")).toContainText("6.00,");
|
||||
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ describe("RunnerCanvas", () => {
|
||||
).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("keeps first-person HUD affordances hidden in third-person mode", async () => {
|
||||
it("keeps the crosshair hidden in third-person mode while still showing interaction prompts", async () => {
|
||||
const runtimeScene = buildRuntimeSceneFromDocument(
|
||||
createEmptySceneDocument()
|
||||
);
|
||||
@@ -362,17 +362,33 @@ describe("RunnerCanvas", () => {
|
||||
?.setSceneLoadStateHandler.mock.calls[0]?.[0] as
|
||||
| ((state: RuntimeSceneLoadState) => void)
|
||||
| undefined;
|
||||
const publishInteractionPrompt = runtimeHostInstances[0]
|
||||
?.setInteractionPromptHandler.mock.calls[0]?.[0] as
|
||||
| ((prompt: {
|
||||
sourceEntityId: string;
|
||||
prompt: string;
|
||||
distance: number;
|
||||
range: number;
|
||||
} | null) => void)
|
||||
| undefined;
|
||||
|
||||
act(() => {
|
||||
publishSceneLoadState?.({
|
||||
status: "ready",
|
||||
message: null
|
||||
});
|
||||
publishInteractionPrompt?.({
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
prompt: "Use Console",
|
||||
distance: 1.2,
|
||||
range: 2
|
||||
});
|
||||
});
|
||||
|
||||
expect(document.querySelector(".runner-canvas__crosshair")).toBeNull();
|
||||
expect(
|
||||
screen.queryByTestId("runner-interaction-prompt")
|
||||
).toBeNull();
|
||||
expect(screen.getByTestId("runner-interaction-prompt")).toBeVisible();
|
||||
expect(screen.getByTestId("runner-interaction-prompt-text")).toHaveTextContent(
|
||||
"Use Console"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user