diff --git a/backend/endpoints/activity.py b/backend/endpoints/activity.py index 0d11a8d60..eb0a7afe6 100644 --- a/backend/endpoints/activity.py +++ b/backend/endpoints/activity.py @@ -7,10 +7,11 @@ from decorators.auth import protected_route from endpoints.responses.activity import ActivityClearSchema, ActivityEntrySchema from handler.activity_handler import ActivityEntry, activity_handler from handler.auth.constants import Scope -from handler.database import db_device_handler, db_rom_handler +from handler.database import db_device_handler, db_rom_handler, db_save_handler from handler.socket_handler import socket_handler from logger.logger import log from utils.router import APIRouter +from utils.screenshots import continue_playing_screenshot router = APIRouter( prefix="/activity", @@ -69,6 +70,11 @@ async def device_heartbeat( existing["started_at"] if existing else datetime.now(timezone.utc).isoformat() ) + latest_save = db_save_handler.get_latest_saves_for_roms( + user_id=request.user.id, rom_ids=[rom.id] + ).get(rom.id) + screenshot_path = continue_playing_screenshot(rom, latest_save) or "" + platform = rom.platform entry = ActivityEntry( user_id=request.user.id, @@ -77,6 +83,7 @@ async def device_heartbeat( rom_id=rom.id, rom_name=rom.name or rom.fs_name, rom_cover_path=rom.path_cover_s or "", + screenshot_path=screenshot_path, platform_slug=platform.slug if platform else "", platform_name=(platform.custom_name or platform.name) if platform else "", device_id=device.id, diff --git a/backend/endpoints/responses/activity.py b/backend/endpoints/responses/activity.py index 6ee4a4a9d..b16a0cd96 100644 --- a/backend/endpoints/responses/activity.py +++ b/backend/endpoints/responses/activity.py @@ -8,6 +8,7 @@ class ActivityEntrySchema(BaseModel): rom_id: int rom_name: str rom_cover_path: str = "" + screenshot_path: str = "" platform_slug: str platform_name: str device_id: str diff --git a/backend/endpoints/responses/rom.py b/backend/endpoints/responses/rom.py index 91d35aae1..f708283b5 100644 --- a/backend/endpoints/responses/rom.py +++ b/backend/endpoints/responses/rom.py @@ -400,6 +400,8 @@ class SiblingRomSchema(BaseModel): class SimpleRomSchema(RomSchema): + screenshot_path: str | None = None + @classmethod def from_orm_with_request( cls, @@ -407,8 +409,10 @@ class SimpleRomSchema(RomSchema): request: Request, files: Sequence[RomFile] | None = None, siblings: Sequence[tuple[Rom, bool]] | None = None, + screenshot_path: str | None = None, ) -> SimpleRomSchema: db_rom = cls.populate_properties(db_rom, request) + db_rom.screenshot_path = screenshot_path # type: ignore[assignment] # The list endpoint passes pre-fetched `files`/`siblings` (batched via # get_files_for_roms / get_siblings_for_roms, no per-row hydration). @@ -445,6 +449,7 @@ class SimpleRomSchema(RomSchema): db_rom.included_files = [] # type: ignore[assignment] db_rom.included_sibling_roms = [] # type: ignore[assignment] db_rom.has_notes = False # type: ignore[assignment] + db_rom.screenshot_path = None # type: ignore[assignment] return cls.model_validate(db_rom) diff --git a/backend/endpoints/roms/__init__.py b/backend/endpoints/roms/__init__.py index b04cb6eb1..26bedb07e 100644 --- a/backend/endpoints/roms/__init__.py +++ b/backend/endpoints/roms/__init__.py @@ -46,7 +46,7 @@ from endpoints.responses.rom import ( from exceptions.endpoint_exceptions import RomNotFoundInDatabaseException from exceptions.fs_exceptions import RomAlreadyExistsException from handler.auth.constants import Scope -from handler.database import db_rom_handler +from handler.database import db_rom_handler, db_save_handler from handler.database.base_handler import sync_session from handler.filesystem import fs_resource_handler, fs_rom_handler from handler.filesystem.assets_handler import validate_image_upload @@ -70,6 +70,7 @@ from utils.filesystem import sanitize_filename from utils.hashing import crc32_to_hex from utils.nginx import FileRedirectResponse, ZipContentLine, ZipResponse from utils.router import APIRouter +from utils.screenshots import continue_playing_screenshot from utils.validation import ValidationError from .files import router as files_router @@ -630,12 +631,24 @@ def get_roms( rom_ids, user_id=request.user.id, session=session ) + # Continue-playing rail + screenshot_by_rom: dict[int, str | None] = {} + if last_played: + latest_saves = db_save_handler.get_latest_saves_for_roms( + user_id=request.user.id, rom_ids=rom_ids, session=session + ) + for item in items: + screenshot_by_rom[item.id] = continue_playing_screenshot( + item, latest_saves.get(item.id) + ) + return [ SimpleRomSchema.from_orm_with_request( db_rom=item, request=request, files=files_by_rom.get(item.id, []), siblings=siblings_by_rom.get(item.id, []), + screenshot_path=screenshot_by_rom.get(item.id), ) for item in items ] diff --git a/backend/endpoints/sockets/activity.py b/backend/endpoints/sockets/activity.py index 8e48cbcbb..db1a6e41b 100644 --- a/backend/endpoints/sockets/activity.py +++ b/backend/endpoints/sockets/activity.py @@ -21,9 +21,15 @@ from typing import Any, TypedDict from endpoints.responses.activity import ActivityClearSchema from handler.activity_handler import ActivityEntry, activity_handler -from handler.database import db_device_handler, db_rom_handler, db_user_handler +from handler.database import ( + db_device_handler, + db_rom_handler, + db_save_handler, + db_user_handler, +) from handler.socket_handler import socket_handler from logger.logger import log +from utils.screenshots import continue_playing_screenshot # Socket-session key holding the authenticated user id, written by the connect # handler. Identity for every activity event is derived from this, not payload. @@ -92,6 +98,13 @@ async def _build_entry( device = db_device_handler.get_device(device_id=device_id, user_id=user_id) device_type = device.client if device else None + # "Where they are" image — the player's latest save screenshot, else the + # title screen / first gameplay screenshot (frontend falls back to cover). + latest_save = db_save_handler.get_latest_saves_for_roms( + user_id=user_id, rom_ids=[rom_id] + ).get(rom_id) + screenshot_path = continue_playing_screenshot(rom, latest_save) or "" + return ActivityEntry( user_id=user.id, username=user.username, @@ -99,6 +112,7 @@ async def _build_entry( rom_id=rom.id, rom_name=rom.name or rom.fs_name, rom_cover_path=rom.path_cover_s or "", + screenshot_path=screenshot_path, platform_slug=platform.slug if platform else "", platform_name=((platform.custom_name or platform.name) if platform else ""), device_id=device_id, diff --git a/backend/handler/activity_handler.py b/backend/handler/activity_handler.py index f65eccf79..4416dabf7 100644 --- a/backend/handler/activity_handler.py +++ b/backend/handler/activity_handler.py @@ -22,6 +22,7 @@ class ActivityEntry(TypedDict): rom_id: int rom_name: str rom_cover_path: str # small cover path, may be empty + screenshot_path: str # "where they are" image (save/title/screenshot), may be empty platform_slug: str platform_name: str device_id: str diff --git a/backend/handler/database/saves_handler.py b/backend/handler/database/saves_handler.py index d33d405ca..9242c7e9e 100644 --- a/backend/handler/database/saves_handler.py +++ b/backend/handler/database/saves_handler.py @@ -132,6 +132,33 @@ class DBSavesHandler(DBBaseHandler): query = query.order_by(desc(Save.updated_at)) return session.scalars(query).all() + @begin_session + def get_latest_saves_for_roms( + self, + user_id: int, + rom_ids: Sequence[int], + session: Session = None, # type: ignore + ) -> dict[int, Save]: + """The most recent save per ROM for a user, keyed by `rom_id`. + + Batched for the continue-playing rail, which enriches each card with + the in-game screenshot captured alongside the user's latest save. + """ + if not rom_ids: + return {} + + saves = session.scalars( + select(Save) + .filter(Save.user_id == user_id, Save.rom_id.in_(rom_ids)) + .order_by(desc(Save.updated_at)) + ).all() + + latest: dict[int, Save] = {} + for save in saves: + # Saves come newest-first, so the first one seen per ROM wins. + latest.setdefault(save.rom_id, save) + return latest + @begin_session def update_save( self, diff --git a/backend/tests/handler/database/test_saves_handler.py b/backend/tests/handler/database/test_saves_handler.py index e0527bd42..cce626cc6 100644 --- a/backend/tests/handler/database/test_saves_handler.py +++ b/backend/tests/handler/database/test_saves_handler.py @@ -749,3 +749,82 @@ class TestDBSavesHandlerSummary: ) assert count_slot is not None assert count_slot["count"] == 5 + + +class TestDBSavesHandlerGetLatestSavesForRoms: + """Cover the continue-playing rail's batch lookup of the newest save per + ROM.""" + + def test_returns_newest_save_per_rom(self, admin_user: User, rom: Rom): + from datetime import datetime, timedelta, timezone + + base_time = datetime.now(timezone.utc) + + older = db_save_handler.add_save( + Save( + rom_id=rom.id, + user_id=admin_user.id, + file_name="latest_old.sav", + file_name_no_tags="latest_old", + file_name_no_ext="latest_old", + file_extension="sav", + emulator="test_emu", + file_path=f"{rom.platform_slug}/saves", + file_size_bytes=100, + ) + ) + newer = db_save_handler.add_save( + Save( + rom_id=rom.id, + user_id=admin_user.id, + file_name="latest_new.sav", + file_name_no_tags="latest_new", + file_name_no_ext="latest_new", + file_extension="sav", + emulator="test_emu", + file_path=f"{rom.platform_slug}/saves", + file_size_bytes=100, + ) + ) + db_save_handler.update_save( + older.id, {"updated_at": base_time - timedelta(hours=2)} + ) + db_save_handler.update_save( + newer.id, {"updated_at": base_time - timedelta(hours=1)} + ) + + latest = db_save_handler.get_latest_saves_for_roms( + user_id=admin_user.id, rom_ids=[rom.id] + ) + + assert set(latest.keys()) == {rom.id} + assert latest[rom.id].id == newer.id + + def test_empty_rom_ids_returns_empty_dict(self, admin_user: User): + assert ( + db_save_handler.get_latest_saves_for_roms(user_id=admin_user.id, rom_ids=[]) + == {} + ) + + def test_excludes_other_users_saves( + self, admin_user: User, editor_user: User, rom: Rom + ): + db_save_handler.add_save( + Save( + rom_id=rom.id, + user_id=editor_user.id, + file_name="other_user.sav", + file_name_no_tags="other_user", + file_name_no_ext="other_user", + file_extension="sav", + emulator="test_emu", + file_path=f"{rom.platform_slug}/saves", + file_size_bytes=100, + ) + ) + + latest = db_save_handler.get_latest_saves_for_roms( + user_id=admin_user.id, rom_ids=[rom.id] + ) + + assert latest == {} diff --git a/backend/utils/screenshots.py b/backend/utils/screenshots.py index f9e131ab7..349f5297f 100644 --- a/backend/utils/screenshots.py +++ b/backend/utils/screenshots.py @@ -1,5 +1,9 @@ import os +from config import FRONTEND_RESOURCES_PATH +from models.assets import Save +from models.rom import Rom + # Image formats every modern browser can decode. Shared by the per-ROM # (endpoints/roms/screenshot.py) and per-user (endpoints/screenshots.py) # screenshot upload endpoints. @@ -11,3 +15,23 @@ ALLOWED_SCREENSHOT_EXTENSIONS = frozenset( def is_allowed_screenshot_file(file_name: str) -> bool: _, ext = os.path.splitext(file_name) return ext.lower() in ALLOWED_SCREENSHOT_EXTENSIONS + + +def continue_playing_screenshot(rom: Rom, latest_save: Save | None) -> str | None: + """The "where you left off" image for a rom, in priority order: the latest + save's screenshot, then the title screen, then the first gameplay + screenshot. None lets the frontend fall back to cover art. Shared by the + continue-playing rail and the live-activity board.""" + if latest_save is not None and latest_save.screenshot is not None: + return latest_save.screenshot.download_path + + title_screen = (rom.ss_metadata or {}).get("title_screen_path") or ( + rom.gamelist_metadata or {} + ).get("title_screen_path") + if title_screen: + return f"{FRONTEND_RESOURCES_PATH}/{title_screen}" + + if rom.merged_screenshots: + return rom.merged_screenshots[0] + + return None diff --git a/docs/FRONTEND_ARCHITECTURE.md b/docs/FRONTEND_ARCHITECTURE.md index aebf1abf6..26ce4a254 100644 --- a/docs/FRONTEND_ARCHITECTURE.md +++ b/docs/FRONTEND_ARCHITECTURE.md @@ -1030,6 +1030,7 @@ Request Flow with Cache: - `getSupportedEJSCores()`: platform → EmulatorJS core mapping - `isEJSEmulationSupported()`: WebGL + config check - `isCDBasedSystem()`: 31 CD-based platforms +- `isArcadeSystem()`: 3 arcade platforms **Game Status:** diff --git a/frontend/assets/default/miximage.png b/frontend/assets/default/miximage.png index 50e4acef9..626cde0c5 100644 Binary files a/frontend/assets/default/miximage.png and b/frontend/assets/default/miximage.png differ diff --git a/frontend/src/__generated__/models/SimpleRomSchema.ts b/frontend/src/__generated__/models/SimpleRomSchema.ts index b0a248cc2..3f83b9918 100644 --- a/frontend/src/__generated__/models/SimpleRomSchema.ts +++ b/frontend/src/__generated__/models/SimpleRomSchema.ts @@ -90,5 +90,6 @@ export type SimpleRomSchema = { merged_ra_metadata: (RomRAMetadata | null); files: Array; sibling_roms: Array; + screenshot_path?: (string | null); }; diff --git a/frontend/src/services/api/activity.ts b/frontend/src/services/api/activity.ts index 259b1290f..3069cfece 100644 --- a/frontend/src/services/api/activity.ts +++ b/frontend/src/services/api/activity.ts @@ -7,6 +7,9 @@ export interface ActivityEntry { rom_id: number; rom_name: string; rom_cover_path: string; + // "Where they are" image (latest save screenshot / title / first + // screenshot); empty when none — the card then shows cover art. + screenshot_path: string; platform_slug: string; platform_name: string; device_id: string; diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 2c3678fce..e703b7753 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -875,3 +875,9 @@ export const CD_BASED_SYSTEMS = new Set([ export function isCDBasedSystem(platformSlug: string): boolean { return CD_BASED_SYSTEMS.has(platformSlug.toLowerCase()); } + +export const ARCADE_SYSTEMS = new Set(["arcade", "neogeoaes", "neogeomvs"]); + +export function isArcadeSystem(platformSlug: string): boolean { + return ARCADE_SYSTEMS.has(platformSlug.toLowerCase()); +} diff --git a/frontend/src/v2/components/Activity/ActivityCard.vue b/frontend/src/v2/components/Activity/ActivityCard.vue index e6d4ffdf8..e9df2f23c 100644 --- a/frontend/src/v2/components/Activity/ActivityCard.vue +++ b/frontend/src/v2/components/Activity/ActivityCard.vue @@ -10,11 +10,15 @@ // session counter is the single live indicator. import { RAvatar, RIcon } from "@v2/lib"; import type { RouteLocationRaw } from "vue-router"; +import CoverArtPip from "@/v2/components/shared/CoverArtPip.vue"; import GameCover from "@/v2/components/shared/GameCover.vue"; interface Props { to: RouteLocationRaw; coverSrc: string | null; + /** Cover-art URL for the corner PIP — set only when `coverSrc` is a + * screenshot, so the game stays identifiable. Null shows no PIP. */ + pipCoverSrc?: string | null; romName: string; platformName: string; username: string; @@ -38,7 +42,15 @@ defineProps(); :cover-src="coverSrc" :title="romName" class="activity-card__art" - /> + > + + +
@@ -50,17 +62,18 @@ defineProps();
- - {{ username }} - -
- -
- {{ elapsedLabel }} - +
+ + {{ username }} + +
+ {{ elapsedLabel }} + +
+
@@ -76,15 +89,25 @@ defineProps(); gap: 8px; text-decoration: none; color: inherit; + /* Each card keeps its cover's natural width and wraps — no grow/shrink. */ + flex: 0 0 auto; } /* GameCover owns the radius / overflow / placeholder background; the card - adds the hover lift (rise + shadow) on top. */ -.activity-card__art { + adds the hover lift (rise + shadow) on top. + Fixed HEIGHT with NATURAL WIDTH (gallery-card behavior): the compound + selector beats GameCover's base `width: 100%` so the box derives its width + from the measured image ratio at this height. */ +.activity-card .activity-card__art { + height: 190px; + width: auto; transition: transform var(--r-motion-fast) var(--r-motion-ease-out), box-shadow var(--r-motion-fast) var(--r-motion-ease-out); } +html[data-bp~="xs"] .activity-card .activity-card__art { + height: 150px; +} .activity-card:hover .activity-card__art { transform: translateY(-4px); box-shadow: 0 12px 28px color-mix(in srgb, black 45%, transparent); @@ -94,7 +117,11 @@ defineProps(); display: flex; flex-direction: column; gap: 2px; - min-width: 0; + /* Match the cover's width and ellipsize inside it, without letting long + names widen the card past the (natural-width) cover above. */ + width: 0; + min-width: 100%; + max-width: 100%; } .activity-card__rom { @@ -133,7 +160,6 @@ defineProps(); .activity-card__meta { display: flex; align-items: center; - margin-top: 4px; font-size: var(--r-font-size-xs); color: var(--r-color-fg-faint); } diff --git a/frontend/src/v2/components/Gallery/GalleryShell.vue b/frontend/src/v2/components/Gallery/GalleryShell.vue index 0ae70ad19..d7d73baab 100644 --- a/frontend/src/v2/components/Gallery/GalleryShell.vue +++ b/frontend/src/v2/components/Gallery/GalleryShell.vue @@ -58,7 +58,11 @@ import GameListHeader from "@/v2/components/Gallery/GameListHeader.vue"; import GameListRow from "@/v2/components/Gallery/GameListRow.vue"; import GameListSkeletonRow from "@/v2/components/Gallery/GameListSkeletonRow.vue"; import SelectionBar from "@/v2/components/Gallery/SelectionBar.vue"; -import { type ListSortKey } from "@/v2/components/Gallery/listColumns"; +import { + LIST_COVER_HEIGHT_PX, + LIST_COVER_WIDTH_PX, + type ListSortKey, +} from "@/v2/components/Gallery/listColumns"; import { GameCard, GameCardSkeleton } from "@/v2/components/GameCard"; import { useBreakpoint } from "@/v2/composables/useBreakpoint"; import { coverRatio, isBoxartStyle } from "@/v2/composables/useCoverArt"; @@ -269,7 +273,19 @@ const coverAspectRatio = computed(() => // Measured natural cover ratios feeding the flow-packer — GameCard reports // each cover's ratio on load (`onCardRatio`), the packer reads `ratioAt`, // and `ratioVersion` bumps (debounced) to trigger a single re-pack. -const { ratioVersion, ratioAt, onCardRatio } = useGalleryCoverRatios(); +// `maxRatio` (widest cover in this gallery) drives the list view's cover +// column width. +const { ratioVersion, ratioAt, onCardRatio, maxRatio, resetMaxRatio } = + useGalleryCoverRatios(); + +// List-view cover column width: the widest cover at the row's cover height, +// clamped so a portrait-only list stays tight and an outlier can't make the +// column absurd. Wide (landscape) covers then show whole instead of being +// clipped, and every row shares the width so titles stay aligned. +const listCoverWidth = computed(() => { + const w = Math.round(LIST_COVER_HEIGHT_PX * maxRatio.value); + return Math.min(128, Math.max(LIST_COVER_WIDTH_PX, w)); +}); // 2D arrow / gamepad nav for both layouts of the gallery. Two passes: // * Grid mode — rows are `.r-v2-shell__row` (the per-virtualizer-item @@ -577,6 +593,15 @@ watch(virtualItems, () => { syncFetches(viewportRange.value); }); +// Recompute the list cover-column max when the gallery's rom set changes +// (context switch, filter, sort) so a previous platform's wide covers +// don't keep the column wide. Keyed on `romIdIndex` (not `virtualItems`) +// so grid re-packs don't trigger the O(total) rebuild. +watch( + () => galleryRoms.romIdIndex, + () => resetMaxRatio(), +); + // List mode pins a column header below the toolbar; AlphaStrip jumps // must land BELOW both pinned bars or the destination row would slide // behind the column header. Matches the height set in @@ -853,6 +878,7 @@ defineExpose({ :sort-key="listSortKey" :sort-dir="orderDir" :show-platform-column="showPlatformColumn" + :cover-width="listCoverWidth" @sort="onListSort" /> @@ -897,11 +923,14 @@ defineExpose({ :position="asListRow(item as GalleryItem).position" :webp="supportsWebp" :show-platform-column="showPlatformColumn" + :cover-width="listCoverWidth" + @ratio="onCardRatio" />
diff --git a/frontend/src/v2/components/Gallery/GameListHeader.vue b/frontend/src/v2/components/Gallery/GameListHeader.vue index ad01905e6..7a4cc4893 100644 --- a/frontend/src/v2/components/Gallery/GameListHeader.vue +++ b/frontend/src/v2/components/Gallery/GameListHeader.vue @@ -32,10 +32,14 @@ interface Props { * name on `GameListRow` + `GameListSkeletonRow` so all three stay in * lockstep. */ showPlatformColumn?: boolean; + /** Width of the cover column (px) — shared with every row so the title + * column aligns. Set by the shell from the gallery's widest cover. */ + coverWidth?: number; } const props = withDefaults(defineProps(), { showPlatformColumn: true, + coverWidth: 48, }); const emit = defineEmits<{ @@ -45,7 +49,10 @@ const emit = defineEmits<{ const { t } = useI18n(); const columns = computed(() => getListColumns(props.showPlatformColumn)); const gridStyle = computed(() => ({ - gridTemplateColumns: getListGridTemplate(props.showPlatformColumn), + gridTemplateColumns: getListGridTemplate( + props.showPlatformColumn, + props.coverWidth, + ), })); const galleryRoms = storeGalleryRoms(); diff --git a/frontend/src/v2/components/Gallery/GameListRow.vue b/frontend/src/v2/components/Gallery/GameListRow.vue index e14385c5f..324c50610 100644 --- a/frontend/src/v2/components/Gallery/GameListRow.vue +++ b/frontend/src/v2/components/Gallery/GameListRow.vue @@ -72,6 +72,9 @@ interface Props { /** Include the `platform` column. Mirrors `GameListHeader` so the row * stays aligned with the column header above it. */ showPlatformColumn?: boolean; + /** Cover column width (px) — shared with the header so the title column + * aligns. Set by the shell from the gallery's widest cover. */ + coverWidth?: number; } const props = withDefaults(defineProps(), { @@ -79,8 +82,15 @@ const props = withDefaults(defineProps(), { rom: undefined, webp: false, showPlatformColumn: true, + coverWidth: 48, }); +const emit = defineEmits<{ + /** Forwards the cover's measured natural ratio so the shell can size the + * cover column to the gallery's widest cover. */ + (e: "ratio", payload: { romId: number; ratio: number }): void; +}>(); + const router = useRouter(); const galleryRoms = storeGalleryRoms(); const selection = storeGallerySelection(); @@ -121,7 +131,10 @@ function onCheckboxClick(e: MouseEvent) { } const gridStyle = computed(() => ({ - gridTemplateColumns: getListGridTemplate(props.showPlatformColumn), + gridTemplateColumns: getListGridTemplate( + props.showPlatformColumn, + props.coverWidth, + ), })); const platformMeta = computed(() => { @@ -321,6 +334,7 @@ onBeforeUnmount(() => { decorative :show-title="false" :show-platform-icon="false" + @ratio="emit('ratio', $event)" />
@@ -579,13 +593,12 @@ onBeforeUnmount(() => { justify-content: flex-end; } -/* Cover sits in its own fixed-width column (right-aligned, vertically - centred) so the title/meta column starts at the same x on every row and - the cover hugs the title side. */ +/* Cover sits in its own fixed-width column (centred) so the title/meta + column starts at the same x on every row. */ .game-list-row__cover { display: flex; align-items: center; - justify-content: flex-end; + justify-content: center; } /* Bound the xs cover to its fixed column: at the fixed xs height a wide diff --git a/frontend/src/v2/components/Gallery/GameListSkeletonRow.vue b/frontend/src/v2/components/Gallery/GameListSkeletonRow.vue index 7869c76df..a41c40968 100644 --- a/frontend/src/v2/components/Gallery/GameListSkeletonRow.vue +++ b/frontend/src/v2/components/Gallery/GameListSkeletonRow.vue @@ -27,15 +27,21 @@ interface Props { * `GameListRow` so the bootstrap-phase skeleton stays aligned with * whichever variant the surrounding list is rendering. */ showPlatformColumn?: boolean; + /** Cover column width (px) — shared with the header / rows. */ + coverWidth?: number; } const props = withDefaults(defineProps(), { showPlatformColumn: true, + coverWidth: 48, }); const columns = computed(() => getListColumns(props.showPlatformColumn)); const gridStyle = computed(() => ({ - gridTemplateColumns: getListGridTemplate(props.showPlatformColumn), + gridTemplateColumns: getListGridTemplate( + props.showPlatformColumn, + props.coverWidth, + ), })); @@ -112,11 +118,11 @@ const gridStyle = computed(() => ({ justify-content: flex-end; } -/* Right-align the cover block to match the real row. */ +/* Centre the cover block to match the real row. */ .r-glr-skel__cover { display: flex; align-items: center; - justify-content: flex-end; + justify-content: center; } .r-glr-skel__title { diff --git a/frontend/src/v2/components/Gallery/listColumns.ts b/frontend/src/v2/components/Gallery/listColumns.ts index fa6327f44..583d6cd22 100644 --- a/frontend/src/v2/components/Gallery/listColumns.ts +++ b/frontend/src/v2/components/Gallery/listColumns.ts @@ -116,11 +116,16 @@ export function getListColumns(showPlatform: boolean): readonly ListColumn[] { /** CSS-grid template paired with `getListColumns`. The `platform` slot * is inserted between `name` and `fs_size_bytes` when present so column * order matches the array. */ -export function getListGridTemplate(showPlatform: boolean): string { +export function getListGridTemplate( + showPlatform: boolean, + coverWidthPx = 48, +): string { const platformTrack = showPlatform ? " 200px" : ""; - // Cover track = the xs cover height (64px), so any portrait→square cover - // fits without clipping and the title column starts at a fixed x. - return `36px 64px minmax(0, 1.6fr)${platformTrack} 88px 96px 84px 56px 110px 110px 88px`; + // Cover track widens to the widest cover in the gallery (set by the + // shell from measured ratios), so landscape covers show whole instead of + // being clipped, while portrait-only lists stay tight. The title column + // starts at a fixed x because every row shares this width. + return `36px ${coverWidthPx}px minmax(0, 1.6fr)${platformTrack} 88px 96px 84px 56px 110px 110px 88px`; } /** Default exports — the cross-platform variant. Used by the bootstrap- diff --git a/frontend/src/v2/components/GameCard/GameCard.vue b/frontend/src/v2/components/GameCard/GameCard.vue index 4c6703723..e86211d52 100644 --- a/frontend/src/v2/components/GameCard/GameCard.vue +++ b/frontend/src/v2/components/GameCard/GameCard.vue @@ -44,6 +44,7 @@ import { useRouter } from "vue-router"; import type { SimpleRom } from "@/stores/roms"; import GameActionBtn from "@/v2/components/GameActions/GameActionBtn.vue"; import SiblingBadge from "@/v2/components/GameCard/SiblingBadge.vue"; +import CoverArtPip from "@/v2/components/shared/CoverArtPip.vue"; import GameCover from "@/v2/components/shared/GameCover.vue"; import { useBackgroundArt } from "@/v2/composables/useBackgroundArt"; import { useCoverArt } from "@/v2/composables/useCoverArt"; @@ -104,6 +105,10 @@ interface Props { * (edit dialog) and external provider URLs (match dialog source * variants). Bypasses the path/webp/url_cover chain. */ coverSrc?: string | null; + /** When a `coverSrc` override is shown (e.g. the continue-playing + * screenshot), float a small 2D cover-art thumbnail in the bottom-right + * corner so the game stays identifiable. No-op without a `coverSrc`. */ + coverPip?: boolean; /** Paint a brand-coloured outline to mark the card as selected * (cover-variant picker, multi-select gallery). When `selectable` * is true this prop is ignored — the card subscribes directly to @@ -135,6 +140,7 @@ const props = withDefaults(defineProps(), { noHover: false, showTitle: true, coverSrc: undefined, + coverPip: false, selected: false, selectable: false, position: undefined, @@ -152,6 +158,9 @@ const art = useCoverArt(() => props.rom, { const coverUrl = art.coverUrl; const fallbackUrl = art.fallbackUrl; const coverAspectRatio = art.ratio; +// Cover-art PIP — only when an override image (a screenshot) is actually +// covering the rom's own art, and the consumer opted in. +const showCoverPip = computed(() => props.coverPip && !!props.coverSrc); // Alt-art styles (box3d / physical / miximage) drop the card frame so the // artwork floats — but only while a real image renders; with no cover the // placeholder keeps its grey box so the title stays readable. @@ -233,7 +242,11 @@ const { morphTransition } = useViewTransition(); // between ~1 and ~7 live `useGameActions` per card, which dominates a // virtualised grid's cost. Safe to call conditionally (no lifecycle hooks). const actions = - props.static || props.decorative ? null : useGameActions(() => props.rom); + props.static || props.decorative + ? null + : useGameActions(() => props.rom, { + coverEl: () => coverRef.value?.el() ?? null, + }); if (actions) provide(GAME_ACTIONS_KEY, actions); // Stop propagation so the card's morph + router push doesn't fire when @@ -455,6 +468,11 @@ function onStaticKeydown(e: KeyboardEvent) {
+ + + diff --git a/frontend/src/v2/components/shared/GameCover.vue b/frontend/src/v2/components/shared/GameCover.vue index 800b1bee8..fc13c41ff 100644 --- a/frontend/src/v2/components/shared/GameCover.vue +++ b/frontend/src/v2/components/shared/GameCover.vue @@ -29,6 +29,10 @@ import { type BoxartStyle, type CoverArtRom, } from "@/v2/composables/useCoverArt"; +import { + getCoverRatio, + setCoverRatio, +} from "@/v2/composables/useGalleryCoverRatios"; import { pendingMorphName } from "@/v2/composables/useViewTransition"; // inheritAttrs stays ON (default): consumers pass a `class` (e.g. @@ -122,14 +126,26 @@ const coverLoaded = ref(false); const activeSrc = computed(() => showFallback.value ? art.fallbackUrl.value : art.coverUrl.value, ); -// Natural ratio (w / h) of the rendered image, measured on load — drives -// the box shape. Null until decoded / for the placeholder (→ style ratio). -const naturalRatio = ref(null); +// Rom id to key the measured ratio under — but ONLY when this is the rom's +// own cover. With a `coverSrc` override (the cover shows a screenshot / +// marquee / preview blob instead) the measured ratio belongs to that image, +// not the rom's cover, so it must not land on the shared rom-id key the +// gallery flow-packer reads (it stays keyed by URL only). The morph still +// uses `props.morphId` directly — unaffected. +const ratioRomId = computed(() => (props.coverSrc ? null : props.morphId)); +// Natural ratio (w / h) of the rendered image. Seeded from the shared +// by-URL cache so a cover measured elsewhere (e.g. the gallery card the +// user just clicked) renders at its true shape immediately — no stretch +// during the morph. Falls back to the style ratio until the image decodes. +const naturalRatio = ref( + getCoverRatio({ url: activeSrc.value, romId: ratioRomId.value }), +); function measureNaturalRatio() { const el = imgEl.value; if (el && el.naturalWidth > 0 && el.naturalHeight > 0) { const r = el.naturalWidth / el.naturalHeight; naturalRatio.value = r; + setCoverRatio({ url: activeSrc.value, romId: ratioRomId.value }, r); emit("ratio", r); } } @@ -137,7 +153,7 @@ watch(activeSrc, (src) => { // Seed from the session-seen set: a URL we've already bloomed once skips the // reveal so a recycled card doesn't re-flash it (and doesn't pay the blur). coverLoaded.value = !!src && revealedCoverSrcs.has(src); - naturalRatio.value = null; + naturalRatio.value = getCoverRatio({ url: src, romId: ratioRomId.value }); }); const onCoverLoad = () => { coverLoaded.value = true; @@ -154,6 +170,7 @@ const coverActive = computed( const { isVideoPlaying, playLoad } = useCoverAnimation({ el: imgEl, + containerEl: rootEl, videoEl, animateCD: art.animateCD, animateCartridge: art.animateCartridge, @@ -231,6 +248,7 @@ defineExpose({ " :alt="title" :style="{ objectFit: art.objectFit.value }" + class="game-cover__img" :class="{ 'game-cover__img--behind': isVideoPlaying, 'game-cover__img--reveal': !coverLoaded && art.motionEnabled.value, @@ -259,6 +277,17 @@ defineExpose({ playsinline preload="none" /> + + @@ -281,22 +310,24 @@ defineExpose({ background: transparent; } -/* Direct-child selector so the placeholder's own isn't matched. */ -.game-cover > img { +/* The cover image. (The placeholder's own uses its own class.) */ +.game-cover__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; - /* Three motions ride this , each on its own property so they never + /* Four motions ride this , each on its own property so they never clobber each other: opacity crossfades to the hover video, filter + - scale drive the blur-up reveal on first paint, and the spin owns - `rotate` (set imperatively in useCoverAnimation). */ + scale drive the blur-up reveal on first paint, the spin owns `transform` + (set per-frame in useCoverAnimation), and `margin-top` is the + cartridge/disc slot-in slide (eased here so it composes with the spin). */ transition: opacity 0.35s ease, filter 0.6s ease, - scale 0.65s cubic-bezier(0.22, 1, 0.36, 1); + scale 0.65s cubic-bezier(0.22, 1, 0.36, 1), + margin 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55); } .game-cover__img--behind { opacity: 0; @@ -315,7 +346,7 @@ defineExpose({ @media (prefers-reduced-motion: reduce) { /* Keep a gentle opacity fade, drop the blur/scale flourish. */ - .game-cover > img { + .game-cover__img { transition: opacity 0.25s ease; } .game-cover__img--reveal { @@ -326,9 +357,9 @@ defineExpose({ .game-cover__video { position: absolute; - inset: 0; - width: 100%; - height: 100%; + top: 0.75rem; + left: 0.35rem; + width: 97%; object-fit: contain; opacity: 0; transition: opacity 0.35s ease; @@ -337,4 +368,19 @@ defineExpose({ .game-cover__video--playing { opacity: 1; } + +.game-cover__video-frame { + position: absolute; + top: 0; + width: 100%; + object-fit: contain; + opacity: 0; + transition: opacity 0.35s ease; + pointer-events: none; + transform: scale(1.01); + filter: hue-rotate(15deg); +} +.game-cover__video-frame--playing { + opacity: 1; +} diff --git a/frontend/src/v2/composables/useCoverAnimation/index.ts b/frontend/src/v2/composables/useCoverAnimation/index.ts index 11b58b623..2df4c980b 100644 --- a/frontend/src/v2/composables/useCoverAnimation/index.ts +++ b/frontend/src/v2/composables/useCoverAnimation/index.ts @@ -1,18 +1,25 @@ // useCoverAnimation — the "juicy" motion layer for alt-art game covers. // -// v2 rebuild of v1's deprecated `useGameAnimation` against a raw -// (v2 has no Vuetify VImg internals). Three behaviours, all driven by the -// card's hover/focus `active` signal and the flags `useCoverArt` resolves: -// * CD spin — physical art on a CD-based platform spins up on -// hover (accelerate) and coasts down on leave. -// * Cartridge — physical art on a cartridge platform does a one-shot -// "slot-in" drop when first hovered. -// * Hover video — miximage art crossfades to its `path_video` clip a -// beat after hover, and resets on leave. +// v2 port of v1's `useGameAnimation` (which drove a Vuetify VImg; v2 drives a +// raw ). Three behaviours, all gated by the card's hover/focus `active` +// signal and the flags `useCoverArt` resolves: +// * CD spin — physical art on a CD platform spins up on hover +// (accelerate) and coasts down on leave. The launch +// flourish spins it at max while it slides down into the +// drive and vanishes. +// * Cartridge — physical art on a cartridge platform seats fully into +// its bay on launch (no hover animation, matching v1). +// * Hover video — miximage art crossfades to its `path_video` clip a beat +// after hover, and resets on leave. +// +// The v1 trick (kept here because it's the part that makes it feel right): +// the slide is `margin-top` with an overshoot transition, while the spin is +// `transform: rotate` — two *different* properties, so they compose. A single +// `transform` for both can't be eased independently (the per-frame spin would +// fight the eased slide). // // All motion is gated by the user's `disableAnimations` setting (via -// `motionEnabled`) AND the OS `prefers-reduced-motion` — when either says -// no, the cover stays a still image. +// `motionEnabled`) AND the OS `prefers-reduced-motion`. import { computed, onBeforeUnmount, @@ -31,22 +38,31 @@ export interface SpinConfig { decel: number; } -// Mirrors v1's ANIMATION_CONFIG (maxRotationSpeed / acceleration / -// deceleration), kept as deg/sec(²) for the frame-rate-independent step. +// Mirrors v1's ANIMATION_CONFIG, kept as deg/sec(²) for the frame-rate- +// independent step. export const SPIN_CONFIG: SpinConfig = { maxSpeed: 5000, accel: 2500, decel: 1500, }; +// Cartridge slot-in depth on launch, as a fraction of the cover height +// (v1 seated at 1/3 on play). There is no cartridge hover animation. +const CART_SEAT_FRACTION = 1 / 3; + +// How long the player waits (ms) for the launch flourish before booting — +// the margin transition is 500ms; a little extra lets the motion read. +const CD_LOAD_MS = 700; +const CART_LOAD_MS = 600; + // Delay before the hover video kicks in, so fast scans across the gallery -// don't fire a burst of