mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 13:43:49 +01:00
Added beta functionality for export/import feature
This commit is contained in:
parent
ac3e5c8c9e
commit
d09179cd4f
@ -296,4 +296,8 @@
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#import-game-file-selector {
|
||||
display:none;
|
||||
}
|
@ -750,7 +750,8 @@
|
||||
<a id="changelog-link" class="a-link-button" style="display:block;"> Changelog </a>
|
||||
<a id="save-game-link" class="a-link-button" style="display:block;"> Save Game </a>
|
||||
<a id="export-game-link" class="a-link-button" style="display:block;"> Export Game </a>
|
||||
<a id="import-game-link" class="a-link-button" style="display:block;"> Import Game </a>
|
||||
<input type="file" id="import-game-file-selector" name="file"/>
|
||||
<a id="import-game-link" class="a-link-button" style="display:block;" onclick="saveObject.importGame();"> Import Game </a>
|
||||
<a id="delete-game-link" class="a-link-button" style="display:block;"> Delete Game </a>
|
||||
<a id="debug-delete-scripts-link" class="a-link-button tooltip" style="display:block;">
|
||||
(DEBUG) Delete Active Scripts
|
||||
|
@ -535,6 +535,10 @@ CONSTANTS = {
|
||||
"RAM Upgrades on your home computer",
|
||||
|
||||
Changelog:
|
||||
"v0.20.1<br>" +
|
||||
"-Fixed bug where sometimes scripts would crash without showing the error<br>" +
|
||||
"-Added Deepscan programs to Dark Web<br>" +
|
||||
"-" +
|
||||
"v0.20.0<br>" +
|
||||
"-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " +
|
||||
"such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " +
|
||||
|
@ -71,7 +71,7 @@ function checkForMessagesToSend() {
|
||||
sendMessage(bitrunnersTest);
|
||||
} if (jumper5 && !jumper5.recvd && Player.hacking_skill >= 900) {
|
||||
sendMessage(jumper5);
|
||||
Player.getHomeComputer.programs.push(Programs.Flight);
|
||||
Player.getHomeComputer().programs.push(Programs.Flight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,19 +33,13 @@ BitburnerSaveObject.prototype.saveGame = function() {
|
||||
Engine.createStatusText("Game saved!");
|
||||
}
|
||||
|
||||
loadGame = function(saveObj, imported=false) {
|
||||
var saveString = "";
|
||||
if (imported) {
|
||||
|
||||
} else {
|
||||
if (!window.localStorage.getItem("bitburnerSave")) {
|
||||
console.log("No save file to load");
|
||||
return false;
|
||||
}
|
||||
var saveString = decodeURIComponent(escape(atob(window.localStorage.getItem("bitburnerSave"))));
|
||||
loadGame = function(saveObj) {
|
||||
if (!window.localStorage.getItem("bitburnerSave")) {
|
||||
console.log("No save file to load");
|
||||
return false;
|
||||
}
|
||||
|
||||
saveObj = JSON.parse(saveString, Reviver);
|
||||
var saveString = decodeURIComponent(escape(atob(window.localStorage.getItem("bitburnerSave"))));
|
||||
saveObj = JSON.parse(saveString, Reviver);
|
||||
|
||||
Player = JSON.parse(saveObj.PlayerSave, Reviver);
|
||||
AllServers = JSON.parse(saveObj.AllServersSave, Reviver);
|
||||
@ -87,7 +81,119 @@ loadGame = function(saveObj, imported=false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
loadImportedGame = function(saveObj, saveString) {
|
||||
var tempSaveObj = null;
|
||||
var tempPlayer = null;
|
||||
var tempAllServers = null;
|
||||
var tempCompanies = null;
|
||||
var tempFactions = null;
|
||||
var tempSpecialServerIps = null;
|
||||
var tempAugmentations = null;
|
||||
var tempAliases = null;
|
||||
var tempMessages = null;
|
||||
try {
|
||||
saveString = decodeURIComponent(escape(atob(saveString)));
|
||||
tempSaveObj = new BitburnerSaveObject();
|
||||
tempSaveObj = JSON.parse(saveString, Reviver);
|
||||
|
||||
tempPlayer = JSON.parse(tempSaveObj.PlayerSave, Reviver);
|
||||
tempAllServers = JSON.parse(tempSaveObj.AllServersSave, Reviver);
|
||||
tempCompanies = JSON.parse(tempSaveObj.CompaniesSave, Reviver);
|
||||
tempFactions = JSON.parse(tempSaveObj.FactionsSave, Reviver);
|
||||
tempSpecialServerIps = JSON.parse(tempSaveObj.SpecialServerIpsSave, Reviver);
|
||||
tempAugmentations = JSON.parse(tempSaveObj.AugmentationsSave, Reviver);
|
||||
if (tempSaveObj.hasOwnProperty("AliasesSave")) {
|
||||
try {
|
||||
tempAliases = JSON.parse(tempSaveObj.AliasesSave, Reviver);
|
||||
} catch(e) {
|
||||
tempAliases = {};
|
||||
}
|
||||
} else {
|
||||
tempAliases = {};
|
||||
}
|
||||
if (tempSaveObj.hasOwnProperty("MessagesSave")) {
|
||||
try {
|
||||
tempMessages = JSON.parse(tempSaveObj.MessagesSave, Reviver);
|
||||
} catch(e) {
|
||||
initMessages();
|
||||
}
|
||||
} else {
|
||||
initMessages();
|
||||
}
|
||||
if (tempSaveObj.hasOwnProperty("VersionSave")) {
|
||||
try {
|
||||
var ver = JSON.parse(tempSaveObj.VersionSave, Reviver);
|
||||
if (ver != CONSTANTS.Version) {
|
||||
createNewUpdateText();
|
||||
}
|
||||
} catch(e) {
|
||||
createNewUpdateText();
|
||||
}
|
||||
} else {
|
||||
createNewUpdateText();
|
||||
}
|
||||
} catch(e) {
|
||||
dialogBoxCreate("Error importing game");
|
||||
return false;
|
||||
}
|
||||
|
||||
saveObj = tempSaveObj;
|
||||
Player = tempPlayer;
|
||||
AllServers = tempAllServers;
|
||||
Companies = tempCompanies;
|
||||
Factions = tempFactions;
|
||||
SpecialServerIps = tempSpecialServerIps;
|
||||
Augmentations = tempAugmentations;
|
||||
if (tempAliases) {
|
||||
Aliases = tempAliases;
|
||||
}
|
||||
|
||||
if (tempMessages) {
|
||||
Messages = tempMessages;
|
||||
}
|
||||
|
||||
dialogBoxCreate("Imported game");
|
||||
return true;
|
||||
}
|
||||
|
||||
BitburnerSaveObject.prototype.exportGame = 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);
|
||||
this.AliasesSave = JSON.stringify(Aliases);
|
||||
this.MessagesSave = JSON.stringify(Messages);
|
||||
this.VersionSave = JSON.stringify(CONSTANTS.Version);
|
||||
|
||||
var saveString = btoa(unescape(encodeURIComponent(JSON.stringify(this))));
|
||||
|
||||
var file = new Blob([saveString], {type: 'text/plain'});
|
||||
if (window.navigator.msSaveOrOpenBlob) {// IE10+
|
||||
window.navigator.msSaveOrOpenBlob(file, filename);
|
||||
} else { // Others
|
||||
var a = document.createElement("a"),
|
||||
url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = "bitburnerSave.json";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
BitburnerSaveObject.prototype.importGame = function() {
|
||||
if (window.File && window.FileReader && window.FileList && window.Blob) {
|
||||
var fileSelector = clearEventListeners("import-game-file-selector");
|
||||
fileSelector.addEventListener("change", openImportFileHandler, false);
|
||||
$("#import-game-file-selector").click();
|
||||
} else {
|
||||
dialogBoxCreate("ERR: Your browser does not support HTML5 File API. Cannot import.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -114,4 +220,21 @@ BitburnerSaveObject.fromJSON = function(value) {
|
||||
return Generic_fromJSON(BitburnerSaveObject, value.data);
|
||||
}
|
||||
|
||||
Reviver.constructors.BitburnerSaveObject = BitburnerSaveObject;
|
||||
Reviver.constructors.BitburnerSaveObject = BitburnerSaveObject;
|
||||
|
||||
//Import game
|
||||
|
||||
function openImportFileHandler(evt) {
|
||||
var file = evt.target.files[0];
|
||||
if (!file) {
|
||||
dialogBoxCreate("Invalid file selected");
|
||||
return;
|
||||
}
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
var contents = e.target.result;
|
||||
loadImportedGame(saveObject, contents);
|
||||
};
|
||||
reader.readAsText(file);
|
||||
}
|
@ -890,7 +890,7 @@ var Engine = {
|
||||
//Active scripts list
|
||||
Engine.ActiveScriptsList = document.getElementById("active-scripts-list");
|
||||
|
||||
//Save and Delete buttons
|
||||
//Save, Delete, Import/Export buttons
|
||||
Engine.Clickables.saveMainMenuButton = document.getElementById("save-game-link");
|
||||
Engine.Clickables.saveMainMenuButton.addEventListener("click", function() {
|
||||
saveObject.saveGame();
|
||||
@ -903,6 +903,11 @@ var Engine = {
|
||||
return false;
|
||||
});
|
||||
|
||||
document.getElementById("export-game-link").addEventListener("click", function() {
|
||||
saveObject.exportGame();
|
||||
return false;
|
||||
});
|
||||
|
||||
//Character Overview Save button
|
||||
var charOverviewSaveButton = document.getElementById("character-overview-save-button");
|
||||
charOverviewSaveButton.addEventListener("click", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user