Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/app/routes/-GameRoutePendingShell.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @vitest-environment happy-dom

import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";

import { GameRoutePendingShell } from "./-GameRoutePendingShell";

describe("GameRoutePendingShell", () => {
it("announces loading while preserving the Observatory frame", () => {
render(<GameRoutePendingShell />);

expect(
screen.getByRole("status", { name: "Loading Dungeon Observatory" }),
).toBeTruthy();
expect(screen.getByRole("main").getAttribute("aria-busy")).toBe("true");
expect(screen.getByText("Dungeon Observatory")).toBeTruthy();
});
});
48 changes: 48 additions & 0 deletions src/app/routes/-GameRoutePendingShell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export function GameRoutePendingShell() {
return (
<main
id="main-content"
aria-busy="true"
className="flex h-dvh w-dvw flex-col overflow-hidden bg-background text-foreground"
>
<header className="flex min-h-[3.75rem] shrink-0 items-center justify-between border-panel-border/70 border-b bg-panel/95 px-4">
<div className="space-y-1">
<p className="rune-text text-panel-title">Runestone</p>
<p className="font-mono text-[10px] text-muted-foreground uppercase tracking-widest">
Dungeon Observatory
</p>
</div>
<span className="font-mono text-[10px] text-dungeon-rune uppercase tracking-widest">
Preparing run
</span>
</header>

<div className="grid min-h-0 flex-1 bg-panel-border/70 lg:grid-cols-[minmax(16rem,0.8fr)_minmax(20rem,1.6fr)_minmax(16rem,0.75fr)] lg:gap-px">
<aside aria-hidden="true" className="hidden bg-panel/95 p-4 lg:block">
<div className="h-full animate-pulse rounded-xl bg-muted/40 motion-reduce:animate-none" />
</aside>

<section
aria-label="Dungeon viewport loading"
className="relative flex min-h-0 items-center justify-center overflow-hidden bg-dungeon-fog"
>
<div
role="status"
aria-label="Loading Dungeon Observatory"
className="flex w-64 flex-col items-center gap-4 text-center"
>
<div className="h-28 w-full animate-pulse rounded-xl border border-panel-border/70 bg-panel/80 motion-reduce:animate-none" />
<div className="h-3 w-40 animate-pulse rounded-full bg-muted motion-reduce:animate-none" />
<p className="font-mono text-xs text-panel-body uppercase tracking-widest">
Loading Dungeon Observatory
</p>
</div>
</section>

<aside aria-hidden="true" className="hidden bg-panel/95 p-4 lg:block">
<div className="h-full animate-pulse rounded-xl bg-muted/40 motion-reduce:animate-none" />
</aside>
</div>
</main>
);
}
22 changes: 6 additions & 16 deletions src/app/routes/game.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import { createFileRoute } from "@tanstack/react-router";
import { lazy, Suspense } from "react";

import { APP_CONFIG } from "../../../app.config";

import { GameRouteContent } from "./-GameRouteContent";
import { GameRoutePendingShell } from "./-GameRoutePendingShell";
import { requirePersistedAuthSession } from "./-requirePersistedAuthSession";

const GameRouteContent = lazy(() =>
import("./-GameRouteContent").then((module) => ({
default: module.GameRouteContent,
})),
);

export const Route = createFileRoute("/game")({
ssr: APP_CONFIG.SSR,
beforeLoad: requirePersistedAuthSession,
component: LazyGamePage,
component: GameRouteContent,
pendingComponent: GameRoutePendingShell,
pendingMs: 0,
pendingMinMs: 0,
});

function LazyGamePage() {
return (
<Suspense fallback={null}>
<GameRouteContent />
</Suspense>
);
}
9 changes: 0 additions & 9 deletions src/entities/corridor/model/useCorridorMeshScenes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useGLTF } from "@react-three/drei";
import type * as THREE from "three";
import { preloadGltfAssets } from "@/shared/lib";

