diff --git a/css/interactivetutorial.css b/css/interactivetutorial.css new file mode 100644 index 000000000..4e2de6828 --- /dev/null +++ b/css/interactivetutorial.css @@ -0,0 +1,50 @@ +/* interactivetutorial.css */ +#interactive-tutorial-container { + display: none; + position: fixed; /* Stay in place */ + left: 0; + top: 0; + height: 100%; /* Full height */ + margin: 20% auto; + padding: 10px; + border: 5px solid #FFFFFF; + width: 40%; + overflow: auto; /* Enable scroll if needed */ + background-color: black; /* Fallback color */ + background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ +} + +#interactive-tutorial-text { + +} + +#interactive-tutorial-exit, +#interactive-tutorial-next { + color: #aaa; + font-size: 20px; + font-weight: bold; + -webkit-border-radius: 12px; + -moz-border-radius: 12px; + border-radius: 12px; + -moz-box-shadow: 1px 1px 3px #000; + -webkit-box-shadow: 1px 1px 3px #000; + box-shadow: 1px 1px 3px #000; +} + +#interactive-tutorial-exit { + float: left; +} + +#interactive-tutorial-next { + float: right; +} + +#interactive-tutorial-exit:hover, +#interactive-tutorial-exit:focus, +#interactive-tutorial-next:hover, +#interactive-tutorial-next:focus { + color: white; + text-decoration: none; + cursor: pointer; +} + diff --git a/css/popupboxes.css b/css/popupboxes.css index b3a6d15d4..5b6e6d1fe 100644 --- a/css/popupboxes.css +++ b/css/popupboxes.css @@ -16,7 +16,7 @@ #dialog-box-content { background-color: black; - margin: 20% auto; /* 15% from the top and centered */ + margin: 20% auto; /* 20% from the top and centered */ padding: 10px; border: 5px solid #FFFFFF; width: 40%; /* Could be more or less, depending on screen size */ diff --git a/index.html b/index.html index 0d3a402b8..1a4ccd4d1 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,7 @@ + @@ -655,5 +656,12 @@ Cancel Work + +
+

