mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-23 08:03:48 +01:00
Changed import so it saves and reloads the page
This commit is contained in:
parent
5af10c8406
commit
08b0c7710d
@ -460,75 +460,8 @@ function loadImportedGame(saveObj, saveString) {
|
|||||||
console.error("ERROR: Failed to parse AllGangsSave: " + e);
|
console.error("ERROR: Failed to parse AllGangsSave: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
saveObject.saveGame(Engine.indexedDb);
|
||||||
var popupId = "import-game-restart-game-notice";
|
location.reload();
|
||||||
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</>);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,6 +236,8 @@ const Engine = {
|
|||||||
characterInfo: null,
|
characterInfo: null,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
indexedDb: undefined,
|
||||||
|
|
||||||
// Time variables (milliseconds unix epoch time)
|
// Time variables (milliseconds unix epoch time)
|
||||||
_lastUpdate: new Date().getTime(),
|
_lastUpdate: new Date().getTime(),
|
||||||
_idleSpeed: 200, // Speed (in ms) at which the main loop is updated
|
_idleSpeed: 200, // Speed (in ms) at which the main loop is updated
|
||||||
@ -815,7 +817,7 @@ const Engine = {
|
|||||||
Engine.Counters.autoSaveCounter = Infinity;
|
Engine.Counters.autoSaveCounter = Infinity;
|
||||||
} else {
|
} else {
|
||||||
Engine.Counters.autoSaveCounter = Settings.AutosaveInterval * 5;
|
Engine.Counters.autoSaveCounter = Settings.AutosaveInterval * 5;
|
||||||
saveObject.saveGame(indexedDb);
|
saveObject.saveGame(Engine.indexedDb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1468,13 +1470,13 @@ const Engine = {
|
|||||||
// Save, Delete, Import/Export buttons
|
// Save, Delete, Import/Export buttons
|
||||||
Engine.Clickables.saveMainMenuButton = document.getElementById("save-game-link");
|
Engine.Clickables.saveMainMenuButton = document.getElementById("save-game-link");
|
||||||
Engine.Clickables.saveMainMenuButton.addEventListener("click", function() {
|
Engine.Clickables.saveMainMenuButton.addEventListener("click", function() {
|
||||||
saveObject.saveGame(indexedDb);
|
saveObject.saveGame(Engine.indexedDb);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
Engine.Clickables.deleteMainMenuButton = document.getElementById("delete-game-link");
|
Engine.Clickables.deleteMainMenuButton = document.getElementById("delete-game-link");
|
||||||
Engine.Clickables.deleteMainMenuButton.addEventListener("click", function() {
|
Engine.Clickables.deleteMainMenuButton.addEventListener("click", function() {
|
||||||
saveObject.deleteGame(indexedDb);
|
saveObject.deleteGame(Engine.indexedDb);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1485,7 +1487,7 @@ const Engine = {
|
|||||||
|
|
||||||
// Character Overview buttons
|
// Character Overview buttons
|
||||||
document.getElementById("character-overview-save-button").addEventListener("click", function() {
|
document.getElementById("character-overview-save-button").addEventListener("click", function() {
|
||||||
saveObject.saveGame(indexedDb);
|
saveObject.saveGame(Engine.indexedDb);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1597,7 +1599,7 @@ const Engine = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var indexedDb, indexedDbRequest;
|
var indexedDbRequest;
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
if (!window.indexedDB) {
|
if (!window.indexedDB) {
|
||||||
return Engine.load(null); // Will try to load from localstorage
|
return Engine.load(null); // Will try to load from localstorage
|
||||||
@ -1617,8 +1619,8 @@ window.onload = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
indexedDbRequest.onsuccess = function(e) {
|
indexedDbRequest.onsuccess = function(e) {
|
||||||
indexedDb = e.target.result;
|
Engine.indexedDb = e.target.result;
|
||||||
var transaction = indexedDb.transaction(["savestring"]);
|
var transaction = Engine.indexedDb.transaction(["savestring"]);
|
||||||
var objectStore = transaction.objectStore("savestring");
|
var objectStore = transaction.objectStore("savestring");
|
||||||
var request = objectStore.get("save");
|
var request = objectStore.get("save");
|
||||||
request.onerror = function(e) {
|
request.onerror = function(e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user