mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 18:50:56 +02:00
more work on bn13
This commit is contained in:
+5035
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
declare module "!!raw-loader!*" {
|
||||
const contents: { default: string };
|
||||
export = contents;
|
||||
}
|
||||
@@ -42,11 +42,11 @@ export function OptionsModal(props: IProps): React.ReactElement {
|
||||
<Box display="flex" flexDirection="row" alignItems="center">
|
||||
<Typography>Theme: </Typography>
|
||||
<Select onChange={(event) => setTheme(event.target.value)} value={theme}>
|
||||
<MenuItem value="vs-dark">dark</MenuItem>
|
||||
<MenuItem value="light">light</MenuItem>
|
||||
<MenuItem value="monokai">monokai</MenuItem>
|
||||
<MenuItem value="solarized-dark">solarized-dark</MenuItem>
|
||||
<MenuItem value="solarized-light">solarized-light</MenuItem>
|
||||
<MenuItem value="vs-dark">dark</MenuItem>
|
||||
<MenuItem value="light">light</MenuItem>
|
||||
</Select>
|
||||
</Box>
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ import { dialogBoxCreate } from "../../ui/React/DialogBox";
|
||||
import { isScriptFilename } from "../../Script/isScriptFilename";
|
||||
import { Script } from "../../Script/Script";
|
||||
import { TextFile } from "../../TextFile";
|
||||
import { calculateRamUsage } from "../../Script/RamCalculations";
|
||||
import { calculateRamUsage, checkInfiniteLoop } from "../../Script/RamCalculations";
|
||||
import { RamCalculationErrorCode } from "../../Script/RamCalculationErrorCodes";
|
||||
import { numeralWrapper } from "../../ui/numeralFormat";
|
||||
import { CursorPositions } from "../CursorPositions";
|
||||
import { libSource } from "../NetscriptDefinitions";
|
||||
|
||||
import { NetscriptFunctions } from "../../NetscriptFunctions";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
import { Settings } from "../../Settings/Settings";
|
||||
@@ -32,6 +32,8 @@ import TextField from "@mui/material/TextField";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import SettingsIcon from "@mui/icons-material/Settings";
|
||||
|
||||
import libSource from "!!raw-loader!../NetscriptDefinitions.d.ts";
|
||||
|
||||
let symbolsLoaded = false;
|
||||
let symbols: string[] = [];
|
||||
export function SetupTextEditor(): void {
|
||||
@@ -53,7 +55,7 @@ export function SetupTextEditor(): void {
|
||||
}
|
||||
symbols = populate(ns);
|
||||
|
||||
const exclude = ["heart", "break", "exploit", "bypass", "corporation"];
|
||||
const exclude = ["heart", "break", "exploit", "bypass", "corporation", "alterReality"];
|
||||
symbols = symbols.filter((symbol: string) => !exclude.includes(symbol)).sort();
|
||||
}
|
||||
|
||||
@@ -88,6 +90,7 @@ export function Root(props: IProps): React.ReactElement {
|
||||
const editorRef = useRef<IStandaloneCodeEditor | null>(null);
|
||||
const [filename, setFilename] = useState(props.filename ? props.filename : lastFilename);
|
||||
const [code, setCode] = useState<string>(props.filename ? props.code : lastCode);
|
||||
const [decorations, setDecorations] = useState<string[]>([]);
|
||||
hostname = props.filename ? props.hostname : hostname;
|
||||
if (hostname === "") {
|
||||
hostname = props.player.getCurrentServer().hostname;
|
||||
@@ -224,14 +227,46 @@ export function Root(props: IProps): React.ReactElement {
|
||||
setFilename(event.target.value);
|
||||
}
|
||||
|
||||
function infLoop(newCode: string): void {
|
||||
if (editorRef.current === null) return;
|
||||
if (!filename.endsWith(".ns") && !filename.endsWith(".js")) return;
|
||||
const awaitWarning = checkInfiniteLoop(newCode);
|
||||
if (awaitWarning !== -1) {
|
||||
const newDecorations = editorRef.current.deltaDecorations(decorations, [
|
||||
{
|
||||
range: {
|
||||
startLineNumber: awaitWarning,
|
||||
startColumn: 1,
|
||||
endLineNumber: awaitWarning,
|
||||
endColumn: 10,
|
||||
},
|
||||
options: {
|
||||
isWholeLine: true,
|
||||
glyphMarginClassName: "myGlyphMarginClass",
|
||||
glyphMarginHoverMessage: {
|
||||
value: "Possible infinite loop, await something.",
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
setDecorations(newDecorations);
|
||||
} else {
|
||||
const newDecorations = editorRef.current.deltaDecorations(decorations, []);
|
||||
setDecorations(newDecorations);
|
||||
}
|
||||
}
|
||||
|
||||
function updateCode(newCode?: string): void {
|
||||
if (newCode === undefined) return;
|
||||
lastCode = newCode;
|
||||
if (editorRef.current !== null) {
|
||||
lastPosition = editorRef.current.getPosition();
|
||||
}
|
||||
setCode(newCode);
|
||||
updateRAM(newCode);
|
||||
try {
|
||||
if (editorRef.current !== null) {
|
||||
lastPosition = editorRef.current.getPosition();
|
||||
infLoop(newCode);
|
||||
}
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
// calculate it once the first time the file is loaded.
|
||||
@@ -319,7 +354,7 @@ export function Root(props: IProps): React.ReactElement {
|
||||
.find((l: any) => l.id === "javascript")
|
||||
.loader();
|
||||
l.language.tokenizer.root.unshift(["ns", { token: "ns" }]);
|
||||
for (const symbol of symbols) l.language.tokenizer.root.unshift(["\\." + symbol, { token: "netscriptfunction" }]);
|
||||
for (const symbol of symbols) l.language.tokenizer.root.unshift([symbol, { token: "netscriptfunction" }]);
|
||||
const otherKeywords = ["let", "const", "var", "function"];
|
||||
const otherKeyvars = ["true", "false", "null", "undefined"];
|
||||
otherKeywords.forEach((k) => l.language.tokenizer.root.unshift([k, { token: "otherkeywords" }]));
|
||||
@@ -327,8 +362,9 @@ export function Root(props: IProps): React.ReactElement {
|
||||
l.language.tokenizer.root.unshift(["this", { token: "this" }]);
|
||||
})();
|
||||
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, "netscript.d.ts");
|
||||
monaco.languages.typescript.typescriptDefaults.addExtraLib(libSource, "netscript.d.ts");
|
||||
const source = (libSource + "").replace(/export /g, "");
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(source, "netscript.d.ts");
|
||||
monaco.languages.typescript.typescriptDefaults.addExtraLib(source, "netscript.d.ts");
|
||||
loadThemes(monaco);
|
||||
}
|
||||
// 370px 71%, 725px 85.1%, 1085px 90%, 1300px 91.7%
|
||||
@@ -361,7 +397,7 @@ export function Root(props: IProps): React.ReactElement {
|
||||
defaultValue={code}
|
||||
onChange={updateCode}
|
||||
theme={options.theme}
|
||||
options={options}
|
||||
options={{ ...options, glyphMargin: true }}
|
||||
/>
|
||||
<Box display="flex" flexDirection="row" sx={{ m: 1 }} alignItems="center">
|
||||
<Button onClick={beautify}>Beautify</Button>
|
||||
|
||||
@@ -64,7 +64,7 @@ export async function loadThemes(monaco: { editor: any }): Promise<void> {
|
||||
},
|
||||
});
|
||||
|
||||
monaco.editor.defineTheme("solarish-dark", {
|
||||
monaco.editor.defineTheme("solarized-dark", {
|
||||
base: "vs-dark",
|
||||
inherit: true,
|
||||
rules: [
|
||||
@@ -113,16 +113,16 @@ export async function loadThemes(monaco: { editor: any }): Promise<void> {
|
||||
foreground: "268bd2",
|
||||
},
|
||||
{
|
||||
token: "type.identifier.js",
|
||||
foreground: "b58900",
|
||||
token: "type.identifier.js",
|
||||
foreground: "b58900",
|
||||
},
|
||||
{
|
||||
token: "delimiter.square.js",
|
||||
foreground: "0087ff",
|
||||
token: "delimiter.square.js",
|
||||
foreground: "0087ff",
|
||||
},
|
||||
{
|
||||
token: "delimiter.bracket.js",
|
||||
foreground: "0087ff",
|
||||
token: "delimiter.bracket.js",
|
||||
foreground: "0087ff",
|
||||
},
|
||||
{
|
||||
token: "this",
|
||||
@@ -141,13 +141,13 @@ export async function loadThemes(monaco: { editor: any }): Promise<void> {
|
||||
},
|
||||
});
|
||||
|
||||
monaco.editor.defineTheme("solarish-light", {
|
||||
monaco.editor.defineTheme("solarized-light", {
|
||||
base: "vs",
|
||||
inherit: true,
|
||||
rules: [
|
||||
{
|
||||
foreground: "657b83",
|
||||
background: "fdf6e3",
|
||||
background: "fdf6e3",
|
||||
token: "",
|
||||
},
|
||||
{
|
||||
@@ -191,16 +191,16 @@ export async function loadThemes(monaco: { editor: any }): Promise<void> {
|
||||
foreground: "268bd2",
|
||||
},
|
||||
{
|
||||
token: "type.identifier.js",
|
||||
foreground: "b58900",
|
||||
token: "type.identifier.js",
|
||||
foreground: "b58900",
|
||||
},
|
||||
{
|
||||
token: "delimiter.square.js",
|
||||
foreground: "0087ff",
|
||||
token: "delimiter.square.js",
|
||||
foreground: "0087ff",
|
||||
},
|
||||
{
|
||||
token: "delimiter.bracket.js",
|
||||
foreground: "0087ff",
|
||||
token: "delimiter.bracket.js",
|
||||
foreground: "0087ff",
|
||||
},
|
||||
{
|
||||
token: "this",
|
||||
|
||||
Reference in New Issue
Block a user