v0.28.0 Changed - Integrate ACE editor

This commit is contained in:
danielyxie 2017-09-01 09:12:40 -05:00
parent fd2642cfe9
commit b17f89eba7
12 changed files with 20854 additions and 479 deletions

1
.gitignore vendored

@ -1,3 +1,4 @@
Changelog.txt Changelog.txt
Netburner.txt Netburner.txt
README.md README.md
/node_modules

@ -40,6 +40,7 @@
-moz-box-shadow: 1px 1px 3px #000; -moz-box-shadow: 1px 1px 3px #000;
-webkit-box-shadow: 1px 1px 3px #000; -webkit-box-shadow: 1px 1px 3px #000;
box-shadow: 1px 1px 3px #000; box-shadow: 1px 1px 3px #000;
background-color:black;
} }
#interactive-tutorial-exit { #interactive-tutorial-exit {
@ -65,4 +66,3 @@
text-decoration: none; text-decoration: none;
cursor: pointer; cursor: pointer;
} }

@ -16,6 +16,42 @@
} }
/* Script Editor */ /* Script Editor */
#script-editor-container {
background-color:transparent;
}
#javascript-editor {
margin: 10px;
height: 80%;
width: 100%;
margin-left: 6px;
padding-left: 6px;
padding-top: 6px;
padding-bottom: 6px;
border: 2px solid var(--my-highlight-color);
z-index: 1;
font-family: 'Lucida Console', 'Lucida Sans Unicode', 'Fira Mono', 'Consolas', 'Courier New', Courier, monospace, 'Times New Roman';
}
#javascript-editor textarea {
color: var(--my-font-color);
}
.ace_line,
.ace_line * {
color: var(--my-font-color);
background-color:transparent;
margin:0px;
padding:0px;
}
.ace_text-input {
font-size:16px;
background-color:transparent;
}
/* This temp element is used for auto adjusting filename field */ /* This temp element is used for auto adjusting filename field */
.tmp-element { .tmp-element {
visibility: hidden; visibility: hidden;
@ -56,6 +92,7 @@
#script-editor-wrapper { #script-editor-wrapper {
height:100%; height:100%;
width: 70%; width: 70%;
background:transparent;
} }
#script-editor-filename-wrapper { #script-editor-filename-wrapper {
@ -103,28 +140,6 @@
color: #ffffff; color: #ffffff;
} }
#script-editor-text {
color: var(--my-font-color);
height: 80%;
width: 100%;
margin-left: 6px;
padding-left: 6px;
padding-top: 6px;
padding-bottom: 6px;
border: 2px solid var(--my-highlight-color);
-webkit-box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
-moz-box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
}
/* Active scripts */ /* Active scripts */
.active-scripts-list { .active-scripts-list {
list-style-type: none; list-style-type: none;
@ -261,6 +276,7 @@
box-shadow: 1px 1px 3px #000; box-shadow: 1px 1px 3px #000;
margin: 4px; margin: 4px;
padding: 4px; padding: 4px;
background-color:black;
} }
.active-scripts-button:hover, .active-scripts-button:hover,

@ -29,6 +29,7 @@
padding: 2px; padding: 2px;
margin: 6px; margin: 6px;
border: 1px solid white; border: 1px solid white;
background-color:black;
} }
.popup-box-button:hover, .popup-box-button:hover,
@ -43,6 +44,12 @@
cursor: default; cursor: default;
} }
#yes-no-text-input-box-input {
color: var(--my-font-color);
border: 1px solid white;
background-color:black;
}
.dialog-box-container, .dialog-box-container,
#log-box-container { #log-box-container {
display: block; display: block;
@ -94,20 +101,6 @@
cursor: pointer; cursor: pointer;
} }
/* Purchase server box */
#purchase-server-box-container {
transition: opacity 400ms ease-in;
}
#purchase-server-box-input {
color: white;
}
/* Purchase Augmentation Box */
#purchase-augmentation-box-container {
transition: opacity 400ms ease-in;
}
/* Faction invitation box */ /* Faction invitation box */
#faction-invitation-box-container { #faction-invitation-box-container {
transition: opacity 400ms ease-in; transition: opacity 400ms ease-in;

