feat: add random game button and localization for random ROM functionality

This commit is contained in:
zurdi
2026-06-19 12:40:10 +00:00
parent 68793c1f93
commit fcccb5d583
19 changed files with 132 additions and 19 deletions

View File

@@ -81,5 +81,8 @@
"cover-style": "Стил на корица",
"firmware-verified": "Потвърден",
"old-horizontal-cases": "Стари хоризонтални кутии",
"old-squared-cases": "Стари квадратни кутии"
"old-squared-cases": "Стари квадратни кутии",
"random-rom": "Случаен ROM",
"random-rom-empty": "Няма ROM в тази платформа",
"random-rom-error": "Неуспешно избиране на случаен ROM"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Styl obalu",
"firmware-verified": "Ověřeno",
"old-horizontal-cases": "Staré horizontální obaly",
"old-squared-cases": "Staré čtvercové obaly"
"old-squared-cases": "Staré čtvercové obaly",
"random-rom": "Náhodné ROM",
"random-rom-empty": "Na této platformě nejsou žádné ROM",
"random-rom-error": "Nepodařilo se vybrat náhodné ROM"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Cover-Stil",
"firmware-verified": "Verifiziert",
"old-horizontal-cases": "Alte horizontale Hüllen",
"old-squared-cases": "Alte quadratische Hüllen"
"old-squared-cases": "Alte quadratische Hüllen",
"random-rom": "Zufälliges ROM",
"random-rom-empty": "Keine ROMs auf dieser Plattform",
"random-rom-error": "Zufälliges ROM konnte nicht ausgewählt werden"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Cover style",
"firmware-verified": "Verified",
"old-horizontal-cases": "Old horizontal cases",
"old-squared-cases": "Old squared cases"
"old-squared-cases": "Old squared cases",
"random-rom": "Random ROM",
"random-rom-empty": "No ROMs in this platform",
"random-rom-error": "Couldn't pick a random ROM"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Cover style",
"firmware-verified": "Verified",
"old-horizontal-cases": "Old horizontal cases",
"old-squared-cases": "Old squared cases"
"old-squared-cases": "Old squared cases",
"random-rom": "Random ROM",
"random-rom-empty": "No ROMs in this platform",
"random-rom-error": "Couldn't pick a random ROM"
}

View File

