script editor now saves on server that opened the file and displays server name

This commit is contained in:
Olivier Gagnon 2021-10-15 21:27:02 -04:00
parent e38bfc70cf
commit 02b085cc75
5 changed files with 36 additions and 24 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

@ -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);
}
@ -343,7 +349,7 @@ export function Root(props: IProps): React.ReactElement {
tabIndex={1}
value={filename}
onChange={onFilenameChange}
InputProps={{ startAdornment: <Typography>Script&nbsp;name:&nbsp;</Typography> }}
InputProps={{ startAdornment: <Typography>{hostname}:~/</Typography> }}
/>
<IconButton onClick={() => setOptionsOpen(true)}>
<>

@ -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 ? (