@ -1,20 +1,20 @@
/** This removes all padding and margins as well as /** This removes all padding and margins as well as
setting a default font size and family for the page **/ setting a default font size and family for the page **/
:root{ :root{
--my-font-color: #66ff33; --my-font-color: #66ff33;
--my-background-color: #000000; --my-background-color: #000000;
--my-highlight-color: #ffffff; --my-highlight-color: #ffffff;
} }
* { * {
margin: 0; margin: 0;
padding: 0; padding: 0;
font-size: 16px; font-size: 16px;
font-family: 'Lucida Console', 'Lucida Sans Unicode', 'Fira Mono', 'Consolas', 'Courier New', Courier, monospace, 'Times New Roman'; font-family: 'Lucida Console', 'Lucida Sans Unicode', 'Fira Mono', 'Consolas', 'Courier New', Courier, monospace, 'Times New Roman';
/*background-color: #252527;*/ }
body {
background-color: var(--my-background-color); background-color: var(--my-background-color);
} }
@ -41,6 +41,10 @@ span {
padding: 4px; padding: 4px;
} }
#entire-game-container {
background-color:transparent;
}
/* Disable border highlight on elements */ /* Disable border highlight on elements */
input:focus, input:focus,
textarea:focus, textarea:focus,
@ -346,6 +350,7 @@ a:link, a:visited {
-webkit-box-shadow: 1px 1px 3px #000; -webkit-box-shadow: 1px 1px 3px #000;
box-shadow: 1px 1px 3px #000; box-shadow: 1px 1px 3px #000;
height: 22px; height: 22px;
background-color:black;
} }
#character-overview-save-button:hover, #character-overview-save-button:hover,

21128
dist/bundle.js vendored

File diff suppressed because one or more lines are too long

@ -89,6 +89,24 @@
</ul> </ul>
</div> </div>
<div id="script-editor-container" class="generic-menupage-container">
<div id="script-editor-wrapper">
<div id="script-editor-filename-wrapper">
<p id="script-editor-filename-tag"> <strong style="background-color:#555;">Script name: </strong></p>
<input id="script-editor-filename" type="text" maxlength="30" tabindex="1"> </input>
</div>
<div id="javascript-editor"></div>
<div id="script-editor-buttons-wrapper">
<span id="script-editor-save-and-close-button" class="a-link-button">Save & Close (Ctrl + b)</span>
<p id="script-editor-status-text"> </p>
<a id="script-editor-netscript-doc-button" class="a-link-button" href="https://bitburner.wikia.com/wiki/Netscript" target="_blank"> Netscript Documentation </a>
</div>
</div> <!-- End wrapper -->
</div>
<!-- Terminal page --> <!-- Terminal page -->
<div id="terminal-container"> <div id="terminal-container">
<table id="terminal"> <table id="terminal">
@ -108,23 +126,6 @@
</div> </div>
</div> </div>
<!-- Script editor -->
<div id="script-editor-container" class="generic-menupage-container">
<div id="script-editor-wrapper">
<div id="script-editor-filename-wrapper">
<p id="script-editor-filename-tag"> <strong style="background-color:#555;">Script name: </strong></p>
<input id="script-editor-filename" type="text" maxlength="30" tabindex="1"> </input>
</div>
<textarea id="script-editor-text" tabindex="2" autofocus> </textarea>
<div id="script-editor-buttons-wrapper">
<span id="script-editor-save-and-close-button" class="a-link-button">Save & Close (Ctrl + b)</span>
<p id="script-editor-status-text"> </p>
<a id="script-editor-netscript-doc-button" class="a-link-button" href="https://bitburner.wikia.com/wiki/Netscript" target="_blank"> Netscript Documentation </a>
</div>
</div>
<p> <br><br> </p>
</div>
<!-- Active scripts info page --> <!-- Active scripts info page -->
<div id="active-scripts-container" class="generic-menupage-container"> <div id="active-scripts-container" class="generic-menupage-container">
<p id="active-scripts-text"> This page displays a list of all of your scripts that are currently running across every machine. It also <p id="active-scripts-text"> This page displays a list of all of your scripts that are currently running across every machine. It also

