From 06775b20fa5d8ee014b1d3eb77e7bce890c8f959 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Mon, 11 Oct 2021 17:57:17 -0400 Subject: [PATCH] saving file now saves game --- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 5 +++++ src/Settings/Settings.ts | 7 +++++++ src/ui/React/GameOptionsRoot.tsx | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 0e79df831..32121add1 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -22,6 +22,7 @@ import { WorkerScript } from "../../Netscript/WorkerScript"; import { Settings } from "../../Settings/Settings"; import { iTutorialNextStep, ITutorial, iTutorialSteps } from "../../InteractiveTutorial"; import { debounce } from "lodash"; +import { saveObject } from "../../SaveObject"; import Button from "@mui/material/Button"; import Typography from "@mui/material/Typography"; @@ -176,6 +177,7 @@ export function Root(props: IProps): React.ReactElement { for (let i = 0; i < server.scripts.length; i++) { if (filename == server.scripts[i].filename) { server.scripts[i].saveScript(filename, code, props.player.currentServer, server.scripts); + saveObject.saveGame(); props.router.toTerminal(); return; } @@ -189,6 +191,7 @@ export function Root(props: IProps): React.ReactElement { for (let i = 0; i < server.textFiles.length; ++i) { if (server.textFiles[i].fn === filename) { server.textFiles[i].write(code); + saveObject.saveGame(); props.router.toTerminal(); return; } @@ -199,6 +202,8 @@ export function Root(props: IProps): React.ReactElement { dialogBoxCreate("Invalid filename. Must be either a script (.script, .js, or .ns) or " + " or text file (.txt)"); return; } + + saveObject.saveGame(); props.router.toTerminal(); } diff --git a/src/Settings/Settings.ts b/src/Settings/Settings.ts index 79a64995e..8b206e6a1 100644 --- a/src/Settings/Settings.ts +++ b/src/Settings/Settings.ts @@ -68,6 +68,11 @@ interface IDefaultSettings { */ MaxTerminalCapacity: number; + /** + * Save the game when you save any file. + */ + SaveGameOnFileSave: boolean; + /** * Whether the player should be asked to confirm purchasing each and every augmentation. */ @@ -168,6 +173,7 @@ export const defaultSettings: IDefaultSettings = { MaxLogCapacity: 50, MaxPortCapacity: 50, MaxTerminalCapacity: 200, + SaveGameOnFileSave: true, SuppressBuyAugmentationConfirmation: false, SuppressFactionInvites: false, SuppressHospitalizationPopup: false, @@ -226,6 +232,7 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = { MaxTerminalCapacity: defaultSettings.MaxTerminalCapacity, OwnedAugmentationsOrder: OwnedAugmentationsOrderSetting.AcquirementTime, PurchaseAugmentationsOrder: PurchaseAugmentationsOrderSetting.Default, + SaveGameOnFileSave: defaultSettings.SaveGameOnFileSave, SuppressBuyAugmentationConfirmation: defaultSettings.SuppressBuyAugmentationConfirmation, SuppressFactionInvites: defaultSettings.SuppressFactionInvites, SuppressHospitalizationPopup: defaultSettings.SuppressHospitalizationPopup, diff --git a/src/ui/React/GameOptionsRoot.tsx b/src/ui/React/GameOptionsRoot.tsx index 53def414d..275c527a4 100644 --- a/src/ui/React/GameOptionsRoot.tsx +++ b/src/ui/React/GameOptionsRoot.tsx @@ -77,6 +77,7 @@ export function GameOptionsRoot(props: IProps): React.ReactElement { const [disableTextEffects, setDisableTextEffects] = useState(Settings.DisableTextEffects); const [enableBashHotkeys, setEnableBashHotkeys] = useState(Settings.EnableBashHotkeys); const [enableTimestamps, setEnableTimestamps] = useState(Settings.EnableTimestamps); + const [saveGameOnFileSave, setSaveGameOnFileSave] = useState(Settings.SaveGameOnFileSave); const [locale, setLocale] = useState(Settings.Locale); const [diagnosticOpen, setDiagnosticOpen] = useState(false); @@ -165,6 +166,10 @@ export function GameOptionsRoot(props: IProps): React.ReactElement { setEnableTimestamps(event.target.checked); Settings.EnableTimestamps = event.target.checked; } + function handleSaveGameOnFile(event: React.ChangeEvent): void { + setSaveGameOnFileSave(event.target.checked); + Settings.SaveGameOnFileSave = event.target.checked; + } function startImport(): void { if (!window.File || !window.FileReader || !window.FileList || !window.Blob) return; @@ -505,6 +510,19 @@ export function GameOptionsRoot(props: IProps): React.ReactElement { /> + + } + label={ + Save your game any time a file is saved in the script editor.} + > + Save game on file save + + } + /> + + Sets the locale for displaying numbers.}> Locale