mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
Merge pull request #2357 from rommapp/misc/play-btn-component
misc: Add PlayBtn component to unify button logic
This commit is contained in:
@@ -5,45 +5,21 @@ import { computed, inject, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import AdminMenu from "@/components/common/Game/AdminMenu.vue";
|
||||
import CopyRomDownloadLinkDialog from "@/components/common/Game/Dialog/CopyDownloadLink.vue";
|
||||
import PlayBtn from "@/components/common/Game/PlayBtn.vue";
|
||||
import romApi from "@/services/api/rom";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeConfig from "@/stores/config";
|
||||
import storeDownload from "@/stores/download";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import {
|
||||
getDownloadLink,
|
||||
is3DSCIARom,
|
||||
isEJSEmulationSupported,
|
||||
isRuffleEmulationSupported,
|
||||
} from "@/utils";
|
||||
import { getDownloadLink, is3DSCIARom } from "@/utils";
|
||||
|
||||
const props = defineProps<{ rom: DetailedRom }>();
|
||||
const downloadStore = storeDownload();
|
||||
const heartbeatStore = storeHeartbeat();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const playInfoIcon = ref("mdi-play");
|
||||
const qrCodeIcon = ref("mdi-qrcode");
|
||||
const configStore = storeConfig();
|
||||
const { config } = storeToRefs(configStore);
|
||||
const auth = storeAuth();
|
||||
const { t } = useI18n();
|
||||
|
||||
const platformSlug = computed(() =>
|
||||
props.rom.platform_slug in config.value.PLATFORMS_VERSIONS
|
||||
? config.value.PLATFORMS_VERSIONS[props.rom.platform_slug]
|
||||
: props.rom.platform_slug,
|
||||
);
|
||||
|
||||
const ejsEmulationSupported = computed(() => {
|
||||
return isEJSEmulationSupported(platformSlug.value, heartbeatStore.value);
|
||||
});
|
||||
|
||||
const ruffleEmulationSupported = computed(() => {
|
||||
return isRuffleEmulationSupported(platformSlug.value, heartbeatStore.value);
|
||||
});
|
||||
|
||||
const is3DSRom = computed(() => {
|
||||
return is3DSCIARom(props.rom);
|
||||
});
|
||||
@@ -105,34 +81,7 @@ async function copyDownloadLink(rom: DetailedRom) {
|
||||
>
|
||||
<v-icon icon="mdi-content-copy" />
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-if="ejsEmulationSupported"
|
||||
:disabled="rom.missing_from_fs"
|
||||
class="flex-grow-1"
|
||||
@click="
|
||||
$router.push({
|
||||
name: 'emulatorjs',
|
||||
params: { rom: rom?.id },
|
||||
})
|
||||
"
|
||||
:aria-label="`Play ${rom.name}`"
|
||||
>
|
||||
<v-icon :icon="playInfoIcon" />
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-if="ruffleEmulationSupported"
|
||||
:disabled="rom.missing_from_fs"
|
||||
class="flex-grow-1"
|
||||
@click="
|
||||
$router.push({
|
||||
name: 'ruffle',
|
||||
params: { rom: rom?.id },
|
||||
})
|
||||
"
|
||||
:aria-label="`Play ${rom.name}`"
|
||||
>
|
||||
<v-icon :icon="playInfoIcon" />
|
||||
</v-btn>
|
||||
<play-btn :rom="rom" class="flex-grow-1" />
|
||||
<v-btn
|
||||
v-if="is3DSRom"
|
||||
:disabled="rom.missing_from_fs"
|
||||
|
||||
@@ -1,55 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
import type { Emitter } from "mitt";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, inject, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import AdminMenu from "@/components/common/Game/AdminMenu.vue";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
import PlayBtn from "@/components/common/Game/PlayBtn.vue";
|
||||
import romApi from "@/services/api/rom";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeConfig from "@/stores/config";
|
||||
import storeDownload from "@/stores/download";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import {
|
||||
isEJSEmulationSupported,
|
||||
isRuffleEmulationSupported,
|
||||
is3DSCIARom,
|
||||
} from "@/utils";
|
||||
import { is3DSCIARom } from "@/utils";
|
||||
|
||||
const props = defineProps<{ rom: SimpleRom; sizeActionBar: number }>();
|
||||
const { t } = useI18n();
|
||||
const emit = defineEmits(["menu-open", "menu-close"]);
|
||||
const downloadStore = storeDownload();
|
||||
const heartbeatStore = storeHeartbeat();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const configStore = storeConfig();
|
||||
const { config } = storeToRefs(configStore);
|
||||
const auth = storeAuth();
|
||||
const { t } = useI18n();
|
||||
const playBtnRef = ref<InstanceType<typeof PlayBtn>>();
|
||||
|
||||
const computedSize = computed(() => {
|
||||
return props.sizeActionBar === 1 ? "small" : "x-small";
|
||||
});
|
||||
|
||||
const platformSlug = computed(() => {
|
||||
return props.rom.platform_slug in config.value.PLATFORMS_VERSIONS
|
||||
? config.value.PLATFORMS_VERSIONS[props.rom.platform_slug]
|
||||
: props.rom.platform_slug;
|
||||
});
|
||||
|
||||
const ejsEmulationSupported = computed(() => {
|
||||
return isEJSEmulationSupported(platformSlug.value, heartbeatStore.value);
|
||||
});
|
||||
|
||||
const ruffleEmulationSupported = computed(() => {
|
||||
return isRuffleEmulationSupported(platformSlug.value, heartbeatStore.value);
|
||||
});
|
||||
|
||||
const is3DSRom = computed(() => {
|
||||
return is3DSCIARom(props.rom);
|
||||
});
|
||||
|
||||
const isEmulationSupported = computed(() => {
|
||||
// Default to true if playBtnRef is not set
|
||||
return playBtnRef.value?.isEmulationSupported ?? true;
|
||||
});
|
||||
|
||||
const menuOpen = ref(false);
|
||||
|
||||
watch(menuOpen, (val) => {
|
||||
@@ -71,43 +53,16 @@ watch(menuOpen, (val) => {
|
||||
:aria-label="`${t('rom.download')} ${rom.name}`"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col
|
||||
v-if="ejsEmulationSupported || ruffleEmulationSupported"
|
||||
class="d-flex"
|
||||
>
|
||||
<v-btn
|
||||
v-if="ejsEmulationSupported"
|
||||
:disabled="rom.missing_from_fs"
|
||||
<v-col v-if="isEmulationSupported" class="d-flex">
|
||||
<play-btn
|
||||
ref="playBtnRef"
|
||||
:rom="rom"
|
||||
icon-embedded
|
||||
@click.prevent
|
||||
class="action-bar-btn-small flex-grow-1"
|
||||
:size="computedSize"
|
||||
@click="
|
||||
$router.push({
|
||||
name: ROUTES.EMULATORJS,
|
||||
params: { rom: rom?.id },
|
||||
})
|
||||
"
|
||||
icon="mdi-play"
|
||||
variant="text"
|
||||
rounded="0"
|
||||
:aria-label="`Play ${rom.name}`"
|
||||
/>
|
||||
<v-btn
|
||||
v-if="ruffleEmulationSupported"
|
||||
:disabled="rom.missing_from_fs"
|
||||
@click.prevent
|
||||
class="action-bar-btn-small flex-grow-1"
|
||||
:size="computedSize"
|
||||
@click="
|
||||
$router.push({
|
||||
name: ROUTES.RUFFLE,
|
||||
params: { rom: rom?.id },
|
||||
})
|
||||
"
|
||||
icon="mdi-play"
|
||||
variant="text"
|
||||
rounded="0"
|
||||
:aria-label="`Play ${rom.name}`"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col v-if="is3DSRom" class="d-flex">
|
||||
|
||||
75
frontend/src/components/common/Game/PlayBtn.vue
Normal file
75
frontend/src/components/common/Game/PlayBtn.vue
Normal file
@@ -0,0 +1,75 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, useAttrs } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
import storeConfig from "@/stores/config";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import { type SimpleRom } from "@/stores/roms";
|
||||
import { isEJSEmulationSupported, isRuffleEmulationSupported } from "@/utils";
|
||||
|
||||
const props = defineProps<{ rom: SimpleRom; iconEmbedded?: boolean }>();
|
||||
const attrs = useAttrs();
|
||||
const configStore = storeConfig();
|
||||
const heartbeatStore = storeHeartbeat();
|
||||
const router = useRouter();
|
||||
const { config } = storeToRefs(configStore);
|
||||
const { value: heartbeat } = storeToRefs(heartbeatStore);
|
||||
|
||||
const isEmulationSupported = computed(() => {
|
||||
return (
|
||||
isEJSEmulationSupported(
|
||||
props.rom.platform_slug,
|
||||
heartbeat.value,
|
||||
config.value,
|
||||
) ||
|
||||
isRuffleEmulationSupported(
|
||||
props.rom.platform_slug,
|
||||
heartbeat.value,
|
||||
config.value,
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
function goToPlayer(rom: SimpleRom) {
|
||||
if (
|
||||
isEJSEmulationSupported(rom.platform_slug, heartbeat.value, config.value)
|
||||
) {
|
||||
router.push({
|
||||
name: ROUTES.EMULATORJS,
|
||||
params: { rom: rom.id },
|
||||
});
|
||||
} else if (
|
||||
isRuffleEmulationSupported(rom.platform_slug, heartbeat.value, config.value)
|
||||
) {
|
||||
router.push({
|
||||
name: ROUTES.RUFFLE,
|
||||
params: { rom: rom.id },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ isEmulationSupported });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="isEmulationSupported">
|
||||
<v-btn
|
||||
v-if="iconEmbedded"
|
||||
v-bind="attrs"
|
||||
:disabled="rom.missing_from_fs"
|
||||
:aria-label="`Play ${rom.name}`"
|
||||
icon="mdi-play"
|
||||
@click="goToPlayer(rom)"
|
||||
/>
|
||||
<v-btn
|
||||
v-else
|
||||
v-bind="attrs"
|
||||
:disabled="rom.missing_from_fs"
|
||||
:aria-label="`Play ${rom.name}`"
|
||||
@click="goToPlayer(rom)"
|
||||
>
|
||||
<v-icon>mdi-play</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
</template>
|
||||
@@ -5,24 +5,17 @@ import { computed } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import AdminMenu from "@/components/common/Game/AdminMenu.vue";
|
||||
import FavBtn from "@/components/common/Game/FavBtn.vue";
|
||||
import PlayBtn from "@/components/common/Game/PlayBtn.vue";
|
||||
import RAvatarRom from "@/components/common/Game/RAvatar.vue";
|
||||
import MissingFromFSIcon from "@/components/common/MissingFromFSIcon.vue";
|
||||
import PlatformIcon from "@/components/common/Platform/Icon.vue";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
import romApi from "@/services/api/rom";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeConfig from "@/stores/config";
|
||||
import storeDownload from "@/stores/download";
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import storeRoms, { type SimpleRom } from "@/stores/roms";
|
||||
import {
|
||||
formatBytes,
|
||||
isEJSEmulationSupported,
|
||||
isRuffleEmulationSupported,
|
||||
languageToEmoji,
|
||||
regionToEmoji,
|
||||
} from "@/utils";
|
||||
import { formatBytes, languageToEmoji, regionToEmoji } from "@/utils";
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
@@ -38,9 +31,6 @@ const downloadStore = storeDownload();
|
||||
const romsStore = storeRoms();
|
||||
const { filteredRoms, selectedRoms, fetchingRoms, fetchTotalRoms } =
|
||||
storeToRefs(romsStore);
|
||||
const heartbeatStore = storeHeartbeat();
|
||||
const configStore = storeConfig();
|
||||
const { config } = storeToRefs(configStore);
|
||||
const auth = storeAuth();
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
|
||||
@@ -102,22 +92,6 @@ function rowClick(_: Event, row: { item: SimpleRom }) {
|
||||
romsStore.resetSelection();
|
||||
}
|
||||
|
||||
function getTruePlatformSlug(platformSlug: string) {
|
||||
return platformSlug in config.value.PLATFORMS_VERSIONS
|
||||
? config.value.PLATFORMS_VERSIONS[platformSlug]
|
||||
: platformSlug;
|
||||
}
|
||||
|
||||
function checkIfEJSEmulationSupported(platformSlug: string) {
|
||||
const slug = getTruePlatformSlug(platformSlug);
|
||||
return isEJSEmulationSupported(slug, heartbeatStore.value);
|
||||
}
|
||||
|
||||
function checkIfRuffleEmulationSupported(platformSlug: string) {
|
||||
const slug = getTruePlatformSlug(platformSlug);
|
||||
return isRuffleEmulationSupported(slug, heartbeatStore.value);
|
||||
}
|
||||
|
||||
function updateSelectAll() {
|
||||
if (selectedRoms.value.length === filteredRoms.value.length) {
|
||||
romsStore.resetSelection();
|
||||
@@ -317,34 +291,7 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) {
|
||||
>
|
||||
<v-icon>mdi-download</v-icon>
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-if="checkIfEJSEmulationSupported(item.platform_slug)"
|
||||
:disabled="item.missing_from_fs"
|
||||
variant="text"
|
||||
size="small"
|
||||
@click.stop="
|
||||
$router.push({
|
||||
name: ROUTES.EMULATORJS,
|
||||
params: { rom: item?.id },
|
||||
})
|
||||
"
|
||||
>
|
||||
<v-icon>mdi-play</v-icon>
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-if="checkIfRuffleEmulationSupported(item.platform_slug)"
|
||||
:disabled="item.missing_from_fs"
|
||||
variant="text"
|
||||
size="small"
|
||||
@click.stop="
|
||||
$router.push({
|
||||
name: ROUTES.RUFFLE,
|
||||
params: { rom: item?.id },
|
||||
})
|
||||
"
|
||||
>
|
||||
<v-icon>mdi-play</v-icon>
|
||||
</v-btn>
|
||||
<play-btn :rom="item" @click.stop variant="text" size="small" />
|
||||
<v-menu
|
||||
v-if="
|
||||
auth.scopes.includes('roms.write') ||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { defineStore } from "pinia";
|
||||
import type { ConfigResponse, EjsControlsButton } from "@/__generated__";
|
||||
import api from "@/services/api";
|
||||
|
||||
export type Config = ConfigResponse;
|
||||
type ExclusionTypes =
|
||||
| "EXCLUDED_PLATFORMS"
|
||||
| "EXCLUDED_SINGLE_EXT"
|
||||
|
||||
@@ -3,6 +3,7 @@ import { storeToRefs } from "pinia";
|
||||
import { computed } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
import type { RomFileSchema, RomUserStatus } from "@/__generated__";
|
||||
import type { Config } from "@/stores/config";
|
||||
import type { Heartbeat } from "@/stores/heartbeat";
|
||||
import storeNavigation from "@/stores/navigation";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
@@ -456,16 +457,19 @@ const gl =
|
||||
*
|
||||
* @param platformSlug The platform slug.
|
||||
* @param heartbeat The heartbeat object.
|
||||
* @param config Optional configuration object.
|
||||
* @returns True if supported, false otherwise.
|
||||
*/
|
||||
export function isEJSEmulationSupported(
|
||||
platformSlug: string,
|
||||
heartbeat: Heartbeat,
|
||||
config?: Config,
|
||||
) {
|
||||
if (heartbeat.EMULATION.DISABLE_EMULATOR_JS) return false;
|
||||
|
||||
const slug = config?.PLATFORMS_VERSIONS[platformSlug] || platformSlug;
|
||||
return (
|
||||
!heartbeat.EMULATION.DISABLE_EMULATOR_JS &&
|
||||
getSupportedEJSCores(platformSlug).length > 0 &&
|
||||
gl instanceof WebGLRenderingContext
|
||||
getSupportedEJSCores(slug).length > 0 && gl instanceof WebGLRenderingContext
|
||||
);
|
||||
}
|
||||
|
||||
@@ -521,16 +525,18 @@ export function getControlSchemeForPlatform(
|
||||
*
|
||||
* @param platformSlug The platform slug.
|
||||
* @param heartbeat The heartbeat object.
|
||||
* @param config Optional configuration object.
|
||||
* @returns True if supported, false otherwise.
|
||||
*/
|
||||
export function isRuffleEmulationSupported(
|
||||
platformSlug: string,
|
||||
heartbeat: Heartbeat,
|
||||
config?: Config,
|
||||
) {
|
||||
return (
|
||||
["flash", "browser"].includes(platformSlug.toLowerCase()) &&
|
||||
!heartbeat.EMULATION.DISABLE_RUFFLE_RS
|
||||
);
|
||||
if (heartbeat.EMULATION.DISABLE_RUFFLE_RS) return false;
|
||||
|
||||
const slug = config?.PLATFORMS_VERSIONS[platformSlug] || platformSlug;
|
||||
return ["flash", "browser"].includes(slug.toLowerCase());
|
||||
}
|
||||
|
||||
type PlayingStatus = RomUserStatus | "backlogged" | "now_playing" | "hidden";
|
||||
|
||||
Reference in New Issue
Block a user