mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 01:33:54 +01:00
Adding script editor options and some bug fixes
This commit is contained in:
parent
0f5d2a7c6a
commit
3296a817fd
@ -36,12 +36,10 @@
|
||||
}
|
||||
|
||||
#javascript-editor textarea {
|
||||
color: var(--my-font-color);
|
||||
}
|
||||
|
||||
.ace_line,
|
||||
.ace_line * {
|
||||
color: var(--my-font-color);
|
||||
background-color:transparent;
|
||||
margin:0px;
|
||||
padding:0px;
|
||||
@ -140,6 +138,26 @@
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
#script-editor-options-panel {
|
||||
position:absolute;
|
||||
right: 9%;
|
||||
bottom:15%;
|
||||
border:2px solid white;
|
||||
width:19%;
|
||||
background-color:#444;
|
||||
padding:2px;
|
||||
overflow:auto;
|
||||
z-index: 1;
|
||||
color: white;
|
||||
}
|
||||
|
||||
#script-editor-options-panel fieldset {
|
||||
margin-top:8px;
|
||||
margin-bottom:8px;
|
||||
padding: 2px;
|
||||
font-size:12px;
|
||||
}
|
||||
|
||||
/* Active scripts */
|
||||
.active-scripts-list {
|
||||
list-style-type: none;
|
||||
@ -406,6 +424,7 @@
|
||||
margin: 6px;
|
||||
display: inline-block;
|
||||
color: var(--my-font-color);
|
||||
background-color:black;
|
||||
}
|
||||
|
||||
#faction-donate-amount-txt {
|
||||
|
17399
dist/bundle.js
vendored
17399
dist/bundle.js
vendored
File diff suppressed because one or more lines are too long
41
index.html
41
index.html
@ -105,6 +105,47 @@
|
||||
<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 id="script-editor-options-panel">
|
||||
<h1 style="color:white;"> Script Editor Options </h1>
|
||||
<fieldset>
|
||||
<label for="script-editor-option-theme">Theme</label>
|
||||
<select id="script-editor-option-theme">
|
||||
<option value="Chaos">Chaos</option>
|
||||
<option value="Chrome">Chrome</option>
|
||||
<option value="Monokai">Monokai</option>
|
||||
<option value="Solarized_Dark">Solarized Dark</option>
|
||||
<option value="Solarized_Light">Solarized Light</option>
|
||||
<option value="Terminal">Terminal</option>
|
||||
<option value="Twilight">Twilight</option>
|
||||
<option value="XCode">XCode</option>
|
||||
</select>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label for="script-editor-option-keybinding">Key Binding</label>
|
||||
<select id="script-editor-option-keybinding">
|
||||
<option value="ace">Ace</option>
|
||||
<option value="vim">Vim</option>
|
||||
<option value="emacs">Emacs</option>
|
||||
</select>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label for="script-editor-option-highlightactiveline">Highlight Active Line</label>
|
||||
<input type="checkbox" name="script-editor-option-highlightactiveline" id="script-editor-option-highlightactiveline" checked>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label for="script-editor-option-showinvisibles">Show Invisibles</label></td>
|
||||
<input type="checkbox" name="script-editor-option-showinvisibles" id="script-editor-option-showinvisibles">
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label for="script-editor-option-usesofttab">Use Soft Tab</label></td>
|
||||
<input type="checkbox" name="script-editor-option-usesofttab" id="script-editor-option-usesofttab" checked>
|
||||
</fieldset>
|
||||
</div> <!-- End script editor options panel -->
|
||||
</div>
|
||||
|
||||
<!-- Terminal page -->
|
||||
|
@ -849,7 +849,7 @@ function purchaseAugmentationBoxCreate(aug, fac) {
|
||||
yesNoBoxClose();
|
||||
});
|
||||
|
||||
yesNoBoxCreate("<h2>aug.name</h2><br>" +
|
||||
yesNoBoxCreate("<h2>" + aug.name + "</h2><br>" +
|
||||
aug.info + "<br><br>" +
|
||||
"<br>Would you like to purchase the " + aug.name + " Augmentation for $" +
|
||||
formatNumber(aug.baseCost * fac.augmentationPriceMult, 2) + "?");
|
||||
|
@ -235,8 +235,12 @@ Gang.prototype.processGains = function(numCycles=1) {
|
||||
console.log("ERROR: respectGains is NaN");
|
||||
}
|
||||
if (!isNaN(wantedLevelGains)) {
|
||||
this.wanted += (wantedLevelGains * this.storedCycles);
|
||||
if (this.wanted < 1) {this.wanted = 1;}
|
||||
if (this.wanted === 1 && wantedLevelGains < 0) {
|
||||
//Do nothing
|
||||
} else {
|
||||
this.wanted += (wantedLevelGains * this.storedCycles);
|
||||
if (this.wanted < 1) {this.wanted = 1;}
|
||||
}
|
||||
} else {
|
||||
console.log("ERROR: wantedLevelGains is NaN");
|
||||
}
|
||||
|
@ -13,11 +13,10 @@ import {isValidIPAddress} from "../utils/IPAddress.js";
|
||||
import {isString} from "../utils/StringHelperFunctions.js";
|
||||
|
||||
/* Evaluator
|
||||
* Evaluates the Abstract Syntax Tree for Netscript
|
||||
* generated by the Parser class
|
||||
* Evaluates/Interprets the Abstract Syntax Tree generated by Acorns parser
|
||||
*
|
||||
* Returns a promise
|
||||
*/
|
||||
// Evaluator should return a Promise, so that any call to evaluate() can just
|
||||
//wait for that promise to finish before continuing
|
||||
function evaluate(exp, workerScript) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var env = workerScript.env;
|
||||
@ -196,11 +195,11 @@ function evaluate(exp, workerScript) {
|
||||
resolve(false);
|
||||
break;
|
||||
case "ReturnStatement":
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Not implemented ReturnStatement"));
|
||||
var lineNum = getErrorLineNumber(exp, workerScript);
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Return statements are not yet implemented in Netscript (line " + (lineNum+1) + ")"));
|
||||
break;
|
||||
case "BreakStatement":
|
||||
reject("BREAKSTATEMENT");
|
||||
//reject(makeRuntimeRejectMsg(workerScript, "Not implemented BreakStatement"));
|
||||
break;
|
||||
case "IfStatement":
|
||||
evaluateIf(exp, workerScript).then(function(forLoopRes) {
|
||||
@ -210,7 +209,8 @@ function evaluate(exp, workerScript) {
|
||||
});
|
||||
break;
|
||||
case "SwitchStatement":
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Not implemented SwitchStatement"));
|
||||
var lineNum = getErrorLineNumber(exp, workerScript);
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Switch statements are not yet implemented in Netscript (line " + (lineNum+1) + ")"));
|
||||
break;e
|
||||
case "WhileStatement":
|
||||
evaluateWhile(exp, workerScript).then(function(forLoopRes) {
|
||||
@ -239,7 +239,8 @@ function evaluate(exp, workerScript) {
|
||||
});
|
||||
break;
|
||||
default:
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Unrecognized token: " + exp.type + ". This is currently unsupported in Netscript"));
|
||||
var lineNum = getErrorLineNumber(exp, workerScript);
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Unrecognized token: " + exp.type + " (line " + (lineNum+1) + "). This is currently unsupported in Netscript"));
|
||||
break;
|
||||
} //End switch
|
||||
}, Settings.CodeInstructionRunTime); //End setTimeout, the Netscript operation run time
|
||||
@ -644,6 +645,15 @@ function runScriptFromScript(server, scriptname, args, workerScript, threads=1)
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
//Takes in a
|
||||
function getErrorLineNumber(exp, workerScript) {
|
||||
var code = workerScript.scriptRef.scriptRef.code;
|
||||
|
||||
//Split code up to the start of the node
|
||||
code = code.substring(0, exp.start);
|
||||
return (code.match(/\n/g) || []).length;
|
||||
}
|
||||
|
||||
function isScriptErrorMessage(msg) {
|
||||
if (!isString(msg)) {return false;}
|
||||
let splitMsg = msg.split("|");
|
||||
|
@ -1,6 +1,15 @@
|
||||
var ace = require('brace');
|
||||
require('brace/mode/javascript');
|
||||
require('brace/theme/chaos');
|
||||
require('brace/theme/chrome');
|
||||
require('brace/theme/monokai');
|
||||
require('brace/theme/solarized_dark');
|
||||
require('brace/theme/solarized_light');
|
||||
require('brace/theme/terminal');
|
||||
require('brace/theme/twilight');
|
||||
require('brace/theme/xcode');
|
||||
require("brace/keybinding/vim");
|
||||
require("brace/keybinding/emacs");
|
||||
|
||||
import {CONSTANTS} from "./Constants.js";
|
||||
import {Engine} from "./engine.js";
|
||||
@ -18,6 +27,12 @@ import {compareArrays} from "../utils/HelperFunctions.j
|
||||
import {formatNumber, numOccurrences,
|
||||
numNetscriptOperators} from "../utils/StringHelperFunctions.js";
|
||||
|
||||
var keybindings = {
|
||||
ace: null,
|
||||
vim: "ace/keyboard/vim",
|
||||
emacs: "ace/keyboard/emacs",
|
||||
};
|
||||
|
||||
function scriptEditorInit() {
|
||||
//Initialize save and close button
|
||||
var closeButton = document.getElementById("script-editor-save-and-close-button");
|
||||
@ -27,25 +42,48 @@ function scriptEditorInit() {
|
||||
return false;
|
||||
});
|
||||
|
||||
//Allow tabs (four spaces) in all textareas
|
||||
var textareas = document.getElementsByTagName('textarea');
|
||||
var count = textareas.length;
|
||||
for(var i=0;i<count;i++){
|
||||
textareas[i].onkeydown = function(e){
|
||||
if(e.keyCode==9 || e.which==9){
|
||||
e.preventDefault();
|
||||
var start = this.selectionStart;
|
||||
var end = this.selectionEnd;
|
||||
//Initialize ACE 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);
|
||||
|
||||
//Set textarea value to: text before caret + four spaces + text after caret
|
||||
let spaces = " ";
|
||||
this.value = this.value.substring(0, start) + spaces + this.value.substring(end);
|
||||
/* Script editor options */
|
||||
//Theme
|
||||
var themeDropdown = document.getElementById("script-editor-option-theme");
|
||||
themeDropdown.selectedIndex = 2;
|
||||
themeDropdown.onchange = function() {
|
||||
var val = themeDropdown.value;
|
||||
var themePath = "ace/theme/" + val.toLowerCase();
|
||||
editor.setTheme(themePath);
|
||||
};
|
||||
|
||||
//Keybinding
|
||||
var keybindingDropdown = document.getElementById("script-editor-option-keybinding");
|
||||
keybindingDropdown.onchange = function() {
|
||||
var val = keybindingDropdown.value;
|
||||
editor.setKeyboardHandler(keybindings[val.toLowerCase()]);
|
||||
};
|
||||
|
||||
//Highlight Active line
|
||||
var highlightActiveChkBox = document.getElementById("script-editor-option-highlightactiveline");
|
||||
highlightActiveChkBox.onchange = function() {
|
||||
editor.setHighlightActiveLine(highlightActiveChkBox.checked);
|
||||
};
|
||||
|
||||
//Show Invisibles
|
||||
var showInvisiblesChkBox = document.getElementById("script-editor-option-showinvisibles");
|
||||
showInvisiblesChkBox.onchange = function() {
|
||||
editor.setShowInvisibles(showInvisiblesChkBox.checked);
|
||||
};
|
||||
|
||||
//Use Soft Tab
|
||||
var softTabChkBox = document.getElementById("script-editor-option-usesofttab");
|
||||
softTabChkBox.onchange = function() {
|
||||
editor.getSession().setUseSoftTabs(softTabChkBox.checked);
|
||||
};
|
||||
|
||||
//Put caret at after the four spaces
|
||||
this.selectionStart = this.selectionEnd = start + spaces.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
document.addEventListener("DOMContentLoaded", scriptEditorInit, false);
|
||||
|
||||
|
@ -1,9 +1,3 @@
|
||||
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 {gameOptionsBoxOpen, gameOptionsBoxClose}from "../utils/GameOptions.js";
|
||||
import {clearEventListeners} from "../utils/HelperFunctions.js";
|
||||
@ -1072,13 +1066,6 @@ let Engine = {
|
||||
},
|
||||
|
||||
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"
|
||||
var terminal = document.getElementById("terminal-tab");
|
||||
var createScript = document.getElementById("create-script-tab");
|
||||
@ -1143,7 +1130,7 @@ let Engine = {
|
||||
processPassiveFactionRepGain(numCyclesOffline);
|
||||
|
||||
//Gang progress for BitNode 2
|
||||
if (Player.bitNodeN != null && Player.bitNodeN == 2 && Player.inGang()) {
|
||||
if (Player.bitNodeN != null && Player.bitNodeN === 2 && Player.inGang()) {
|
||||
Player.gang.process(numCyclesOffline);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user