Merge pull request #2429 from MartinFournier/fix/export-bonus

Fix export bonus not being applied when using options menu
This commit is contained in:
hydroflame 2022-01-08 12:43:28 -05:00 committed by GitHub
commit 8d7bc1755c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

@ -41,6 +41,7 @@ class BitburnerSaveObject {
AllGangsSave = ""; AllGangsSave = "";
LastExportBonus = ""; LastExportBonus = "";
StaneksGiftSave = ""; StaneksGiftSave = "";
SaveTimestamp = "";
getSaveString(): string { getSaveString(): string {
this.PlayerSave = JSON.stringify(Player); this.PlayerSave = JSON.stringify(Player);
@ -56,6 +57,8 @@ class BitburnerSaveObject {
this.VersionSave = JSON.stringify(CONSTANTS.VersionNumber); this.VersionSave = JSON.stringify(CONSTANTS.VersionNumber);
this.LastExportBonus = JSON.stringify(ExportBonus.LastExportBonus); this.LastExportBonus = JSON.stringify(ExportBonus.LastExportBonus);
this.StaneksGiftSave = JSON.stringify(staneksGift); this.StaneksGiftSave = JSON.stringify(staneksGift);
this.SaveTimestamp = new Date().getTime().toString();
if (Player.inGang()) { if (Player.inGang()) {
this.AllGangsSave = JSON.stringify(AllGangs); this.AllGangsSave = JSON.stringify(AllGangs);
} }

@ -389,7 +389,11 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
<GameOptionsRoot <GameOptionsRoot
player={player} player={player}
save={() => saveObject.saveGame()} save={() => saveObject.saveGame()}
export={() => saveObject.exportGame()} export={() => {
// Apply the export bonus before saving the game
onExport(player);
saveObject.exportGame()
}}
forceKill={killAllScripts} forceKill={killAllScripts}
softReset={() => { softReset={() => {
dialogBoxCreate("Soft Reset!"); dialogBoxCreate("Soft Reset!");
@ -400,8 +404,9 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
) : page === Page.Augmentations ? ( ) : page === Page.Augmentations ? (
<AugmentationsRoot <AugmentationsRoot
exportGameFn={() => { exportGameFn={() => {
saveObject.exportGame(); // Apply the export bonus before saving the game
onExport(player); onExport(player);
saveObject.exportGame();
}} }}
installAugmentationsFn={() => { installAugmentationsFn={() => {
installAugmentations(); installAugmentations();

@ -246,16 +246,14 @@ export function GameOptionsRoot(props: IProps): React.ReactElement {
return; return;
} }
const data: ImportData = { const data: ImportData = {
base64: contents, base64: contents,
parsed: parsedSave, 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 timestamp = parsedSave.data.SaveTimestamp;
const exportTimestamp = parsedSave.data.LastExportBonus; if (timestamp && timestamp !== '0') {
if (exportTimestamp && exportTimestamp !== '0') { data.exportDate = new Date(parseInt(timestamp, 10))
data.exportDate = new Date(parseInt(exportTimestamp, 10))
} }
setImportData(data) setImportData(data)

@ -19,6 +19,7 @@ async function getSave(file) {
VersionSave: JSON.parse(saveData.VersionSave), VersionSave: JSON.parse(saveData.VersionSave),
LastExportBonus: JSON.parse(saveData.LastExportBonus), LastExportBonus: JSON.parse(saveData.LastExportBonus),
StaneksGiftSave: JSON.parse(saveData.StaneksGiftSave), StaneksGiftSave: JSON.parse(saveData.StaneksGiftSave),
SaveTimestamp: new Date(parseInt(saveData.SaveTimestamp ?? '0', 10)).toLocaleString(),
} }
const serverStrings = JSON.parse(saveData.AllServersSave); const serverStrings = JSON.parse(saveData.AllServersSave);