var Engine = {
Debug: true,
//Clickable objects
Clickables: {
//Main menu buttons
terminalMainMenuButton: null,
characterMainMenuButton: null,
scriptEditorMainMenuButton: null,
activeScriptsMainMenuButton: null,
worldMainMenuButton: null,
createProgramMainMenuButton: null,
factionsMainMenuButton: null,
augmentationsMainMenuButton: null,
tutorialMainMenuButton: null,
saveMainMenuButton: null,
deleteMainMenuButton: null,
},
//Display objects
Display: {
//Progress bar
progress: null,
//Display for status text (such as "Saved" or "Loaded")
statusText: null,
hacking_skill: null,
//Main menu content
terminalContent: null,
characterContent: null,
scriptEditorContent: null,
activeScriptsContent: null,
worldContent: null,
createProgramContent: null,
factionsContent: null,
factionContent: null,
augmentationsContent: null,
tutorialContent: null,
locationContent: null,
workInProgressContent: null,
//Character info
characterInfo: null,
//Script editor text
scriptEditorText: null,
},
//Current page status
Page: {
Terminal: "Terminal",
CharacterInfo: "CharacterInfo",
ScriptEditor: "ScriptEditor",
ActiveScripts: "ActiveScripts",
World: "World",
CreateProgram: "CreateProgram",
Factions: "Factions",
Faction: "Faction",
Augmentations: "Augmentations",
Tutorial: "Tutorial",
Location: "Location",
workInProgress: "WorkInProgress",
},
currentPage: null,
//Time variables (milliseconds unix epoch time)
_lastUpdate: new Date().getTime(),
_idleSpeed: 200, //Speed (in ms) at which the main loop is updated
//Save function
saveGame: function() {
var PlayerSave = JSON.stringify(Player);
var AllServersSave = JSON.stringify(AllServers);
var CompaniesSave = JSON.stringify(Companies);
var FactionsSave = JSON.stringify(Factions);
var SpecialServerIpsSave = JSON.stringify(SpecialServerIps);
var AugmentationsSave = JSON.stringify(Augmentations);
window.localStorage.setItem("netburnerPlayerSave", PlayerSave);
window.localStorage.setItem("netburnerAllServersSave", AllServersSave);
window.localStorage.setItem("netburnerCompaniesSave", CompaniesSave);
window.localStorage.setItem("netburnerFactionsSave", FactionsSave);
window.localStorage.setItem("netburnerSpecialServerIpsSave", SpecialServerIpsSave);
window.localStorage.setItem("netburnerAugmentationsSave", AugmentationsSave);
console.log("Game saved to local storage");
},
//Load saved game function
loadSave: function() {
//Check to see if file exists
if (!window.localStorage.getItem("netburnerPlayerSave")) {
console.log("No Player save to load");
return false;
} else if (!window.localStorage.getItem("netburnerAllServersSave")) {
console.log("No AllServers save to load");
return false;
} else if (!window.localStorage.getItem("netburnerCompaniesSave")) {
console.log("No Companies save to load");
return false;
} else if (!window.localStorage.getItem("netburnerFactionsSave")) {
console.log("No Factions save to load");
return false;
} else if (!window.localStorage.getItem("netburnerSpecialServerIpsSave")) {
console.log("No Special Server Ips save to load");
return false;
} else if (!window.localStorage.getItem("netburnerAugmentationsSave")) {
console.log("No Augmentations save to load");
return false;
} else {
var PlayerSave = window.localStorage.getItem("netburnerPlayerSave");
var AllServersSave = window.localStorage.getItem("netburnerAllServersSave");
var CompaniesSave = window.localStorage.getItem("netburnerCompaniesSave");
var FactionsSave = window.localStorage.getItem("netburnerFactionsSave");
var SpecialServerIpsSave = window.localStorage.getItem("netburnerSpecialServerIpsSave");
var AugmentationsSave = window.localStorage.getItem("netburnerAugmentationsSave");
Player = JSON.parse(PlayerSave, Reviver);
AllServers = JSON.parse(AllServersSave, Reviver);
Companies = JSON.parse(CompaniesSave, Reviver);
Factions = JSON.parse(FactionsSave, Reviver);
SpecialServerIps = JSON.parse(SpecialServerIpsSave, Reviver);
Augmentations = JSON.parse(AugmentationsSave, Reviver);
return true;
}
},
//Delete saved game function
deleteSave: function() {
//TODO if a save doesn't exist..maybe I shouldn't return? I just keep going
//or else nothing gets deleted. TODO Fix this
if (window.localStorage.getItem("netburnerPlayerSave")) {
window.localStorage.removeItem("netburnerPlayerSave");
}
if (window.localStorage.getItem("netburnerAllServersSave")) {
window.localStorage.removeItem("netburnerAllServersSave");
}
if (window.localStorage.getItem("netburnerCompaniesSave")) {
window.localStorage.removeItem("netburnerCompaniesSave");
}
if (window.localStorage.getItem("netburnerFactionsSave")) {
window.localStorage.removeItem("netburnerFactionsSave");
}
if (window.localStorage.getItem("netburnerSpecialServerIpsSave")) {
window.localStorage.removeItem("netburnerSpecialServerIpsSave");
}
if (window.localStorage.getItem("netburnerAugmentationsSave")) {
window.localStorage.removeItem("netburnerAugmentationsSave");
}
},
/* Load content when a main menu button is clicked */
loadTerminalContent: function() {
Engine.hideAllContent();
Engine.Display.terminalContent.style.visibility = "visible";
Engine.currentPage = Engine.Page.Terminal;
},
loadCharacterContent: function() {
Engine.hideAllContent();
Engine.Display.characterContent.style.visibility = "visible";
Engine.displayCharacterInfo();
Engine.currentPage = Engine.Page.CharacterInfo;
},
loadScriptEditorContent: function(filename = "", code = "") {
Engine.hideAllContent();
Engine.Display.scriptEditorContent.style.visibility = "visible";
if (filename == "") {
document.getElementById("script-editor-filename").value = "untitled";
} else {
document.getElementById("script-editor-filename").value = filename;
}
document.getElementById("script-editor-text").value = code;
Engine.currentPage = Engine.Page.ScriptEditor;
},
loadActiveScriptsContent: function() {
Engine.hideAllContent();
Engine.Display.activeScriptsContent.style.visibility = "visible";
Engine.currentPage = Engine.Page.ActiveScripts;
},
loadWorldContent: function() {
Engine.hideAllContent();
Engine.Display.worldContent.style.visibility = "visible";
Engine.displayWorldInfo();
Engine.currentPage = Engine.Page.World;
},
loadCreateProgramContent: function() {
Engine.hideAllContent();
Engine.Display.createProgramContent.style.visibility = "visible";
Engine.currentPage = Engine.Page.CreateProgram;
},
loadFactionsContent: function() {
Engine.hideAllContent();
Engine.Display.factionsContent.style.visibility = "visible";
Engine.displayFactionsInfo();
Engine.currentPage = Engine.Page.Factions;
},
loadFactionContent: function() {
Engine.hideAllContent();
Engine.Display.factionContent.style.visibility = "visible";
Engine.currentPage = Engine.Page.Faction;
},
loadAugmentationsContent: function() {
Engine.hideAllContent();
Engine.Display.augmentationsContent.style.visibility = "visible";
Engine.displayAugmentationsContent();
Engine.currentPage = Engine.Page.Augmentations;
},
loadTutorialContent: function() {
Engine.hideAllContent();
Engine.Display.tutorialContent.style.visibility = "visible";
Engine.currentPage = Engine.Page.Tutorial;
},
loadLocationContent: function() {
Engine.hideAllContent();
Engine.Display.locationContent.style.visibility = "visible";
displayLocationContent();
Engine.currentPage = Engine.Page.Location;
},
loadWorkInProgressContent: function() {
Engine.hideAllContent();
var mainMenu = document.getElementById("mainmenu-container");
mainMenu.style.visibility = "hidden";
Engine.Display.workInProgressContent.style.visibility = "visible";
Engine.currentPage = Engine.Page.WorkInProgress;
},
//Helper function that hides all content
hideAllContent: function() {
Engine.Display.terminalContent.style.visibility = "hidden";
Engine.Display.characterContent.style.visibility = "hidden";
Engine.Display.scriptEditorContent.style.visibility = "hidden";
Engine.Display.activeScriptsContent.style.visibility = "hidden";
Engine.Display.worldContent.style.visibility = "hidden";
Engine.Display.createProgramContent.style.visibility = "hidden";
Engine.Display.factionsContent.style.visibility = "hidden";
Engine.Display.factionContent.style.visibility = "hidden";
Engine.Display.augmentationsContent.style.visibility = "hidden";
Engine.Display.tutorialContent.style.visibility = "hidden";
Engine.Display.locationContent.style.visibility = "hidden";
Engine.Display.workInProgressContent.style.visibility = "hidden";
//Location lists
Engine.aevumLocationsList.style.display = "none";
Engine.chongqingLocationsList.style.display = "none";
Engine.sector12LocationsList.style.display = "none";
Engine.newTokyoLocationsList.style.display = "none";
Engine.ishimaLocationsList.style.display = "none";
Engine.volhavenLocationsList.style.display = "none";
},
/* Display character info */
displayCharacterInfo: function() {
var companyPosition = "";
if (Player.companyPosition != "") {
companyPosition = Player.companyPosition.positionName;
}
Engine.Display.characterInfo.innerHTML = 'Current City: ' + Player.city + '
' +
'Employer: ' + Player.companyName + '
' +
'Job Title: ' + companyPosition + '
' +
'Money: $' + (Player.money.toFixed(2)).toLocaleString() + '
' +
'Hacking Level: ' + (Player.hacking_skill).toLocaleString() + '
' +
'Strength: ' + (Player.strength.toLocaleString() + '
' +
'Defense: ' + (Player.defense).toLocaleString() + '
' +
'Dexterity: ' + (Player.dexterity).toLocaleString() + '
' +
'Agility: ' + (Player.agility).toLocaleString() + '
' +
'Charisma: ' + (Player.charisma).toLocaleString() + '
' +
'Servers owned: ' + Player.purchasedServers.length + '
' +
'Hacking experience: ' + (Player.hacking_exp.toFixed(4)).toLocaleString() + '
' +
'Strength experience: ' + (Player.strength_exp.toFixed(4)).toLocaleString() + '
' +
'Defense experience: ' + (Player.defense_exp.toFixed(4)).toLocaleString() + '
' +
'Dexterity experience: ' + (Player.dexterity_exp.toFixed(4)).toLocaleString() + '
' +
'Agility experience: ' + (Player.agility_exp.toFixed(4)).toLocaleString() + '
' +
'Charisma experience: ' + (Player.charisma_exp.toFixed(4)).toLocaleString() + '
';
},
/* Display locations in the world*/
aevumLocationsList: null,
chongqingLocationsList: null,
sector12LocationsList: null,
newTokyoLocationsList: null,
ishimaLocationsList: null,
volhavenLocationsList: null,
displayWorldInfo: function() {
Engine.aevumLocationsList.style.display = "none";
Engine.chongqingLocationsList.style.display = "none";
Engine.sector12LocationsList.style.display = "none";
Engine.newTokyoLocationsList.style.display = "none";
Engine.ishimaLocationsList.style.display = "none";
Engine.volhavenLocationsList.style.display = "none";
switch(Player.city) {
case Locations.Aevum:
Engine.aevumLocationsList.style.display = "inline";
break;
case Locations.Chongqing:
Engine.chongqingLocationsList.style.display = "inline";
break;
case Locations.Sector12:
Engine.sector12LocationsList.style.display = "inline";
break;
case Locations.NewTokyo:
Engine.newTokyoLocationsList.style.display = "inline";
break;
case Locations.Ishima:
Engine.ishimaLocationsList.style.display = "inline";
break;
case Locations.Volhaven:
Engine.volhavenLocationsList.style.display = "inline";
break;
default:
console.log("Invalid city value in Player object!");
break;
}
},
/* Functions used to update information on the Active Scripts page */
ActiveScriptsList: null,
//Creates and adds the