Merge pull request #1523 from danielyxie/dev

more improvements.
This commit is contained in:
hydroflame 2021-10-15 21:30:01 -04:00 committed by GitHub
commit 13a3a136dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 28 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

@ -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;
}

@ -61,6 +61,7 @@ export function SetupTextEditor(): void {
interface IProps {
filename: string;
code: string;
hostname: string;
player: IPlayer;
router: IRouter;
}
@ -81,12 +82,17 @@ interface IProps {
// 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);
@ -129,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) {
@ -143,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);
}
@ -339,11 +345,12 @@ export function Root(props: IProps): React.ReactElement {
<>
<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)}>
<>

@ -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";

@ -305,7 +305,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}>