mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 04:05:46 +01:00
fix editor not loading
This commit is contained in:
parent
79eb2f7e0b
commit
41593e0dce
36
dist/vendor.bundle.js
vendored
36
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -119,11 +119,10 @@ export class Bladeburner implements IBladeburner {
|
||||
return Math.min(1, this.stamina / (0.5 * this.maxStamina));
|
||||
}
|
||||
|
||||
|
||||
canAttemptBlackOp(actionId: IActionIdentifier): BlackOpsAttempt {
|
||||
// Safety measure - don't repeat BlackOps that are already done
|
||||
if (this.blackops[actionId.name] != null) {
|
||||
return { error: "Tried to start a Black Operation that had already been completed" }
|
||||
return { error: "Tried to start a Black Operation that had already been completed" };
|
||||
}
|
||||
|
||||
const action = this.getActionObject(actionId);
|
||||
@ -151,10 +150,10 @@ export class Bladeburner implements IBladeburner {
|
||||
}
|
||||
|
||||
if (i > 0 && this.blackops[blackops[i - 1]] == null) {
|
||||
return { error: `Preceding Black Op must be completed before starting '${actionId.name}'.` }
|
||||
return { error: `Preceding Black Op must be completed before starting '${actionId.name}'.` };
|
||||
}
|
||||
|
||||
return { isAvailable: true, action }
|
||||
return { isAvailable: true, action };
|
||||
}
|
||||
|
||||
startAction(player: IPlayer, actionId: IActionIdentifier): void {
|
||||
@ -206,6 +205,9 @@ export class Bladeburner implements IBladeburner {
|
||||
this.log(`Error: ${testBlackOp.error}`);
|
||||
break;
|
||||
}
|
||||
if (testBlackOp.action === undefined) {
|
||||
throw new Error("action should not be null");
|
||||
}
|
||||
this.actionTimeToComplete = testBlackOp.action.getActionTime(this);
|
||||
} catch (e: any) {
|
||||
exceptionAlert(e);
|
||||
@ -556,9 +558,7 @@ export class Bladeburner implements IBladeburner {
|
||||
}
|
||||
const pointCost = skill.calculateCost(currentLevel);
|
||||
if (skill.maxLvl !== 0 && currentLevel >= skill.maxLvl) {
|
||||
this.postToConsole(
|
||||
`This skill ${skill.name} is already at max level (${currentLevel}/${skill.maxLvl}).`,
|
||||
);
|
||||
this.postToConsole(`This skill ${skill.name} is already at max level (${currentLevel}/${skill.maxLvl}).`);
|
||||
} else if (this.skillPoints >= pointCost) {
|
||||
this.skillPoints -= pointCost;
|
||||
this.upgradeSkill(skill);
|
||||
@ -2078,7 +2078,7 @@ export class Bladeburner implements IBladeburner {
|
||||
if (actionId.type === ActionTypes["BlackOp"]) {
|
||||
const canRunOp = this.canAttemptBlackOp(actionId);
|
||||
if (!canRunOp.isAvailable) {
|
||||
workerScript.log("bladeburner.startAction", () => canRunOp.error);
|
||||
workerScript.log("bladeburner.startAction", () => canRunOp.error + "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,10 @@ export function Root(props: IProps): React.ReactElement {
|
||||
// Generates a new model for the script
|
||||
function regenerateModel(script: OpenScript): void {
|
||||
if (monacoRef.current !== null) {
|
||||
script.model = monacoRef.current.editor.createModel(script.code, script.fileName.endsWith(".txt") ? "plaintext" : "javascript");
|
||||
script.model = monacoRef.current.editor.createModel(
|
||||
script.code,
|
||||
script.fileName.endsWith(".txt") ? "plaintext" : "javascript",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,53 +333,55 @@ export function Root(props: IProps): React.ReactElement {
|
||||
|
||||
if (editorRef.current === null || monacoRef.current === null) return;
|
||||
|
||||
const files = Object.entries(props.files);
|
||||
if (props.files) {
|
||||
const files = Object.entries(props.files);
|
||||
|
||||
if (!files.length && currentScript !== null) {
|
||||
// Open currentscript
|
||||
regenerateModel(currentScript);
|
||||
editorRef.current.setModel(currentScript.model);
|
||||
editorRef.current.setPosition(currentScript.lastPosition);
|
||||
editorRef.current.revealLineInCenter(currentScript.lastPosition.lineNumber);
|
||||
updateRAM(currentScript.code);
|
||||
editorRef.current.focus();
|
||||
return;
|
||||
}
|
||||
if (!files.length && currentScript !== null) {
|
||||
// Open currentscript
|
||||
regenerateModel(currentScript);
|
||||
editorRef.current.setModel(currentScript.model);
|
||||
editorRef.current.setPosition(currentScript.lastPosition);
|
||||
editorRef.current.revealLineInCenter(currentScript.lastPosition.lineNumber);
|
||||
updateRAM(currentScript.code);
|
||||
editorRef.current.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!files.length) {
|
||||
editorRef.current.focus();
|
||||
return;
|
||||
}
|
||||
if (!files.length) {
|
||||
editorRef.current.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
for (const [filename, code] of files) {
|
||||
// Check if file is already opened
|
||||
const openScript = openScripts.find(
|
||||
(script) => script.fileName === filename && script.hostname === props.hostname,
|
||||
);
|
||||
if (openScript) {
|
||||
// Script is already opened
|
||||
if (openScript.model === undefined || openScript.model === null || openScript.model.isDisposed()) {
|
||||
regenerateModel(openScript);
|
||||
}
|
||||
|
||||
setCurrentScript(openScript);
|
||||
editorRef.current.setModel(openScript.model);
|
||||
editorRef.current.setPosition(openScript.lastPosition);
|
||||
editorRef.current.revealLineInCenter(openScript.lastPosition.lineNumber);
|
||||
updateRAM(openScript.code);
|
||||
} else {
|
||||
// Open script
|
||||
const newScript = new OpenScript(
|
||||
filename,
|
||||
code,
|
||||
props.hostname,
|
||||
new monacoRef.current.Position(0, 0),
|
||||
monacoRef.current.editor.createModel(code, filename.endsWith(".txt") ? "plaintext" : "javascript"),
|
||||
for (const [filename, code] of files) {
|
||||
// Check if file is already opened
|
||||
const openScript = openScripts.find(
|
||||
(script) => script.fileName === filename && script.hostname === props.hostname,
|
||||
);
|
||||
setOpenScripts((oldArray) => [...oldArray, newScript]);
|
||||
setCurrentScript({ ...newScript });
|
||||
editorRef.current.setModel(newScript.model);
|
||||
updateRAM(newScript.code);
|
||||
if (openScript) {
|
||||
// Script is already opened
|
||||
if (openScript.model === undefined || openScript.model === null || openScript.model.isDisposed()) {
|
||||
regenerateModel(openScript);
|
||||
}
|
||||
|
||||
setCurrentScript(openScript);
|
||||
editorRef.current.setModel(openScript.model);
|
||||
editorRef.current.setPosition(openScript.lastPosition);
|
||||
editorRef.current.revealLineInCenter(openScript.lastPosition.lineNumber);
|
||||
updateRAM(openScript.code);
|
||||
} else {
|
||||
// Open script
|
||||
const newScript = new OpenScript(
|
||||
filename,
|
||||
code,
|
||||
props.hostname,
|
||||
new monacoRef.current.Position(0, 0),
|
||||
monacoRef.current.editor.createModel(code, filename.endsWith(".txt") ? "plaintext" : "javascript"),
|
||||
);
|
||||
setOpenScripts((oldArray) => [...oldArray, newScript]);
|
||||
setCurrentScript({ ...newScript });
|
||||
editorRef.current.setModel(newScript.model);
|
||||
updateRAM(newScript.code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -671,7 +676,7 @@ export function Root(props: IProps): React.ReactElement {
|
||||
// 5px padding for top of editor
|
||||
// 44px bottom tool bar + 16px margin
|
||||
// + vim bar 34px
|
||||
const editorHeight = dimensions.height - (112 + (options.vim ? 34 : 0));
|
||||
const editorHeight = dimensions.height - (130 + (options.vim ? 34 : 0));
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -110,6 +110,23 @@ export function TutorialRoot(props: IProps): React.ReactElement {
|
||||
>
|
||||
<Typography>NS1 vs NS2 (or .script vs .js)</Typography>
|
||||
</Link>
|
||||
<br />
|
||||
<Link
|
||||
color="primary"
|
||||
target="_blank"
|
||||
href="https://bitburner.readthedocs.io/en/latest/netscript/netscriptfunctions.html"
|
||||
>
|
||||
<Typography>Simplified list of functions</Typography>
|
||||
</Link>
|
||||
|
||||
<br />
|
||||
<Link
|
||||
color="primary"
|
||||
target="_blank"
|
||||
href="https://github.com/danielyxie/bitburner/blob/dev/markdown/bitburner.ns.md"
|
||||
>
|
||||
<Typography>Complete list of functions</Typography>
|
||||
</Link>
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
|
@ -15,6 +15,7 @@ import { workerScripts } from "../../Netscript/WorkerScripts";
|
||||
import { startWorkerScript } from "../../NetscriptWorker";
|
||||
import { GetServer } from "../../Server/AllServers";
|
||||
import { Theme } from "@mui/material";
|
||||
import { findRunningScript } from "../../Script/ScriptHelpers";
|
||||
|
||||
let layerCounter = 0;
|
||||
|
||||
@ -102,6 +103,7 @@ const useStyles = makeStyles((theme: Theme) =>
|
||||
);
|
||||
|
||||
function LogWindow(props: IProps): React.ReactElement {
|
||||
const [script, setScript] = useState(props.script);
|
||||
const classes = useStyles();
|
||||
const container = useRef<HTMLDivElement>(null);
|
||||
const setRerender = useState(false)[1];
|
||||
@ -116,13 +118,18 @@ function LogWindow(props: IProps): React.ReactElement {
|
||||
}, []);
|
||||
|
||||
function kill(): void {
|
||||
killWorkerScript(props.script, props.script.server, true);
|
||||
killWorkerScript(script, script.server, true);
|
||||
}
|
||||
|
||||
function run(): void {
|
||||
const server = GetServer(props.script.server);
|
||||
const server = GetServer(script.server);
|
||||
if (server === null) return;
|
||||
startWorkerScript(props.script, server);
|
||||
const s = findRunningScript(script.filename, script.args, server);
|
||||
if (s === null) {
|
||||
startWorkerScript(script, server);
|
||||
} else {
|
||||
setScript(s);
|
||||
}
|
||||
}
|
||||
|
||||
function updateLayer(): void {
|
||||
@ -135,7 +142,7 @@ function LogWindow(props: IProps): React.ReactElement {
|
||||
|
||||
function title(): string {
|
||||
const maxLength = 30;
|
||||
const t = `${props.script.filename} ${props.script.args.map((x: any): string => `${x}`).join(" ")}`;
|
||||
const t = `${script.filename} ${script.args.map((x: any): string => `${x}`).join(" ")}`;
|
||||
if (t.length <= maxLength) {
|
||||
return t;
|
||||
}
|
||||
@ -183,8 +190,8 @@ function LogWindow(props: IProps): React.ReactElement {
|
||||
</Typography>
|
||||
|
||||
<Box position="absolute" right={0}>
|
||||
{!workerScripts.has(props.script.pid) && <Button onClick={run}>Run</Button>}
|
||||
{workerScripts.has(props.script.pid) && <Button onClick={kill}>Kill</Button>}
|
||||
{!workerScripts.has(script.pid) && <Button onClick={run}>Run</Button>}
|
||||
{workerScripts.has(script.pid) && <Button onClick={kill}>Kill</Button>}
|
||||
<Button onClick={props.onClose}>Close</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
@ -201,7 +208,7 @@ function LogWindow(props: IProps): React.ReactElement {
|
||||
}
|
||||
>
|
||||
<Box>
|
||||
{props.script.logs.map(
|
||||
{script.logs.map(
|
||||
(line: string, i: number): JSX.Element => (
|
||||
<Typography key={i} className={lineClass(line)}>
|
||||
{line}
|
||||
|
Loading…
Reference in New Issue
Block a user