Added BitNode multipliers for purchased servers. Fixed bugs in new Script Editor implementation. Added documentation for script editors

This commit is contained in:
danielyxie
2019-01-29 22:02:27 -08:00
parent d54f0906f0
commit a09ea46a38
31 changed files with 3355 additions and 2558 deletions
+22 -4
View File
@@ -18,6 +18,7 @@ require("brace/ext/language_tools");
import { NetscriptFunctions } from "../NetscriptFunctions";
import { Settings } from "../Settings/Settings";
import { AceKeybindingSetting } from "../Settings/SettingEnums";
import { clearEventListeners } from "../../utils/uiHelpers/clearEventListeners";
import { createElement } from "../../utils/uiHelpers/createElement";
@@ -43,6 +44,7 @@ function validateInitializationParamters(params) {
class AceEditorWrapper extends ScriptEditor {
constructor() {
super();
this.vimCommandDisplayWrapper = null;
}
init(params) {
@@ -73,7 +75,7 @@ class AceEditorWrapper extends ScriptEditor {
editorElement.style.fontSize = '16px';
this.editor.setOption("showPrintMargin", false);
//Configure some of the VIM keybindings
// Configure some of the VIM keybindings
ace.config.loadModule('ace/keyboard/vim', function(module) {
var VimApi = module.CodeMirror.Vim;
VimApi.defineEx('write', 'w', function(cm, input) {
@@ -90,6 +92,13 @@ class AceEditorWrapper extends ScriptEditor {
});
});
// Store a reference to the VIM command display
this.vimCommandDisplayWrapper = document.getElementById("codemirror-vim-command-display-wrapper");
if (this.vimCommandDisplayWrapper == null) {
console.error(`Could not get Vim Command Display element (id=codemirror-vim-command-display-wrapper)`);
return false;
}
//Function autocompleter
this.editor.setOption("enableBasicAutocompletion", true);
var autocompleter = {
@@ -160,6 +169,11 @@ class AceEditorWrapper extends ScriptEditor {
elem.style.display = "block";
}
// Make sure the Vim command display from CodeMirror is invisible
if (this.vimCommandDisplayWrapper instanceof HTMLElement) {
this.vimCommandDisplayWrapper.style.display = "none";
}
// Theme
const themeDropdown = safeClearEventListeners("script-editor-option-theme", "Theme Selector");
removeChildrenFromElement(themeDropdown);
@@ -195,10 +209,14 @@ class AceEditorWrapper extends ScriptEditor {
// Keybinding
const keybindingDropdown = safeClearEventListeners("script-editor-option-keybinding", "Keybinding Selector");
removeChildrenFromElement(keybindingDropdown);
keybindingDropdown.add(createOptionElement("Ace", "ace"));
keybindingDropdown.add(createOptionElement("Vim", "vim"));
keybindingDropdown.add(createOptionElement("Emacs", "emacs"));
keybindingDropdown.add(createOptionElement("Ace", AceKeybindingSetting.Ace));
keybindingDropdown.add(createOptionElement("Vim", AceKeybindingSetting.Vim));
keybindingDropdown.add(createOptionElement("Emacs", AceKeybindingSetting.Emacs));
if (Settings.EditorKeybinding) {
// Sanitize the Keybinding setting
if (!(Object.values(AceKeybindingSetting).includes(Settings.EditorKeybinding))) {
Settings.EditorKeybinding = AceKeybindingSetting.Ace;
}
var initialIndex = 0;
for (var i = 0; i < keybindingDropdown.options.length; ++i) {
if (keybindingDropdown.options[i].value === Settings.EditorKeybinding) {
+66 -12
View File
@@ -71,6 +71,8 @@ import 'codemirror/keymap/vim.js';
import 'codemirror/keymap/emacs.js';
import 'codemirror/addon/comment/continuecomment.js';
import 'codemirror/addon/dialog/dialog.css';
import 'codemirror/addon/dialog/dialog.js';
import 'codemirror/addon/edit/closebrackets.js';
import 'codemirror/addon/edit/matchbrackets.js';
import 'codemirror/addon/fold/foldcode.js';
@@ -79,6 +81,7 @@ import 'codemirror/addon/fold/foldgutter.css';
import 'codemirror/addon/fold/brace-fold.js';
import 'codemirror/addon/fold/indent-fold.js';
import 'codemirror/addon/fold/comment-fold.js';
import 'codemirror/addon/hint/javascript-hint.js';
import 'codemirror/addon/hint/show-hint.js';
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/addon/lint/lint.js';
@@ -87,10 +90,11 @@ import 'codemirror/addon/search/match-highlighter.js';
import 'codemirror/addon/selection/active-line.js';
window.JSHINT = require('jshint').JSHINT;
import './CodeMirrorNetscriptHint.js';
import './CodeMirrorNetscriptLint.js';
import { NetscriptFunctions } from "../NetscriptFunctions";
import { CodeMirrorThemeSetting } from "../Settings/SettingEnums";
import { CodeMirrorKeybindingSetting,
CodeMirrorThemeSetting } from "../Settings/SettingEnums";
import { Settings } from "../Settings/Settings";
import { clearEventListeners } from "../../utils/uiHelpers/clearEventListeners";
@@ -114,6 +118,8 @@ function validateInitializationParamters(params) {
class CodeMirrorEditorWrapper extends ScriptEditor {
constructor() {
super();
this.vimCommandDisplay = null;
this.vimCommandDisplayWrapper = null;
this.tabsStyleElement = null;
}
@@ -160,6 +166,10 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
this.tabsStyleElement = document.createElement('style');
document.head.appendChild(this.tabsStyleElement);
// Store a reference to the VIM command display
this.vimCommandDisplay = document.getElementById("codemirror-vim-command-display");
this.vimCommandDisplayWrapper = document.getElementById("codemirror-vim-command-display-wrapper");
// Define a "Save" command for CodeMirror so shortcuts like Ctrl + s
// will save in-game
CodeMirror.commands.save = function() { params.saveAndCloseFn(); }
@@ -206,6 +216,21 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
return result;
};
// Configure VIM keybindings
var VimApi = CodeMirror.Vim;
VimApi.defineEx('write', 'w', function(cm, input) {
params.saveAndCloseFn();
});
VimApi.defineEx('quit', 'q', function(cm, input) {
params.quitFn();
});
VimApi.defineEx('xwritequit', 'x', function(cm, input) {
params.saveAndCloseFn();
});
VimApi.defineEx('wqwritequit', 'wq', function(cm, input) {
params.saveAndCloseFn();
});
}
initialized() {
@@ -237,6 +262,11 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
return;
}
// Get and sanitize the keybinding (keymap) setting
if (!(Object.values(CodeMirrorKeybindingSetting).includes(Settings.EditorKeybinding))) {
Settings.EditorKeybinding = CodeMirrorKeybindingSetting.Default;
}
// Initialize CodeMirror Editor
const textAreaElement = safeGetElementById("codemirror-editor", "CodeMirror Textarea");
const formElement = safeGetElementById("codemirror-form-wrapper", "CodeMirror Form Wrapper");
@@ -294,10 +324,10 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
return false;
}
removeChildrenFromElement(keybindingDropdown);
keybindingDropdown.add(createOptionElement("Default", "default"));
keybindingDropdown.add(createOptionElement("Sublime", "sublime"));
keybindingDropdown.add(createOptionElement("Vim", "vim"));
keybindingDropdown.add(createOptionElement("Emacs", "emacs"));
keybindingDropdown.add(createOptionElement("Default", CodeMirrorKeybindingSetting.Default));
keybindingDropdown.add(createOptionElement("Sublime", CodeMirrorKeybindingSetting.Sublime));
keybindingDropdown.add(createOptionElement("Vim", CodeMirrorKeybindingSetting.Vim));
keybindingDropdown.add(createOptionElement("Emacs", CodeMirrorKeybindingSetting.Emacs));
if (Settings.EditorKeybinding) {
var initialIndex = 0;
for (var i = 0; i < keybindingDropdown.options.length; ++i) {
@@ -311,14 +341,39 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
keybindingDropdown.selectedIndex = 0;
}
keybindingDropdown.onchange = () => {
// Set Vim command display to be invisible initially
this.vimCommandDisplayWrapper.style.display = "none";
const val = keybindingDropdown.value;
Settings.EditorKeybinding = val;
this.editor.removeKeyMap("sublime");
this.editor.removeKeyMap("emacs");
this.editor.removeKeyMap("vim");
this.editor.removeKeyMap(CodeMirror.keyMap.default);
this.editor.removeKeyMap(CodeMirror.keyMap.sublime);
this.editor.removeKeyMap(CodeMirror.keyMap.emacs);
this.editor.removeKeyMap(CodeMirror.keyMap.vim);
// Setup the VIM command display
let keys = '';
const handleVimKeyPress = (key) => {
keys = keys + key;
this.vimCommandDisplay.innerHTML = keys;
}
const handleVimCommandDone = (e) => {
keys = '';
this.vimCommandDisplay.innerHTML = keys;
}
if (val === CodeMirrorKeybindingSetting.Vim) {
this.vimCommandDisplayWrapper.style.display = "block";
this.editor.on('vim-keypress', handleVimKeyPress);
this.editor.on('vim-command-done', handleVimCommandDone);
} else {
this.vimCommandDisplayWrapper.style.display = "none";
this.editor.off('vim-keypress', handleVimKeyPress);
this.editor.off('vim-command-done', handleVimCommandDone);
}
this.editor.addKeyMap(val);
this.editor.setOption("keyMap", val);
console.log(`Set keymap to ${val} for CodeMirror`);
};
keybindingDropdown.onchange();
@@ -489,9 +544,8 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
removeFlexibleOption("script-editor-option-flex4-fieldset");
this.editor.refresh();
console.log(this.editor.options);
} catch(e) {
console.error(`Exception caught: ${e}`);
console.error(`Exception caught: ${e}. ${e.stack}`);
return false;
}
}
@@ -33,8 +33,12 @@
}
const sanitizedText = splitText.join("\n");
// Configure JSHINT options
if (!options.indent) // JSHint error.character actually is a column index, this fixes underlining on lines using tabs for indentation
options.indent = 1; // JSHint default value is 4
options.esversion = 6;
JSHINT(sanitizedText, options, options.globals);
var errors = JSHINT.data().errors, result = [];
if (errors) parseErrors(errors, result);