diff --git a/src/SaveObject.jsx b/src/SaveObject.jsx index 884d47d02..5c5b2f485 100755 --- a/src/SaveObject.jsx +++ b/src/SaveObject.jsx @@ -460,75 +460,8 @@ function loadImportedGame(saveObj, saveString) { console.error("ERROR: Failed to parse AllGangsSave: " + e); } } - - var popupId = "import-game-restart-game-notice"; - var txt = createElement("p", { - innerText:"Imported game! You need to SAVE the game and then RELOAD the page " + - "to make sure everything runs smoothly", - }); - var gotitBtn = createElement("a", { - class:"a-link-button", float:"right", padding:"6px", innerText:"Got it!", - clickListener:() => { - removeElementById(popupId); - }, - }); - createPopup(popupId, [txt, gotitBtn]); - gameOptionsBoxClose(); - - // Re-start game - Engine.setDisplayElements(); // Sets variables for important DOM elements - Engine.init(); // Initialize buttons, work, etc. - - // Calculate the number of cycles have elapsed while offline - Engine._lastUpdate = new Date().getTime(); - var lastUpdate = Player.lastUpdate; - var numCyclesOffline = Math.floor((Engine._lastUpdate - lastUpdate) / Engine._idleSpeed); - - // Process offline progress - var offlineProductionFromScripts = loadAllRunningScripts(); // This also takes care of offline production for those scripts - if (Player.isWorking) { - if (Player.workType == CONSTANTS.WorkTypeFaction) { - Player.workForFaction(numCyclesOffline); - } else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) { - Player.createProgramWork(numCyclesOffline); - } else if (Player.workType == CONSTANTS.WorkTypeStudyClass) { - Player.takeClass(numCyclesOffline); - } else if (Player.workType == CONSTANTS.WorkTypeCrime) { - Player.commitCrime(numCyclesOffline); - } else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) { - Player.workPartTime(numCyclesOffline); - } else { - Player.work(numCyclesOffline); - } - } - - // Hacknet Nodes offline progress - var offlineProductionFromHacknetNodes = processHacknetEarnings(numCyclesOffline); - - // Passive faction rep gain offline - processPassiveFactionRepGain(numCyclesOffline); - - // Update total playtime - var time = numCyclesOffline * Engine._idleSpeed; - if (Player.totalPlaytime == null) {Player.totalPlaytime = 0;} - if (Player.playtimeSinceLastAug == null) {Player.playtimeSinceLastAug = 0;} - if (Player.playtimeSinceLastBitnode == null) {Player.playtimeSinceLastBitnode = 0;} - Player.totalPlaytime += time; - Player.playtimeSinceLastAug += time; - Player.playtimeSinceLastBitnode += time; - - // Re-apply augmentations - Player.reapplyAllAugmentations(); - - // Clear terminal - $("#terminal tr:not(:last)").remove(); - - Player.lastUpdate = Engine._lastUpdate; - Engine.start(); // Run main game loop and Scripts loop - const timeOfflineString = convertTimeMsToTimeElapsedString(time); - dialogBoxCreate(<>Offline for {timeOfflineString}. While you were offline, your scripts -generated {Money(offlineProductionFromScripts)} -and your Hacknet Nodes generated hacknetProdInfo); + saveObject.saveGame(Engine.indexedDb); + location.reload(); return true; } diff --git a/src/engine.jsx b/src/engine.jsx index 540328fa3..da215de96 100644 --- a/src/engine.jsx +++ b/src/engine.jsx @@ -236,6 +236,8 @@ const Engine = { characterInfo: null, }, + indexedDb: undefined, + // Time variables (milliseconds unix epoch time) _lastUpdate: new Date().getTime(), _idleSpeed: 200, // Speed (in ms) at which the main loop is updated @@ -815,7 +817,7 @@ const Engine = { Engine.Counters.autoSaveCounter = Infinity; } else { Engine.Counters.autoSaveCounter = Settings.AutosaveInterval * 5; - saveObject.saveGame(indexedDb); + saveObject.saveGame(Engine.indexedDb); } } @@ -1468,13 +1470,13 @@ const Engine = { // Save, Delete, Import/Export buttons Engine.Clickables.saveMainMenuButton = document.getElementById("save-game-link"); Engine.Clickables.saveMainMenuButton.addEventListener("click", function() { - saveObject.saveGame(indexedDb); + saveObject.saveGame(Engine.indexedDb); return false; }); Engine.Clickables.deleteMainMenuButton = document.getElementById("delete-game-link"); Engine.Clickables.deleteMainMenuButton.addEventListener("click", function() { - saveObject.deleteGame(indexedDb); + saveObject.deleteGame(Engine.indexedDb); return false; }); @@ -1485,7 +1487,7 @@ const Engine = { // Character Overview buttons document.getElementById("character-overview-save-button").addEventListener("click", function() { - saveObject.saveGame(indexedDb); + saveObject.saveGame(Engine.indexedDb); return false; }); @@ -1597,7 +1599,7 @@ const Engine = { }, }; -var indexedDb, indexedDbRequest; +var indexedDbRequest; window.onload = function() { if (!window.indexedDB) { return Engine.load(null); // Will try to load from localstorage @@ -1617,8 +1619,8 @@ window.onload = function() { }; indexedDbRequest.onsuccess = function(e) { - indexedDb = e.target.result; - var transaction = indexedDb.transaction(["savestring"]); + Engine.indexedDb = e.target.result; + var transaction = Engine.indexedDb.transaction(["savestring"]); var objectStore = transaction.objectStore("savestring"); var request = objectStore.get("save"); request.onerror = function(e) {