mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 18:18:47 +01:00
feat: integrate playability checks and tooltips for platforms in PlatformListRow and PlatformTile components
This commit is contained in:
7
.vscode/tasks.json
vendored
7
.vscode/tasks.json
vendored
@@ -3,15 +3,14 @@
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Launch frontend",
|
||||
"type": "npm",
|
||||
"path": "frontend",
|
||||
"script": "dev",
|
||||
"type": "shell",
|
||||
"command": "cd frontend && npm i && npm run dev",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Launch backend",
|
||||
"type": "shell",
|
||||
"command": "cd backend && uv run python3 main.py",
|
||||
"command": "cd backend && uv sync --dev && uv run python3 main.py",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
import { RPlatformIcon } from "@v2/lib";
|
||||
import { computed, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import {
|
||||
playableTooltip,
|
||||
usePlatformPlayable,
|
||||
} from "@/v2/composables/usePlatformPlayable";
|
||||
import {
|
||||
pendingMorphName,
|
||||
useViewTransition,
|
||||
@@ -33,10 +37,6 @@ interface Props {
|
||||
familyName?: string | null;
|
||||
category?: string | null;
|
||||
generation?: number | null;
|
||||
/** Whether any ROM on this platform can run in-browser. Pre-computed
|
||||
* by the parent (PlatformsIndex) so the sort comparator and the row
|
||||
* read the same value. */
|
||||
playable?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -45,7 +45,6 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
familyName: null,
|
||||
category: null,
|
||||
generation: null,
|
||||
playable: false,
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
@@ -71,6 +70,9 @@ const generationLabel = computed(() =>
|
||||
: null,
|
||||
);
|
||||
|
||||
const { playable, emulator } = usePlatformPlayable(() => props.slug);
|
||||
const playableLabel = computed(() => playableTooltip(emulator.value));
|
||||
|
||||
function onRowClick(e: MouseEvent) {
|
||||
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) {
|
||||
return;
|
||||
@@ -121,15 +123,13 @@ function onRowClick(e: MouseEvent) {
|
||||
<div
|
||||
class="plat-list-row__cell plat-list-row__cell--meta plat-list-row__cell--center"
|
||||
>
|
||||
<span v-if="playable" class="plat-list-row__playable">
|
||||
<RIcon icon="mdi-play-circle" size="18" />
|
||||
<RTooltip
|
||||
activator="parent"
|
||||
text="Playable in browser"
|
||||
location="top"
|
||||
/>
|
||||
<span
|
||||
class="plat-list-row__playable"
|
||||
:class="{ 'plat-list-row__playable--off': !playable }"
|
||||
>
|
||||
<RIcon :icon="playable ? 'mdi-play-circle' : 'mdi-cancel'" size="18" />
|
||||
<RTooltip activator="parent" :text="playableLabel" location="top" />
|
||||
</span>
|
||||
<span v-else class="plat-list-row__placeholder">—</span>
|
||||
</div>
|
||||
|
||||
<div class="plat-list-row__cell plat-list-row__cell--end">
|
||||
@@ -225,6 +225,10 @@ function onRowClick(e: MouseEvent) {
|
||||
color: var(--r-color-success);
|
||||
}
|
||||
|
||||
.plat-list-row__playable--off {
|
||||
color: var(--r-color-fg-faint);
|
||||
}
|
||||
|
||||
.plat-list-row__meta {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
import { RPlatformIcon } from "@v2/lib";
|
||||
import { computed, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { usePlatformPlayable } from "@/v2/composables/usePlatformPlayable";
|
||||
import {
|
||||
playableTooltip,
|
||||
usePlatformPlayable,
|
||||
} from "@/v2/composables/usePlatformPlayable";
|
||||
import {
|
||||
pendingMorphName,
|
||||
useViewTransition,
|
||||
@@ -69,7 +72,8 @@ const morphStyle = computed(() =>
|
||||
: undefined,
|
||||
);
|
||||
|
||||
const { playable } = usePlatformPlayable(() => props.slug);
|
||||
const { playable, emulator } = usePlatformPlayable(() => props.slug);
|
||||
const playableLabel = computed(() => playableTooltip(emulator.value));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -89,9 +93,12 @@ const { playable } = usePlatformPlayable(() => props.slug);
|
||||
:show-tooltip="false"
|
||||
/>
|
||||
</div>
|
||||
<span v-if="playable" class="plat-tile__playable">
|
||||
<RIcon icon="mdi-play-circle" size="16" />
|
||||
<RTooltip activator="parent" text="Playable in browser" location="top" />
|
||||
<span
|
||||
class="plat-tile__playable"
|
||||
:class="{ 'plat-tile__playable--off': !playable }"
|
||||
>
|
||||
<RIcon :icon="playable ? 'mdi-play-circle' : 'mdi-cancel'" size="16" />
|
||||
<RTooltip activator="parent" :text="playableLabel" location="top" />
|
||||
</span>
|
||||
<div class="plat-tile__name">
|
||||
{{ displayName }}
|
||||
@@ -164,6 +171,10 @@ const { playable } = usePlatformPlayable(() => props.slug);
|
||||
color: var(--r-color-success);
|
||||
}
|
||||
|
||||
.plat-tile__playable--off {
|
||||
color: var(--r-color-fg-faint);
|
||||
}
|
||||
|
||||
.plat-tile:hover .plat-tile__icon {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
@@ -7,16 +7,46 @@
|
||||
// `usePlatformPlayableChecker` is the batch sibling — returns a plain
|
||||
// function (no per-call computed) for surfaces that need to test many
|
||||
// slugs at once (sort comparators, group-by buckets in PlatformsIndex).
|
||||
//
|
||||
// `emulator` resolves to the in-browser engine that actually drives the
|
||||
// platform: "ruffle" for Flash, "dosbox" when the EJS catalogue picks
|
||||
// the dosbox_pure core (DOS is wrapped by EJS but distinctive enough to
|
||||
// surface by name in the UI), "emulatorjs" for everything else playable,
|
||||
// and `null` when nothing on the server can run it.
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, type ComputedRef } from "vue";
|
||||
import storeConfig from "@/stores/config";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import { isEJSEmulationSupported, isRuffleEmulationSupported } from "@/utils";
|
||||
import storeConfig, { type Config } from "@/stores/config";
|
||||
import storeHeartbeat, { type Heartbeat } from "@/stores/heartbeat";
|
||||
import {
|
||||
getSupportedEJSCores,
|
||||
isEJSEmulationSupported,
|
||||
isRuffleEmulationSupported,
|
||||
} from "@/utils";
|
||||
|
||||
export type PlatformEmulator = "emulatorjs" | "ruffle" | "dosbox" | null;
|
||||
|
||||
/** Pure helper — picks the engine that would actually run a platform.
|
||||
* Shared between the reactive and the batch composables so both surface
|
||||
* the same label for the same slug. */
|
||||
function resolveEmulator(
|
||||
slug: string | null | undefined,
|
||||
heartbeat: Heartbeat,
|
||||
config: Config | undefined,
|
||||
): PlatformEmulator {
|
||||
if (!slug) return null;
|
||||
if (isRuffleEmulationSupported(slug, heartbeat, config)) return "ruffle";
|
||||
if (!isEJSEmulationSupported(slug, heartbeat, config)) return null;
|
||||
const resolved = config?.PLATFORMS_VERSIONS[slug] || slug;
|
||||
const cores = getSupportedEJSCores(resolved);
|
||||
if (cores.includes("dosbox_pure")) return "dosbox";
|
||||
return "emulatorjs";
|
||||
}
|
||||
|
||||
export function usePlatformPlayable(getSlug: () => string | null | undefined): {
|
||||
playable: ComputedRef<boolean>;
|
||||
playableEJS: ComputedRef<boolean>;
|
||||
playableRuffle: ComputedRef<boolean>;
|
||||
emulator: ComputedRef<PlatformEmulator>;
|
||||
} {
|
||||
const heartbeatStore = storeHeartbeat();
|
||||
const configStore = storeConfig();
|
||||
@@ -40,17 +70,24 @@ export function usePlatformPlayable(getSlug: () => string | null | undefined): {
|
||||
|
||||
const playable = computed(() => playableEJS.value || playableRuffle.value);
|
||||
|
||||
return { playable, playableEJS, playableRuffle };
|
||||
const emulator = computed<PlatformEmulator>(() =>
|
||||
resolveEmulator(getSlug(), heartbeat.value, configStore.config),
|
||||
);
|
||||
|
||||
return { playable, playableEJS, playableRuffle, emulator };
|
||||
}
|
||||
|
||||
export function usePlatformPlayableChecker(): {
|
||||
isPlayable: ComputedRef<(slug: string | null | undefined) => boolean>;
|
||||
getEmulator: ComputedRef<
|
||||
(slug: string | null | undefined) => PlatformEmulator
|
||||
>;
|
||||
} {
|
||||
const heartbeatStore = storeHeartbeat();
|
||||
const configStore = storeConfig();
|
||||
const { value: heartbeat } = storeToRefs(heartbeatStore);
|
||||
|
||||
// Expose a computed function so callers that consume it inside another
|
||||
// Expose computed functions so callers that consume them inside another
|
||||
// computed (sort comparator, bucket discriminator) re-run when the
|
||||
// heartbeat or admin-toggle state changes.
|
||||
const isPlayable = computed(() => {
|
||||
@@ -65,5 +102,27 @@ export function usePlatformPlayableChecker(): {
|
||||
};
|
||||
});
|
||||
|
||||
return { isPlayable };
|
||||
const getEmulator = computed(() => {
|
||||
const hb = heartbeat.value;
|
||||
const cfg = configStore.config;
|
||||
return (slug: string | null | undefined): PlatformEmulator =>
|
||||
resolveEmulator(slug, hb, cfg);
|
||||
});
|
||||
|
||||
return { isPlayable, getEmulator };
|
||||
}
|
||||
|
||||
/** Human-readable tooltip for the playable badge / column. Shared by
|
||||
* every surface so the wording stays in lock-step. */
|
||||
export function playableTooltip(emulator: PlatformEmulator): string {
|
||||
switch (emulator) {
|
||||
case "ruffle":
|
||||
return "Playable in browser through Ruffle";
|
||||
case "dosbox":
|
||||
return "Playable in browser through DOSBox";
|
||||
case "emulatorjs":
|
||||
return "Playable in browser through EmulatorJS";
|
||||
case null:
|
||||
return "Not supported by EmulatorJS";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +391,6 @@ const groupedBuckets = computed<Bucket[] | null>(() => {
|
||||
:family-name="p.family_name ?? null"
|
||||
:category="p.category ?? null"
|
||||
:generation="p.generation ?? null"
|
||||
:playable="playableById.get(p.id) ?? false"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user