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",
},
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);
//TODO Add factions + companies here when they're done
window.localStorage.setItem("netburnerPlayerSave", PlayerSave);
window.localStorage.setItem("netburnerAllServersSave", AllServersSave);
window.localStorage.setItem("netburnerCompaniesSave", CompaniesSave);
window.localStorage.setItem("netburnerFactionsSave", FactionsSave);
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 {
var PlayerSave = window.localStorage.getItem("netburnerPlayerSave");
var AllServersSave = window.localStorage.getItem("netburnerAllServersSave");
var CompaniesSave = window.localStorage.getItem("netburnerCompaniesSave");
var FactionsSave = window.localStorage.getItem("netburnerFactionsSave");
Player = JSON.parse(PlayerSave, Reviver);
AllServers = JSON.parse(AllServersSave, Reviver);
Companies = JSON.parse(CompaniesSave, Reviver);
Factions = JSON.parse(FactionsSave, 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")) {
console.log("No Player Save to delete");
return false;
} else if (!window.localStorage.getItem("netburnerAllServersSave")) {
console.log("No AllServers Save to delete");
return false;
} else if (!window.localStorage.getItem("netburnerCompaniesSave")) {
console.log("No Companies Save to delete");
return false;
} else if (!window.localStorage.getItem("netburnerFactionsSave")) {
console.log("No Factions Save to delete");
return false;
} else {
window.localStorage.removeItem("netburnerPlayerSave");
window.localStorage.removeItem("netburnerAllServersSave");
window.localStorage.removeItem("netburnerCompaniesSave");
window.localStorage.removeItem("netburnerFactionsSave");
console.log("Deleted saves")
return true;
}
},
/* 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.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.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";
},
//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) + '
' +
'Hacking Level: ' + Player.hacking_skill + '
' +
'Strength: ' + Player.strength + '
' +
'Defense: ' + Player.defense + '
' +
'Dexterity: ' + Player.dexterity + '
' +
'Agility: ' + Player.agility + '
' +
'Charisma: ' + Player.charisma + '
' +
'Servers owned: ' + Player.purchasedServers.length + '
' +
'Hacking Experience: ' + Player.hacking_exp.toFixed(4) + '
';
},
/* 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";
//Engine.aevumLocationsList.style.visibility = "visible";
break;
case Locations.Chongqing:
Engine.chongqingLocationsList.style.display = "inline";
//Engine.chongqingLocationsList.style.visibility = "visible";
break;
case Locations.Sector12:
Engine.sector12LocationsList.style.display = "inline";
//Engine.sector12LocationsList.style.visibility = "visible";
break;
case Locations.NewTokyo:
Engine.newTokyoLocationsList.style.display = "inline";
//Engine.newTokyoLocationsList.style.visibility = "visible";
break;
case Locations.Ishima:
Engine.ishimaLocationsList.style.display = "inline";
//Engine.ishimaLocationsList.style.visibility = "visible";
break;
case Locations.Volhaven:
Engine.volhavenLocationsList.style.display = "inline";
//Engine.volhavenLocationsList.style.visibility = "visible";
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