@@ -81,5 +81,8 @@
"settings": "Ajustes",
"tab-firmware": "Firmware",
"upload-firmware": "Subir firmware",
"browse-platform": "Explorar {platform}"
"browse-platform": "Explorar {platform}",
"random-rom": "ROM aleatorio",
"random-rom-empty": "No hay ROMs en esta plataforma",
"random-rom-error": "No se pudo elegir un ROM aleatorio"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Style de jaquette",
"firmware-verified": "Vérifié",
"old-horizontal-cases": "Anciens boîtiers horizontaux",
"old-squared-cases": "Anciens boîtiers carrés"
"old-squared-cases": "Anciens boîtiers carrés",
"random-rom": "ROM aléatoire",
"random-rom-empty": "Aucune ROM sur cette plateforme",
"random-rom-error": "Impossible de choisir une ROM aléatoire"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Borító stílusa",
"firmware-verified": "Ellenőrzött",
"old-horizontal-cases": "Régi vízszintes tokok",
"old-squared-cases": "Régi négyzetes tokok"
"old-squared-cases": "Régi négyzetes tokok",
"random-rom": "Véletlenszerű ROM",
"random-rom-empty": "Nincs ROM ezen a platformon",
"random-rom-error": "Nem sikerült véletlenszerű ROM-ot választani"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Stile copertina",
"firmware-verified": "Verificato",
"old-horizontal-cases": "Vecchie custodie orizzontali",
"old-squared-cases": "Vecchie custodie quadrate"
"old-squared-cases": "Vecchie custodie quadrate",
"random-rom": "ROM casuale",
"random-rom-empty": "Nessuna ROM in questa piattaforma",
"random-rom-error": "Impossibile scegliere una ROM casuale"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "カバースタイル",
"firmware-verified": "確認済み",
"old-horizontal-cases": "旧横型ケース",
"old-squared-cases": "旧角型ケース"
"old-squared-cases": "旧角型ケース",
"random-rom": "ランダムROM",
"random-rom-empty": "このプラットフォームにROMがありません",
"random-rom-error": "ランダムなROMを選択できませんでした"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "커버 스타일",
"firmware-verified": "확인됨",
"old-horizontal-cases": "옛 가로형 케이스",
"old-squared-cases": "옛 정사각형 케이스"
"old-squared-cases": "옛 정사각형 케이스",
"random-rom": "무작위 ROM",
"random-rom-empty": "이 플랫폼에 ROM이 없습니다",
"random-rom-error": "무작위 ROM을 선택할 수 없습니다"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Styl okładki",
"firmware-verified": "Zweryfikowane",
"old-horizontal-cases": "Stare pudełka poziome",
"old-squared-cases": "Stare pudełka kwadratowe"
"old-squared-cases": "Stare pudełka kwadratowe",
"random-rom": "Losowy ROM",
"random-rom-empty": "Brak ROM-ów na tej platformie",
"random-rom-error": "Nie udało się wybrać losowego ROM-u"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Estilo da capa",
"firmware-verified": "Verificado",
"old-horizontal-cases": "Caixas horizontais antigas",
"old-squared-cases": "Caixas quadradas antigas"
"old-squared-cases": "Caixas quadradas antigas",
"random-rom": "ROM aleatório",
"random-rom-empty": "Nenhuma ROM nesta plataforma",
"random-rom-error": "Não foi possível escolher uma ROM aleatória"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Stil copertă",
"firmware-verified": "Verificat",
"old-horizontal-cases": "Cutii orizontale vechi",
"old-squared-cases": "Cutii pătrate vechi"
"old-squared-cases": "Cutii pătrate vechi",
"random-rom": "ROM aleatoriu",
"random-rom-empty": "Niciun ROM pe această platformă",
"random-rom-error": "Nu s-a putut alege un ROM aleatoriu"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "Стиль обложки",
"firmware-verified": "Проверено",
"old-horizontal-cases": "Старые горизонтальные кейсы",
"old-squared-cases": "Старые квадратные кейсы"
"old-squared-cases": "Старые квадратные кейсы",
"random-rom": "Случайный ROM",
"random-rom-empty": "В этой платформе нет ROM",
"random-rom-error": "Не удалось выбрать случайный ROM"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "封面样式",
"firmware-verified": "已验证",
"old-horizontal-cases": "旧式横向盒装",
"old-squared-cases": "旧式方形盒装"
"old-squared-cases": "旧式方形盒装",
"random-rom": "随机 ROM",
"random-rom-empty": "此平台没有 ROM",
"random-rom-error": "无法选择随机 ROM"
}

View File

@@ -81,5 +81,8 @@
"cover-style": "封面樣式",
"firmware-verified": "已驗證",
"old-horizontal-cases": "舊式橫向卡帶盒",
"old-squared-cases": "舊式方形卡帶盒"
"old-squared-cases": "舊式方形卡帶盒",
"random-rom": "隨機 ROM",
"random-rom-empty": "此平台沒有 ROM",
"random-rom-error": "無法選擇隨機 ROM"
}

View File

