Added offline properties for Script object

This commit is contained in:
Daniel Xie 2016-11-21 05:22:18 -06:00
parent d372ce5980
commit 1a600ad560
3 changed files with 19 additions and 18 deletions

@ -69,9 +69,7 @@
<div id="character-container"> <div id="character-container">
<p id="character-info"> </p> <p id="character-info"> </p>
</div> <!-- End terminal-container --> </div> <!-- End character-container -->
<!-- Always keep the terminal in focus --> <!-- Always keep the terminal in focus -->
<script type="text/javascript"> <script type="text/javascript">

@ -7,9 +7,21 @@ function Script() {
//is executed every second (this may change) //is executed every second (this may change)
this.functionQueue = []; this.functionQueue = [];
this.code = ""; this.code = "";
this.ramUsage = 0; this.ramUsage = 0;
/* Properties to calculate offline progress. Only applies for infinitely looping scripts */
//Time it takes to execute one iteration of the entire script
//Each function takes 1 second, plus hacking time plus and sleep commands
this.executionTimeMillis = 0;
//Number of instructions ("lines") in the code. Any call ending in a ;
//is considered one instruction. Used to calculate executionTime
this.numInstructions = 0;
//Which servers are hacked in one iteration of the script. May contain duplicates
this.serversHacked = [];
} }
//Execute the next function in the Script's function queue //Execute the next function in the Script's function queue
@ -20,6 +32,10 @@ Script.prototype.executeNext() {
(this.functionQueue.shift())(); (this.functionQueue.shift())();
} }
Script.prototype.setCode(code) {
this.code = code;
}
/* Wrapper object that wraps a function with its arguments. /* Wrapper object that wraps a function with its arguments.
* These objects are pushed onto a Script object's function queue. * These objects are pushed onto a Script object's function queue.
* The functions can be called with the standard () operator * The functions can be called with the standard () operator

@ -39,21 +39,8 @@ var Engine = {
//Time variables (milliseconds unix epoch time) //Time variables (milliseconds unix epoch time)
_lastUpdate: new Date().getTime(), _lastUpdate: new Date().getTime(),
_idleSpeed: 200, //Speed (in ms) at which the main loop is updated _idleSpeed: 200, //Speed (in ms) at which the main loop is updated
//Display a status update text
_lastStatus: null,
displayStatusText: function(text) {
Engine.Display.statusText.innerHTML = text;
clearTimeout(Engine._lastStatus);
//Wipe status message after 3 seconds
Engine._lastStatus = setTimeout(function() {
Engine.Display.statusText.innerHTML = "";
}, 3000);
},
//Save function //Save function
saveFile: function() { saveFile: function() {
var tempSaveFile = JSON.stringify(Player); var tempSaveFile = JSON.stringify(Player);