Factions should save and load properly (not fully tested). Terminal now scrolls to the bottom when something is posted

This commit is contained in:
Daniel Xie 2016-12-21 12:36:42 -06:00
parent d656ee3114
commit 8dbca029de
4 changed files with 38 additions and 9 deletions

@ -37,9 +37,12 @@ TESTING TODO:
ctrl+C functionality for all running command like hack(), analyze(), and tail ctrl+C functionality for all running command like hack(), analyze(), and tail
Implemented for hack() and analyze(). Seems to work Implemented for hack() and analyze(). Seems to work
Saving/Loading factions
No errors thrown when saving/loading game at the start
Scroll all the way down when something is post()ed
Tasks TODO: Tasks TODO:
Scroll all the way down when something is post()ed
Script logging functionality? Logs to internal "log file" (property of script itself) Script logging functionality? Logs to internal "log file" (property of script itself)
Tutorial and help Tutorial and help
Secret Servers Secret Servers

@ -8,17 +8,22 @@ function Faction(name) {
this.playerReputation = 0; //"Reputation" within faction this.playerReputation = 0; //"Reputation" within faction
}; };
//TODO
Faction.prototype.init = function() {
}
Faction.prototype.setAugmentations = function(augs) { Faction.prototype.setAugmentations = function(augs) {
for (var i = 0; i < augs.length; i++) { for (var i = 0; i < augs.length; i++) {
this.augmentations.push(augs[i]); this.augmentations.push(augs[i]);
} }
} }
Faction.prototype.toJSON = function() {
return Generic_toJSON("Faction", this);
}
Faction.fromJSON = function(value) {
return Generic_fromJSON(Faction, value.data);
}
Reviver.constructors.Faction = Faction;
//Map of factions indexed by faction name //Map of factions indexed by faction name
Factions = {} Factions = {}

@ -1,18 +1,25 @@
//Terminal //Terminal
/* Write text to terminal */
var post = function(input) { var post = function(input) {
$("#terminal-input").before('<tr class="posted"><td style="color: #66ff33;">' + input.replace( / /g, "&nbsp;" ) + '</td></tr>'); $("#terminal-input").before('<tr class="posted"><td style="color: #66ff33;">' + input.replace( / /g, "&nbsp;" ) + '</td></tr>');
window.scrollTo(0, document.body.scrollHeight); updateTerminalScroll();
} }
//Same thing as post but the td cells have ids so they can be animated for the hack progress bar //Same thing as post but the td cells have ids so they can be animated for the hack progress bar
var hackProgressBarPost = function(input) { var hackProgressBarPost = function(input) {
$("#terminal-input").before('<tr class="posted"><td id="hack-progress-bar" style="color: #66ff33;">' + input + '</td></tr>'); $("#terminal-input").before('<tr class="posted"><td id="hack-progress-bar" style="color: #66ff33;">' + input + '</td></tr>');
window.scrollTo(0, document.body.scrollHeight); updateTerminalScroll();
} }
var hackProgressPost = function(input) { var hackProgressPost = function(input) {
$("#terminal-input").before('<tr class="posted"><td id="hack-progress" style="color: #66ff33;">' + input + '</td></tr>'); $("#terminal-input").before('<tr class="posted"><td id="hack-progress" style="color: #66ff33;">' + input + '</td></tr>');
window.scrollTo(0, document.body.scrollHeight); updateTerminalScroll();
}
function updateTerminalScroll() {
var element = document.getElementById("terminal-container");
element.scrollTop = element.scrollHeight;
} }
var postNetburnerText = function() { var postNetburnerText = function() {

@ -55,11 +55,13 @@ var Engine = {
var PlayerSave = JSON.stringify(Player); var PlayerSave = JSON.stringify(Player);
var AllServersSave = JSON.stringify(AllServers); var AllServersSave = JSON.stringify(AllServers);
var CompaniesSave = JSON.stringify(Companies); var CompaniesSave = JSON.stringify(Companies);
var FactionsSave = JSON.stringify(Factions);
//TODO Add factions + companies here when they're done //TODO Add factions + companies here when they're done
window.localStorage.setItem("netburnerPlayerSave", PlayerSave); window.localStorage.setItem("netburnerPlayerSave", PlayerSave);
window.localStorage.setItem("netburnerAllServersSave", AllServersSave); window.localStorage.setItem("netburnerAllServersSave", AllServersSave);
window.localStorage.setItem("netburnerCompaniesSave", CompaniesSave); window.localStorage.setItem("netburnerCompaniesSave", CompaniesSave);
window.localStorage.setItem("netburnerFactionsSave", FactionsSave);
console.log("Game saved to local storage"); console.log("Game saved to local storage");
}, },
@ -75,19 +77,26 @@ var Engine = {
} else if (!window.localStorage.getItem("netburnerCompaniesSave")) { } else if (!window.localStorage.getItem("netburnerCompaniesSave")) {
console.log("No Companies save to load"); console.log("No Companies save to load");
return false; return false;
} else if (!window.localStorage.getItem("netburnerFactionsSave")) {
console.log("No Factions save to load");
return false;
} else { } else {
var PlayerSave = window.localStorage.getItem("netburnerPlayerSave"); var PlayerSave = window.localStorage.getItem("netburnerPlayerSave");
var AllServersSave = window.localStorage.getItem("netburnerAllServersSave"); var AllServersSave = window.localStorage.getItem("netburnerAllServersSave");
var CompaniesSave = window.localStorage.getItem("netburnerCompaniesSave"); var CompaniesSave = window.localStorage.getItem("netburnerCompaniesSave");
var FactionsSave = window.localStorage.getItem("netburnerFactionsSave");
Player = JSON.parse(PlayerSave, Reviver); Player = JSON.parse(PlayerSave, Reviver);
AllServers = JSON.parse(AllServersSave, Reviver); AllServers = JSON.parse(AllServersSave, Reviver);
Companies = JSON.parse(CompaniesSave, Reviver); Companies = JSON.parse(CompaniesSave, Reviver);
Factions = JSON.parse(FactionsSave, Reviver);
return true; return true;
} }
}, },
//Delete saved game function //Delete saved game function
deleteSave: 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")) { if (!window.localStorage.getItem("netburnerPlayerSave")) {
console.log("No Player Save to delete"); console.log("No Player Save to delete");
return false; return false;
@ -97,10 +106,14 @@ var Engine = {
} else if (!window.localStorage.getItem("netburnerCompaniesSave")) { } else if (!window.localStorage.getItem("netburnerCompaniesSave")) {
console.log("No Companies Save to delete"); console.log("No Companies Save to delete");
return false; return false;
} else if (!window.localStorage.getItem("netburnerFactionsSave")) {
console.log("No Factions Save to delete");
return false;
} else { } else {
window.localStorage.removeItem("netburnerPlayerSave"); window.localStorage.removeItem("netburnerPlayerSave");
window.localStorage.removeItem("netburnerAllServersSave"); window.localStorage.removeItem("netburnerAllServersSave");
window.localStorage.removeItem("netburnerCompaniesSave"); window.localStorage.removeItem("netburnerCompaniesSave");
window.localStorage.removeItem("netburnerFactionsSave");
console.log("Deleted saves") console.log("Deleted saves")
return true; return true;
} }
@ -388,6 +401,7 @@ var Engine = {
initForeignServers(); initForeignServers();
CompanyPositions.init(); CompanyPositions.init();
initCompanies(); initCompanies();
initFactions();
} }
//Main menu buttons and content //Main menu buttons and content