@@ -48,11 +48,15 @@ defineProps<{
* of the page. */
canEdit: boolean;
canScan: boolean;
/** Spinner on the random-game button while the parent resolves which
* ROM to open. */
randomLoading?: boolean;
/** Label text — passed in so the parent owns i18n and this stays a
* presentational composite (no `useI18n` here). */
labels: {
upload: string;
scan: string;
random: string;
};
}>();
@@ -60,6 +64,7 @@ defineEmits<{
(e: "update:tab", v: string): void;
(e: "upload"): void;
(e: "scan"): void;
(e: "random"): void;
}>();
</script>
@@ -125,12 +130,24 @@ defineEmits<{
</a>
</template>
<!-- Action ribbon — Upload / Scan only. Edit and Delete moved
<!-- Action ribbon — Random / Upload / Scan. Edit and Delete moved
inline into the Settings tab (the editable `custom_name` lives
next to the read-only details there, and Delete sits in the
tab's danger zone). Same circular icon-button vocabulary as
the GameDetails action row. -->
the GameDetails action row. Random is open to anyone who can
view the platform — it's a navigation shortcut, not an admin
action — so it sits left of the gated Upload/Scan buttons. -->
<template #actions>
<RBtn
variant="outlined"
surface
icon="mdi-shuffle-variant"
rounded="circle"
:loading="randomLoading"
:aria-label="labels.random"
:tooltip="labels.random"
@click="$emit('random')"
/>
<RBtn
v-if="canEdit"
variant="outlined"

View File

@@ -23,6 +23,7 @@ import { useI18n } from "vue-i18n";
import { onBeforeRouteUpdate, useRoute, useRouter } from "vue-router";
import { ROUTES } from "@/plugins/router";
import platformApi from "@/services/api/platform";
import romApi from "@/services/api/rom";
import storePlatforms, { type Platform } from "@/stores/platforms";
import { formatBytes } from "@/utils";
import FirmwareTab from "@/v2/components/Gallery/FirmwareTab.vue";
@@ -48,6 +49,7 @@ const notFound = ref(false);
const shellRef = ref<InstanceType<typeof GalleryShell> | null>(null);
const deleting = ref(false);
const scanOpen = ref(false);
const randomLoading = ref(false);
// Permissions — `useCan` is reactive against the grants store, so the
// ribbon buttons hide automatically when the user's role changes.
@@ -92,6 +94,7 @@ const tabs = computed<RTabNavItem[]>(() => [
const headLabels = computed(() => ({
upload: t("platform.upload-roms"),
scan: t("platform.scan-platform"),
random: t("platform.random-rom"),
}));
function onTabChange(next: string) {
@@ -312,6 +315,44 @@ function onScan() {
scanOpen.value = true;
}
// Random ROM — pick one game from this platform and jump to its
// details. Mirrors the Home RandomPickWidget approach: a cheap
// count-only fetch gives the `total`, then a single-item fetch at a
// random offset resolves the ROM. Scoped to the current platform via
// `platformIds`.
async function onRandomGame() {
const p = currentPlatform.value;
if (!p || randomLoading.value) return;
randomLoading.value = true;
try {
const { data: head } = await romApi.getRoms({
platformIds: [p.id],
limit: 1,
offset: 0,
});
if (!head.total) {
snackbar.info(t("platform.random-rom-empty"));
return;
}
const randomOffset = Math.floor(Math.random() * head.total);
const { data } = await romApi.getRoms({
platformIds: [p.id],
limit: 1,
offset: randomOffset,
});
const pick = data.items[0];
if (!pick) {
snackbar.info(t("platform.random-rom-empty"));
return;
}
router.push({ name: ROUTES.ROM, params: { rom: pick.id } });
} catch {
snackbar.error(t("platform.random-rom-error"));
} finally {
randomLoading.value = false;
}
}
async function onDelete() {
const p = currentPlatform.value;
if (!p) return;
@@ -377,10 +418,12 @@ async function onDelete() {
:providers="providerChips"
:can-edit="canEditPlatform"
:can-scan="canScan"
:random-loading="randomLoading"
:labels="headLabels"
@update:tab="onTabChange"
@upload="onUploadRoms"
@scan="onScan"
@random="onRandomGame"
/>
</template>
</GalleryShell>
@@ -401,10 +444,12 @@ async function onDelete() {
:providers="providerChips"
:can-edit="canEditPlatform"
:can-scan="canScan"
:random-loading="randomLoading"
:labels="headLabels"
@update:tab="onTabChange"
@upload="onUploadRoms"
@scan="onScan"
@random="onRandomGame"
/>
<RDivider class="r-v2-plat-tabs__divider" />
<div v-if="currentPlatform" class="r-v2-plat-tabs__panel">