mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 02:24:09 +01:00
refactor(v2): extract a shared player shell
EmulatorJS.vue and Ruffle.vue each carry their own copy of the block every v2
player opens with: the synchronous hero seeding, title, platform label and
background-art watch. Ruffle additionally hand-rolls the cover column,
settings card, back buttons and loading spinner that any simple player needs.
Extract two seams:
* usePlayerHero — the seed/hero/title/platform-label block plus the
background-art watch, adopted by both players. The caller keeps ownership
of the `rom` ref because EmulatorJS needs a deep one for the save and
state lists it mutates.
* PlayerShell — the cover column, settings card, play and back buttons, the
full-bleed running stage and the loading state, with `settings`, `stage`
and `brand` slots. Ruffle keeps only its colour picker, brand strip and
stage. EmulatorJS deliberately opts out: its hero sits inside a card with
an alt-art glow and it lays out three panels on its own breakpoints, so it
takes the composable alone.
Stream.vue is left alone: its label comes from the streaming container, its
background art clears while playing, and it has its own back route.
No intended behaviour change. Ruffle's hand-rolled loading spinner is now
RSpinner, matching the other players.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
227
frontend/src/v2/components/Player/PlayerShell.vue
Normal file
227
frontend/src/v2/components/Player/PlayerShell.vue
Normal file
@@ -0,0 +1,227 @@
|
||||
<script setup lang="ts">
|
||||
// PlayerShell — the pre-game chrome a simple v2 player needs: cover column,
|
||||
// settings card, play and back buttons, and the full-bleed running stage. A
|
||||
// player supplies only the controls above the Play button and whatever it
|
||||
// mounts as a stage, through the `settings` and `stage` slots.
|
||||
//
|
||||
// EmulatorJS deliberately does not use this: its hero lives inside a card with
|
||||
// an alt-art glow and it lays out three panels on its own breakpoints. It takes
|
||||
// `usePlayerHero` instead.
|
||||
import { RBtn, RCard, RSpinner } from "@v2/lib";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRouter } from "vue-router";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
import type { DetailedRom, SimpleRom } from "@/stores/roms";
|
||||
import GameCover from "@/v2/components/shared/GameCover.vue";
|
||||
|
||||
interface Props {
|
||||
/** Full rom once loaded, else the cover-only seed during the morph-in. */
|
||||
heroRom: DetailedRom | SimpleRom | null;
|
||||
title: string;
|
||||
platformLabel: string;
|
||||
/** Route rom id, bound before `heroRom` resolves so the morph tag paints. */
|
||||
romId: number;
|
||||
/** The full payload has landed, so the game can actually boot. */
|
||||
ready: boolean;
|
||||
running: boolean;
|
||||
/** Keeps the quit button busy while an exit is still saving. */
|
||||
quitting?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), { quitting: false });
|
||||
|
||||
const emit = defineEmits<{
|
||||
play: [];
|
||||
quit: [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
|
||||
function backToRom() {
|
||||
router.push({ name: ROUTES.ROM, params: { rom: props.romId } });
|
||||
}
|
||||
|
||||
function backToPlatform() {
|
||||
const platformId = props.heroRom?.platform_id;
|
||||
if (platformId == null) return;
|
||||
router.push({ name: ROUTES.PLATFORM, params: { platform: platformId } });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="heroRom" class="r-v2-player">
|
||||
<div v-if="!running" class="r-v2-player__config">
|
||||
<aside class="r-v2-player__cover">
|
||||
<GameCover
|
||||
class="r-v2-player__cover-box"
|
||||
:rom="heroRom"
|
||||
:title="title"
|
||||
:identified="heroRom?.is_identified ?? true"
|
||||
:morph-id="romId"
|
||||
style-context="player"
|
||||
morph-static
|
||||
hover-motion
|
||||
/>
|
||||
<h1 class="r-v2-player__title">
|
||||
{{ title }}
|
||||
</h1>
|
||||
<p class="r-v2-player__subtitle">
|
||||
{{ platformLabel }}
|
||||
</p>
|
||||
</aside>
|
||||
|
||||
<RCard class="r-v2-player__panel" variant="flat">
|
||||
<div class="r-v2-player__settings">
|
||||
<slot name="settings" />
|
||||
|
||||
<RBtn
|
||||
size="large"
|
||||
variant="flat"
|
||||
color="primary"
|
||||
block
|
||||
prepend-icon="mdi-play-circle"
|
||||
class="r-v2-player__play"
|
||||
:loading="!ready"
|
||||
:disabled="!ready"
|
||||
@click="emit('play')"
|
||||
>
|
||||
{{ t("play.play") }}
|
||||
</RBtn>
|
||||
|
||||
<RBtn
|
||||
block
|
||||
variant="text"
|
||||
size="small"
|
||||
prepend-icon="mdi-arrow-left"
|
||||
@click="backToRom"
|
||||
>
|
||||
{{ t("play.back-to-game-details") }}
|
||||
</RBtn>
|
||||
<RBtn
|
||||
block
|
||||
variant="text"
|
||||
size="small"
|
||||
prepend-icon="mdi-view-grid-outline"
|
||||
@click="backToPlatform"
|
||||
>
|
||||
{{ t("play.back-to-gallery") }}
|
||||
</RBtn>
|
||||
</div>
|
||||
</RCard>
|
||||
|
||||
<slot name="brand" />
|
||||
</div>
|
||||
|
||||
<div v-else class="r-v2-player__stage-wrap">
|
||||
<slot name="stage" />
|
||||
<RBtn
|
||||
class="r-v2-player__quit"
|
||||
variant="translucent"
|
||||
prepend-icon="mdi-exit-to-app"
|
||||
:loading="quitting"
|
||||
:disabled="quitting"
|
||||
@click="emit('quit')"
|
||||
>
|
||||
{{ t("play.quit") }}
|
||||
</RBtn>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-else class="r-v2-player__loading">
|
||||
<RSpinner :size="40" :aria-label="t('common.loading')" />
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-v2-player {
|
||||
position: relative;
|
||||
min-height: calc(100vh - var(--r-nav-h));
|
||||
padding: 24px var(--r-row-pad) 48px;
|
||||
}
|
||||
|
||||
.r-v2-player__config {
|
||||
display: grid;
|
||||
grid-template-columns: 240px 1fr;
|
||||
gap: 24px;
|
||||
max-width: 820px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.r-v2-player__cover {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.r-v2-player__cover-box {
|
||||
--r-cover-radius: var(--r-radius-lg);
|
||||
}
|
||||
/* 2D box art keeps a drop shadow; alt-art floats frame-free. */
|
||||
.r-v2-player__cover-box:not(.game-cover--alt) {
|
||||
box-shadow: 0 18px 36px color-mix(in srgb, black 55%, transparent);
|
||||
}
|
||||
|
||||
.r-v2-player__title {
|
||||
margin: 10px 0 0;
|
||||
font-size: var(--r-font-size-xl);
|
||||
font-weight: var(--r-font-weight-bold);
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.r-v2-player__subtitle {
|
||||
margin: 0;
|
||||
font-size: var(--r-font-size-sm);
|
||||
color: var(--r-color-fg-muted);
|
||||
}
|
||||
|
||||
.r-v2-player__panel {
|
||||
background: var(--r-color-bg-elevated) !important;
|
||||
border: 1px solid var(--r-color-border) !important;
|
||||
border-radius: var(--r-radius-lg) !important;
|
||||
backdrop-filter: blur(18px);
|
||||
display: flex !important;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.r-v2-player__settings {
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.r-v2-player__play {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.r-v2-player__stage-wrap {
|
||||
position: fixed;
|
||||
inset: var(--r-nav-h) 0 0 0;
|
||||
background: var(--r-color-canvas-bg);
|
||||
z-index: 1;
|
||||
}
|
||||
.r-v2-player__quit {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.r-v2-player__loading {
|
||||
min-height: calc(100vh - var(--r-nav-h));
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .r-v2-player__config {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
html[data-bp~="xs"] .r-v2-player__cover {
|
||||
max-width: 240px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
76
frontend/src/v2/composables/usePlayerHero/index.ts
Normal file
76
frontend/src/v2/composables/usePlayerHero/index.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
// usePlayerHero — the seed / hero / title block a v2 player view opens with.
|
||||
// EmulatorJS and Ruffle both refetch the full ROM on mount but need a cover in
|
||||
// the DOM *before* that resolves, so the shared-element morph from the gallery
|
||||
// or details cover pairs on entry.
|
||||
//
|
||||
// Seeding is synchronous: from GameDetails the full DetailedRom is already in
|
||||
// `currentRom`; on a direct gallery→play only a SimpleRom exists, so a
|
||||
// cover-only `heroSeed` stands in until the view's own fetch lands.
|
||||
//
|
||||
// The caller owns the `rom` ref — EmulatorJS needs a deep one for the save and
|
||||
// state lists it mutates — and this seeds into it.
|
||||
import { computed, type ComputedRef, type Ref, shallowRef, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute } from "vue-router";
|
||||
import storeRoms, { type DetailedRom, type SimpleRom } from "@/stores/roms";
|
||||
import { useBackgroundArt } from "@/v2/composables/useBackgroundArt";
|
||||
import { usePageTitle } from "@/v2/composables/usePageTitle";
|
||||
import storeGalleryRoms from "@/v2/stores/galleryRoms";
|
||||
|
||||
export function usePlayerHero(rom: Ref<DetailedRom | null>): {
|
||||
romId: number;
|
||||
heroSeed: Ref<SimpleRom | null>;
|
||||
heroRom: ComputedRef<DetailedRom | SimpleRom | null>;
|
||||
title: ComputedRef<string>;
|
||||
platformLabel: ComputedRef<string>;
|
||||
} {
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const setBgArt = useBackgroundArt();
|
||||
|
||||
const romId = Number(route.params.rom);
|
||||
|
||||
const seededRom = storeRoms().currentRom;
|
||||
if (seededRom?.id === romId) {
|
||||
rom.value = seededRom;
|
||||
}
|
||||
const heroSeed = shallowRef<SimpleRom | null>(null);
|
||||
if (!rom.value) {
|
||||
heroSeed.value = storeGalleryRoms().getRomById(romId);
|
||||
}
|
||||
|
||||
const heroRom = computed<DetailedRom | SimpleRom | null>(
|
||||
() => rom.value ?? heroSeed.value,
|
||||
);
|
||||
|
||||
const title = computed(
|
||||
() => heroRom.value?.name || heroRom.value?.fs_name_no_ext || "",
|
||||
);
|
||||
|
||||
usePageTitle(() =>
|
||||
title.value ? t("play.page-title", { name: title.value }) : null,
|
||||
);
|
||||
|
||||
const platformLabel = computed(
|
||||
() =>
|
||||
heroRom.value?.platform_custom_name ||
|
||||
heroRom.value?.platform_display_name ||
|
||||
"",
|
||||
);
|
||||
|
||||
// Background art keeps the plain 2D cover — a blurred disc or cartridge
|
||||
// reads poorly as a full-bleed backdrop.
|
||||
watch(
|
||||
() => {
|
||||
const r = rom.value;
|
||||
if (!r) return null;
|
||||
return r.path_cover_large ?? r.path_cover_small ?? r.url_cover ?? null;
|
||||
},
|
||||
(url) => {
|
||||
if (url) setBgArt(url);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
return { romId, heroSeed, heroRom, title, platformLabel };
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
watch,
|
||||
} from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useRouter } from "vue-router";
|
||||
import type { FirmwareSchema, SaveSchema, StateSchema } from "@/__generated__";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
import firmwareApi from "@/services/api/firmware";
|
||||
@@ -37,21 +37,19 @@ import socket from "@/services/socket";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeConfig from "@/stores/config";
|
||||
import storePlaying from "@/stores/playing";
|
||||
import storeRoms, { type DetailedRom, type SimpleRom } from "@/stores/roms";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import { getSupportedEJSCores } from "@/utils";
|
||||
import AssetPreview from "@/v2/components/Player/AssetPreview.vue";
|
||||
import AssetList from "@/v2/components/shared/AssetList.vue";
|
||||
import AssetStrip from "@/v2/components/shared/AssetStrip.vue";
|
||||
import GameCover from "@/v2/components/shared/GameCover.vue";
|
||||
import { useBackgroundArt } from "@/v2/composables/useBackgroundArt";
|
||||
import { useCoverArt } from "@/v2/composables/useCoverArt";
|
||||
import { useFullscreenPref } from "@/v2/composables/useFullscreenPref";
|
||||
import { useInputModality } from "@/v2/composables/useInputModality";
|
||||
import { usePageTitle } from "@/v2/composables/usePageTitle";
|
||||
import { usePlaySession } from "@/v2/composables/usePlaySession";
|
||||
import { usePlayerHero } from "@/v2/composables/usePlayerHero";
|
||||
import type { SliderBtnGroupItem } from "@/v2/lib/primitives/RSliderBtnGroup/types";
|
||||
import storeGalleryRoms from "@/v2/stores/galleryRoms";
|
||||
import {
|
||||
resolveBezelHost,
|
||||
resolveBezelUrl,
|
||||
@@ -75,7 +73,6 @@ const Player = defineAsyncComponent(
|
||||
);
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const auth = storeAuth();
|
||||
@@ -99,34 +96,7 @@ const rom = ref<DetailedRom | null>(null);
|
||||
const firmwareOptions = ref<FirmwareSchema[]>([]);
|
||||
const selectedSave = ref<SaveSchema | null>(null);
|
||||
|
||||
// Rom id straight from the route param (available before `rom` resolves),
|
||||
// so the hero cover paints its `view-transition-name` immediately and the
|
||||
// shared-element morph from the gallery / details cover pairs on entry.
|
||||
const morphRomId = computed(() => {
|
||||
const r = route.params.rom;
|
||||
return typeof r === "string" ? r : null;
|
||||
});
|
||||
|
||||
// Seed synchronously so the hero cover is already in the DOM when the view
|
||||
// transition captures this view — the morph from the details / gallery cover
|
||||
// then pairs on entry. `onMounted` refetches the full payload.
|
||||
// * From GameDetails: `currentRom` is the full DetailedRom → seed `rom`.
|
||||
// * Direct gallery→play: only a SimpleRom exists (the gallery card) → seed a
|
||||
// cover-only `heroSeed` so the cover still paints its morph tag. `rom`
|
||||
// stays null (its DetailedRom-only fields are read guarded) until mount.
|
||||
const seededRom = storeRoms().currentRom;
|
||||
if (seededRom && String(seededRom.id) === morphRomId.value) {
|
||||
rom.value = seededRom;
|
||||
}
|
||||
const heroSeed = ref<SimpleRom | null>(null);
|
||||
if (!rom.value && morphRomId.value != null) {
|
||||
heroSeed.value = storeGalleryRoms().getRomById(Number(morphRomId.value));
|
||||
}
|
||||
// What the hero cover / title / glow read: the full rom once loaded, else the
|
||||
// lightweight seed during the morph-in window.
|
||||
const heroRom = computed<DetailedRom | SimpleRom | null>(
|
||||
() => rom.value ?? heroSeed.value,
|
||||
);
|
||||
const { romId, heroSeed, heroRom, title, platformLabel } = usePlayerHero(rom);
|
||||
const isSavesTabSelected = ref(true);
|
||||
const selectedState = ref<StateSchema | null>(null);
|
||||
const selectedDisc = ref<DiscSelection>(null);
|
||||
@@ -207,8 +177,6 @@ const discItems = computed<{ title: string; value: DiscSelection }[]>(() => [
|
||||
})),
|
||||
]);
|
||||
|
||||
const setBgArt = useBackgroundArt();
|
||||
|
||||
// The hero cover is the shared GameCover (same component as gallery +
|
||||
// details). We keep a lightweight `useCoverArt` here only to know whether
|
||||
// the active style is alt-art, so the purple glow can be dropped for a
|
||||
@@ -233,7 +201,7 @@ const bezelUrl = computed(() =>
|
||||
// the route param so it binds before `rom` resolves; stored as the compact "0"
|
||||
// hidden / "1" shown marker (anything else fails safe to shown), and defaults
|
||||
// are not written so merely opening a game leaves storage untouched.
|
||||
const showBezel = useLocalStorage(`player:${morphRomId.value}:bezel`, true, {
|
||||
const showBezel = useLocalStorage(`player:${romId}:bezel`, true, {
|
||||
writeDefaults: false,
|
||||
serializer: {
|
||||
read: resolveStoredBezelVisible,
|
||||
@@ -249,22 +217,6 @@ useEventListener(document, "fullscreenchange", () => {
|
||||
bezelHost.value = resolveBezelHost(document.fullscreenElement);
|
||||
});
|
||||
|
||||
// Background art keeps the plain 2D cover — a blurred disc / cartridge
|
||||
// reads poorly as a full-bleed backdrop.
|
||||
const bgCoverUrl = computed(() => {
|
||||
const r = rom.value;
|
||||
if (!r) return null;
|
||||
return r.path_cover_large ?? r.path_cover_small ?? r.url_cover ?? null;
|
||||
});
|
||||
|
||||
watch(
|
||||
bgCoverUrl,
|
||||
(url) => {
|
||||
if (url) setBgArt(url);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
async function onPlay() {
|
||||
// Launch flourish on the visible cover (disc drop+spin / cartridge
|
||||
// slot-in) before booting, so the insert is seen. Returns 0 for non-
|
||||
@@ -357,7 +309,7 @@ watch(selectedCore, (newSelectedCore) => {
|
||||
|
||||
onMounted(async () => {
|
||||
const romResponse = await romApi.getRom({
|
||||
romId: parseInt(route.params.rom as string),
|
||||
romId,
|
||||
});
|
||||
rom.value = romResponse.data;
|
||||
|
||||
@@ -499,21 +451,6 @@ function backToPlatform() {
|
||||
});
|
||||
}
|
||||
|
||||
const title = computed(
|
||||
() => heroRom.value?.name || heroRom.value?.fs_name_no_ext || "",
|
||||
);
|
||||
|
||||
usePageTitle(() =>
|
||||
title.value ? t("play.page-title", { name: title.value }) : null,
|
||||
);
|
||||
|
||||
const platformLabel = computed(
|
||||
() =>
|
||||
heroRom.value?.platform_custom_name ||
|
||||
heroRom.value?.platform_display_name ||
|
||||
"",
|
||||
);
|
||||
|
||||
type AssetTab = "save" | "state";
|
||||
const activeAssetTab = computed<AssetTab>(() =>
|
||||
isSavesTabSelected.value ? "save" : "state",
|
||||
@@ -581,7 +518,7 @@ const selectedAsset = computed<SaveSchema | StateSchema | null>(() =>
|
||||
:rom="heroRom"
|
||||
:title="title"
|
||||
:identified="heroRom?.is_identified ?? true"
|
||||
:morph-id="morphRomId"
|
||||
:morph-id="romId"
|
||||
style-context="player"
|
||||
morph-static
|
||||
hover-motion
|
||||
|
||||
@@ -3,37 +3,24 @@
|
||||
// createPlayer, fullscreen) is ported verbatim from
|
||||
// `src/views/Player/RuffleRS/Base.vue` so playback stays identical; only the
|
||||
// chrome is v2. No shared state with EJS — Flash has its own config.
|
||||
import { RBtn, RCard, RIcon, RSwitch } from "@v2/lib";
|
||||
import {
|
||||
computed,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
ref,
|
||||
watch,
|
||||
} from "vue";
|
||||
import { RIcon, RSwitch } from "@v2/lib";
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
import romApi from "@/services/api/rom";
|
||||
import storePlaying from "@/stores/playing";
|
||||
import storeRoms, { type DetailedRom, type SimpleRom } from "@/stores/roms";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import type { RuffleSourceAPI } from "@/types/ruffle";
|
||||
import { getDownloadPath } from "@/utils";
|
||||
import GameCover from "@/v2/components/shared/GameCover.vue";
|
||||
import { useBackgroundArt } from "@/v2/composables/useBackgroundArt";
|
||||
import PlayerShell from "@/v2/components/Player/PlayerShell.vue";
|
||||
import { useFullscreenPref } from "@/v2/composables/useFullscreenPref";
|
||||
import { usePageTitle } from "@/v2/composables/usePageTitle";
|
||||
import { usePlaySession } from "@/v2/composables/usePlaySession";
|
||||
import storeGalleryRoms from "@/v2/stores/galleryRoms";
|
||||
import { usePlayerHero } from "@/v2/composables/usePlayerHero";
|
||||
import { colorCanvas } from "@/v2/tokens";
|
||||
|
||||
const RUFFLE_VERSION = "0.2.0-nightly.2025.8.14";
|
||||
const DEFAULT_BACKGROUND_COLOR = colorCanvas.bgDeep;
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { fullscreenOnPlay } = useFullscreenPref();
|
||||
const playingStore = storePlaying();
|
||||
const playSession = usePlaySession();
|
||||
@@ -42,31 +29,6 @@ const rom = ref<DetailedRom | null>(null);
|
||||
const gameRunning = ref(false);
|
||||
const backgroundColor = ref<string>(DEFAULT_BACKGROUND_COLOR);
|
||||
|
||||
// Rom id from the route param (available before `rom` resolves) so the hero
|
||||
// cover paints its `view-transition-name` immediately and the shared-element
|
||||
// morph from the gallery / details cover pairs on entry.
|
||||
const morphRomId = computed(() => {
|
||||
const r = route.params.rom;
|
||||
return typeof r === "string" ? r : null;
|
||||
});
|
||||
|
||||
// Seed synchronously so the hero cover is in the DOM when the view transition
|
||||
// captures this view and the morph pairs on entry. From GameDetails the full
|
||||
// DetailedRom is in `currentRom`; on a direct gallery→play only a SimpleRom
|
||||
// exists, so seed a cover-only `heroSeed` (`rom` stays null until `onMounted`
|
||||
// refetches). See EmulatorJS for the same pattern.
|
||||
const seededRom = storeRoms().currentRom;
|
||||
if (seededRom && String(seededRom.id) === morphRomId.value) {
|
||||
rom.value = seededRom;
|
||||
}
|
||||
const heroSeed = ref<SimpleRom | null>(null);
|
||||
if (!rom.value && morphRomId.value != null) {
|
||||
heroSeed.value = storeGalleryRoms().getRomById(Number(morphRomId.value));
|
||||
}
|
||||
const heroRom = computed<DetailedRom | SimpleRom | null>(
|
||||
() => rom.value ?? heroSeed.value,
|
||||
);
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
RufflePlayer: {
|
||||
@@ -84,41 +46,7 @@ declare global {
|
||||
|
||||
window.RufflePlayer = window.RufflePlayer || {};
|
||||
|
||||
const setBgArt = useBackgroundArt();
|
||||
|
||||
// The cover is the shared GameCover (same component as gallery + details +
|
||||
// EmulatorJS) — it owns style/ratio/placeholder. Flash has no disc /
|
||||
// cartridge metadata, so it's effectively always 2D box art here.
|
||||
|
||||
// Background art keeps the plain 2D cover.
|
||||
const bgCoverUrl = computed(() => {
|
||||
const r = rom.value;
|
||||
if (!r) return null;
|
||||
return r.path_cover_large ?? r.path_cover_small ?? r.url_cover ?? null;
|
||||
});
|
||||
|
||||
watch(
|
||||
bgCoverUrl,
|
||||
(url) => {
|
||||
if (url) setBgArt(url);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const title = computed(
|
||||
() => heroRom.value?.name || heroRom.value?.fs_name_no_ext || "",
|
||||
);
|
||||
|
||||
usePageTitle(() =>
|
||||
title.value ? t("play.page-title", { name: title.value }) : null,
|
||||
);
|
||||
|
||||
const platformLabel = computed(
|
||||
() =>
|
||||
heroRom.value?.platform_custom_name ||
|
||||
heroRom.value?.platform_display_name ||
|
||||
"",
|
||||
);
|
||||
const { romId, heroRom, title, platformLabel } = usePlayerHero(rom);
|
||||
|
||||
function onPlay() {
|
||||
gameRunning.value = true;
|
||||
@@ -173,20 +101,8 @@ function onlyQuit() {
|
||||
window.history.back();
|
||||
}
|
||||
|
||||
function backToRom() {
|
||||
router.push({ name: ROUTES.ROM, params: { rom: rom.value?.id } });
|
||||
}
|
||||
function backToPlatform() {
|
||||
router.push({
|
||||
name: ROUTES.PLATFORM,
|
||||
params: { platform: rom.value?.platform_id },
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const romResponse = await romApi.getRom({
|
||||
romId: parseInt(route.params.rom as string),
|
||||
});
|
||||
const romResponse = await romApi.getRom({ romId });
|
||||
rom.value = romResponse.data;
|
||||
|
||||
if (rom.value) {
|
||||
@@ -216,173 +132,52 @@ onBeforeUnmount(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="rom || heroSeed" class="r-v2-ruffle">
|
||||
<!-- Pre-game configuration -->
|
||||
<div v-if="!gameRunning" class="r-v2-ruffle__config">
|
||||
<!-- Cover column -->
|
||||
<aside class="r-v2-ruffle__cover">
|
||||
<GameCover
|
||||
class="r-v2-ruffle__cover-box"
|
||||
:rom="heroRom"
|
||||
:title="title"
|
||||
:identified="heroRom?.is_identified ?? true"
|
||||
:morph-id="morphRomId"
|
||||
style-context="player"
|
||||
morph-static
|
||||
hover-motion
|
||||
<PlayerShell
|
||||
:hero-rom="heroRom"
|
||||
:title="title"
|
||||
:platform-label="platformLabel"
|
||||
:rom-id="romId"
|
||||
:ready="!!rom"
|
||||
:running="gameRunning"
|
||||
@play="onPlay"
|
||||
@quit="onlyQuit"
|
||||
>
|
||||
<template #settings>
|
||||
<div class="r-v2-ruffle__section-label">
|
||||
<RIcon icon="mdi-palette" size="16" />
|
||||
<span>{{ t("play.select-background-color") }}</span>
|
||||
</div>
|
||||
<div class="r-v2-ruffle__color-row">
|
||||
<input
|
||||
v-model="backgroundColor"
|
||||
type="color"
|
||||
class="r-v2-ruffle__color-input"
|
||||
:aria-label="t('play.select-background-color')"
|
||||
:title="t('play.select-background-color')"
|
||||
@change="onBackgroundColorChange"
|
||||
/>
|
||||
<h1 class="r-v2-ruffle__title">
|
||||
{{ title }}
|
||||
</h1>
|
||||
<p class="r-v2-ruffle__subtitle">
|
||||
{{ platformLabel }}
|
||||
</p>
|
||||
</aside>
|
||||
<code class="r-v2-ruffle__color-code">
|
||||
{{ backgroundColor.toUpperCase() }}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<!-- Settings panel -->
|
||||
<RCard class="r-v2-ruffle__panel" variant="flat">
|
||||
<div class="r-v2-ruffle__settings">
|
||||
<div class="r-v2-ruffle__section-label">
|
||||
<RIcon icon="mdi-palette" size="16" />
|
||||
<span>{{ t("play.select-background-color") }}</span>
|
||||
</div>
|
||||
<div class="r-v2-ruffle__color-row">
|
||||
<input
|
||||
v-model="backgroundColor"
|
||||
type="color"
|
||||
class="r-v2-ruffle__color-input"
|
||||
:aria-label="t('play.select-background-color')"
|
||||
:title="t('play.select-background-color')"
|
||||
@change="onBackgroundColorChange"
|
||||
/>
|
||||
<code class="r-v2-ruffle__color-code">
|
||||
{{ backgroundColor.toUpperCase() }}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<RSwitch v-model="fullscreenOnPlay" :label="t('play.full-screen')" />
|
||||
|
||||
<RBtn
|
||||
size="large"
|
||||
variant="flat"
|
||||
color="primary"
|
||||
block
|
||||
prepend-icon="mdi-play-circle"
|
||||
class="r-v2-ruffle__play"
|
||||
:loading="!rom"
|
||||
:disabled="!rom"
|
||||
@click="onPlay"
|
||||
>
|
||||
{{ t("play.play") }}
|
||||
</RBtn>
|
||||
|
||||
<RBtn
|
||||
block
|
||||
variant="text"
|
||||
size="small"
|
||||
prepend-icon="mdi-arrow-left"
|
||||
@click="backToRom"
|
||||
>
|
||||
{{ t("play.back-to-game-details") }}
|
||||
</RBtn>
|
||||
<RBtn
|
||||
block
|
||||
variant="text"
|
||||
size="small"
|
||||
prepend-icon="mdi-view-grid-outline"
|
||||
@click="backToPlatform"
|
||||
>
|
||||
{{ t("play.back-to-gallery") }}
|
||||
</RBtn>
|
||||
</div>
|
||||
</RCard>
|
||||
<RSwitch v-model="fullscreenOnPlay" :label="t('play.full-screen')" />
|
||||
</template>
|
||||
|
||||
<template #brand>
|
||||
<div class="r-v2-ruffle__brand">
|
||||
<span>{{ t("play.powered-by") }}</span>
|
||||
<img src="/assets/ruffle/ruffle.svg" alt="Ruffle" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Running state — full bleed minus nav -->
|
||||
<div v-else class="r-v2-ruffle__stage-wrap">
|
||||
<template #stage>
|
||||
<div id="r-v2-ruffle-stage" class="r-v2-ruffle__stage" />
|
||||
<RBtn
|
||||
class="r-v2-ruffle__quit"
|
||||
variant="translucent"
|
||||
prepend-icon="mdi-exit-to-app"
|
||||
@click="onlyQuit"
|
||||
>
|
||||
{{ t("play.quit") }}
|
||||
</RBtn>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-else class="r-v2-ruffle__loading">
|
||||
<div class="r-v2-ruffle__spinner" :aria-label="t('common.loading')" />
|
||||
</section>
|
||||
</template>
|
||||
</PlayerShell>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-v2-ruffle {
|
||||
position: relative;
|
||||
min-height: calc(100vh - var(--r-nav-h));
|
||||
padding: 24px var(--r-row-pad) 48px;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__config {
|
||||
display: grid;
|
||||
grid-template-columns: 240px 1fr;
|
||||
gap: 24px;
|
||||
max-width: 820px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__cover {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__cover-box {
|
||||
--r-cover-radius: var(--r-radius-lg);
|
||||
}
|
||||
/* 2D box art keeps a drop shadow; alt-art (rare for Flash) floats frame-free. */
|
||||
.r-v2-ruffle__cover-box:not(.game-cover--alt) {
|
||||
box-shadow: 0 18px 36px color-mix(in srgb, black 55%, transparent);
|
||||
}
|
||||
|
||||
.r-v2-ruffle__title {
|
||||
margin: 10px 0 0;
|
||||
font-size: var(--r-font-size-xl);
|
||||
font-weight: var(--r-font-weight-bold);
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__subtitle {
|
||||
margin: 0;
|
||||
font-size: var(--r-font-size-sm);
|
||||
color: var(--r-color-fg-muted);
|
||||
}
|
||||
|
||||
.r-v2-ruffle__panel {
|
||||
background: var(--r-color-bg-elevated) !important;
|
||||
border: 1px solid var(--r-color-border) !important;
|
||||
border-radius: var(--r-radius-lg) !important;
|
||||
backdrop-filter: blur(18px);
|
||||
display: flex !important;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__settings {
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__section-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -423,10 +218,6 @@ onBeforeUnmount(() => {
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__play {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__brand {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
@@ -442,49 +233,9 @@ onBeforeUnmount(() => {
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
/* Running state */
|
||||
.r-v2-ruffle__stage-wrap {
|
||||
position: fixed;
|
||||
inset: var(--r-nav-h) 0 0 0;
|
||||
background: var(--r-color-canvas-bg);
|
||||
z-index: 1;
|
||||
}
|
||||
.r-v2-ruffle__stage {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
--splash-screen-background: none;
|
||||
}
|
||||
.r-v2-ruffle__quit {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.r-v2-ruffle__loading {
|
||||
min-height: calc(100vh - var(--r-nav-h));
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
.r-v2-ruffle__spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid var(--r-color-surface-hover);
|
||||
border-top-color: var(--r-color-brand-primary);
|
||||
animation: r-v2-ruffle-spin 0.8s linear infinite;
|
||||
}
|
||||
@keyframes r-v2-ruffle-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .r-v2-ruffle__config {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
html[data-bp~="xs"] .r-v2-ruffle__cover {
|
||||
max-width: 240px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user