@ -1,5 +1,5 @@
let CONSTANTS = { let CONSTANTS = {
Version: "0.28.0", Version: "0.28.1",
//Max level for any skill, assuming no multipliers. Determined by max numerical value in javascript for experience //Max level for any skill, assuming no multipliers. Determined by max numerical value in javascript for experience
//and the skill level formula in Player.js. Note that all this means it that when experience hits MAX_INT, then //and the skill level formula in Player.js. Note that all this means it that when experience hits MAX_INT, then
@ -395,7 +395,8 @@ let CONSTANTS = {
"any server, regardless of where the script is running. This command requires root access to the target server, but " + "any server, regardless of where the script is running. This command requires root access to the target server, but " +
"there is no required hacking level to run the command. Returns " + "there is no required hacking level to run the command. Returns " +
"0.1. Works offline at a slower rate<br> Example: weaken('foodnstuff');<br><br>" + "0.1. Works offline at a slower rate<br> Example: weaken('foodnstuff');<br><br>" +
"<i>print(x)</i> <br>Prints a value or a variable to the scripts logs (which can be viewed with the 'tail [script]' terminal command ). <br><br>" + "<i>print(x)</i><br>Prints a value or a variable to the scripts logs (which can be viewed with the 'tail [script]' terminal command ). <br><br>" +
"<i>tprint(x)</i><br>Prints a value or a variable to the Terminal<br><br>" +
"<i>clearLog()</i><br>Clears the script's logs. <br><br>" + "<i>clearLog()</i><br>Clears the script's logs. <br><br>" +
"<i>scan(hostname/ip)</i><br>Returns an array containing the hostnames of all servers that are one node away from the specified server. " + "<i>scan(hostname/ip)</i><br>Returns an array containing the hostnames of all servers that are one node away from the specified server. " +
"The argument must be a string containing the IP or hostname of the target server. The hostnames in the returned array are strings.<br><br>" + "The argument must be a string containing the IP or hostname of the target server. The hostnames in the returned array are strings.<br><br>" +
@ -858,6 +859,9 @@ let CONSTANTS = {
"World Stock Exchange account and TIX API Access<br>", "World Stock Exchange account and TIX API Access<br>",
LatestUpdate: LatestUpdate:
"v0.28.1<br>" +
"-The script editor now uses the open-source Ace editor, which provides a much better experience when coding!<br>" +
"-Added tprint() Netscript function<br><br>" +
"v0.28.0<br>" + "v0.28.0<br>" +
"-Added BitNode-4: The Singularity<br>" + "-Added BitNode-4: The Singularity<br>" +
"-Added BitNode-11: The Big Crash<br>" + "-Added BitNode-11: The Big Crash<br>" +

@ -23,6 +23,7 @@ import {StockMarket, StockSymbols, SymbolToStockMap, initStockSymbols,
sellStock, updateStockPrices, displayStockMarketContent, sellStock, updateStockPrices, displayStockMarketContent,
updateStockTicker, updateStockPlayerPosition, updateStockTicker, updateStockPlayerPosition,
Stock} from "./StockMarket.js"; Stock} from "./StockMarket.js";
import {post} from "./Terminal.js";
import {WorkerScript, workerScripts, import {WorkerScript, workerScripts,
killWorkerScript, NetscriptPorts} from "./NetscriptWorker.js"; killWorkerScript, NetscriptPorts} from "./NetscriptWorker.js";
@ -223,6 +224,12 @@ function NetscriptFunctions(workerScript) {
} }
workerScript.scriptRef.log(args.toString()); workerScript.scriptRef.log(args.toString());
}, },
tprint : function(args) {
if (args === undefined || args === null) {
throw makeRuntimeRejectMsg(workerScript, "tprint() call has incorrect number of arguments. Takes 1 argument");
}
post(workerScript.scriptRef.filename + ": " + args.toString());
},
clearLog : function() { clearLog : function() {
workerScript.scriptRef.clearLog(); workerScript.scriptRef.clearLog();
}, },
@ -1696,4 +1703,4 @@ function NetscriptFunctions(workerScript) {
} }
} }
export {NetscriptFunctions, initSingularitySFFlags}; export {NetscriptFunctions, initSingularitySFFlags, hasSingularitySF};

