Newer
Older
/**
* Restore the emulator's viewport to the minimal size, should make all
* the other emulator's meta-information (info, buttons, etc.) visible.
*/
minimize() {
const canvasContainer = document.getElementById("canvas-container")!;
const engineCanvas = document.getElementById("engine-canvas")!;
canvasContainer.classList.remove("fullscreen");
engineCanvas.style.width = "";
engineCanvas.style.height = "";
window.removeEventListener("resize", this.crop);
}
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
crop() {
// @todo let's make this more flexible
const engineCanvas = document.getElementById("engine-canvas")!;
// calculates the window ratio as this is fundamental to
// determine the proper way to crop the fullscreen
const windowRatio = window.innerWidth / window.innerHeight;
// in case the window is wider (more horizontal than the base ratio)
// this means that we must crop horizontally
if (windowRatio > DISPLAY_RATIO) {
engineCanvas.style.width = `${
window.innerWidth * (DISPLAY_RATIO / windowRatio)
}px`;
engineCanvas.style.height = `${window.innerHeight}px`;
} else {
engineCanvas.style.width = `${window.innerWidth}px`;
engineCanvas.style.height = `${
window.innerHeight * (windowRatio / DISPLAY_RATIO)
}px`;
}
}
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
async fetchRom(romPath: string): Promise<[string, Uint8Array]> {
// extracts the name of the ROM from the provided
// path by splitting its structure
const romPathS = romPath.split(/\//g);
let romName = romPathS[romPathS.length - 1].split("?")[0];
const romNameS = romName.split(/\./g);
romName = `${romNameS[0]}.${romNameS[romNameS.length - 1]}`;
// loads the ROM data and converts it into the
// target byte array buffer (to be used by WASM)
const response = await fetch(ROM_PATH);
const blob = await response.blob();
const arrayBuffer = await blob.arrayBuffer();
const romData = new Uint8Array(arrayBuffer);
// returns both the name of the ROM and the data
// contents as a byte array
return [romName, romData];
}
}
type Global = {
modalCallback: Function | null;
//@todo check if this is really required
const global: Global = {
modalCallback: null
declare global {
interface Window {
panic: (message: string) => void;
window.panic = (message: string) => {
console.error(message);
const wasm = async () => {
await _wasm();
GameBoy.set_panic_hook_ws();
startApp("app", BACKGROUNDS);
const emulator = new Emulator();
await emulator.main();