mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-29 19:13:49 +01:00
When game is opened it will automatically try to load from local save, otherwise it begins a new game. Also fixed up save functions
This commit is contained in:
parent
f38fd340f4
commit
00f8a31246
@ -63,34 +63,40 @@ var Engine = {
|
|||||||
|
|
||||||
window.localStorage.setItem("netburnerPlayerSave", PlayerSave);
|
window.localStorage.setItem("netburnerPlayerSave", PlayerSave);
|
||||||
window.localStorage.setItem("netburnerForeignServersSave", ForeignServersSave)
|
window.localStorage.setItem("netburnerForeignServersSave", ForeignServersSave)
|
||||||
|
console.log("Game saved to local storage");
|
||||||
Engine.displayStatusText("Saved!");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//Load saved game function
|
//Load saved game function
|
||||||
loadSave: function() {
|
loadSave: function() {
|
||||||
//Check to see if file exists
|
//Check to see if file exists
|
||||||
if (!window.localStorage.getItem("netburnerPlayerSave")) {
|
if (!window.localStorage.getItem("netburnerPlayerSave")) {
|
||||||
//TODO Add this displayStatusText function
|
console.log("No Player save to load");
|
||||||
Engine.displayStatusText("No Player save file present for load!");
|
return false;
|
||||||
} else if (!window.localStorage.getItem("netburnerForeignServersSave")) {
|
} else if (!window.localStorage.getItem("netburnerForeignServersSave")) {
|
||||||
Engine.displayStatusText("No Foreign Serverssave file present for load!");
|
console.log("No ForeignServers save to load");
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
var PlayerSave = window.localStorage.getItem("netburnerPlayerSave");
|
var PlayerSave = window.localStorage.getItem("netburnerPlayerSave");
|
||||||
var ForeignServersSave = window.localStorage.getItem("netburnerForeignServersSave");
|
var ForeignServersSave = window.localStorage.getItem("netburnerForeignServersSave");
|
||||||
Player = JSON.parse(PlayerSave);
|
Player = JSON.parse(PlayerSave);
|
||||||
ForeignServers = JSON.parse(ForeignServersSave);
|
ForeignServers = JSON.parse(ForeignServersSave);
|
||||||
Engine.displayStatusText("Loaded successfully!");
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//Delete saved game function
|
//Delete saved game function
|
||||||
deleteSave: function() {
|
deleteSave: function() {
|
||||||
if (!window.localStorage.getItem("netburnerSave")) {
|
if (!window.localStorage.getItem("netburnerPlayerSave")) {
|
||||||
Engine.displayStatusText("No save file present for deletion");
|
console.log("No Player Save to delete");
|
||||||
|
return false;
|
||||||
|
} else if (!window.localStorage.getItem("netburnerForeignServersSave")) {
|
||||||
|
console.log("No ForeignServers Save to delete");
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
window.localStorage.removeItem("netburnerSave");
|
window.localStorage.removeItem("netburnerPlayerSave");
|
||||||
Engine.displayStatusText("Deleted successfully!");
|
window.localStorage.removeItem("netburnerForeignServersSave");
|
||||||
|
console.log("Deleted saves")
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -169,8 +175,6 @@ var Engine = {
|
|||||||
Engine._actionProgressStr = "[ ]";
|
Engine._actionProgressStr = "[ ]";
|
||||||
Engine._actionTimeStr = "Time left: ";
|
Engine._actionTimeStr = "Time left: ";
|
||||||
Player.startAction = false;
|
Player.startAction = false;
|
||||||
|
|
||||||
//document.getElementById("hack-progress-bar").style.whiteSpace = "pre";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine.updateHackProgress();
|
Engine.updateHackProgress();
|
||||||
@ -185,6 +189,7 @@ var Engine = {
|
|||||||
_actionInProgress: false,
|
_actionInProgress: false,
|
||||||
updateHackProgress: function() {
|
updateHackProgress: function() {
|
||||||
if (Engine._actionInProgress == true) {
|
if (Engine._actionInProgress == true) {
|
||||||
|
//TODO Do this calculation based on numCycles rather than idle speed
|
||||||
Engine._actionTimeLeft -= (Engine._idleSpeed/ 1000); //Substract idle speed (ms)
|
Engine._actionTimeLeft -= (Engine._idleSpeed/ 1000); //Substract idle speed (ms)
|
||||||
|
|
||||||
//Calculate percent filled
|
//Calculate percent filled
|
||||||
@ -215,15 +220,19 @@ var Engine = {
|
|||||||
/* Initialization */
|
/* Initialization */
|
||||||
init: function() {
|
init: function() {
|
||||||
//Initialization functions
|
//Initialization functions
|
||||||
//TODO Might need to move these into a new "BeginGame()" function. init() is called
|
if (Engine.loadSave()) {
|
||||||
//every time the window is opened and we don't want to do these init() functions every
|
console.log("Loaded game from save");
|
||||||
//time
|
Companies.init();
|
||||||
Player.init();
|
CompanyPositions.init();
|
||||||
|
} else {
|
||||||
|
//No save found, start new game
|
||||||
|
console.log("Initializing new game");
|
||||||
|
Player.init();
|
||||||
|
ForeignServers.init();
|
||||||
|
Companies.init();
|
||||||
|
CompanyPositions.init();
|
||||||
|
}
|
||||||
|
|
||||||
ForeignServers.init();
|
|
||||||
|
|
||||||
Companies.init();
|
|
||||||
CompanyPositions.init();
|
|
||||||
|
|
||||||
//Load, save, and delete buttons
|
//Load, save, and delete buttons
|
||||||
//Engine.Clickables.saveButton = document.getElementById("save");
|
//Engine.Clickables.saveButton = document.getElementById("save");
|
||||||
|
Loading…
Reference in New Issue
Block a user