import { CORRIDOR_GLTF_CONFIG } from "../config";

Expand All @@ -11,14 +10,6 @@ type CorridorMeshScenes = {
wallVariationScene: THREE.Group;
};

preloadGltfAssets(useGLTF, [
CORRIDOR_GLTF_CONFIG.WALL.PATH,
CORRIDOR_GLTF_CONFIG.WALL_CRACKED.PATH,
CORRIDOR_GLTF_CONFIG.WALL_SHELVES.PATH,
CORRIDOR_GLTF_CONFIG.FLOOR_TILE.PATH,
CORRIDOR_GLTF_CONFIG.TORCH.PATH,
]);

export const useCorridorMeshScenes = (
corridorId: string,
): CorridorMeshScenes => {
Expand Down
16 changes: 2 additions & 14 deletions src/entities/enemy/ui/EnemyMesh.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { useGLTF } from "@react-three/drei";
import type { RapierRigidBody } from "@react-three/rapier";
import { CapsuleCollider, RigidBody } from "@react-three/rapier";
import type { RefObject } from "react";
import { useRef } from "react";
import { getPlayerPosition, preloadGltfAssets } from "@/shared/lib";
import { getPlayerPosition } from "@/shared/lib";

import {
ENEMY_ANIMATION_PATHS,
ENEMY_ENTITY_CONFIG,
ENEMY_GLTF_CONFIG,
} from "../config";
import { ENEMY_ENTITY_CONFIG, ENEMY_GLTF_CONFIG } from "../config";
import type { EnemyMeshActions, EnemyMeshSettings } from "../model";
import {
useEnemyGltfResources,
Expand All @@ -18,13 +13,6 @@ import {
useEnemyPhysicsLoop,
} from "../model";

preloadGltfAssets(useGLTF, [
ENEMY_GLTF_CONFIG.CHARACTER.PATH,
ENEMY_ANIMATION_PATHS.MOVEMENT_BASIC,
ENEMY_ANIMATION_PATHS.GENERAL,
ENEMY_ANIMATION_PATHS.COMBAT_MELEE,
]);

type EnemyMeshProps = {
settings: EnemyMeshSettings;
actions: EnemyMeshActions;
Expand Down
10 changes: 0 additions & 10 deletions src/entities/room/ui/RoomMesh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useMemo } from "react";

import { ROOM_CONFIG } from "@/shared/config";
import type { Vector3Tuple } from "@/shared/lib";
import { preloadGltfAssets } from "@/shared/lib";

import { ROOM_GLTF_CONFIG } from "../config";
import {
Expand Down Expand Up @@ -31,15 +30,6 @@ type RoomMeshProps = {
showGrid?: boolean;
};

preloadGltfAssets(useGLTF, [
ROOM_GLTF_CONFIG.FLOOR_TILE.PATH,
ROOM_GLTF_CONFIG.WALL.PATH,
ROOM_GLTF_CONFIG.WALL_DOORWAY.PATH,
ROOM_GLTF_CONFIG.COLUMN.PATH,
ROOM_GLTF_CONFIG.TORCH.PATH,
ROOM_GLTF_CONFIG.CHEST.PATH,
]);

export function RoomMesh({
position,
surface,
Expand Down
30 changes: 30 additions & 0 deletions src/features/auth/model/useAuthUsernameSubmission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ describe("useAuthUsernameSubmission", () => {
mockGetAuthClientStorage.mockReturnValue(memoryStorage);
mockCreateUserMutation.mockResolvedValue(TEST_USER_PROFILE);
mockSubmitAuthUsername.mockResolvedValue(TEST_USER_PROFILE);
mockPreloadRoute.mockResolvedValue(undefined);
mockNavigate.mockResolvedValue(undefined);
});

it("submits usernames through the shared orchestration helper", async () => {
Expand Down Expand Up @@ -120,4 +122,32 @@ describe("useAuthUsernameSubmission", () => {
expect(mockPreloadRoute).not.toHaveBeenCalled();
expect(mockNavigate).not.toHaveBeenCalled();
});

it("does not wait for the game runtime preload before navigating", async () => {
let resolvePreload: (() => void) | undefined;
mockPreloadRoute.mockReturnValueOnce(
new Promise<void>((resolve) => {
resolvePreload = resolve;
}),
);
mockNavigate.mockResolvedValueOnce(undefined);
const { result } = renderHook(() =>
useAuthUsernameSubmission({
sendAuthEvent: vi.fn(),
sessionUuid: "existing-session-uuid",
}),
);

const submission = result.current.handleUsernameFormSubmit({
username: "runestone_hero",
});
await vi.waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith({
to: AUTH_ROUTE_PATHS.GAME,
});
});

resolvePreload?.();
await submission;
});
});
8 changes: 5 additions & 3 deletions src/features/auth/model/useAuthUsernameSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ export const useAuthUsernameSubmission = ({
return;
}

await router.preloadRoute({
to: AUTH_ROUTE_PATHS.GAME,
});
void router
.preloadRoute({
to: AUTH_ROUTE_PATHS.GAME,
})
.catch(() => undefined);
await router.navigate({
to: AUTH_ROUTE_PATHS.GAME,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const MOBILE_ACTION_BUTTON_LAYOUT_CLASS_NAMES = {
ROOT: "pointer-events-auto flex flex-col gap-2 touch-none select-none",
BUTTON: "h-12 w-12 rounded-full p-0 shadow-lg backdrop-blur-md",
BUTTON: "size-11 rounded-full p-0 shadow-lg backdrop-blur-md",
ICON: "h-5 w-5",
} as const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ describe("MobileActionButtonZone", () => {
expect(runButton.className).toBe(
MOBILE_ACTION_BUTTON_LAYOUT_CLASS_NAMES.BUTTON,
);
expect(runButton.className).toContain("size-11");
expect(runButton.className).not.toMatch(/h-12|w-12/);
expect(zoneRoot.className).toBe(
MOBILE_ACTION_BUTTON_LAYOUT_CLASS_NAMES.ROOT,
);
Expand Down
1 change: 1 addition & 0 deletions src/features/responsive-layout/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export {
createResponsiveMediaQuerySubscriptions,
type ResponsiveMediaQueryEntry,
type ResponsiveMediaQuerySubscription,
readResponsiveMediaQueryMatch,
removeResponsiveMediaQuerySubscriptions,
} from "./responsiveMediaQuerySubscriptions";
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ type ResponsiveMediaQuerySubscription = {
listener: (event: MediaQueryListEvent) => void;
};

export const readResponsiveMediaQueryMatch = (
query: string,
fallback: boolean,
): boolean => {
if (typeof window === "undefined") {
return fallback;
}

return window.matchMedia(query).matches;
};

export const createResponsiveMediaQuerySubscriptions = (
entries: readonly ResponsiveMediaQueryEntry[],
): ResponsiveMediaQuerySubscription[] => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// @vitest-environment happy-dom

import { renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";

import { RESPONSIVE_LAYOUT_MEDIA_QUERIES } from "../config";

vi.mock("../lib", async (importOriginal) => {
const original = await importOriginal<typeof import("../lib")>();

return {
...original,
createResponsiveMediaQuerySubscriptions: () => [],
};
});

import { useResponsiveGameLayout } from "./useResponsiveGameLayout";

describe("useResponsiveGameLayout initial state", () => {
it("uses current desktop media queries before subscription effects run", () => {
const mediaQueries = {
[RESPONSIVE_LAYOUT_MEDIA_QUERIES.DESKTOP_MIN_WIDTH]: true,
[RESPONSIVE_LAYOUT_MEDIA_QUERIES.TABLET_STANDARD_WIDTH]: false,
[RESPONSIVE_LAYOUT_MEDIA_QUERIES.TABLET_COARSE_WIDTH]: false,
[RESPONSIVE_LAYOUT_MEDIA_QUERIES.MOBILE_MAX_WIDTH]: false,
[RESPONSIVE_LAYOUT_MEDIA_QUERIES.LANDSCAPE]: true,
[RESPONSIVE_LAYOUT_MEDIA_QUERIES.PORTRAIT]: false,
};

vi.spyOn(window, "matchMedia").mockImplementation(
(query) =>
({
matches: Boolean(mediaQueries[query as keyof typeof mediaQueries]),
}) as MediaQueryList,
);

const { result } = renderHook(() => useResponsiveGameLayout());

expect(result.current).toEqual({
isDesktopLayout: true,
isMobileLayout: false,
isTabletLayout: false,
isLandscape: true,
isPortrait: false,
});
});
});
45 changes: 38 additions & 7 deletions src/features/responsive-layout/model/useResponsiveGameLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,50 @@ import {
createResponsiveGameLayoutSnapshot,
createResponsiveMediaQuerySubscriptions,
type ResponsiveGameLayoutSnapshot,
readResponsiveMediaQueryMatch,
removeResponsiveMediaQuerySubscriptions,
} from "../lib";

export type ResponsiveGameLayout = ResponsiveGameLayoutSnapshot;

export function useResponsiveGameLayout(): ResponsiveGameLayout {
const [isDesktopWidth, setIsDesktopWidth] = useState(false);
const [isTabletWidth, setIsTabletWidth] = useState(false);
const [isCoarsePointerTabletWidth, setIsCoarsePointerTabletWidth] =
useState(false);
const [isMobile, setIsMobile] = useState(false);
const [isLandscape, setIsLandscape] = useState(true);
const [isPortrait, setIsPortrait] = useState(false);
const [isDesktopWidth, setIsDesktopWidth] = useState(() =>
readResponsiveMediaQueryMatch(
RESPONSIVE_LAYOUT_MEDIA_QUERIES.DESKTOP_MIN_WIDTH,
false,
),
);
const [isTabletWidth, setIsTabletWidth] = useState(() =>
readResponsiveMediaQueryMatch(
RESPONSIVE_LAYOUT_MEDIA_QUERIES.TABLET_STANDARD_WIDTH,
false,
),
);
const [isCoarsePointerTabletWidth, setIsCoarsePointerTabletWidth] = useState(
() =>
readResponsiveMediaQueryMatch(
RESPONSIVE_LAYOUT_MEDIA_QUERIES.TABLET_COARSE_WIDTH,
false,
),
);
const [isMobile, setIsMobile] = useState(() =>
readResponsiveMediaQueryMatch(
RESPONSIVE_LAYOUT_MEDIA_QUERIES.MOBILE_MAX_WIDTH,
false,
),
);
const [isLandscape, setIsLandscape] = useState(() =>
readResponsiveMediaQueryMatch(
RESPONSIVE_LAYOUT_MEDIA_QUERIES.LANDSCAPE,
true,
),
);
const [isPortrait, setIsPortrait] = useState(() =>
readResponsiveMediaQueryMatch(
RESPONSIVE_LAYOUT_MEDIA_QUERIES.PORTRAIT,
false,
),
);

useEffect(() => {
const subscriptions = createResponsiveMediaQuerySubscriptions([
Expand Down
2 changes: 1 addition & 1 deletion src/features/settings/config/settingsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const SETTINGS_STORAGE_KEYS = {

export const SETTINGS_COPY = {
PAGE_TITLE: "Settings",
PAGE_DESCRIPTION: "Adjust audio levels and haptic feedback.",
PAGE_DESCRIPTION: "Tune audio, rendering, and haptic feedback for your run.",
AUDIO_SECTION: "Audio",
HAPTICS_SECTION: "Haptics",
MASTER_VOLUME_LABEL: "Master Volume",
Expand Down
Loading
Loading