@ -1513,7 +1513,7 @@ PlayerObject.prototype.finishCrime = function(cancelled) {
//Cancels the player's current "work" assignment and gives the proper rewards //Cancels the player's current "work" assignment and gives the proper rewards
//Used only for Singularity functions, so no popups are created //Used only for Singularity functions, so no popups are created
PlayerObject.prototype.singularityStopWork = function() { PlayerObject.prototype.singularityStopWork = function() {
if (!this.isWorking) {return null;} if (!this.isWorking) {return "";}
var res; //Earnings text for work var res; //Earnings text for work
switch (this.workType) { switch (this.workType) {
case CONSTANTS.WorkTypeStudyClass: case CONSTANTS.WorkTypeStudyClass:

@ -1,3 +1,7 @@
var ace = require('brace');
require('brace/mode/javascript');
require('brace/theme/monokai');
import {CONSTANTS} from "./Constants.js"; import {CONSTANTS} from "./Constants.js";
import {Engine} from "./engine.js"; import {Engine} from "./engine.js";
import {iTutorialSteps, iTutorialNextStep, import {iTutorialSteps, iTutorialNextStep,
@ -47,14 +51,12 @@ document.addEventListener("DOMContentLoaded", scriptEditorInit, false);
//Updates line number and RAM usage in script //Updates line number and RAM usage in script
function updateScriptEditorContent() { function updateScriptEditorContent() {
var txt = $("#script-editor-text")[0]; var editor = ace.edit('javascript-editor');
var lineNum = txt.value.substr(0, txt.selectionStart).split("\n").length; var code = editor.getValue();
var code = document.getElementById("script-editor-text").value;
var codeCopy = code.repeat(1); var codeCopy = code.repeat(1);
var ramUsage = calculateRamUsage(codeCopy); var ramUsage = calculateRamUsage(codeCopy);
document.getElementById("script-editor-status-text").innerText = document.getElementById("script-editor-status-text").innerText =
"Line Number: " + lineNum + ", RAM: " + formatNumber(ramUsage, 2).toString() + "GB"; "RAM: " + formatNumber(ramUsage, 2).toString() + "GB";
} }
//Define key commands in script editor (ctrl o to save + close, etc.) //Define key commands in script editor (ctrl o to save + close, etc.)
@ -75,7 +77,8 @@ function saveAndCloseScriptEditor() {
dialogBoxCreate("Leave the script name as 'foodnstuff'!"); dialogBoxCreate("Leave the script name as 'foodnstuff'!");
return; return;
} }
var code = document.getElementById("script-editor-text").value; var editor = ace.edit('javascript-editor');
var code = editor.getValue();
code = code.replace(/\s/g, ""); code = code.replace(/\s/g, "");
if (code.indexOf("while(true){hack('foodnstuff');}") == -1) { if (code.indexOf("while(true){hack('foodnstuff');}") == -1) {
dialogBoxCreate("Please copy and paste the code from the tutorial!"); dialogBoxCreate("Please copy and paste the code from the tutorial!");
@ -134,7 +137,8 @@ function Script() {
Script.prototype.saveScript = function() { Script.prototype.saveScript = function() {
if (Engine.currentPage == Engine.Page.ScriptEditor) { if (Engine.currentPage == Engine.Page.ScriptEditor) {
//Update code and filename //Update code and filename
var code = document.getElementById("script-editor-text").value; var editor = ace.edit('javascript-editor');
var code = editor.getValue();
this.code = code.replace(/^\s+|\s+$/g, ''); this.code = code.replace(/^\s+|\s+$/g, '');
var filename = document.getElementById("script-editor-filename").value + ".script"; var filename = document.getElementById("script-editor-filename").value + ".script";

@ -1,3 +1,9 @@
var ace = require('brace');
require('brace/mode/javascript');
require('brace/theme/monokai');
require('brace/theme/terminal');
require('brace/theme/twilight');
import {dialogBoxCreate} from "../utils/DialogBox.js"; import {dialogBoxCreate} from "../utils/DialogBox.js";
import {gameOptionsBoxOpen, gameOptionsBoxClose}from "../utils/GameOptions.js"; import {gameOptionsBoxOpen, gameOptionsBoxClose}from "../utils/GameOptions.js";
import {clearEventListeners} from "../utils/HelperFunctions.js"; import {clearEventListeners} from "../utils/HelperFunctions.js";
@ -30,7 +36,8 @@ import {initLiterature} from "./Literature.js";
import {Locations, displayLocationContent, import {Locations, displayLocationContent,
initLocationButtons} from "./Location.js"; initLocationButtons} from "./Location.js";
import {checkForMessagesToSend, initMessages} from "./Message.js"; import {checkForMessagesToSend, initMessages} from "./Message.js";
import {initSingularitySFFlags} from "./NetscriptFunctions.js"; import {initSingularitySFFlags,
hasSingularitySF} from "./NetscriptFunctions.js";
import {updateOnlineScriptTimes, import {updateOnlineScriptTimes,
runScriptsLoop} from "./NetscriptWorker.js"; runScriptsLoop} from "./NetscriptWorker.js";
import {Player} from "./Player.js"; import {Player} from "./Player.js";
@ -180,9 +187,6 @@ let Engine = {
//Character info //Character info
characterInfo: null, characterInfo: null,
//Script editor text
scriptEditorText: null,
}, },
//Current page status //Current page status
@ -232,11 +236,12 @@ let Engine = {
loadScriptEditorContent: function(filename = "", code = "") { loadScriptEditorContent: function(filename = "", code = "") {
Engine.hideAllContent(); Engine.hideAllContent();
Engine.Display.scriptEditorContent.style.visibility = "visible"; Engine.Display.scriptEditorContent.style.visibility = "visible";
var editor = ace.edit('javascript-editor');
if (filename != "") { if (filename != "") {
document.getElementById("script-editor-filename").value = filename; document.getElementById("script-editor-filename").value = filename;
document.getElementById("script-editor-text").value = code; editor.setValue(code);
} }
document.getElementById("script-editor-text").focus(); editor.focus();
updateScriptEditorContent(); updateScriptEditorContent();
Engine.currentPage = Engine.Page.ScriptEditor; Engine.currentPage = Engine.Page.ScriptEditor;
document.getElementById("create-script-menu-link").classList.add("active"); document.getElementById("create-script-menu-link").classList.add("active");
@ -1013,6 +1018,13 @@ let Engine = {
}, },
load: function() { load: function() {
//Load script editor
var editor = ace.edit('javascript-editor');
editor.getSession().setMode('ace/mode/javascript');
editor.setTheme('ace/theme/monokai');
document.getElementById('javascript-editor').style.fontSize='16px';
editor.setOption("showPrintMargin", false);
//Initialize main menu accordion panels to all start as "open" //Initialize main menu accordion panels to all start as "open"
var terminal = document.getElementById("terminal-tab"); var terminal = document.getElementById("terminal-tab");
var createScript = document.getElementById("create-script-tab"); var createScript = document.getElementById("create-script-tab");
@ -1271,9 +1283,6 @@ let Engine = {
//Init Location buttons //Init Location buttons
initLocationButtons(); initLocationButtons();
//Script editor
Engine.Display.scriptEditorText = document.getElementById("script-editor-text");
//Tutorial buttons //Tutorial buttons
Engine.Clickables.tutorialNetworkingButton = document.getElementById("tutorial-networking-link"); Engine.Clickables.tutorialNetworkingButton = document.getElementById("tutorial-networking-link");
Engine.Clickables.tutorialNetworkingButton.addEventListener("click", function() { Engine.Clickables.tutorialNetworkingButton.addEventListener("click", function() {
@ -1292,7 +1301,12 @@ let Engine = {
Engine.Clickables.tutorialNetscriptButton = document.getElementById("tutorial-netscript-link"); Engine.Clickables.tutorialNetscriptButton = document.getElementById("tutorial-netscript-link");
Engine.Clickables.tutorialNetscriptButton.addEventListener("click", function() { Engine.Clickables.tutorialNetscriptButton.addEventListener("click", function() {
if (Player.bitNodeN === 4 || hasSingularitySF) {
Engine.displayTutorialPage(CONSTANTS.TutorialNetscriptText + CONSTANTS.TutorialSingularityFunctionsText);
} else {
Engine.displayTutorialPage(CONSTANTS.TutorialNetscriptText); Engine.displayTutorialPage(CONSTANTS.TutorialNetscriptText);
}
}); });
Engine.Clickables.tutorialTravelingButton = document.getElementById("tutorial-traveling-link"); Engine.Clickables.tutorialTravelingButton = document.getElementById("tutorial-traveling-link");