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

@ -647,6 +647,11 @@ export function runScriptFromScript(
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
const runningScriptObj = server.getRunningScript(scriptname, args);
if (runningScriptObj != null) {

@ -58,6 +58,7 @@ import { Reputation } from "../../ui/React/Reputation";
import { Money } from "../../ui/React/Money";
import React from "react";
import { serverMetadata } from "../../Server/data/servers";
export function init(this: IPlayer): void {
/* 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 {
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 && server.backdoorInstalled) return 0.75;
}

@ -55,12 +55,13 @@ export function SetupTextEditor(): void {
symbols = populate(ns);
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 {
filename: string;
code: string;
hostname: string;
player: IPlayer;
router: IRouter;
}
@ -75,17 +76,23 @@ interface IProps {
// https://www.npmjs.com/package/@monaco-editor/react#development-playground
// 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://blog.checklyhq.com/customizing-monaco/
// These variables are used to reload a script when it's clicked on. Because we
// won't have references to the old script.
let lastFilename = "";
let lastCode = "";
let hostname = "";
let lastPosition: monaco.Position | null = null;
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);
hostname = props.filename ? props.hostname : hostname;
if (hostname === "") {
hostname = props.player.getCurrentServer().hostname;
}
const [ram, setRAM] = useState("RAM: ???");
const [updatingRam, setUpdatingRam] = 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) {
//Make sure filename + code properly follow tutorial
if (filename !== "n00dles.script") {
dialogBoxCreate("Leave the script name as 'n00dles'!");
dialogBoxCreate("Leave the script name as 'n00dles.script'!");
return;
}
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;
for (let i = 0; i < server.scripts.length; i++) {
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;
}
}
if (!found) {
const script = new Script();
script.saveScript(filename, code, props.player.currentServer, server.scripts);
script.saveScript(filename, code, hostname, server.scripts);
server.scripts.push(script);
}
@ -311,20 +318,39 @@ export function Root(props: IProps): React.ReactElement {
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.typescriptDefaults.addExtraLib(libSource, "netscript.d.ts");
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 (
<>
<Box display="flex" flexDirection="row" alignItems="center">
<TextField
placeholder="filename"
type="text"
tabIndex={1}
value={filename}
onChange={onFilenameChange}
InputProps={{ startAdornment: <Typography>Script&nbsp;name:&nbsp;</Typography> }}
InputProps={{ startAdornment: <Typography>{hostname}:~/</Typography> }}
/>
<IconButton onClick={() => setOptionsOpen(true)}>
<>
@ -337,7 +363,7 @@ export function Root(props: IProps): React.ReactElement {
beforeMount={beforeMount}
onMount={onMount}
loading={<Typography>Loading script editor!</Typography>}
height="90%"
height={p + "%"}
defaultLanguage="javascript"
defaultValue={code}
onChange={updateCode}

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

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

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

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

@ -315,7 +315,13 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
) : page === Page.Stats ? (
<CharacterStats />
) : 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 ? (
<ActiveScriptsRoot workerScripts={workerScripts} />
) : page === Page.Hacknet ? (

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

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