Fixed Script Editor last filename not keeping proper track

This commit is contained in:
Olivier Gagnon 2021-10-08 00:21:30 -04:00
parent ec3037f8c6
commit 3ca7c49ce8
5 changed files with 22 additions and 17 deletions

@ -15,7 +15,7 @@ import { TextFile } from "../../TextFile";
import { calculateRamUsage } from "../../Script/RamCalculations"; import { calculateRamUsage } from "../../Script/RamCalculations";
import { RamCalculationErrorCode } from "../../Script/RamCalculationErrorCodes"; import { RamCalculationErrorCode } from "../../Script/RamCalculationErrorCodes";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
import { CursorPositions } from "../../ScriptEditor/CursorPositions"; import { CursorPositions } from "../CursorPositions";
import { libSource } from "../NetscriptDefinitions"; import { libSource } from "../NetscriptDefinitions";
import { NetscriptFunctions } from "../../NetscriptFunctions"; import { NetscriptFunctions } from "../../NetscriptFunctions";
import { WorkerScript } from "../../Netscript/WorkerScript"; import { WorkerScript } from "../../Netscript/WorkerScript";
@ -201,7 +201,7 @@ export function Root(props: IProps): React.ReactElement {
} }
function onFilenameChange(event: React.ChangeEvent<HTMLInputElement>): void { function onFilenameChange(event: React.ChangeEvent<HTMLInputElement>): void {
lastFilename = filename; lastFilename = event.target.value;
setFilename(event.target.value); setFilename(event.target.value);
} }
@ -296,8 +296,13 @@ export function Root(props: IProps): React.ReactElement {
return ( return (
<> <>
<Box display="flex" flexDirection="row" alignItems="center"> <Box display="flex" flexDirection="row" alignItems="center">
<Typography>Script name: </Typography> <TextField
<TextField type="text" tabIndex={1} value={filename} onChange={onFilenameChange} /> type="text"
tabIndex={1}
value={filename}
onChange={onFilenameChange}
InputProps={{ startAdornment: <Typography>Script&nbsp;name:&nbsp;</Typography> }}
/>
<IconButton onClick={() => setOptionsOpen(true)}> <IconButton onClick={() => setOptionsOpen(true)}>
<> <>
<SettingsIcon /> <SettingsIcon />

@ -168,7 +168,7 @@ export function SidebarRoot(props: IProps): React.ReactElement {
if (flashTerminal) iTutorialNextStep(); if (flashTerminal) iTutorialNextStep();
} }
function clickCreateScripts(): void { function clickScriptEditor(): void {
props.router.toScriptEditor(); props.router.toScriptEditor();
} }
@ -274,7 +274,7 @@ export function SidebarRoot(props: IProps): React.ReactElement {
clickStats(); clickStats();
} else if (event.keyCode === KEY.E && event.altKey) { } else if (event.keyCode === KEY.E && event.altKey) {
event.preventDefault(); event.preventDefault();
clickCreateScripts(); clickScriptEditor();
} else if (event.keyCode === KEY.S && event.altKey) { } else if (event.keyCode === KEY.S && event.altKey) {
event.preventDefault(); event.preventDefault();
clickActiveScripts(); clickActiveScripts();
@ -367,18 +367,18 @@ export function SidebarRoot(props: IProps): React.ReactElement {
<ListItem <ListItem
classes={{ root: classes.listitem }} classes={{ root: classes.listitem }}
button button
key={"Create Scripts"} key={"Script Editor"}
className={clsx({ className={clsx({
[classes.active]: props.page === Page.CreateScript, [classes.active]: props.page === Page.ScriptEditor,
})} })}
onClick={clickCreateScripts} onClick={clickScriptEditor}
> >
<ListItemIcon> <ListItemIcon>
<CreateIcon color={props.page !== Page.CreateScript ? "secondary" : "primary"} /> <CreateIcon color={props.page !== Page.ScriptEditor ? "secondary" : "primary"} />
</ListItemIcon> </ListItemIcon>
<ListItemText> <ListItemText>
<Typography color={props.page !== Page.CreateScript ? "secondary" : "primary"}> <Typography color={props.page !== Page.ScriptEditor ? "secondary" : "primary"}>
Create Script Script Editor
</Typography> </Typography>
</ListItemText> </ListItemText>
</ListItem> </ListItem>

@ -14,7 +14,7 @@ import { CONSTANTS } from "./Constants";
import { Factions, initFactions } from "./Faction/Factions"; import { Factions, initFactions } from "./Faction/Factions";
import { processPassiveFactionRepGain, inviteToFaction } from "./Faction/FactionHelpers"; import { processPassiveFactionRepGain, inviteToFaction } from "./Faction/FactionHelpers";
import { Router } from "./ui/GameRoot"; import { Router } from "./ui/GameRoot";
import { SetupTextEditor } from "./ScriptEditor/ui/Root"; import { SetupTextEditor } from "./ScriptEditor/ui/ScriptEditorRoot";
import { import {
getHackingWorkRepGain, getHackingWorkRepGain,

@ -50,7 +50,7 @@ import { HacknetRoot } from "../Hacknet/ui/HacknetRoot";
import { GenericLocation } from "../Locations/ui/GenericLocation"; import { GenericLocation } from "../Locations/ui/GenericLocation";
import { LocationCity } from "../Locations/ui/City"; import { LocationCity } from "../Locations/ui/City";
import { ProgramsRoot } from "../Programs/ui/ProgramsRoot"; import { ProgramsRoot } from "../Programs/ui/ProgramsRoot";
import { Root as ScriptEditorRoot } from "../ScriptEditor/ui/Root"; import { Root as ScriptEditorRoot } from "../ScriptEditor/ui/ScriptEditorRoot";
import { MilestonesRoot } from "../Milestones/ui/MilestonesRoot"; import { MilestonesRoot } from "../Milestones/ui/MilestonesRoot";
import { TerminalRoot } from "../Terminal/ui/TerminalRoot"; import { TerminalRoot } from "../Terminal/ui/TerminalRoot";
import { TutorialRoot } from "../Tutorial/ui/TutorialRoot"; import { TutorialRoot } from "../Tutorial/ui/TutorialRoot";
@ -232,7 +232,7 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
toScriptEditor: (fn: string, c: string) => { toScriptEditor: (fn: string, c: string) => {
filename = fn; filename = fn;
code = c; code = c;
setPage(Page.CreateScript); setPage(Page.ScriptEditor);
}, },
toSleeves: () => setPage(Page.Sleeves), toSleeves: () => setPage(Page.Sleeves),
toStockMarket: () => setPage(Page.StockMarket), toStockMarket: () => setPage(Page.StockMarket),
@ -303,7 +303,7 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
<SleeveRoot /> <SleeveRoot />
) : page === Page.Stats ? ( ) : page === Page.Stats ? (
<CharacterStats /> <CharacterStats />
) : page === Page.CreateScript ? ( ) : page === Page.ScriptEditor ? (
<ScriptEditorRoot filename={filename} code={code} player={player} router={Router} /> <ScriptEditorRoot filename={filename} code={code} player={player} router={Router} />
) : page === Page.ActiveScripts ? ( ) : page === Page.ActiveScripts ? (
<ActiveScriptsRoot workerScripts={workerScripts} /> <ActiveScriptsRoot workerScripts={workerScripts} />

@ -13,7 +13,7 @@ export enum Page {
City, City,
Corporation, Corporation,
CreateProgram, CreateProgram,
CreateScript, ScriptEditor,
DevMenu, DevMenu,
Faction, Faction,
Factions, Factions,