From 356267177298848b9fd5af8b8db67b0413cbd5e4 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Fri, 7 Jan 2022 08:58:12 -0500 Subject: [PATCH 1/2] Add SaveTimestamp to saveString, used in import --- src/SaveObject.tsx | 3 +++ src/ui/React/GameOptionsRoot.tsx | 8 +++----- tools/pretty-save.js | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/SaveObject.tsx b/src/SaveObject.tsx index 906241609..3392abede 100755 --- a/src/SaveObject.tsx +++ b/src/SaveObject.tsx @@ -41,6 +41,7 @@ class BitburnerSaveObject { AllGangsSave = ""; LastExportBonus = ""; StaneksGiftSave = ""; + SaveTimestamp = ""; getSaveString(): string { this.PlayerSave = JSON.stringify(Player); @@ -56,6 +57,8 @@ class BitburnerSaveObject { this.VersionSave = JSON.stringify(CONSTANTS.VersionNumber); this.LastExportBonus = JSON.stringify(ExportBonus.LastExportBonus); this.StaneksGiftSave = JSON.stringify(staneksGift); + this.SaveTimestamp = new Date().getTime().toString(); + if (Player.inGang()) { this.AllGangsSave = JSON.stringify(AllGangs); } diff --git a/src/ui/React/GameOptionsRoot.tsx b/src/ui/React/GameOptionsRoot.tsx index 2085fe62c..37c36df7b 100644 --- a/src/ui/React/GameOptionsRoot.tsx +++ b/src/ui/React/GameOptionsRoot.tsx @@ -246,16 +246,14 @@ export function GameOptionsRoot(props: IProps): React.ReactElement { return; } - const data: ImportData = { base64: contents, parsed: parsedSave, } - // We don't always seem to have this value in the save file. Exporting from the option menu does not set the bonus I think. - const exportTimestamp = parsedSave.data.LastExportBonus; - if (exportTimestamp && exportTimestamp !== '0') { - data.exportDate = new Date(parseInt(exportTimestamp, 10)) + const timestamp = parsedSave.data.SaveTimestamp; + if (timestamp && timestamp !== '0') { + data.exportDate = new Date(parseInt(timestamp, 10)) } setImportData(data) diff --git a/tools/pretty-save.js b/tools/pretty-save.js index 6cdc974ab..6f3a93d68 100644 --- a/tools/pretty-save.js +++ b/tools/pretty-save.js @@ -19,6 +19,7 @@ async function getSave(file) { VersionSave: JSON.parse(saveData.VersionSave), LastExportBonus: JSON.parse(saveData.LastExportBonus), StaneksGiftSave: JSON.parse(saveData.StaneksGiftSave), + SaveTimestamp: new Date(parseInt(saveData.SaveTimestamp ?? '0', 10)).toLocaleString(), } const serverStrings = JSON.parse(saveData.AllServersSave); From b9ad1d3082af2f07c53bec82eaa5079939fc1ea7 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Fri, 7 Jan 2022 09:03:04 -0500 Subject: [PATCH 2/2] Apply export bonus when using options menu Also applies the bonus before saving the game instead of after --- src/ui/GameRoot.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ui/GameRoot.tsx b/src/ui/GameRoot.tsx index 4c37690a7..2fe3afc86 100644 --- a/src/ui/GameRoot.tsx +++ b/src/ui/GameRoot.tsx @@ -389,7 +389,11 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme saveObject.saveGame()} - export={() => saveObject.exportGame()} + export={() => { + // Apply the export bonus before saving the game + onExport(player); + saveObject.exportGame() + }} forceKill={killAllScripts} softReset={() => { dialogBoxCreate("Soft Reset!"); @@ -400,8 +404,9 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme ) : page === Page.Augmentations ? ( { - saveObject.exportGame(); + // Apply the export bonus before saving the game onExport(player); + saveObject.exportGame(); }} installAugmentationsFn={() => { installAugmentations();