[refactor] Breaking out page tracking from 'engine'

This commit is contained in:
Steven Evans 2018-07-19 21:51:18 -04:00
parent 56da0f9214
commit 26b0840f26
13 changed files with 219 additions and 94 deletions

@ -1,4 +1,3 @@
import {Engine} from "./engine";
import {workerScripts,
addWorkerScript,
killWorkerScript} from "./NetscriptWorker";
@ -14,6 +13,7 @@ import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {removeElement} from "../utils/uiHelpers/removeElement";
import {Page, routing} from "./ui/navigationTracking";
/* {
* serverName: {
@ -196,7 +196,7 @@ function updateActiveScriptsItems(maxTasks=150) {
}
}
if (Engine.currentPage !== Engine.Page.ActiveScripts) {return;}
if (!routing.isOn(Page.ActiveScripts)) {return;}
var total = 0;
for (var i = 0; i < workerScripts.length; ++i) {
try {

@ -20,6 +20,7 @@ import {appendLineBreaks} from "../utils/uiHelpers/app
import {clearObject} from "../utils/helpers/clearObject";
import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import {Page, routing} from "./ui/navigationTracking";
import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {formatNumber} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt";
@ -145,7 +146,7 @@ var consoleHelpText = {
//Keypresses for Console
$(document).keydown(function(event) {
if (Engine.currentPage === Engine.Page.Bladeburner) {
if (routing.isOn(Page.Bladeburner)) {
//if (DomElems.consoleInput && !event.ctrlKey && !event.shiftKey && !event.altKey) {
// DomElems.consoleInput.focus();
//}
@ -915,7 +916,7 @@ Bladeburner.prototype.process = function() {
}
}
if (Engine.currentPage === Engine.Page.Bladeburner) {
if (routing.isOn(Page.Bladeburner)) {
this.updateContent();
}
}
@ -1257,7 +1258,7 @@ Bladeburner.prototype.completeAction = function() {
return hackWorldDaemon(Player.bitNodeN);
}
if (Engine.currentPage === Engine.Page.Bladeburner) {
if (routing.isOn(Page.Bladeburner)) {
this.createActionAndSkillsContent();
}
@ -2201,7 +2202,7 @@ Bladeburner.prototype.updateContent = function() {
}
Bladeburner.prototype.updateOverviewContent = function() {
if (Engine.currentPage !== Engine.Page.Bladeburner) {return;}
if (!routing.isOn(Page.Bladeburner)) {return;}
DomElems.overviewRank.childNodes[0].nodeValue = "Rank: " + formatNumber(this.rank, 2);
DomElems.overviewStamina.innerText = "Stamina: " + formatNumber(this.stamina, 3) + " / " + formatNumber(this.maxStamina, 3);
DomElems.overviewGen1.innerHTML =
@ -3505,7 +3506,7 @@ Bladeburner.prototype.upgradeSkillNetscriptFn = function(skillName, workerScript
this.skillPoints -= cost;
this.upgradeSkill(skill);
if (Engine.currentPage === Engine.Page.Bladeburner && DomElems.currentTab.toLowerCase() === "skills") {
if (routing.isOn(Page.Bladeburner) && DomElems.currentTab.toLowerCase() === "skills") {
this.createActionAndSkillsContent();
}
if (workerScript.shouldLog("upgradeSkill")) {
@ -3627,7 +3628,7 @@ Bladeburner.prototype.joinBladeburnerFactionNetscriptFn = function(workerScript)
if (workerScript.shouldLog("joinBladeburnerFaction")) {
workerScript.log("Joined Bladeburners Faction");
}
if (Engine.currentPage === Engine.Page.Bladeburner) {
if (routing.isOn(Page.Bladeburner)) {
removeChildrenFromElement(DomElems.overviewDiv);
this.createOverviewContent();
}

@ -1,5 +1,4 @@
import {BitNodeMultipliers} from "./BitNode";
import {Engine} from "./engine";
import {Factions} from "./Faction";
import {showLiterature} from "./Literature";
import {Locations} from "./Location";
@ -13,6 +12,7 @@ import {Reviver, Generic_toJSON,
import numeral from "numeral/min/numeral.min";
import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import {Page, routing} from "./ui/navigationTracking";
import {formatNumber, generateRandomString} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt";
import {isString} from "../utils/helpers/isString";
@ -3118,7 +3118,7 @@ Corporation.prototype.process = function() {
this.state.nextState();
if (Engine.currentPage === Engine.Page.Corporation) {this.updateUIContent();}
if (routing.isOn(Page.Corporation)) {this.updateUIContent();}
}
}

@ -9,6 +9,7 @@ import {HackingMission, setInMission} from "./Missions";
import {Player} from "./Player";
import {Settings} from "./Settings";
import {Page, routing} from "./ui/navigationTracking";
import {dialogBoxCreate} from "../utils/DialogBox";
import {factionInvitationBoxCreate} from "../utils/FactionInvitationBox";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
@ -137,7 +138,7 @@ function inviteToFaction(faction) {
if (Settings.SuppressFactionInvites) {
faction.alreadyInvited = true;
Player.factionInvitations.push(faction.name);
if (Engine.currentPage === Engine.Page.Factions) {
if (routing.isOn(Page.Factions)) {
Engine.loadFactionsContent();
}
} else {

@ -9,6 +9,7 @@ import {Reviver, Generic_toJSON,
import {createAccordionElement} from "../utils/uiHelpers/createAccordionElement";
import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import {Page, routing} from "./ui/navigationTracking";
import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt";
@ -24,7 +25,7 @@ import {yesNoBoxCreate, yesNoTxtInpBoxCreate,
/* Gang.js */
//Switch between territory and management screen with 1 and 2
$(document).keydown(function(event) {
if (Engine.currentPage == Engine.Page.Gang && !yesNoBoxOpen) {
if (routing.isOn(Page.Gang) && !yesNoBoxOpen) {
if (gangMemberFilter != null && gangMemberFilter === document.activeElement) {return;}
if (event.keyCode === 49) {
if(gangTerritorySubpage.style.display === "block") {

@ -9,6 +9,7 @@ import {clearEventListeners} from "../utils/uiHelpers/clearEv
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";
import {createElement} from "../utils/uiHelpers/createElement";
import {Page, routing} from "./ui/navigationTracking";
import {formatNumber} from "../utils/StringHelperFunctions";
import {getElementById} from "../utils/uiHelpers/getElementById";
@ -273,7 +274,7 @@ function purchaseHacknet() {
Player.loseMoney(cost);
Player.hacknetNodes.push(node);
if (Engine.currentPage === Engine.Page.HacknetNodes) {
if (routing.isOn(Page.HacknetNodes)) {
displayHacknetNodesContent();
}
updateTotalHacknetProduction();

@ -13,7 +13,6 @@ import {Companies, Company, CompanyPosition,
import {CONSTANTS} from "./Constants";
import {Programs} from "./CreateProgram";
import {DarkWebItems} from "./DarkWeb";
import {Engine} from "./engine";
import {AllGangs} from "./Gang";
import {Factions, Faction, joinFaction,
factionExists, purchaseAugmentation} from "./Faction";
@ -50,6 +49,7 @@ import {makeRuntimeRejectMsg, netscriptDelay, runScriptFromScript,
import {NetscriptPort} from "./NetscriptPort";
import Decimal from "decimal.js";
import {Page, routing} from "./ui/navigationTracking";
import {dialogBoxCreate} from "../utils/DialogBox";
import {isPowerOfTwo} from "../utils/helpers/isPowerOfTwo";
import {arrayToString} from "../utils/helpers/arrayToString";
@ -1415,7 +1415,7 @@ function NetscriptFunctions(workerScript) {
var newTotal = origTotal + totalPrice;
stock.playerShares += shares;
stock.playerAvgPx = newTotal / stock.playerShares;
if (Engine.currentPage == Engine.Page.StockMarket) {
if (routing.isOn(Page.StockMarket)) {
updateStockPlayerPosition(stock);
}
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.buyStock == null) {
@ -1456,7 +1456,7 @@ function NetscriptFunctions(workerScript) {
if (stock.playerShares == 0) {
stock.playerAvgPx = 0;
}
if (Engine.currentPage == Engine.Page.StockMarket) {
if (routing.isOn(Page.StockMarket)) {
updateStockPlayerPosition(stock);
}
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.sellStock == null) {

@ -33,6 +33,7 @@ import {post} from "./ui/postToTerminal";
import {TextFile} from "./TextFile";
import {parse, Node} from "../utils/acorn";
import {Page, routing} from "./ui/navigationTracking";
import {dialogBoxCreate} from "../utils/DialogBox";
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";
@ -260,7 +261,7 @@ function updateScriptEditorContent() {
//Define key commands in script editor (ctrl o to save + close, etc.)
$(document).keydown(function(e) {
if (Settings.DisableHotkeys === true) {return;}
if (Engine.currentPage == Engine.Page.ScriptEditor) {
if (routing.isOn(Page.ScriptEditor)) {
//Ctrl + b
if (e.keyCode == 66 && (e.ctrlKey || e.metaKey)) {
e.preventDefault();
@ -364,7 +365,7 @@ function Script() {
//Get the script data from the Script Editor and save it to the object
Script.prototype.saveScript = function() {
if (Engine.currentPage == Engine.Page.ScriptEditor) {
if (routing.isOn(Page.ScriptEditor)) {
//Update code and filename
var editor = ace.edit('javascript-editor');
var code = editor.getValue();

@ -1,5 +1,4 @@
import {CONSTANTS} from "./Constants";
import {Engine} from "./engine";
import {Locations} from "./Location";
import {hasWallStreetSF, wallStreetSFLvl} from "./NetscriptFunctions";
import {WorkerScript} from "./NetscriptWorker";
@ -9,6 +8,7 @@ import {dialogBoxCreate} from "../utils/DialogBox";
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";
import {Page, routing} from "./ui/navigationTracking";
import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt";
@ -593,7 +593,7 @@ function updateStockPrices() {
processOrders(stock, OrderTypes.LimitSell, PositionTypes.Long);
processOrders(stock, OrderTypes.StopBuy, PositionTypes.Long);
processOrders(stock, OrderTypes.StopSell, PositionTypes.Short);
if (Engine.currentPage == Engine.Page.StockMarket) {
if (routing.isOn(Page.StockMarket)) {
updateStockTicker(stock, true);
}
} else {
@ -602,7 +602,7 @@ function updateStockPrices() {
processOrders(stock, OrderTypes.LimitSell, PositionTypes.Short);
processOrders(stock, OrderTypes.StopBuy, PositionTypes.Short);
processOrders(stock, OrderTypes.StopSell, PositionTypes.Long);
if (Engine.currentPage == Engine.Page.StockMarket) {
if (routing.isOn(Page.StockMarket)) {
updateStockTicker(stock, false);
}
}
@ -1182,7 +1182,7 @@ function setStockTickerClickHandlers() {
//'increase' argument is a boolean indicating whether the price increased or decreased
function updateStockTicker(stock, increase) {
if (Engine.currentPage !== Engine.Page.StockMarket) {return;}
if (!routing.isOn(Page.StockMarket)) {return;}
if (!(stock instanceof Stock)) {
console.log("Invalid stock in updateStockTicker():");
console.log(stock);
@ -1207,7 +1207,7 @@ function updateStockTicker(stock, increase) {
}
function updateStockPlayerPosition(stock) {
if (Engine.currentPage !== Engine.Page.StockMarket) {return;}
if (!routing.isOn(Page.StockMarket)) {return;}
if (!(stock instanceof Stock)) {
console.log("Invalid stock in updateStockPlayerPosition():");
console.log(stock);
@ -1277,7 +1277,7 @@ function updateStockPlayerPosition(stock) {
}
function updateStockOrderList(stock) {
if (Engine.currentPage !== Engine.Page.StockMarket) {return;}
if (!routing.isOn(Page.StockMarket)) {return;}
var tickerId = "stock-market-ticker-" + stock.symbol;
var orderList = document.getElementById(tickerId + "-order-list");
if (orderList == null) {

@ -35,6 +35,7 @@ import {TextFile, getTextFile} from "./TextFile";
import {containsAllStrings, longestCommonStart,
formatNumber} from "../utils/StringHelperFunctions";
import {Page, routing} from "./ui/navigationTracking";
import {KEY} from "../utils/helpers/keyCodes";
import {addOffset} from "../utils/helpers/addOffset";
import {isString} from "../utils/helpers/isString";
@ -57,7 +58,7 @@ function postNetburnerText() {
//Defines key commands in terminal
$(document).keydown(function(event) {
//Terminal
if (Engine.currentPage == Engine.Page.Terminal) {
if (routing.isOn(Page.Terminal)) {
var terminalInput = document.getElementById("terminal-input-text-box");
if (terminalInput != null && !event.ctrlKey && !event.shiftKey) {terminalInput.focus();}
@ -228,13 +229,13 @@ $(document).keydown(function(event) {
//Keep terminal in focus
let terminalCtrlPressed = false, shiftKeyPressed = false;
$(document).ready(function() {
if (Engine.currentPage === Engine.Page.Terminal) {
if (routing.isOn(Page.Terminal)) {
$('.terminal-input').focus();
}
});
$(document).keydown(function(e) {
if (Engine.currentPage == Engine.Page.Terminal) {
if (e.which == 17) {
if (routing.isOn(Page.Terminal)) {
if (e.which == KEY.CTRL) {
terminalCtrlPressed = true;
} else if (e.shiftKey) {
shiftKeyPressed = true;
@ -250,8 +251,8 @@ $(document).keydown(function(e) {
}
})
$(document).keyup(function(e) {
if (Engine.currentPage == Engine.Page.Terminal) {
if (e.which == 17) {
if (routing.isOn(Page.Terminal)) {
if (e.which == KEY.CTRL) {
terminalCtrlPressed = false;
}
if (e.shiftKey) {

@ -65,6 +65,7 @@ import {StockMarket, StockSymbols,
displayStockMarketContent} from "./StockMarket";
import {Terminal, postNetburnerText} from "./Terminal";
import {KEY} from "../utils/helpers/keyCodes";
import {Page, routing} from "./ui/navigationTracking";
// These should really be imported with the module that is presenting that UI, but because they very much depend on the
// cascade order, we'll pull them all in here.
@ -126,7 +127,7 @@ $(document).keydown(function(e) {
Engine.loadCreateProgramContent();
} else if (e.keyCode === KEY.F && e.altKey) {
//Overriden by Fconf
if (Engine.currentPage === Engine.Page.Terminal && FconfSettings.ENABLE_BASH_HOTKEYS) {
if (routing.isOn(Page.Terminal) && FconfSettings.ENABLE_BASH_HOTKEYS) {
return;
}
e.preventDefault();
@ -255,44 +256,15 @@ let Engine = {
characterInfo: null,
},
//Current page status
Page: {
Terminal: "Terminal",
CharacterInfo: "CharacterInfo",
ScriptEditor: "ScriptEditor",
ActiveScripts: "ActiveScripts",
HacknetNodes: "HacknetNodes",
World: "World",
CreateProgram: "CreateProgram",
Factions: "Factions",
Faction: "Faction",
Augmentations: "Augmentations",
Tutorial: "Tutorial",
DevMenu: "Dev Menu",
Location: "Location",
workInProgress: "WorkInProgress",
RedPill: "RedPill",
CinematicText: "CinematicText",
Infiltration: "Infiltration",
StockMarket: "StockMarket",
Gang: "Gang",
Mission: "Mission",
Corporation: "Corporation",
Bladeburner: "Bladeburner",
},
currentPage: null,
//Time variables (milliseconds unix epoch time)
_lastUpdate: new Date().getTime(),
_idleSpeed: 200, //Speed (in ms) at which the main loop is updated
/* Load content when a main menu button is clicked */
loadTerminalContent: function() {
Engine.hideAllContent();
Engine.Display.terminalContent.style.display = "block";
Engine.currentPage = Engine.Page.Terminal;
routing.navigateTo(Page.Terminal);
document.getElementById("terminal-menu-link").classList.add("active");
},
@ -300,7 +272,7 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.characterContent.style.display = "block";
Engine.displayCharacterInfo();
Engine.currentPage = Engine.Page.CharacterInfo;
routing.navigateTo(Page.CharacterInfo);
document.getElementById("stats-menu-link").classList.add("active");
},
@ -314,7 +286,7 @@ let Engine = {
}
editor.focus();
updateScriptEditorContent();
Engine.currentPage = Engine.Page.ScriptEditor;
routing.navigateTo(Page.ScriptEditor);
document.getElementById("create-script-menu-link").classList.add("active");
},
@ -322,7 +294,7 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.activeScriptsContent.style.display = "block";
updateActiveScriptsItems();
Engine.currentPage = Engine.Page.ActiveScripts;
routing.navigateTo(Page.ActiveScripts);
document.getElementById("active-scripts-menu-link").classList.add("active");
},
@ -330,7 +302,7 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.hacknetNodesContent.style.display = "block";
displayHacknetNodesContent();
Engine.currentPage = Engine.Page.HacknetNodes;
routing.navigateTo(Page.HacknetNodes);
document.getElementById("hacknet-nodes-menu-link").classList.add("active");
},
@ -338,7 +310,7 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.worldContent.style.display = "block";
Engine.displayWorldInfo();
Engine.currentPage = Engine.Page.World;
routing.navigateTo(Page.World);
document.getElementById("city-menu-link").classList.add("active");
},
@ -346,7 +318,7 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.createProgramContent.style.display = "block";
displayCreateProgramContent();
Engine.currentPage = Engine.Page.CreateProgram;
routing.navigateTo(Page.CreateProgram);
document.getElementById("create-program-menu-link").classList.add("active");
},
@ -354,21 +326,21 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.factionsContent.style.display = "block";
Engine.displayFactionsInfo();
Engine.currentPage = Engine.Page.Factions;
routing.navigateTo(Page.Factions);
document.getElementById("factions-menu-link").classList.add("active");
},
loadFactionContent: function() {
Engine.hideAllContent();
Engine.Display.factionContent.style.display = "block";
Engine.currentPage = Engine.Page.Faction;
routing.navigateTo(Page.Faction);
},
loadAugmentationsContent: function() {
Engine.hideAllContent();
Engine.Display.augmentationsContent.style.display = "block";
displayAugmentationsContent();
Engine.currentPage = Engine.Page.Augmentations;
routing.navigateTo(Page.Augmentations);
document.getElementById("augmentations-menu-link").classList.add("active");
},
@ -376,7 +348,7 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.tutorialContent.style.display = "block";
Engine.displayTutorialContent();
Engine.currentPage = Engine.Page.Tutorial;
routing.navigateTo(Page.Tutorial);
document.getElementById("tutorial-menu-link").classList.add("active");
},
@ -384,7 +356,7 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.devMenuContent.style.display = "block";
Engine.displayDevMenuContent();
Engine.currentPage = Engine.Page.DevMenu;
routing.navigateTo(Page.DevMenu);
document.getElementById("dev-menu-link").classList.add("active");
},
@ -392,7 +364,7 @@ let Engine = {
Engine.hideAllContent();
Engine.Display.locationContent.style.display = "block";
displayLocationContent();
Engine.currentPage = Engine.Page.Location;
routing.navigateTo(Page.Location);
},
loadTravelContent: function() {
@ -438,7 +410,7 @@ let Engine = {
//mainMenu.style.visibility = "hidden";
mainMenu.style.visibility = "hidden";
Engine.Display.workInProgressContent.style.display = "block";
Engine.currentPage = Engine.Page.WorkInProgress;
routing.navigateTo(Page.WorkInProgress);
},
loadRedPillContent: function() {
@ -446,7 +418,7 @@ let Engine = {
var mainMenu = document.getElementById("mainmenu-container");
mainMenu.style.visibility = "hidden";
Engine.Display.redPillContent.style.display = "block";
Engine.currentPage = Engine.Page.RedPill;
routing.navigateTo(Page.RedPill);
},
loadCinematicTextContent: function() {
@ -454,19 +426,19 @@ let Engine = {
var mainMenu = document.getElementById("mainmenu-container");
mainMenu.style.visibility = "hidden";
Engine.Display.cinematicTextContent.style.display = "block";
Engine.currentPage = Engine.Page.CinematicText;
routing.navigateTo(Page.CinematicText);
},
loadInfiltrationContent: function() {
Engine.hideAllContent();
Engine.Display.infiltrationContent.style.display = "block";
Engine.currentPage = Engine.Page.Infiltration;
routing.navigateTo(Page.Infiltration);
},
loadStockMarketContent: function() {
Engine.hideAllContent();
Engine.Display.stockMarketContent.style.display = "block";
Engine.currentPage = Engine.Page.StockMarket;
routing.navigateTo(Page.StockMarket);
displayStockMarketContent();
},
@ -474,10 +446,10 @@ let Engine = {
Engine.hideAllContent();
if (document.getElementById("gang-container") || Player.inGang()) {
displayGangContent();
Engine.currentPage = Engine.Page.Gang;
routing.navigateTo(Page.Gang);
} else {
Engine.loadTerminalContent();
Engine.currentPage = Engine.Page.Terminal;
routing.navigateTo(Page.Terminal);
}
},
@ -486,7 +458,7 @@ let Engine = {
document.getElementById("mainmenu-container").style.visibility = "hidden";
document.getElementById("character-overview-wrapper").style.visibility = "hidden";
Engine.Display.missionContent.style.display = "block";
Engine.currentPage = Engine.Page.Mission;
routing.navigateTo(Page.Mission);
},
loadCorporationContent: function() {
@ -494,7 +466,7 @@ let Engine = {
Engine.hideAllContent();
document.getElementById("character-overview-wrapper").style.visibility = "hidden";
Player.corporation.createUI();
Engine.currentPage = Engine.Page.Corporation;
routing.navigateTo(Page.Corporation);
}
},
@ -502,7 +474,7 @@ let Engine = {
if (Player.bladeburner instanceof Bladeburner) {
try {
Engine.hideAllContent();
Engine.currentPage = Engine.Page.Bladeburner;
routing.navigateTo(Page.Bladeburner);
Player.bladeburner.createContent();
} catch(e) {
exceptionAlert(e);
@ -1073,7 +1045,7 @@ let Engine = {
if (Engine.Counters.updateActiveScriptsDisplay <= 0) {
//Always update, but make the interval longer if the page isn't active
updateActiveScriptsItems();
if (Engine.currentPage === Engine.Page.ActiveScripts) {
if (routing.isOn(Page.ActiveScripts)) {
Engine.Counters.updateActiveScriptsDisplay = 5;
} else {
Engine.Counters.updateActiveScriptsDisplay = 10;
@ -1082,11 +1054,11 @@ let Engine = {
if (Engine.Counters.updateDisplays <= 0) {
Engine.displayCharacterOverviewInfo();
if (Engine.currentPage == Engine.Page.CharacterInfo) {
if (routing.isOn(Page.CharacterInfo)) {
Engine.displayCharacterInfo();
} else if (Engine.currentPage == Engine.Page.HacknetNodes) {
} else if (routing.isOn(Page.HacknetNodes)) {
updateHacknetNodesContent();
} else if (Engine.currentPage == Engine.Page.CreateProgram) {
} else if (routing.isOn(Page.CreateProgram)) {
displayCreateProgramContent();
}
@ -1098,16 +1070,16 @@ let Engine = {
}
if (Engine.Counters.updateDisplaysMed <= 0) {
if (Engine.currentPage === Engine.Page.Corporation) {
if (routing.isOn(Page.Corporation)) {
Player.corporation.updateUIContent();
}
Engine.Counters.updateDisplaysMed = 9;
}
if (Engine.Counters.updateDisplaysLong <= 0) {
if (Engine.currentPage === Engine.Page.Gang) {
if (routing.isOn(Page.Gang)) {
updateGangContent();
} else if (Engine.currentPage === Engine.Page.ScriptEditor) {
} else if (routing.isOn(Page.ScriptEditor)) {
updateScriptEditorContent();
}
Engine.Counters.updateDisplaysLong = 15;
@ -1445,7 +1417,7 @@ let Engine = {
setDisplayElements: function() {
//Content elements
Engine.Display.terminalContent = document.getElementById("terminal-container");
Engine.currentPage = Engine.Page.Terminal;
routing.navigateTo(Page.Terminal);
Engine.Display.characterContent = document.getElementById("character-container");
Engine.Display.characterContent.style.display = "none";

@ -0,0 +1,146 @@
/**
* The full-screen page the player is currently be on.
* These pages are mutually exclusive.
*/
export enum Page {
/**
* (Default) The terminal is where the player issues all commands, executes scripts, etc.
*/
Terminal = "Terminal",
/**
* Displays most of the statistics about the player.
*/
CharacterInfo = "CharacterInfo",
/**
* The console for editing Netscript files.
*/
ScriptEditor = "ScriptEditor",
/**
* Monitor the scripts currently executing across the servers.
*/
ActiveScripts = "ActiveScripts",
/**
* View, purchase, and upgrade Hacknet nodes.
*/
HacknetNodes = "HacknetNodes",
/**
* View the city the player is currently in.
*/
World = "World",
/**
* The list of programs the player could potentially build.
*/
CreateProgram = "CreateProgram",
/**
* The list of all factions, and invites, available to the player.
*/
Factions = "Factions",
/**
* Information about a specific faction.
*/
Faction = "Faction",
/**
* The list of installed, and yet-to-be installed, augmentations the player has purchased.
*/
Augmentations = "Augmentations",
/**
* A collection of in-game material to learn about the game.
*/
Tutorial = "Tutorial",
/**
* A collection of items to manipulate the state of the game. Useful for development.
*/
DevMenu = "Dev Menu",
/**
* Information about the specific location the player at (job, company, etc.);
*/
Location = "Location",
/**
* A blocking page to show the player they are currently doing some action (building a program, working, etc.).
*/
workInProgress = "WorkInProgress",
/**
* A special screen to show the player they've reached a certain point in the game.
*/
RedPill = "RedPill",
/**
* A special screen to show the player they've reached a certain point in the game.
*/
CinematicText = "CinematicText",
/**
* Mini-game to infiltrate a company, gaining experience from successful progress.
*/
Infiltration = "Infiltration",
/**
* View the in-game stock market.
*/
StockMarket = "StockMarket",
/**
* Manage gang actions and members.
*/
Gang = "Gang",
/**
* Perform missions for a Faction.
*/
Mission = "Mission",
/**
* Manage a corporation.
*/
Corporation = "Corporation",
/**
* Manage special Bladeburner activities.
*/
Bladeburner = "Bladeburner",
}
/**
* This class keeps track of player navigation/routing within the game.
*/
class Routing {
/**
* Tracking the what page the user is currently on.
*/
private currentPage: Page | null = null;
/**
* Determines if the player is currently on the specified page.
* @param page The page to compare against the current state.
*/
isOn(page: Page) {
return this.currentPage === page;
}
/**
* Routes the player to the appropriate page.
* @param page The page to navigate to.
*/
navigateTo(page: Page) {
this.currentPage = page;
}
}
/**
* The routing instance for tracking page navigation.
*/
export const routing: Routing = new Routing();

@ -1,7 +1,8 @@
import {Faction, joinFaction} from "../src/Faction";
import {joinFaction} from "../src/Faction";
import {Engine} from "../src/engine";
import {Player} from "../src/Player";
import {clearEventListeners} from "./uiHelpers/clearEventListeners";
import {Page, routing} from "../src/ui/navigationTracking";
/* Faction Invitation Pop-up box */
function factionInvitationBoxClose() {
@ -30,7 +31,7 @@ function factionInvitationBoxCreate(faction) {
faction.alreadyInvited = true;
Player.factionInvitations.push(faction.name);
if (Engine.currentPage === Engine.Page.Factions) {
if (routing.isOn(Page.Factions)) {
Engine.loadFactionsContent();
}
@ -45,7 +46,7 @@ function factionInvitationBoxCreate(faction) {
}
joinFaction(faction);
factionInvitationBoxClose();
if (Engine.currentPage === Engine.Page.Factions) {
if (routing.isOn(Page.Factions)) {
Engine.loadFactionsContent();
}
return false;