2017-05-05 03:08:44 +02:00
|
|
|
/* SaveObject.js
|
|
|
|
* Defines the object used to save/load games
|
|
|
|
*/
|
|
|
|
var saveObject = new BitburnerSaveObject();
|
|
|
|
|
|
|
|
function BitburnerSaveObject() {
|
|
|
|
this.PlayerSave = "";
|
|
|
|
this.AllServersSave = "";
|
|
|
|
this.CompaniesSave = "";
|
|
|
|
this.FactionsSave = "";
|
|
|
|
this.SpecialServerIpsSave = "";
|
|
|
|
this.AugmentationsSave = "";
|
2017-05-23 17:12:09 +02:00
|
|
|
this.AliasesSave = "";
|
2017-06-02 06:15:45 +02:00
|
|
|
this.MessagesSave = "";
|
2017-05-05 03:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BitburnerSaveObject.prototype.saveGame = function() {
|
|
|
|
this.PlayerSave = JSON.stringify(Player);
|
|
|
|
this.AllServersSave = JSON.stringify(AllServers);
|
|
|
|
this.CompaniesSave = JSON.stringify(Companies);
|
|
|
|
this.FactionsSave = JSON.stringify(Factions);
|
|
|
|
this.SpecialServerIpsSave = JSON.stringify(SpecialServerIps);
|
|
|
|
this.AugmentationsSave = JSON.stringify(Augmentations);
|
2017-05-23 17:12:09 +02:00
|
|
|
this.AliasesSave = JSON.stringify(Aliases);
|
2017-06-02 06:15:45 +02:00
|
|
|
this.MessagesSave = JSON.stringify(Messages);
|
2017-05-05 03:08:44 +02:00
|
|
|
|
2017-05-05 06:54:40 +02:00
|
|
|
var saveString = btoa(unescape(encodeURIComponent(JSON.stringify(this))));
|
2017-05-05 03:08:44 +02:00
|
|
|
window.localStorage.setItem("bitburnerSave", saveString);
|
2017-05-15 18:54:23 +02:00
|
|
|
|
2017-05-15 19:23:20 +02:00
|
|
|
console.log("Game saved!");
|
2017-05-15 18:54:23 +02:00
|
|
|
Engine.createStatusText("Game saved!");
|
2017-05-05 03:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
loadGame = function(saveObj) {
|
|
|
|
if (!window.localStorage.getItem("bitburnerSave")) {
|
|
|
|
console.log("No save file to load");
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-05 06:54:40 +02:00
|
|
|
var saveString = decodeURIComponent(escape(atob(window.localStorage.getItem("bitburnerSave"))));
|
2017-05-05 03:08:44 +02:00
|
|
|
saveObj = JSON.parse(saveString, Reviver);
|
|
|
|
|
|
|
|
Player = JSON.parse(saveObj.PlayerSave, Reviver);
|
|
|
|
AllServers = JSON.parse(saveObj.AllServersSave, Reviver);
|
|
|
|
Companies = JSON.parse(saveObj.CompaniesSave, Reviver);
|
|
|
|
Factions = JSON.parse(saveObj.FactionsSave, Reviver);
|
|
|
|
SpecialServerIps = JSON.parse(saveObj.SpecialServerIpsSave, Reviver);
|
|
|
|
Augmentations = JSON.parse(saveObj.AugmentationsSave, Reviver);
|
2017-05-23 19:36:35 +02:00
|
|
|
if (saveObj.hasOwnProperty("AliasesSave")) {
|
2017-05-23 18:15:17 +02:00
|
|
|
try {
|
|
|
|
Aliases = JSON.parse(saveObj.AliasesSave, Reviver);
|
|
|
|
} catch(e) {
|
|
|
|
Aliases = {};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Aliases = {};
|
|
|
|
}
|
2017-06-02 06:15:45 +02:00
|
|
|
if (saveObj.hasOwnProperty("MessagesSave")) {
|
|
|
|
try {
|
|
|
|
Messages = JSON.parse(saveObj.MessagesSave, Reviver);
|
|
|
|
} catch(e) {
|
|
|
|
initMessages();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
initMessages();
|
|
|
|
}
|
2017-05-23 18:15:17 +02:00
|
|
|
|
2017-05-05 03:08:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitburnerSaveObject.prototype.deleteGame = function() {
|
|
|
|
if (window.localStorage.getItem("bitburnerSave")) {
|
|
|
|
window.localStorage.removeItem("bitburnerSave");
|
|
|
|
}
|
2017-05-15 18:54:23 +02:00
|
|
|
Engine.createStatusText("Game deleted!");
|
2017-05-05 03:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BitburnerSaveObject.prototype.toJSON = function() {
|
|
|
|
return Generic_toJSON("BitburnerSaveObject", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
BitburnerSaveObject.fromJSON = function(value) {
|
|
|
|
return Generic_fromJSON(BitburnerSaveObject, value.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
Reviver.constructors.BitburnerSaveObject = BitburnerSaveObject;
|