From 962b057ff8434facdc88f5b08739edb39d724ce4 Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Mon, 19 Dec 2016 12:20:19 -0600 Subject: [PATCH] Implemented basic functionality for the Active Tabs menu. Works for online production --- README.md | 31 +++- css/menupages.css | 29 +++- css/styles.css | 1 - index.html | 13 +- src/Company.js | 268 ++++++++++++++++++++----------- src/Netscript/Evaluator.js | 15 +- src/Netscript/NetscriptWorker.js | 60 ++++++- src/Player.js | 6 +- src/Script.js | 16 +- src/Server.js | 2 +- src/Terminal.js | 50 +----- src/engine.js | 140 ++++++++++++++-- utils/StringHelperFunctions.js | 2 +- 13 files changed, 444 insertions(+), 189 deletions(-) diff --git a/README.md b/README.md index 7c5e3c9fe..3ff79b42c 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,35 @@ TESTING TODO: If a script has bad syntax...it fucks everything up when you try to run it so fix that Try catch for script? Check that killing scripts still works fine (TESTED - LOoks to work fine) - Check that if script has bad syntax it wont run at all and everthing works normally - Check if script throws during runtime it shuts down correctly + Check that if script has bad syntax it wont run at all and everthing works normally (Seems to work fine) + Check if script throws during runtime it shuts down correctly (seems to work fine) + + Adjust leveling formula. Goes up way too high at first + http://gamedev.stackexchange.com/questions/55151/rpg-logarithmic-leveling-formula + - might be too slow now? + + Scripts tab that shows script stats + Seems to work, at least the basics (for online production) Tasks TODO: Script offline progress - - + ctrl+C functionality for all running command like hack(), analyze(), and tail Scroll all the way down when something is post()ed - Scripts tab that shows script stats Script logging functionality? Logs to internal "log file" (property of script itself) - Parse script firs tot see if there are any syntax errors, and tell user if there are (when user calls "run") Tutorial and help Server growth - Companies + + Hack time formula needs rebalancing I think + Factions + Augmentations Update CONSTANTS.HelpText - Account for Max possible int when gaining exp \ No newline at end of file + Account for Max possible int when gaining exp + Text in script editor that says ("ctrl + x" to save and quit) + + Companies + Add possible CompanyPositions for every Company + Applying/working for companies + + OPTIMIZATION + https://gamealchemist.wordpress.com/2013/05/01/lets-get-those-javascript-arrays-to-work-fast/ \ No newline at end of file diff --git a/css/menupages.css b/css/menupages.css index 263b176c9..c880b3c01 100644 --- a/css/menupages.css +++ b/css/menupages.css @@ -24,9 +24,6 @@ padding-left: 10px; height: 100%; margin-left: 10%; - width: 99%; - color: #66ff33; - } #script-editor-filename-row-div { @@ -65,4 +62,30 @@ -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; +} + +/* Active scripts */ +#active-scripts-container { + position: fixed; + padding-top: 10px; + padding-left: 10px; + height: 100%; + margin-left: 10%; + width: 99%; +} + +.active-scripts-list>li h2{ + color: #66ff33; + padding-top: 10px; + padding-left: 10px; + background-color: #333; + text-decoration: none; +} + +.active-scripts-list>li p { + color: #66ff33; + padding: 10px; + padding-left: 40px; + background-color: #333; + text-decoration: none; } \ No newline at end of file diff --git a/css/styles.css b/css/styles.css index 5bb4b47aa..940dcc4db 100644 --- a/css/styles.css +++ b/css/styles.css @@ -51,7 +51,6 @@ p { color: white; } - h1 { padding: 8px; } diff --git a/index.html b/index.html index 22aa62308..d9708f22a 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,7 @@ + @@ -48,12 +49,13 @@ Character +
  • Create Script
  • -
  • + Active Scripts
  • object for a given workerScript + addActiveScriptsItem: function(workerscript) { + console.log("addActiveScriptsItem called"); + var item = document.createElement("li"); + + Engine.createActiveScriptsText(workerscript, item); + + //Add the li element onto the list + if (Engine.ActiveScriptsList == null) { + Engine.ActiveScriptsList = document.getElementById("active-scripts-list"); + } + Engine.ActiveScriptsList.appendChild(item); + }, + + //Update the ActiveScriptsItems array + updateActiveScriptsItems: function() { + for (var i = 0; i < workerScripts.length; ++i) { + Engine.updateActiveScriptsItemContent(i, workerScripts[i]); + } + }, + + //Updates the content of the given item in the Active Scripts list + updateActiveScriptsItemContent: function(i, workerscript) { + var list = Engine.ActiveScriptsList.getElementsByTagName("li"); + if (i >= list.length) { + throw new Error("Trying to update an out-of-range Active Scripts Item"); + } + + var item = list[i]; + + //Clear the item + while (item.firstChild) { + item.removeChild(item.firstChild); + } + + //Add the updated text back + Engine.createActiveScriptsText(workerscript, item); + }, + + createActiveScriptsText(workerscript, item) { + //Script name + var scriptName = document.createElement("h2"); + scriptName.appendChild(document.createTextNode(workerscript.name)); + item.appendChild(scriptName); + + var itemText = document.createElement("p"); + + //Server ip/hostname + var hostname = workerscript.getServer().hostname; + var serverIpHostname = "Server: " + hostname + "(" + workerscript.serverIp + ")"; + + //Online money/s + var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime; + var onlineMpsText = "Online production: $" + onlineMps.toFixed(2) + "/second"; + + //Offline money/s + var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime; + var offlineMpsText = "Offline production: $" + offlineMps.toFixed(2) + "/second"; + + itemText.innerHTML = serverIpHostname + "
    " + onlineMpsText + "
    " + offlineMpsText + "
    "; + + item.appendChild(itemText); + }, + /* Main Event Loop */ idleTimer: function() { //Get time difference @@ -161,7 +251,6 @@ var Engine = { window.requestAnimationFrame(Engine.idleTimer); }, - //TODO Account for numCycles in Code, hasn't been done yet updateGame: function(numCycles = 1) { //Manual hack if (Player.startAction == true) { @@ -173,10 +262,18 @@ var Engine = { Engine._actionTimeStr = "Time left: "; Player.startAction = false; } + + //Counters Engine.decrementAllCounters(numCycles); Engine.checkCounters(); + //Manual hacks Engine.updateHackProgress(numCycles); + + //Update the running time of all active scripts + updateOnlineScriptTimes(numCycles); + + }, //Counters for the main event loop. Represent the number of game cycles are required @@ -184,6 +281,7 @@ var Engine = { Counters: { autoSaveCounter: 300, //Autosave every minute updateSkillLevelsCounter: 10, //Only update skill levels every 2 seconds. Might improve performance + updateDisplays: 10, //Update displays such as Active Scripts display and character display }, decrementAllCounters: function(numCycles = 1) { @@ -206,6 +304,16 @@ var Engine = { Player.updateSkillLevels(); Engine.Counters.updateSkillLevelsCounter = 10; } + + if (Engine.Counters.updateDisplays <= 0) { + if (Engine.currentPage == Engine.Page.ActiveScripts) { + Engine.updateActiveScriptsItems(); + } else if (Engine.currentPage == Engine.Page.CharacterInfo) { + Engine.displayCharacterInfo(); + } + + Engine.Counters.updateDisplays = 10; + } }, /* Calculates the hack progress for a manual (non-scripted) hack and updates the progress bar/time accordingly */ @@ -251,18 +359,15 @@ var Engine = { //Initialization functions if (Engine.loadSave()) { console.log("Loaded game from save"); - Companies.init(); CompanyPositions.init(); - console.log("Calling loadAllRunningScripts()"); loadAllRunningScripts(); - console.log("Finished calling loadAllRunningScripts()"); } else { //No save found, start new game console.log("Initializing new game"); Player.init(); initForeignServers(); - Companies.init(); CompanyPositions.init(); + initCompanies(); } //Main menu buttons and content @@ -283,7 +388,18 @@ var Engine = { Engine.loadScriptEditorContent(); return false; }); - + + Engine.Clickables.activeScriptsMainMenuButton = document.getElementById("active-scripts-menu-link"); + Engine.Clickables.activeScriptsMainMenuButton.addEventListener("click", function() { + Engine.loadActiveScriptsContent(); + return false; + }); + //Active scripts list + Engine.ActiveScriptsList = document.getElementById("active-scripts-list"); + + + + Engine.Clickables.saveMainMenuButton = document.getElementById("save-game-link"); Engine.Clickables.saveMainMenuButton.addEventListener("click", function() { Engine.saveGame(); @@ -302,6 +418,8 @@ var Engine = { 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"; //Character info Engine.Display.characterInfo = document.getElementById("character-info"); diff --git a/utils/StringHelperFunctions.js b/utils/StringHelperFunctions.js index 9d6621bd2..eb8a4dc3d 100644 --- a/utils/StringHelperFunctions.js +++ b/utils/StringHelperFunctions.js @@ -1,4 +1,4 @@ -//Netscript String helper functions +//Netburner String helper functions //Searches for every occurence of searchStr within str and returns an array of the indices of //all these occurences