mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
Merge branch 'emulatorjs-ui' into emulatorjs
This commit is contained in:
BIN
frontend/assets/powered_by_emulatorjs.png
Normal file
BIN
frontend/assets/powered_by_emulatorjs.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
@@ -1,14 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import romApi from "@/services/api/rom";
|
||||
import storeDownload from "@/stores/download";
|
||||
import AdminMenu from "@/components/Game/AdminMenu/Base.vue";
|
||||
import romApi from "@/services/api/rom";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeDownload from "@/stores/download";
|
||||
import type { Rom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { inject, ref } from "vue";
|
||||
|
||||
const props = defineProps<{ rom: Rom }>();
|
||||
const downloadStore = storeDownload();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const auth = storeAuth();
|
||||
const emulation = ref(false);
|
||||
const playInfoIcon = ref("mdi-play")
|
||||
|
||||
function toggleEmulation(){
|
||||
emulation.value = !emulation.value
|
||||
playInfoIcon.value = emulation.value ? "mdi-information" : "mdi-play"
|
||||
emitter?.emit('showEmulation', null)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -30,8 +41,8 @@ const auth = storeAuth();
|
||||
</v-btn>
|
||||
</v-col>
|
||||
<v-col>
|
||||
<v-btn rounded="0" block :href="`/play/${rom.id}`" :disabled="false">
|
||||
<v-icon icon="mdi-play" size="large"/>
|
||||
<v-btn rounded="0" block @click="toggleEmulation">
|
||||
<v-icon :icon="playInfoIcon" size="large" />
|
||||
</v-btn>
|
||||
</v-col>
|
||||
<v-col>
|
||||
|
||||
239
frontend/src/components/Details/Emulation.vue
Normal file
239
frontend/src/components/Details/Emulation.vue
Normal file
@@ -0,0 +1,239 @@
|
||||
<script setup lang="ts">
|
||||
import type { SaveSchema, StateSchema } from "@/__generated__";
|
||||
import romApi from "@/services/api/rom";
|
||||
import stateApi from "@/services/api/state";
|
||||
import type { Rom } from "@/stores/roms";
|
||||
import { formatBytes } from "@/utils";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { useDisplay } from "vuetify";
|
||||
|
||||
defineProps<{ rom: Rom }>();
|
||||
const route = useRoute();
|
||||
const rom = ref<Rom | null>(null);
|
||||
const saveRef = ref<SaveSchema | null>(null);
|
||||
const stateRef = ref<StateSchema | null>(null);
|
||||
const gameRunning = ref(false);
|
||||
const fullScreenOnPlay = ref(true);
|
||||
const { smAndDown, mdAndUp } = useDisplay();
|
||||
|
||||
const EXTENSION_REGEX = new RegExp("\.(([a-z]+\.)*)$");
|
||||
|
||||
const script = document.createElement("script");
|
||||
script.src = "/assets/emulatorjs/loader.js";
|
||||
script.async = true;
|
||||
window.EJS_player = "#game";
|
||||
window.EJS_pathtodata = "/assets/emulatorjs/";
|
||||
window.EJS_color = "#A453FF";
|
||||
window.EJS_alignStartButton = "center";
|
||||
window.EJS_startOnLoaded = true;
|
||||
window.EJS_fullscreenOnLoaded = true;
|
||||
window.EJS_defaultOptions = {
|
||||
"save-state-location": "browser",
|
||||
};
|
||||
|
||||
function buildStateName(rom: Rom): string {
|
||||
const states = rom.states.map((s) => s.file_name);
|
||||
const romName = rom.file_name.replace(EXTENSION_REGEX, "").trim();
|
||||
let stateName = `${romName}.state.auto`;
|
||||
if (!states.includes(stateName)) return stateName;
|
||||
|
||||
let i = 1;
|
||||
stateName = `${romName}.state1`;
|
||||
while (states.includes(stateName)) {
|
||||
i++;
|
||||
stateName = `${romName}.state${i}`;
|
||||
}
|
||||
|
||||
return stateName;
|
||||
}
|
||||
|
||||
window.EJS_onSaveState = function ({
|
||||
state,
|
||||
}: {
|
||||
screenshot: File;
|
||||
state: File;
|
||||
}) {
|
||||
if (window.EJS_emulator.saveInBrowserSupported()) {
|
||||
window.EJS_emulator.storage.states.put(
|
||||
window.EJS_emulator.getBaseFileName() + ".state",
|
||||
state
|
||||
);
|
||||
window.EJS_emulator.displayMessage(
|
||||
window.EJS_emulator.localization("SAVE SAVED TO BROWSER")
|
||||
);
|
||||
}
|
||||
if (stateRef.value) {
|
||||
stateApi
|
||||
.updateState({
|
||||
state: stateRef.value,
|
||||
file: new File([state], stateRef.value.file_name, {
|
||||
type: "application/octet-stream",
|
||||
}),
|
||||
})
|
||||
.then(({ data }) => {
|
||||
stateRef.value = data;
|
||||
});
|
||||
} else if (rom.value) {
|
||||
stateApi
|
||||
.uploadStates({
|
||||
rom: rom.value,
|
||||
states: [
|
||||
new File([state], buildStateName(rom.value), {
|
||||
type: "application/octet-stream",
|
||||
}),
|
||||
],
|
||||
})
|
||||
.then(({ data }) => {
|
||||
if (rom.value) rom.value.states = data.states;
|
||||
stateRef.value = data.states.pop();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
window.EJS_onGameStart = () => {};
|
||||
|
||||
onMounted(() => {
|
||||
romApi
|
||||
.getRom({ romId: parseInt(route.params.rom as string) })
|
||||
.then((response) => {
|
||||
rom.value = response.data;
|
||||
window.EJS_core = rom.value.platform_slug;
|
||||
window.EJS_gameID = rom.value.id;
|
||||
window.EJS_gameName = rom.value.name;
|
||||
window.EJS_backgroundImage = `/assets/romm/resources/${rom.value.path_cover_l}`;
|
||||
window.EJS_gameUrl = rom.value.download_path;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
|
||||
function toggleFullScreen() {
|
||||
window.EJS_fullscreenOnLoaded = !window.EJS_fullscreenOnLoaded;
|
||||
}
|
||||
|
||||
function onPlay() {
|
||||
gameRunning.value = true;
|
||||
window.EJS_loadStateURL = stateRef.value?.download_path ?? null;
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<v-row no-gutters>
|
||||
<v-col v-if="rom && !gameRunning" class="12">
|
||||
<v-select
|
||||
density="compact"
|
||||
class="my-1"
|
||||
hide-details
|
||||
variant="outlined"
|
||||
clearable
|
||||
disabled
|
||||
label="BIOS"
|
||||
:items="['gba-bios.zip']"
|
||||
/>
|
||||
<v-select
|
||||
density="compact"
|
||||
class="my-1"
|
||||
hide-details
|
||||
variant="outlined"
|
||||
clearable
|
||||
disabled
|
||||
label="Save"
|
||||
v-model="saveRef"
|
||||
:items="
|
||||
rom.saves.map((s) => ({
|
||||
title: s.file_name,
|
||||
subtitle: `${s.emulator} - ${formatBytes(s.file_size_bytes)}`,
|
||||
value: s,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
<v-select
|
||||
density="compact"
|
||||
class="my-1"
|
||||
hide-details
|
||||
variant="outlined"
|
||||
clearable
|
||||
label="State"
|
||||
v-model="stateRef"
|
||||
:items="
|
||||
rom.states.map((s) => ({
|
||||
title: s.file_name,
|
||||
subtitle: `${s.emulator} - ${formatBytes(s.file_size_bytes)}`,
|
||||
value: s,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
<v-select
|
||||
density="compact"
|
||||
class="my-1"
|
||||
hide-details
|
||||
variant="outlined"
|
||||
clearable
|
||||
disabled
|
||||
label="Patch"
|
||||
:items="[
|
||||
'Advance Wars Balance (AW1) by Kartal',
|
||||
'War Room Sturm (AW1) by Kartal',
|
||||
]"
|
||||
/>
|
||||
<v-switch
|
||||
hide-details
|
||||
v-model="fullScreenOnPlay"
|
||||
@update:model-value="toggleFullScreen"
|
||||
color="romm-accent-1"
|
||||
label="Full screen"
|
||||
/>
|
||||
<v-row no-gutters class="align-center">
|
||||
<v-col cols="12" lg="8" xl="8">
|
||||
<v-btn
|
||||
block
|
||||
density="compact"
|
||||
class="text-romm-accent-1"
|
||||
variant="outlined"
|
||||
size="x-large"
|
||||
@click="onPlay()"
|
||||
>
|
||||
<v-icon class="mr-2">mdi-play</v-icon>Play
|
||||
</v-btn>
|
||||
</v-col>
|
||||
<v-col cols="12" lg="4" xl="4">
|
||||
<img
|
||||
:class="{ 'mt-6': smAndDown, 'ml-7': mdAndUp }"
|
||||
width="150"
|
||||
src="/assets/powered_by_emulatorjs.png"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" rounded id="game-wrapper">
|
||||
<div id="game"></div>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row> </v-row>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
div.ejs_game {
|
||||
background-color: #191d22;
|
||||
}
|
||||
#game-wrapper {
|
||||
aspect-ratio: 16 / 9;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- Other config options: https://emulatorjs.org/docs/Options.html -->
|
||||
|
||||
<!-- config.biosUrl = window.EJS_biosUrl; -->
|
||||
<!-- config.VirtualGamepadSettings = window.EJS_VirtualGamepadSettings; -->
|
||||
<!-- config.buttonOpts = window.EJS_Buttons; -->
|
||||
<!-- config.volume = window.EJS_volume; -->
|
||||
<!-- config.defaultControllers = window.EJS_defaultControls; -->
|
||||
<!-- config.cheats = window.EJS_cheats; -->
|
||||
<!-- config.defaultOptions = window.EJS_defaultOptions; -->
|
||||
<!-- config.gamePatchUrl = window.EJS_gamePatchUrl; -->
|
||||
<!-- config.gameParentUrl = window.EJS_gameParentUrl; -->
|
||||
<!-- config.netplayUrl = window.EJS_netplayServer; -->
|
||||
<!-- config.threads = window.EJS_threads; -->
|
||||
@@ -58,7 +58,7 @@ onMounted(() => {});
|
||||
<v-divider />
|
||||
</template>
|
||||
|
||||
<v-list class="pa-0">
|
||||
<v-list class="py-0">
|
||||
<v-list-group value="Platforms" fluid>
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-list-item v-bind="props">
|
||||
@@ -80,7 +80,7 @@ onMounted(() => {});
|
||||
/>
|
||||
</v-list-group>
|
||||
</v-list>
|
||||
<v-list>
|
||||
<v-list class="py-0">
|
||||
<v-list-group
|
||||
value="Library"
|
||||
v-if="auth.scopes.includes('roms.write')"
|
||||
@@ -107,7 +107,7 @@ onMounted(() => {});
|
||||
</v-list-group>
|
||||
</v-list>
|
||||
|
||||
<v-list>
|
||||
<v-list class="py-0">
|
||||
<v-list-group value="Settings" fluid>
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-list-item v-bind="props">
|
||||
|
||||
@@ -27,7 +27,6 @@ const downloadStore = storeDownload();
|
||||
<v-btn
|
||||
class="action-bar-btn"
|
||||
:href="`/play/${rom.id}`"
|
||||
:disabled="false"
|
||||
icon="mdi-play"
|
||||
size="x-small"
|
||||
rounded="0"
|
||||
|
||||
@@ -134,7 +134,6 @@ function rowClick(_: Event, row: any) {
|
||||
size="small"
|
||||
variant="text"
|
||||
:href="`/play/${item.raw.id}`"
|
||||
:disabled="false"
|
||||
class="my-1 bg-terciary"
|
||||
rounded="0"
|
||||
><v-icon>mdi-play</v-icon></v-btn
|
||||
|
||||
@@ -27,10 +27,6 @@ const routes = [
|
||||
name: "rom",
|
||||
component: () => import("@/views/Details/Base.vue"),
|
||||
},
|
||||
{
|
||||
path: "/play/:rom",
|
||||
component: () => import("@/views/Play/Base.vue"),
|
||||
},
|
||||
{
|
||||
path: "/library/scan",
|
||||
name: "scan",
|
||||
@@ -65,6 +61,10 @@ const routes = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "/play/:rom",
|
||||
component: () => import("@/components/Details/Emulation.vue"),
|
||||
},
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
|
||||
1
frontend/src/types/emitter.d.ts
vendored
1
frontend/src/types/emitter.d.ts
vendored
@@ -42,6 +42,7 @@ export type Events = {
|
||||
rom: Rom;
|
||||
states: StateSchema[];
|
||||
};
|
||||
showEmulation: null;
|
||||
toggleDrawer: null;
|
||||
toggleDrawerRail: null;
|
||||
snackbarShow: SnackbarStatus;
|
||||
|
||||
@@ -9,25 +9,31 @@ import type { EnhancedRomSchema, PlatformSchema } from "@/__generated__";
|
||||
import ActionBar from "@/components/Details/ActionBar.vue";
|
||||
import BackgroundHeader from "@/components/Details/BackgroundHeader.vue";
|
||||
import Cover from "@/components/Details/Cover.vue";
|
||||
import DeleteAssetDialog from "@/components/Dialog/Asset/DeleteAssets.vue";
|
||||
import DetailsInfo from "@/components/Details/DetailsInfo.vue";
|
||||
import Emulation from "@/components/Details/Emulation.vue";
|
||||
import Saves from "@/components/Details/Saves.vue";
|
||||
import Screenshots from "@/components/Details/Screenshots.vue";
|
||||
import States from "@/components/Details/States.vue";
|
||||
import TitleInfo from "@/components/Details/Title.vue";
|
||||
import DeleteAssetDialog from "@/components/Dialog/Asset/DeleteAssets.vue";
|
||||
import LoadingDialog from "@/components/Dialog/Loading.vue";
|
||||
import DeleteRomDialog from "@/components/Dialog/Rom/DeleteRom.vue";
|
||||
import EditRomDialog from "@/components/Dialog/Rom/EditRom.vue";
|
||||
import SearchRomDialog from "@/components/Dialog/Rom/SearchRom.vue";
|
||||
import romApi from "@/services/api/rom";
|
||||
import platformApi from "@/services/api/platform";
|
||||
import romApi from "@/services/api/rom";
|
||||
|
||||
const route = useRoute();
|
||||
const rom = ref<EnhancedRomSchema>();
|
||||
const platform = ref<PlatformSchema>();
|
||||
const tab = ref<"details" | "saves" | "screenshots">("details");
|
||||
const tab = ref<"details" | "saves" | "screenshots" | "emulation">("details");
|
||||
const { smAndDown, mdAndUp } = useDisplay();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const showEmulation = ref(false);
|
||||
emitter?.on("showEmulation", () => {
|
||||
showEmulation.value = !showEmulation.value;
|
||||
tab.value = showEmulation.value ? "emulation" : "details";
|
||||
});
|
||||
|
||||
async function fetchDetails() {
|
||||
if (!route.params.rom) return;
|
||||
@@ -139,16 +145,19 @@ watch(
|
||||
}"
|
||||
no-gutters
|
||||
>
|
||||
<v-tabs v-model="tab" slider-color="romm-accent-1" rounded="0">
|
||||
<v-tabs v-if="!showEmulation" v-model="tab" slider-color="romm-accent-1" rounded="0">
|
||||
<v-tab value="details" rounded="0">Details</v-tab>
|
||||
<v-tab value="saves" rounded="0"> Saves </v-tab>
|
||||
<v-tab value="states" rounded="0"> States </v-tab>
|
||||
<v-tab value="screenshots" rounded="0"> Screenshots </v-tab>
|
||||
<v-tab value="saves" rounded="0">Saves</v-tab>
|
||||
<v-tab value="states" rounded="0">States</v-tab>
|
||||
<v-tab value="screenshots" rounded="0">Screenshots</v-tab>
|
||||
</v-tabs>
|
||||
<v-tabs v-if="showEmulation" v-model="tab" slider-color="romm-accent-1" rounded="0">
|
||||
<v-tab value="emulation" rounded="0">Emulation</v-tab>
|
||||
</v-tabs>
|
||||
</v-row>
|
||||
<v-row no-gutters class="mb-4">
|
||||
<v-col cols="12">
|
||||
<v-window v-model="tab" class="py-2">
|
||||
<v-window v-if="!showEmulation" v-model="tab" class="py-2">
|
||||
<v-window-item value="details">
|
||||
<details-info :rom="rom" :platform="platform" />
|
||||
</v-window-item>
|
||||
@@ -162,6 +171,11 @@ watch(
|
||||
<screenshots :rom="rom" />
|
||||
</v-window-item>
|
||||
</v-window>
|
||||
<v-window v-if="showEmulation" v-model="tab" class="py-2">
|
||||
<v-window-item value="emulation">
|
||||
<emulation :rom="rom" />
|
||||
</v-window-item>
|
||||
</v-window>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-col>
|
||||
|
||||
@@ -12,6 +12,7 @@ const rom = ref<Rom | null>(null);
|
||||
const saveRef = ref<SaveSchema | null>(null);
|
||||
const stateRef = ref<StateSchema | null>(null);
|
||||
const gameRunning = ref(false);
|
||||
const gameWindow = ref(9);
|
||||
|
||||
const EXTENSION_REGEX = new RegExp("\.(([a-z]+\.)*)$");
|
||||
|
||||
@@ -87,9 +88,7 @@ window.EJS_onSaveState = function ({
|
||||
}
|
||||
};
|
||||
|
||||
window.EJS_onGameStart = () => {
|
||||
gameRunning.value = true;
|
||||
};
|
||||
window.EJS_onGameStart = () => {};
|
||||
|
||||
onMounted(() => {
|
||||
romApi
|
||||
@@ -108,59 +107,86 @@ onMounted(() => {
|
||||
});
|
||||
|
||||
function onPlay() {
|
||||
gameWindow.value = 12;
|
||||
gameRunning.value = true;
|
||||
window.EJS_loadStateURL = stateRef.value?.download_path ?? null;
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<v-container class="h-100">
|
||||
<v-row class="h-100">
|
||||
<v-col v-if="rom && !gameRunning" class="v-col-3">
|
||||
<v-select
|
||||
clearable
|
||||
disabled
|
||||
label="Save"
|
||||
v-model="saveRef"
|
||||
:items="
|
||||
rom.saves.map((s) => ({
|
||||
title: s.file_name,
|
||||
subtitle: `${s.emulator} - ${formatBytes(s.file_size_bytes)}`,
|
||||
value: s,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
<v-select
|
||||
clearable
|
||||
label="State"
|
||||
v-model="stateRef"
|
||||
:items="
|
||||
rom.states.map((s) => ({
|
||||
title: s.file_name,
|
||||
subtitle: `${s.emulator} - ${formatBytes(s.file_size_bytes)}`,
|
||||
value: s,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
<v-select clearable disabled label="BIOS" :items="['gba-bios.zip']" />
|
||||
<v-select
|
||||
clearable
|
||||
disabled
|
||||
label="Patch"
|
||||
:items="[
|
||||
'Advance Wars Balance (AW1) by Kartal',
|
||||
'War Room Sturm (AW1) by Kartal',
|
||||
]"
|
||||
/>
|
||||
<v-btn rounded="0" size="x-large" @click="onPlay()"> Play </v-btn>
|
||||
</v-col>
|
||||
<v-col>
|
||||
<v-sheet rounded id="game-wrapper">
|
||||
<div id="game"></div>
|
||||
</v-sheet>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
<v-row no-gutters >
|
||||
<v-col v-if="rom && !gameRunning" cols="3" class="px-3">
|
||||
<v-img class="mx-auto mt-6 mb-5" width="250" src="/assets/powered_by_emulatorjs.png" />
|
||||
<v-select
|
||||
class="my-1"
|
||||
hide-details
|
||||
variant="outlined"
|
||||
clearable
|
||||
disabled
|
||||
label="BIOS"
|
||||
:items="['gba-bios.zip']"
|
||||
/>
|
||||
<v-select
|
||||
class="my-1"
|
||||
hide-details
|
||||
variant="outlined"
|
||||
clearable
|
||||
disabled
|
||||
label="Save"
|
||||
v-model="saveRef"
|
||||
:items="
|
||||
rom.saves.map((s) => ({
|
||||
title: s.file_name,
|
||||
subtitle: `${s.emulator} - ${formatBytes(s.file_size_bytes)}`,
|
||||
value: s,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
<v-select
|
||||
class="my-1"
|
||||
hide-details
|
||||
variant="outlined"
|
||||
clearable
|
||||
label="State"
|
||||
v-model="stateRef"
|
||||
:items="
|
||||
rom.states.map((s) => ({
|
||||
title: s.file_name,
|
||||
subtitle: `${s.emulator} - ${formatBytes(s.file_size_bytes)}`,
|
||||
value: s,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
<v-select
|
||||
class="my-1"
|
||||
hide-details
|
||||
variant="outlined"
|
||||
clearable
|
||||
disabled
|
||||
label="Patch"
|
||||
:items="[
|
||||
'Advance Wars Balance (AW1) by Kartal',
|
||||
'War Room Sturm (AW1) by Kartal',
|
||||
]"
|
||||
/>
|
||||
<v-btn
|
||||
class="mt-4"
|
||||
block
|
||||
rounded="0"
|
||||
variant="outlined"
|
||||
size="x-large"
|
||||
@click="onPlay()"
|
||||
>
|
||||
<v-icon class="mr-2">mdi-play</v-icon>Play
|
||||
</v-btn>
|
||||
</v-col>
|
||||
|
||||
<v-col class="my-4 bg-primary" :cols="gameWindow" rounded id="game-wrapper">
|
||||
<v-img v-if="!gameRunning" :src="`/assets/romm/resources/${rom?.path_cover_l}`" />
|
||||
<div id="game"></div>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user