+ Exit tutorial + Continue +
+ \ No newline at end of file diff --git a/src/Faction.js b/src/Faction.js index ea82ad32f..86e781680 100644 --- a/src/Faction.js +++ b/src/Faction.js @@ -23,6 +23,12 @@ Faction.prototype.setInfo = function(inf) { this.info = inf; } +Faction.prototype.reset = function() { + this.isMember = false; + this.isBanned = false; + this.playerReputation = 0; +} + Faction.prototype.toJSON = function() { return Generic_toJSON("Faction", this); } @@ -730,8 +736,9 @@ displayFactionContent = function(factionName) { } displayFactionAugmentations = function(factionName) { - document.getElementById("faction-augmentations-page-desc").innerHTML = "Lists all augmentations that are available to purchase from" + factionName; + document.getElementById("faction-augmentations-page-desc").innerHTML = "Lists all augmentations that are available to purchase from " + factionName; var faction = Factions[factionName]; + console.log("fac augs: " + faction.augmentations); var augmentationsList = document.getElementById("faction-augmentations-list"); while (augmentationsList.firstChild) { @@ -739,6 +746,7 @@ displayFactionAugmentations = function(factionName) { } for (var i = 0; i < faction.augmentations.length; ++i) { + console.log("here"); (function () { var aug = Augmentations[faction.augmentations[i]]; var item = document.createElement("li"); diff --git a/src/InteractiveTutorial.js b/src/InteractiveTutorial.js new file mode 100644 index 000000000..391d287ce --- /dev/null +++ b/src/InteractiveTutorial.js @@ -0,0 +1,276 @@ +/* InteractiveTutorial.js */ +iTutorialSteps = { + Start: "Start", + GoToCharacterPage: "Click on the Character page menu link", + CharacterPage: "Introduction to Character page", + CharacterGoToTerminalPage: "Click on the Terminal link", + TerminalIntro: "Introduction to terminal interface", + TerminalHelp: "Using the help command to display all options in terminal", + TerminalLs: "Use the ls command to show all programs/scripts. Right now we have NUKE.exe", + TerminalScan: "Using the scan command to display all available connections", + TerminalConnect: "Using the telnet/connect command to connect to another server", + TerminalAnalyze: "Use the analyze command to display details about this server", + TerminalNuke: "Use the NUKE Program to gain root access to a server", + TerminalManualHack: "Use the hack command to manually hack a server", + TerminalCreateScript: "Create a script using nano", + TerminalTypeScript: "This occurs in the Script Editor page...type the script then save and close"," + TerminalRunScript: "Use the run command to run a script", + TerminalGoToActiveScriptsPage: "Go to the ActiveScriptsPage", + ActiveScriptsPage: "Introduction to the Active Scripts Page", + ActiveScriptsToTerminal: "Go from Active Scripts Page Back to Terminal", + TerminalTailScript: "Use the tail command to show a script's logs", + GoToHacknetNodesPage: "Go to the Hacknet Nodes page", + HacknetNodesIntroduction: "Introduction to Hacknet Nodes", + HacknetNodesPurchase: "Have the user purchase a Hacknet Node", + HacknetNodesGoToWorldPage: "Go to the world page", + WorldDescription: "Tell the user to explore..theres a lot of different stuff to do out there", + WorldGoToTutorialPage: "Go to the Tutorial Page", + TutorialPageInfo: "The tutorial page contains a lot of info on different subjects", + End: "End", +} + +var currITutorialStep = iTutorialSteps.Start; +var iTutorialIsRunning = false; + +function iTutorialStart() { + currITutorialStep = iTutorialSteps.Start; + iTutorialIsRunning = true; + + document.getElementById("interactive-tutorial-container").style.display = "block"; + + //Exit tutorial button + var exitButton = clearEventListeners("interactive-tutorial-exit"); + exitButton.addEventListener("click", function() { + iTutorialEnd(); + }); +} + +function iTutorialEvaluateStep() { + switch(currITutorialStep) { + case iTutorialSteps.Start: + iTutorialSetText("Welcome to Bitburner, a cyberpunk-themed incremental RPG!

" + + "This tutorial will show you the basics of the game to help you get started. " + + "You may skip the tutorial at any time"); + var next = clearEventListeners("interactive-tutorial-next"); + next.addEventListener("click", function() { + iTutorialNextStep(); + return false; + }); + break; + case iTutorialSteps.GoToCharacterPage: + iTutorialSetText("Let's start by heading to the Character page. Click the 'Character' tab on " + + "the main navigation menu (left-hand side of the screen)"); + + //No next button + var next = clearEventListeners("interactive-tutorial-next"); + next.style.display = "none"; + + //Initialize everything necessary to open the "Character" page + Engine.Clickables.characterMainMenuButton = document.getElementById("character-menu-link"); + Engine.Clickables.characterMainMenuButton.addEventListener("click", function() { + Engine.loadCharacterContent(); + iTutorialNextStep(); //Opening the character page will go to the next step + return false; + }); + break; + case iTutorialSteps.CharacterPage: + iTutorialSetText("The Character page shows a lot of important information about your progress, " + + "such as your stats, skills, money, and bonuses/multipliers. ") + var next = clearEventListeners("interactive-tutorial-next"); + next.style.display = "inline-block"; + next.addEventListener("click", function() { + iTutorialNextStep(); + return false; + }); + break; + case iTutorialSteps.CharacterGoToTerminalPage: + iTutorialSetText("Let's head to your computer's terminal by clicking the 'Terminal' tab on the " + + "main navigation menu"); + //No next button + var next = clearEventListeners("interactive-tutorial-next"); + next.style.display = "none"; + + //Initialize everything necessary to open the 'Terminal' Page + Engine.Clickables.terminalMainMenuButton = document.getElementById("terminal-menu-link"); + Engine.Clickables.terminalMainMenuButton.addEventListener("click", function() { + Engine.loadTerminalContent(); + iTutorialNextStep(); + return false; + }); + break; + case iTutorialSteps.TerminalIntro: + break; + case iTutorialSteps.TerminalHelp: + break; + case iTutorialSteps.TerminalLs: + break; + case iTutorialSteps.TerminalScan: + break; + case iTutorialSteps.TerminalConnect: + break; + case iTutorialSteps.TerminalAnalyze: + break; + case iTutorialSteps.TerminalNuke: + break; + case iTutorialSteps.TerminalManualHack: + break; + case iTutorialSteps.TerminalCreateScript: + break; + case iTutorialSteps.TerminalTypeScript: + break; + case iTutorialSteps.TerminalRunScript: + break; + case iTutorialSteps.TerminalGoToActiveScriptsPage: + break; + case iTutorialSteps.ActiveScriptsPage: + break; + case iTutorialSteps.ActiveScriptsToTerminal: + break; + case iTutorialSteps.TerminalTailScript: + break; + case iTutorialSteps.GoToHacknetNodesPage: + break; + case iTutorialSteps.HacknetNodesIntroduction: + break; + case iTutorialSteps.HacknetNodesPurchase: + break; + case iTutorialSteps.HacknetNodesGoToWorldPage: + break; + case iTutorialSteps.WorldDescription: + break; + case iTutorialSteps.WorldGoToTutorialPage: + break; + case iTutorialSteps.TutorialPageInfo: + break; + case iTutorialSteps.End: + break; + default: + throw new Error("Invalid tutorial step"); + } +} + +//Go to the next step and evaluate it +function iTutorialNextStep() { + switch(currITutorialStep) { + case iTutorialSteps.Start: + currITutorialStep = iTutorialSteps.GoToCharacterPage; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.GoToCharacterPage: + currITutorialStep = iTutorialSteps.CharacterPage; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.CharacterPage: + currITutorialStep = iTutorialSteps.CharacterGoToTerminalPage; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.CharacterGoToTerminalPage: + currITutorialStep = iTutorialSteps.TerminalIntro; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalIntro: + currITutorialStep = iTutorialSteps.TerminalHelp; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalHelp: + currITutorialStep = iTutorialSteps.TerminalLs; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalLs: + currITutorialStep = iTutorialSteps.TerminalScan; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalScan: + currITutorialStep = iTutorialSteps.TerminalConnect; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalConnect: + currITutorialStep = iTutorialSteps.TerminalAnalyze; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalAnalyze: + currITutorialStep = iTutorialSteps.TerminalNuke; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalNuke: + currITutorialStep = iTutorialSteps.TerminalManualHack; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalManualHack: + currITutorialStep = iTutorialSteps.TerminalCreateScript; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalCreateScript: + currITutorialStep = iTutorialSteps.TerminalTypeScript; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalTypeScript: + currITutorialStep = iTutorialSteps.TerminalRunScript; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalRunScript: + currITutorialStep = iTutorialSteps.TerminalGoToActiveScriptsPage; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalGoToActiveScriptsPage: + currITutorialStep = iTutorialSteps.ActiveScriptsPage; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.ActiveScriptsPage: + currITutorialStep = iTutorialSteps.ActiveScriptsToTerminal; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.ActiveScriptsToTerminal: + currITutorialStep = iTutorialSteps.TerminalTailScript; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TerminalTailScript: + currITutorialStep = iTutorialSteps.GoToHacknetNodesPage; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.GoToHacknetNodesPage: + currITutorialStep = iTutorialSteps.HacknetNodesIntroduction; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.HacknetNodesIntroduction: + currITutorialStep = iTutorialSteps.HacknetNodesPurchase; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.HacknetNodesPurchase: + currITutorialStep = iTutorialSteps.HacknetNodesGoToWorldPage; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.HacknetNodesGoToWorldPage: + currITutorialStep = iTutorialSteps.WorldDescription; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.WorldDescription: + currITutorialStep = iTutorialSteps.WorldGoToTutorialPage; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.WorldGoToTutorialPage: + currITutorialStep = iTutorialSteps.TutorialPageInfo; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.TutorialPageInfo: + currITutorialStep = iTutorialSteps.End; + iTutorialEvaluateStep(); + break; + case iTutorialSteps.End: + break; + default: + throw new Error("Invalid tutorial step"); + } +} + +function iTutorialEnd() { + currITutorialStep = iTutorialSteps.End; + iTutorialIsRunning = false; +} + +function iTutorialSetText(txt) { + var textBox = document.getElementById("interactive-tutorial-text"); + if (textBox == null) {throw new Error("Could not find text box"); return;} + textBox.innerHTML = txt; + +} \ No newline at end of file diff --git a/src/Prestige.js b/src/Prestige.js index 7b56d2e12..8c9911fd1 100644 --- a/src/Prestige.js +++ b/src/Prestige.js @@ -133,19 +133,17 @@ function prestigeAugmentation() { } Companies = {}; - //Delete Factions + //Reset Factions for (var member in Factions) { - delete Factions[member]; + Factions[member].reset(); } - Factions = {}; //Inititialization SpecialServerIps = new SpecialServerIpsMap(); Player.init(); initForeignServers(); initCompanies(); - initFactions(); - CompanyPositions.init(); + //CompanyPositions.init(); Dont think this is needed Engine.loadTerminalContent(); } \ No newline at end of file diff --git a/src/engine.js b/src/engine.js index 1b7bb393d..c45844671 100644 --- a/src/engine.js +++ b/src/engine.js @@ -670,6 +670,120 @@ var Engine = { } }, + load: function() { + //Load game from save or create new game + if (loadGame(saveObject)) { + console.log("Loaded game from save"); + Engine.setDisplayElements(); //Sets variables for important DOM elements + Engine.init(); //Initialize main game loop, buttons, etc. + CompanyPositions.init(); + + //Calculate the number of cycles have elapsed while offline + var thisUpdate = new Date().getTime(); + var lastUpdate = Player.lastUpdate; + var numCyclesOffline = Math.floor((thisUpdate - lastUpdate) / Engine._idleSpeed); + + /* Process offline progress */ + processServerGrowth(numCyclesOffline); //Should be done before offline production for scripts + loadAllRunningScripts(); //This also takes care of offline production for those scripts + if (Player.isWorking) { + if (Player.workType == CONSTANTS.WorkTypeFaction) { + Player.workForFaction(numCyclesOffline); + } else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) { + Player.createProgramWork(numCyclesOffline); + } else if (Player.workType == CONSTANTS.WorkTypeStudyClass) { + Player.takeClass(numCyclesOffline); + } else { + Player.work(numCyclesOffline); + } + } + + //Hacknet Nodes offline progress + processAllHacknetNodeEarnings(numCyclesOffline); + + //Passive faction rep gain offline + processPassiveFactionRepGain(numCyclesOffline); + } else { + //No save found, start new game + console.log("Initializing new game"); + Engine.setDisplayElements(); //Sets variables for important DOM elements + SpecialServerIps = new SpecialServerIpsMap(); + Player.init(); + initForeignServers(); + initCompanies(); + initFactions(); + CompanyPositions.init(); + initAugmentations(); + + //Start tutorial + } + }, + + setDisplayElements: function() { + //Content elements + Engine.Display.terminalContent = document.getElementById("terminal-container"); + Engine.currentPage = Engine.Page.Terminal; + + Engine.Display.characterContent = document.getElementById("character-container"); + Engine.Display.characterContent.style.visibility = "hidden"; + + Engine.Display.scriptEditorContent = document.getElementById("script-editor-container"); + Engine.Display.scriptEditorContent.style.visibility = "hidden"; + + Engine.Display.activeScriptsContent = document.getElementById("active-scripts-container"); + Engine.Display.activeScriptsContent.style.visibility = "hidden"; + + Engine.Display.hacknetNodesContent = document.getElementById("hacknet-nodes-container"); + Engine.Display.hacknetNodesContent.style.visibility = "hidden"; + + Engine.Display.worldContent = document.getElementById("world-container"); + Engine.Display.worldContent.style.visibility = "hidden"; + + Engine.Display.createProgramContent = document.getElementById("create-program-container"); + Engine.Display.createProgramContent.style.visibility = "hidden"; + + Engine.Display.factionsContent = document.getElementById("factions-container"); + Engine.Display.factionsContent.style.visibility = "hidden"; + + + Engine.Display.factionContent = document.getElementById("faction-container"); + Engine.Display.factionContent.style.visibility = "hidden"; + + Engine.Display.factionAugmentationsContent = document.getElementById("faction-augmentations-container"); + Engine.Display.factionAugmentationsContent.style.visibility = "hidden"; + + Engine.Display.augmentationsContent = document.getElementById("augmentations-container"); + Engine.Display.augmentationsContent.style.visibility = "hidden"; + + Engine.Display.tutorialContent = document.getElementById("tutorial-container"); + Engine.Display.tutorialContent.style.visibility = "hidden"; + + //Character info + Engine.Display.characterInfo = document.getElementById("character-info"); + + //Location lists + Engine.aevumLocationsList = document.getElementById("aevum-locations-list"); + Engine.chongqingLocationsList = document.getElementById("chongqing-locations-list"); + Engine.sector12LocationsList = document.getElementById("sector12-locations-list"); + Engine.newTokyoLocationsList = document.getElementById("newtokyo-locations-list"); + Engine.ishimaLocationsList = document.getElementById("ishima-locations-list"); + Engine.volhavenLocationsList = document.getElementById("volhaven-locations-list"); + + //Location page (page that shows up when you visit a specific location in World) + Engine.Display.locationContent = document.getElementById("location-container"); + Engine.Display.locationContent.style.visibility = "hidden"; + + //Work In Progress + Engine.Display.workInProgressContent = document.getElementById("work-in-progress-container"); + Engine.Display.workInProgressContent.style.visibility = "hidden"; + + //Init Location buttons + initLocationButtons(); + + //Script editor + Engine.Display.scriptEditorText = document.getElementById("script-editor-text"); + } + /* Initialization */ init: function() { //Main menu buttons and content @@ -795,48 +909,6 @@ var Engine = { Engine.displayTutorialContent(); }); - - //Content elements - Engine.Display.terminalContent = document.getElementById("terminal-container"); - Engine.currentPage = Engine.Page.Terminal; - - Engine.Display.characterContent = document.getElementById("character-container"); - Engine.Display.characterContent.style.visibility = "hidden"; - - Engine.Display.scriptEditorContent = document.getElementById("script-editor-container"); - Engine.Display.scriptEditorContent.style.visibility = "hidden"; - - Engine.Display.activeScriptsContent = document.getElementById("active-scripts-container"); - Engine.Display.activeScriptsContent.style.visibility = "hidden"; - - Engine.Display.hacknetNodesContent = document.getElementById("hacknet-nodes-container"); - Engine.Display.hacknetNodesContent.style.visibility = "hidden"; - - Engine.Display.worldContent = document.getElementById("world-container"); - Engine.Display.worldContent.style.visibility = "hidden"; - - Engine.Display.createProgramContent = document.getElementById("create-program-container"); - Engine.Display.createProgramContent.style.visibility = "hidden"; - - Engine.Display.factionsContent = document.getElementById("factions-container"); - Engine.Display.factionsContent.style.visibility = "hidden"; - - - Engine.Display.factionContent = document.getElementById("faction-container"); - Engine.Display.factionContent.style.visibility = "hidden"; - - Engine.Display.factionAugmentationsContent = document.getElementById("faction-augmentations-container"); - Engine.Display.factionAugmentationsContent.style.visibility = "hidden"; - - Engine.Display.augmentationsContent = document.getElementById("augmentations-container"); - Engine.Display.augmentationsContent.style.visibility = "hidden"; - - Engine.Display.tutorialContent = document.getElementById("tutorial-container"); - Engine.Display.tutorialContent.style.visibility = "hidden"; - - //Character info - Engine.Display.characterInfo = document.getElementById("character-info"); - //Create Program buttons var portHackALink = document.getElementById("create-program-porthack"); var bruteSshALink = document.getElementById("create-program-brutessh"); @@ -864,69 +936,7 @@ var Engine = { }); - //Location lists - Engine.aevumLocationsList = document.getElementById("aevum-locations-list"); - Engine.chongqingLocationsList = document.getElementById("chongqing-locations-list"); - Engine.sector12LocationsList = document.getElementById("sector12-locations-list"); - Engine.newTokyoLocationsList = document.getElementById("newtokyo-locations-list"); - Engine.ishimaLocationsList = document.getElementById("ishima-locations-list"); - Engine.volhavenLocationsList = document.getElementById("volhaven-locations-list"); - //Location page (page that shows up when you visit a specific location in World) - Engine.Display.locationContent = document.getElementById("location-container"); - Engine.Display.locationContent.style.visibility = "hidden"; - - //Work In Progress - Engine.Display.workInProgressContent = document.getElementById("work-in-progress-container"); - Engine.Display.workInProgressContent.style.visibility = "hidden"; - - //Init Location buttons - initLocationButtons(); - - //Script editor - Engine.Display.scriptEditorText = document.getElementById("script-editor-text"); - - //Load game from save or create new game - if (loadGame(saveObject)) { - console.log("Loaded game from save"); - CompanyPositions.init(); - - //Calculate the number of cycles have elapsed while offline - var thisUpdate = new Date().getTime(); - var lastUpdate = Player.lastUpdate; - var numCyclesOffline = Math.floor((thisUpdate - lastUpdate) / Engine._idleSpeed); - - /* Process offline progress */ - processServerGrowth(numCyclesOffline); //Should be done before offline production for scripts - loadAllRunningScripts(); //This also takes care of offline production for those scripts - if (Player.isWorking) { - if (Player.workType == CONSTANTS.WorkTypeFaction) { - Player.workForFaction(numCyclesOffline); - } else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) { - Player.createProgramWork(numCyclesOffline); - } else if (Player.workType == CONSTANTS.WorkTypeStudyClass) { - Player.takeClass(numCyclesOffline); - } else { - Player.work(numCyclesOffline); - } - } - - //Hacknet Nodes offline progress - processAllHacknetNodeEarnings(numCyclesOffline); - - //Passive faction rep gain offline - processPassiveFactionRepGain(numCyclesOffline); - } else { - //No save found, start new game - console.log("Initializing new game"); - SpecialServerIps = new SpecialServerIpsMap(); - Player.init(); - initForeignServers(); - initCompanies(); - initFactions(); - CompanyPositions.init(); - initAugmentations(); - } //Message at the top of terminal postNetburnerText(); @@ -959,7 +969,7 @@ var Engine = { }; window.onload = function() { - Engine.init(); + Engine.load(); }; diff --git a/utils/FactionInvitationBox.js b/utils/FactionInvitationBox.js index d95f38645..e32a64ccf 100644 --- a/utils/FactionInvitationBox.js +++ b/utils/FactionInvitationBox.js @@ -36,9 +36,10 @@ factionInvitationBoxCreate = function(faction) { factionInvitationSetText("You have received a faction invitation from " + faction.name); //TODO Faction invitation message - var yesButton = document.getElementById("faction-invitation-box-yes"); - var newYesButton = yesButton.cloneNode(true); - yesButton.parentNode.replaceChild(newYesButton, yesButton); + var newYesButton = clearEventListeners("faction-invitation-box-yes"); + //var yesButton = document.getElementById("faction-invitation-box-yes"); + //var newYesButton = yesButton.cloneNode(true); + //yesButton.parentNode.replaceChild(newYesButton, yesButton); newYesButton.addEventListener("click", function() { joinFaction(faction); diff --git a/utils/HelperFunctions.js b/utils/HelperFunctions.js index d4cc22a3f..1771934e1 100644 --- a/utils/HelperFunctions.js +++ b/utils/HelperFunctions.js @@ -18,4 +18,14 @@ function addOffset(n, percentage) { var offset = n * (percentage / 100); return n * (Math.random() * (2 * offset) - offset); +} + +//Given an element by its Id(usually an 'a' element), removes all event listeners +//from that element by cloning and replacing. Then returns the new cloned element +function clearEventListeners(elemId) { + var elem = document.getElementById(elemId); + if (elem == null) {console.log("ERR: Could not find element for: " + elemId); return null;} + var newElem = elem.cloneNode(true); + elem.parentNode.replaceChild(newElem, elem); + return elem; } \ No newline at end of file diff --git a/utils/PurchaseAugmentationBox.js b/utils/PurchaseAugmentationBox.js index dd3ef0670..ec77c3f2b 100644 --- a/utils/PurchaseAugmentationBox.js +++ b/utils/PurchaseAugmentationBox.js @@ -35,9 +35,10 @@ purchaseAugmentationBoxCreate = function(aug, fac) { formatNumber(aug.baseCost * fac.augmentationPriceMult, 2) + "?"); //Clear old event listeners from Confirm button - var confirmButton = document.getElementById("purchase-augmentation-box-confirm"); - var newConfirmButton = confirmButton.cloneNode(true); - confirmButton.parentNode.replaceChild(newConfirmButton, confirmButton); + var newConfirmButton = clearEventListeners("purchase-augmentation-box-confirm"); + //var confirmButton = document.getElementById("purchase-augmentation-box-confirm"); + //var newConfirmButton = confirmButton.cloneNode(true); + //confirmButton.parentNode.replaceChild(newConfirmButton, confirmButton); newConfirmButton.addEventListener("click", function() { diff --git a/utils/PurchaseRamForHomeBox.js b/utils/PurchaseRamForHomeBox.js index da3e1ca0f..752dd2387 100644 --- a/utils/PurchaseRamForHomeBox.js +++ b/utils/PurchaseRamForHomeBox.js @@ -47,9 +47,10 @@ purchaseRamForHomeBoxCreate = function() { purchaseRamForHomeBoxOpen(); //Clear old event listeners from Confirm button - var confirmButton = document.getElementById("purchase-ram-for-home-box-confirm"); - var newConfirmButton = confirmButton.cloneNode(true); - confirmButton.parentNode.replaceChild(newConfirmButton, confirmButton); + var newConfirmButton = clearEventListeners("purchase-ram-for-home-box-confirm"); + //var confirmButton = document.getElementById("purchase-ram-for-home-box-confirm"); + //var newConfirmButton = confirmButton.cloneNode(true); + //confirmButton.parentNode.replaceChild(newConfirmButton, confirmButton); newConfirmButton.addEventListener("click", function() { purchaseRamForHomeBoxClose(); purchaseRamForHomeComputer(cost); diff --git a/utils/PurchaseServerBox.js b/utils/PurchaseServerBox.js index e4ed91782..fbaf78a89 100644 --- a/utils/PurchaseServerBox.js +++ b/utils/PurchaseServerBox.js @@ -31,9 +31,10 @@ purchaseServerBoxCreate = function(ram, cost) { purchaseServerBoxSetText("Would you like to purchase a new server with " + ram + "GB of RAM for $" + cost + "?" ); //Clear old event listeners from Confirm button - var confirmButton = document.getElementById("purchase-server-box-confirm"); - var newConfirmButton = confirmButton.cloneNode(true); - confirmButton.parentNode.replaceChild(newConfirmButton, confirmButton); + var newConfirmButton = clearEventListeners("purchase-server-box-confirm"); + //var confirmButton = document.getElementById("purchase-server-box-confirm"); + //var newConfirmButton = confirmButton.cloneNode(true); + //confirmButton.parentNode.replaceChild(newConfirmButton, confirmButton); newConfirmButton.addEventListener("click", function() { purchaseServerBoxClose(); purchaseServer(ram, cost); diff --git a/utils/TravelBox.js b/utils/TravelBox.js index 32aa0953c..89232d2f8 100644 --- a/utils/TravelBox.js +++ b/utils/TravelBox.js @@ -30,9 +30,10 @@ travelBoxCreate = function(destCityName, cost) { travelBoxSetText("Would you like to travel to " + destCityName + "? The trip will cost $" + cost + "."); //Clear old event listeners from Confirm button - var confirmButton = document.getElementById("travel-box-confirm"); - var newConfirmButton = confirmButton.cloneNode(true); - confirmButton.parentNode.replaceChild(newConfirmButton, confirmButton); + var newConfirmButton = clearEventListeners("travel-box-confirm"); + //var confirmButton = document.getElementById("travel-box-confirm"); + //var newConfirmButton = confirmButton.cloneNode(true); + //confirmButton.parentNode.replaceChild(newConfirmButton, confirmButton); newConfirmButton.addEventListener("click", function() { travelBoxClose(); travelToCity(destCityName, cost);