MISC: Support compression of save data (#1162)

* Use Compression Streams API instead of jszip or other libraries.
* Remove usage of base64 in the new binary format.
* Do not convert binary data to string and back. The type of save data is SaveData, it's either string (old base64 format) or Uint8Array (new binary format).
* Proper support for interacting with electron-related code. Electron-related code assumes that save data is in the base64 format.
* Proper support for other tools (DevMenu, pretty-save.js). Full support for DevMenu will be added in a follow-up PR. Check the comments in src\DevMenu\ui\SaveFileDev.tsx for details.
This commit is contained in:
catloversg
2024-03-28 11:08:09 +07:00
committed by GitHub
parent 75dabd10be
commit 8553bcb8fc
22 changed files with 358 additions and 289 deletions
+4 -4
View File
@@ -71,8 +71,8 @@ export const GameOptionsSidebar = (props: IProps): React.ReactElement => {
async function onImport(event: React.ChangeEvent<HTMLInputElement>): Promise<void> {
try {
const base64Save = await saveObject.getImportStringFromFile(event.target.files);
const data = await saveObject.getImportDataFromString(base64Save);
const saveData = await saveObject.getSaveDataFromFile(event.target.files);
const data = await saveObject.getImportDataFromSaveData(saveData);
setImportData(data);
setImportSaveOpen(true);
} catch (e: unknown) {
@@ -88,7 +88,7 @@ export const GameOptionsSidebar = (props: IProps): React.ReactElement => {
if (!importData) return;
try {
await saveObject.importGame(importData.base64);
await saveObject.importGame(importData.saveData);
} catch (e: unknown) {
SnackbarEvents.emit(String(e), ToastVariant.ERROR, 5000);
}
@@ -99,7 +99,7 @@ export const GameOptionsSidebar = (props: IProps): React.ReactElement => {
function compareSaveGame(): void {
if (!importData) return;
Router.toPage(Page.ImportSave, { base64Save: importData.base64 });
Router.toPage(Page.ImportSave, { saveData: importData.saveData });
setImportSaveOpen(false);
setImportData(null);
}