mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 18:11:16 +01:00
add save and exit button
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
loadEmulatorJSSave,
|
||||
loadEmulatorJSState,
|
||||
createQuickLoadButton,
|
||||
createSaveQuitButton,
|
||||
} from "./utils";
|
||||
import type { Emitter } from "mitt";
|
||||
import type { Events } from "@/types/emitter";
|
||||
@@ -108,11 +109,6 @@ window.EJS_defaultOptions = {
|
||||
window.EJS_gameName = romRef.value.fs_name_no_tags
|
||||
.replace(INVALID_CHARS_REGEX, "")
|
||||
.trim();
|
||||
// Disable quick save and quick load
|
||||
window.EJS_Buttons = {
|
||||
quickSave: false,
|
||||
quickLoad: false,
|
||||
};
|
||||
|
||||
function onBeforeUnload(event: BeforeUnloadEvent) {
|
||||
event.preventDefault();
|
||||
@@ -316,6 +312,32 @@ window.EJS_onGameStart = async () => {
|
||||
}
|
||||
});
|
||||
|
||||
const saveAndQuit = createSaveQuitButton();
|
||||
saveAndQuit.addEventListener("click", async () => {
|
||||
if (!romRef.value || !window.EJS_emulator) return window.history.back();
|
||||
const screenshotFile = await window.EJS_emulator.gameManager.screenshot();
|
||||
|
||||
// Force a save of the current state
|
||||
const stateFile = window.EJS_emulator.gameManager.getState();
|
||||
await saveState({
|
||||
rom: romRef.value,
|
||||
stateFile,
|
||||
screenshotFile,
|
||||
});
|
||||
|
||||
// Force a save of the save file
|
||||
const saveFile = window.EJS_emulator.gameManager.getSaveFile();
|
||||
await saveSave({
|
||||
rom: romRef.value,
|
||||
save: saveRef.value,
|
||||
saveFile,
|
||||
screenshotFile,
|
||||
});
|
||||
|
||||
window.EJS_emulator.callEvent("exit");
|
||||
window.history.back();
|
||||
});
|
||||
|
||||
window.addEventListener("beforeunload", onBeforeUnload);
|
||||
};
|
||||
</script>
|
||||
@@ -349,7 +371,7 @@ window.EJS_onGameStart = async () => {
|
||||
background-size: 40%;
|
||||
}
|
||||
|
||||
#game .ejs_menu_bar .ejs_menu_button:last-child {
|
||||
#game .ejs_menu_bar .ejs_menu_button:nth-child(-1) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ export function createQuickLoadButton(): HTMLButtonElement {
|
||||
'<path d="M12,7L17,12H14V16H10V12H7L12,7M19,21H5A2,2 0 0,1 3,19V5A2,2 0 0,1 5,3H19A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21M19,19V5H5V19H19Z"></path>';
|
||||
const text = document.createElement("span");
|
||||
text.classList.add("ejs_menu_text");
|
||||
text.innerText = "Quick Load";
|
||||
text.innerText = "Load Latest State";
|
||||
button.classList.add("ejs_menu_button");
|
||||
button.appendChild(svg);
|
||||
button.appendChild(text);
|
||||
@@ -156,3 +156,25 @@ export function createQuickLoadButton(): HTMLButtonElement {
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
export function createSaveQuitButton(): HTMLButtonElement {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||
svg.setAttribute("role", "presentation");
|
||||
svg.setAttribute("focusable", "false");
|
||||
svg.setAttribute("viewBox", "2 2 20 20");
|
||||
svg.innerHTML =
|
||||
'<path d="M19,3H5C3.89,3 3,3.89 3,5V9H5V5H19V19H5V15H3V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3M10.08,15.58L11.5,17L16.5,12L11.5,7L10.08,8.41L12.67,11H3V13H12.67L10.08,15.58Z"></path>';
|
||||
const text = document.createElement("span");
|
||||
text.classList.add("ejs_menu_text", "ejs_menu_text_right");
|
||||
text.innerText = "Save & Quit";
|
||||
button.classList.add("ejs_menu_button");
|
||||
button.appendChild(svg);
|
||||
button.appendChild(text);
|
||||
|
||||
const ejsMenuBar = document.querySelector("#game .ejs_menu_bar");
|
||||
ejsMenuBar?.appendChild(button);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user