merge dev

This commit is contained in:
Olivier Gagnon 2021-10-15 21:39:53 -04:00
commit 3e3aa1a0fe
14 changed files with 104 additions and 40 deletions

32
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

@ -339,7 +339,7 @@ export class Bladeburner implements IBladeburner {
action.type = ActionTypes["Hyperbolic Regeneration Chamber"]; action.type = ActionTypes["Hyperbolic Regeneration Chamber"];
action.name = "Hyperbolic Regeneration Chamber"; action.name = "Hyperbolic Regeneration Chamber";
break; break;
case "stir trouble": case "incite violence":
action.type = ActionTypes["Incite Violence"]; action.type = ActionTypes["Incite Violence"];
action.name = "Incite Violence"; action.name = "Incite Violence";
break; break;
@ -1513,6 +1513,8 @@ export class Bladeburner implements IBladeburner {
if (this.logging.general) { if (this.logging.general) {
this.log(`Incited violence in the synthoid communities.`); this.log(`Incited violence in the synthoid communities.`);
} }
const city = this.cities[this.city];
city.chaos *= 2;
this.startAction(player, this.action); this.startAction(player, this.action);
break; break;
} }

@ -647,6 +647,11 @@ export function runScriptFromScript(
return 0; return 0;
} }
args = args.map((arg) => {
if (typeof arg === "number") return arg;
return arg + ""; // force cast to string
});
// Check if the script is already running // Check if the script is already running
const runningScriptObj = server.getRunningScript(scriptname, args); const runningScriptObj = server.getRunningScript(scriptname, args);
if (runningScriptObj != null) { if (runningScriptObj != null) {

@ -58,6 +58,7 @@ import { Reputation } from "../../ui/React/Reputation";
import { Money } from "../../ui/React/Money"; import { Money } from "../../ui/React/Money";
import React from "react"; import React from "react";
import { serverMetadata } from "../../Server/data/servers";
export function init(this: IPlayer): void { export function init(this: IPlayer): void {
/* Initialize Player's home computer */ /* Initialize Player's home computer */
@ -606,7 +607,9 @@ export function process(this: IPlayer, router: IRouter, numCycles = 1): void {
} }
export function cancelationPenalty(this: IPlayer): number { export function cancelationPenalty(this: IPlayer): number {
const server = GetServer(this.companyName); const data = serverMetadata.find((s) => s.specialName === this.companyName);
if (!data) throw new Error("Couldn't find server for company " + this.companyName);
const server = GetServer(data.hostname);
if (server instanceof Server) { if (server instanceof Server) {
if (server && server.backdoorInstalled) return 0.75; if (server && server.backdoorInstalled) return 0.75;
} }

@ -55,12 +55,13 @@ export function SetupTextEditor(): void {
symbols = populate(ns); symbols = populate(ns);
const exclude = ["heart", "break", "exploit", "bypass", "corporation"]; const exclude = ["heart", "break", "exploit", "bypass", "corporation"];
symbols = symbols.filter((symbol: string) => !exclude.includes(symbol)); symbols = symbols.filter((symbol: string) => !exclude.includes(symbol)).sort();
} }
interface IProps { interface IProps {
filename: string; filename: string;
code: string; code: string;
hostname: string;
player: IPlayer; player: IPlayer;
router: IRouter; router: IRouter;
} }
@ -75,17 +76,23 @@ interface IProps {
// https://www.npmjs.com/package/@monaco-editor/react#development-playground // https://www.npmjs.com/package/@monaco-editor/react#development-playground
// https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-custom-languages // https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-custom-languages
// https://github.com/threehams/typescript-error-guide/blob/master/stories/components/Editor.tsx#L11-L39 // https://github.com/threehams/typescript-error-guide/blob/master/stories/components/Editor.tsx#L11-L39
// https://blog.checklyhq.com/customizing-monaco/
// These variables are used to reload a script when it's clicked on. Because we // These variables are used to reload a script when it's clicked on. Because we
// won't have references to the old script. // won't have references to the old script.
let lastFilename = ""; let lastFilename = "";
let lastCode = ""; let lastCode = "";
let hostname = "";
let lastPosition: monaco.Position | null = null; let lastPosition: monaco.Position | null = null;
export function Root(props: IProps): React.ReactElement { export function Root(props: IProps): React.ReactElement {
const editorRef = useRef<IStandaloneCodeEditor | null>(null); const editorRef = useRef<IStandaloneCodeEditor | null>(null);
const [filename, setFilename] = useState(props.filename ? props.filename : lastFilename); const [filename, setFilename] = useState(props.filename ? props.filename : lastFilename);
const [code, setCode] = useState<string>(props.filename ? props.code : lastCode); const [code, setCode] = useState<string>(props.filename ? props.code : lastCode);
hostname = props.filename ? props.hostname : hostname;
if (hostname === "") {
hostname = props.player.getCurrentServer().hostname;
}
const [ram, setRAM] = useState("RAM: ???"); const [ram, setRAM] = useState("RAM: ???");
const [updatingRam, setUpdatingRam] = useState(false); const [updatingRam, setUpdatingRam] = useState(false);
const [optionsOpen, setOptionsOpen] = useState(false); const [optionsOpen, setOptionsOpen] = useState(false);
@ -128,7 +135,7 @@ export function Root(props: IProps): React.ReactElement {
if (ITutorial.isRunning && ITutorial.currStep === iTutorialSteps.TerminalTypeScript) { if (ITutorial.isRunning && ITutorial.currStep === iTutorialSteps.TerminalTypeScript) {
//Make sure filename + code properly follow tutorial //Make sure filename + code properly follow tutorial
if (filename !== "n00dles.script") { if (filename !== "n00dles.script") {
dialogBoxCreate("Leave the script name as 'n00dles'!"); dialogBoxCreate("Leave the script name as 'n00dles.script'!");
return; return;
} }
if (code.replace(/\s/g, "").indexOf("while(true){hack('n00dles');}") == -1) { if (code.replace(/\s/g, "").indexOf("while(true){hack('n00dles');}") == -1) {
@ -142,14 +149,14 @@ export function Root(props: IProps): React.ReactElement {
let found = false; let found = false;
for (let i = 0; i < server.scripts.length; i++) { for (let i = 0; i < server.scripts.length; i++) {
if (filename == server.scripts[i].filename) { if (filename == server.scripts[i].filename) {
server.scripts[i].saveScript(filename, code, props.player.currentServer, server.scripts); server.scripts[i].saveScript(filename, code, hostname, server.scripts);
found = true; found = true;
} }
} }
if (!found) { if (!found) {
const script = new Script(); const script = new Script();
script.saveScript(filename, code, props.player.currentServer, server.scripts); script.saveScript(filename, code, hostname, server.scripts);
server.scripts.push(script); server.scripts.push(script);
} }
@ -311,20 +318,39 @@ export function Root(props: IProps): React.ReactElement {
return { suggestions: suggestions }; return { suggestions: suggestions };
}, },
}); });
(async function () {
// We have to improve the default js language otherwise theme sucks
const l = await monaco.languages
.getLanguages()
.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" }]);
const otherKeywords = ["let", "const", "var", "function"];
const otherKeyvars = ["true", "false", "null", "undefined"];
otherKeywords.forEach((k) => l.language.tokenizer.root.unshift([k, { token: "otherkeywords" }]));
otherKeyvars.forEach((k) => l.language.tokenizer.root.unshift([k, { token: "otherkeyvars" }]));
l.language.tokenizer.root.unshift(["this", { token: "this" }]);
console.log(l);
})();
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, "netscript.d.ts"); monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, "netscript.d.ts");
monaco.languages.typescript.typescriptDefaults.addExtraLib(libSource, "netscript.d.ts"); monaco.languages.typescript.typescriptDefaults.addExtraLib(libSource, "netscript.d.ts");
loadThemes(monaco); loadThemes(monaco);
} }
// 370px 71%, 725px 85.1%, 1085px 90%, 1300px 91.7%
// fuck around in desmos until you find a function
const p = 11000 / -window.innerHeight + 100;
return ( return (
<> <>
<Box display="flex" flexDirection="row" alignItems="center"> <Box display="flex" flexDirection="row" alignItems="center">
<TextField <TextField
placeholder="filename"
type="text" type="text"
tabIndex={1} tabIndex={1}
value={filename} value={filename}
onChange={onFilenameChange} onChange={onFilenameChange}
InputProps={{ startAdornment: <Typography>Script&nbsp;name:&nbsp;</Typography> }} InputProps={{ startAdornment: <Typography>{hostname}:~/</Typography> }}
/> />
<IconButton onClick={() => setOptionsOpen(true)}> <IconButton onClick={() => setOptionsOpen(true)}>
<> <>
@ -337,7 +363,7 @@ export function Root(props: IProps): React.ReactElement {
beforeMount={beforeMount} beforeMount={beforeMount}
onMount={onMount} onMount={onMount}
loading={<Typography>Loading script editor!</Typography>} loading={<Typography>Loading script editor!</Typography>}
height="90%" height={p + "%"}
defaultLanguage="javascript" defaultLanguage="javascript"
defaultValue={code} defaultValue={code}
onChange={updateCode} onChange={updateCode}

@ -19,6 +19,10 @@ export async function loadThemes(monaco: { editor: any }): Promise<void> {
token: "number", token: "number",
foreground: "ae81ff", foreground: "ae81ff",
}, },
{
token: "otherkeyvars",
foreground: "ae81ff",
},
{ {
foreground: "ae81ff", foreground: "ae81ff",
token: "function", token: "function",
@ -31,11 +35,22 @@ export async function loadThemes(monaco: { editor: any }): Promise<void> {
token: "storage.type.function.js", token: "storage.type.function.js",
foreground: "ae81ff", foreground: "ae81ff",
}, },
{
// { token: "ns",
// foreground: "ae81ff", foreground: "97d92b",
// token: "entity.name.function", },
// }, {
token: "netscriptfunction",
foreground: "53d3e4",
},
{
token: "otherkeywords",
foreground: "53d3e4",
},
{
token: "this",
foreground: "fd971f",
},
], ],
colors: { colors: {
"editor.foreground": "#F8F8F2", "editor.foreground": "#F8F8F2",

@ -2,7 +2,6 @@
* Abstract Base Class for any Server object * Abstract Base Class for any Server object
*/ */
import { CodingContract } from "../CodingContracts"; import { CodingContract } from "../CodingContracts";
import { Message } from "../Message/Message";
import { RunningScript } from "../Script/RunningScript"; import { RunningScript } from "../Script/RunningScript";
import { Script } from "../Script/Script"; import { Script } from "../Script/Script";
import { isValidFilePath } from "../Terminal/DirectoryHelpers"; import { isValidFilePath } from "../Terminal/DirectoryHelpers";

@ -239,7 +239,7 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = {
SuppressMessages: defaultSettings.SuppressMessages, SuppressMessages: defaultSettings.SuppressMessages,
SuppressTravelConfirmation: defaultSettings.SuppressTravelConfirmation, SuppressTravelConfirmation: defaultSettings.SuppressTravelConfirmation,
SuppressBladeburnerPopup: defaultSettings.SuppressBladeburnerPopup, SuppressBladeburnerPopup: defaultSettings.SuppressBladeburnerPopup,
MonacoTheme: "vs-dark", MonacoTheme: "monokai",
MonacoInsertSpaces: false, MonacoInsertSpaces: false,
MonacoFontSize: 20, MonacoFontSize: 20,

@ -215,7 +215,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
let newValue = tabCompletion(command, arg, allPos, value); let newValue = tabCompletion(command, arg, allPos, value);
if (typeof newValue === "string" && newValue !== "") { if (typeof newValue === "string" && newValue !== "") {
if (!newValue.endsWith(" ") && allPos.length === 1) newValue += " "; if (!newValue.endsWith(" ") && !newValue.endsWith("/") && allPos.length === 1) newValue += " ";
saveValue(newValue); saveValue(newValue);
} }
if (Array.isArray(newValue)) { if (Array.isArray(newValue)) {

@ -315,7 +315,13 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
) : page === Page.Stats ? ( ) : page === Page.Stats ? (
<CharacterStats /> <CharacterStats />
) : page === Page.ScriptEditor ? ( ) : page === Page.ScriptEditor ? (
<ScriptEditorRoot filename={filename} code={code} player={player} router={Router} /> <ScriptEditorRoot
filename={filename}
code={code}
hostname={player.getCurrentServer().hostname}
player={player}
router={Router}
/>
) : page === Page.ActiveScripts ? ( ) : page === Page.ActiveScripts ? (
<ActiveScriptsRoot workerScripts={workerScripts} /> <ActiveScriptsRoot workerScripts={workerScripts} />
) : page === Page.Hacknet ? ( ) : page === Page.Hacknet ? (

@ -88,7 +88,6 @@ function LogWindow(props: IProps): React.ReactElement {
killWorkerScript(props.script, props.script.server, true); killWorkerScript(props.script, props.script.server, true);
props.onClose(); props.onClose();
} }
//useEffect(() => TerminalEvents.subscribe(_.debounce(async () => rerender(), 25, { maxWait: 50 })), []);
function updateLayer(): void { function updateLayer(): void {
const c = container.current; const c = container.current;
@ -98,6 +97,15 @@ function LogWindow(props: IProps): React.ReactElement {
rerender(); rerender();
} }
function title(): string {
const maxLength = 30;
const t = `${props.script.filename} ${props.script.args.map((x: any): string => `${x}`).join(" ")}`;
if (t.length <= maxLength) {
return t;
}
return t.slice(0, maxLength - 3) + "...";
}
return ( return (
<Draggable handle=".drag"> <Draggable handle=".drag">
<Paper <Paper
@ -119,7 +127,7 @@ function LogWindow(props: IProps): React.ReactElement {
> >
<Box className="drag" display="flex" alignItems="center"> <Box className="drag" display="flex" alignItems="center">
<Typography color="primary" variant="h6"> <Typography color="primary" variant="h6">
{props.script.filename} {props.script.args.map((x: any): string => `${x}`).join(" ")} {title()}
</Typography> </Typography>
<Box position="absolute" right={0}> <Box position="absolute" right={0}>

@ -302,7 +302,7 @@ export function refreshTheme(): void {
border: "1px solid " + Settings.theme.well, border: "1px solid " + Settings.theme.well,
}, },
standardSuccess: { standardSuccess: {
color: Settings.theme.successLight, color: Settings.theme.primaryLight,
}, },
standardError: { standardError: {
color: Settings.theme.errorlight, color: Settings.theme.errorlight,