Import cartridge .sav files with verified structure, checksums and clock (Closes #44)
Savegames → Import backup now reads an English Crystal .sav (from an emulator, a cartridge dump or the 3DS Virtual Console's sav.dat) and converts it into a native save after a preview. - world/cartridge-save.ts: picks the copy TryLoadSaveFile would load (check values and checksums of the main copy, else the backup), reads the saved WRAM block, the numbered boxes, mail backups, Hall of Fame and Battle Tower by PRET labels (SRAM, SAVE_BLOCK in the profile, checked by check:reference with the SAV constants), engine flags via EngineFlags, scenes via MapScenes, and the map's objects and masks. - Clock: an emulator MBC3 footer plus the time since it was written, FixDays/FixTime with wStart*, mapped to the minute and weekday offsets; without one, the device's time and the saved wCurDay. Day countdowns move with the day difference. - Refused with the reason: unported maps, the Bug-Catching Contest, a Battle Tower challenge, characters outside the naming screen. - Names keep <PK>/<MN> as ᴾᴷ/ᴹᴺ (one character, one tile); trainer names accept the naming screen's alphabet; boxed Eggs validate; native states up to 256 kB load (a full PC exceeded 64 kB). - Tests: the committed debug saves, layout offsets against the symbols, backup fallback, clock footers, day counters, refusals, slot session and the Savegames flow in Chromium and WebKit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
87b05b45f4
commit
592ca43a40
20 files changed
+1821
-40
No files matched your search
@@ -165,3 +165,53 @@ test("save slots: migration, new game, rename, continue, duplicate, delete and i
|
||||
).toContainText("Gold run");
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
|
||||
test("save slots: a cartridge .sav is previewed, refused when blank and imported as a new save", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
const cartridge = resolve(
|
||||
"debug-saves/Pokémon - Crystal Version/Pokémon - Crystal Version/Pokémon - Crystal Version.sav",
|
||||
);
|
||||
test.skip(
|
||||
!existsSync(romPath) || !existsSync(cartridge),
|
||||
"Requires a local user-supplied ROM.",
|
||||
);
|
||||
const errors: string[] = [];
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
await page.goto("/");
|
||||
await page.locator("#rom-file").setInputFiles(romPath);
|
||||
await expect(page.locator("#intro-screen")).toBeVisible();
|
||||
await page.locator("#tab-saves").click();
|
||||
const slots = page.locator("#slot-list > li");
|
||||
await expect(slots).toHaveCount(1);
|
||||
|
||||
// A cartridge save without a game is refused, and nothing changes.
|
||||
const blank = testInfo.outputPath("blank.sav");
|
||||
writeFileSync(blank, new Uint8Array(0x8000).fill(0xff));
|
||||
await page.locator("#save-file").setInputFiles(blank);
|
||||
const preview = page.locator("#import-dialog");
|
||||
await expect(preview).toContainText("This file cannot be imported");
|
||||
await expect(preview).toContainText("holds no saved game");
|
||||
await expect(page.locator("#import-new")).toHaveCount(0);
|
||||
await preview.getByRole("button", { name: "Close" }).click();
|
||||
await expect(slots).toHaveCount(1);
|
||||
|
||||
await page.locator("#save-file").setInputFiles(cartridge);
|
||||
await expect(preview).toContainText("Mattiaᴾᴷ's game");
|
||||
await expect(preview).toContainText("Mattiaᴾᴷ · ID No. 08872");
|
||||
await expect(preview).toContainText("Pokémon Crystal cartridge save");
|
||||
await expect(preview).toContainText("This device's time");
|
||||
await expect(preview).toContainText("Conversion notes");
|
||||
await expect(preview).toContainText("tiles walked count starts from zero");
|
||||
await page.locator("#import-new").click();
|
||||
await expect(page.locator("#status")).toContainText("Backup restored");
|
||||
await expect(slots).toHaveCount(2);
|
||||
await expect(
|
||||
page.locator('#slot-list > li[aria-current="true"]'),
|
||||
).toContainText("Mattiaᴾᴷ");
|
||||
await expect(page.locator("#game-screen")).toHaveAttribute(
|
||||
"data-map",
|
||||
"24:4",
|
||||
);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
Reference in new issue
Block a user