Skip to content

Commit

Permalink
feat: support for zip files
Browse files Browse the repository at this point in the history
Making use of the newly added `buildRomData()` method.
  • Loading branch information
joamag committed Oct 9, 2023
1 parent a0180fd commit c1deb55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

*
* Support for Zip file in Web frontend

### Changed

Expand Down
2 changes: 2 additions & 0 deletions frontends/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"@types/react-dom": "^18.2.11",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"buffer": "^6.0.3",
"emukit": "^0.9.2",
"eslint": "^8.51.0",
"jszip": "^3.10.1",
"nodemon": "^3.0.1",
"parcel": "^2.9.3",
"prettier": "^3.0.3",
Expand Down
16 changes: 15 additions & 1 deletion frontends/web/ts/gb.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loadAsync } from "jszip";
import {
AudioSpecs,
base64ToBuffer,
Expand Down Expand Up @@ -594,7 +595,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
}

get romExts(): string[] {
return ["gb", "gbc"];
return ["gb", "gbc", "zip"];
}

get pixelFormat(): PixelFormat {
Expand Down Expand Up @@ -785,6 +786,19 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
this.gameBoy?.key_lift(keyCode);
}

async buildRomData(file: File): Promise<Uint8Array> {
const arrayBuffer = await file.arrayBuffer();
let romData = new Uint8Array(arrayBuffer);

if (file.name.endsWith(".zip")) {
const zip = await loadAsync(romData);
const firstFile = Object.values(zip.files)[0];
romData = await firstFile.async("uint8array");
}

return romData;
}

serializeState(): Uint8Array {
if (!this.gameBoy) throw new Error("Unable to serialize state");
return StateManager.save(this.gameBoy, SaveStateFormat.Bos);
Expand Down

0 comments on commit c1deb55

Please sign in to comment.