mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 05:33:54 +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));
|
return Math.min(1, this.stamina / (0.5 * this.maxStamina));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
canAttemptBlackOp(actionId: IActionIdentifier): BlackOpsAttempt {
|
canAttemptBlackOp(actionId: IActionIdentifier): BlackOpsAttempt {
|
||||||
// Safety measure - don't repeat BlackOps that are already done
|
// Safety measure - don't repeat BlackOps that are already done
|
||||||
if (this.blackops[actionId.name] != null) {
|
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);
|
const action = this.getActionObject(actionId);
|
||||||
@ -151,10 +150,10 @@ export class Bladeburner implements IBladeburner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i > 0 && this.blackops[blackops[i - 1]] == null) {
|
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 {
|
startAction(player: IPlayer, actionId: IActionIdentifier): void {
|
||||||
@ -206,6 +205,9 @@ export class Bladeburner implements IBladeburner {
|
|||||||
this.log(`Error: ${testBlackOp.error}`);
|
this.log(`Error: ${testBlackOp.error}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (testBlackOp.action === undefined) {
|
||||||
|
throw new Error("action should not be null");
|
||||||
|
}
|
||||||
this.actionTimeToComplete = testBlackOp.action.getActionTime(this);
|
this.actionTimeToComplete = testBlackOp.action.getActionTime(this);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
exceptionAlert(e);
|
exceptionAlert(e);
|
||||||
@ -556,9 +558,7 @@ export class Bladeburner implements IBladeburner {
|
|||||||
}
|
}
|
||||||
const pointCost = skill.calculateCost(currentLevel);
|
const pointCost = skill.calculateCost(currentLevel);
|
||||||
if (skill.maxLvl !== 0 && currentLevel >= skill.maxLvl) {
|
if (skill.maxLvl !== 0 && currentLevel >= skill.maxLvl) {
|
||||||
this.postToConsole(
|
this.postToConsole(`This skill ${skill.name} is already at max level (${currentLevel}/${skill.maxLvl}).`);
|
||||||
`This skill ${skill.name} is already at max level (${currentLevel}/${skill.maxLvl}).`,
|
|
||||||
);
|
|
||||||
} else if (this.skillPoints >= pointCost) {
|
} else if (this.skillPoints >= pointCost) {
|
||||||
this.skillPoints -= pointCost;
|
this.skillPoints -= pointCost;
|
||||||
this.upgradeSkill(skill);
|
this.upgradeSkill(skill);
|
||||||
@ -2078,7 +2078,7 @@ export class Bladeburner implements IBladeburner {
|
|||||||
if (actionId.type === ActionTypes["BlackOp"]) {
|
if (actionId.type === ActionTypes["BlackOp"]) {
|
||||||
const canRunOp = this.canAttemptBlackOp(actionId);
|
const canRunOp = this.canAttemptBlackOp(actionId);
|
||||||
if (!canRunOp.isAvailable) {
|
if (!canRunOp.isAvailable) {
|
||||||
workerScript.log("bladeburner.startAction", () => canRunOp.error);
|
workerScript.log("bladeburner.startAction", () => canRunOp.error + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,10 @@ export function Root(props: IProps): React.ReactElement {
|
|||||||
// Generates a new model for the script
|
// Generates a new model for the script
|
||||||
function regenerateModel(script: OpenScript): void {
|
function regenerateModel(script: OpenScript): void {
|
||||||
if (monacoRef.current !== null) {
|
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;
|
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) {
|
if (!files.length && currentScript !== null) {
|
||||||
// Open currentscript
|
// Open currentscript
|
||||||
regenerateModel(currentScript);
|
regenerateModel(currentScript);
|
||||||
editorRef.current.setModel(currentScript.model);
|
editorRef.current.setModel(currentScript.model);
|
||||||
editorRef.current.setPosition(currentScript.lastPosition);
|
editorRef.current.setPosition(currentScript.lastPosition);
|
||||||
editorRef.current.revealLineInCenter(currentScript.lastPosition.lineNumber);
|
editorRef.current.revealLineInCenter(currentScript.lastPosition.lineNumber);
|
||||||
updateRAM(currentScript.code);
|
updateRAM(currentScript.code);
|
||||||
editorRef.current.focus();
|
editorRef.current.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!files.length) {
|
if (!files.length) {
|
||||||
editorRef.current.focus();
|
editorRef.current.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [filename, code] of files) {
|
for (const [filename, code] of files) {
|
||||||
// Check if file is already opened
|
// Check if file is already opened
|
||||||
const openScript = openScripts.find(
|
const openScript = openScripts.find(
|
||||||
(script) => script.fileName === filename && script.hostname === props.hostname,
|
(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"),
|
|
||||||
);
|
);
|
||||||
setOpenScripts((oldArray) => [...oldArray, newScript]);
|
if (openScript) {
|
||||||
setCurrentScript({ ...newScript });
|
// Script is already opened
|
||||||
editorRef.current.setModel(newScript.model);
|
if (openScript.model === undefined || openScript.model === null || openScript.model.isDisposed()) {
|
||||||
updateRAM(newScript.code);
|
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
|
// 5px padding for top of editor
|
||||||
// 44px bottom tool bar + 16px margin
|
// 44px bottom tool bar + 16px margin
|
||||||
// + vim bar 34px
|
// + vim bar 34px
|
||||||
const editorHeight = dimensions.height - (112 + (options.vim ? 34 : 0));
|
const editorHeight = dimensions.height - (130 + (options.vim ? 34 : 0));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -110,6 +110,23 @@ export function TutorialRoot(props: IProps): React.ReactElement {
|
|||||||
>
|
>
|
||||||
<Typography>NS1 vs NS2 (or .script vs .js)</Typography>
|
<Typography>NS1 vs NS2 (or .script vs .js)</Typography>
|
||||||
</Link>
|
</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>
|
</Box>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -15,6 +15,7 @@ import { workerScripts } from "../../Netscript/WorkerScripts";
|
|||||||
import { startWorkerScript } from "../../NetscriptWorker";
|
import { startWorkerScript } from "../../NetscriptWorker";
|
||||||
import { GetServer } from "../../Server/AllServers";
|
import { GetServer } from "../../Server/AllServers";
|
||||||
import { Theme } from "@mui/material";
|
import { Theme } from "@mui/material";
|
||||||
|
import { findRunningScript } from "../../Script/ScriptHelpers";
|
||||||
|
|
||||||
let layerCounter = 0;
|
let layerCounter = 0;
|
||||||
|
|
||||||
@ -102,6 +103,7 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
function LogWindow(props: IProps): React.ReactElement {
|
function LogWindow(props: IProps): React.ReactElement {
|
||||||
|
const [script, setScript] = useState(props.script);
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const container = useRef<HTMLDivElement>(null);
|
const container = useRef<HTMLDivElement>(null);
|
||||||
const setRerender = useState(false)[1];
|
const setRerender = useState(false)[1];
|
||||||
@ -116,13 +118,18 @@ function LogWindow(props: IProps): React.ReactElement {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function kill(): void {
|
function kill(): void {
|
||||||
killWorkerScript(props.script, props.script.server, true);
|
killWorkerScript(script, script.server, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function run(): void {
|
function run(): void {
|
||||||
const server = GetServer(props.script.server);
|
const server = GetServer(script.server);
|
||||||
if (server === null) return;
|
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 {
|
function updateLayer(): void {
|
||||||
@ -135,7 +142,7 @@ function LogWindow(props: IProps): React.ReactElement {
|
|||||||
|
|
||||||
function title(): string {
|
function title(): string {
|
||||||
const maxLength = 30;
|
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) {
|
if (t.length <= maxLength) {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@ -183,8 +190,8 @@ function LogWindow(props: IProps): React.ReactElement {
|
|||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Box position="absolute" right={0}>
|
<Box position="absolute" right={0}>
|
||||||
{!workerScripts.has(props.script.pid) && <Button onClick={run}>Run</Button>}
|
{!workerScripts.has(script.pid) && <Button onClick={run}>Run</Button>}
|
||||||
{workerScripts.has(props.script.pid) && <Button onClick={kill}>Kill</Button>}
|
{workerScripts.has(script.pid) && <Button onClick={kill}>Kill</Button>}
|
||||||
<Button onClick={props.onClose}>Close</Button>
|
<Button onClick={props.onClose}>Close</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
@ -201,7 +208,7 @@ function LogWindow(props: IProps): React.ReactElement {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
{props.script.logs.map(
|
{script.logs.map(
|
||||||
(line: string, i: number): JSX.Element => (
|
(line: string, i: number): JSX.Element => (
|
||||||
<Typography key={i} className={lineClass(line)}>
|
<Typography key={i} className={lineClass(line)}>
|
||||||
{line}
|
{line}
|
||||||
|
Loading…
Reference in New Issue
Block a user