diff --git a/src/Script/RunningScript.ts b/src/Script/RunningScript.ts index 00c0a338d..469851261 100644 --- a/src/Script/RunningScript.ts +++ b/src/Script/RunningScript.ts @@ -8,7 +8,7 @@ import { IMap } from "../types"; import { Terminal } from "../Terminal"; import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver"; -import { getTimestamp } from "../utils/helpers/getTimestamp"; +import { formatTime } from "../utils/helpers/formatTime"; export class RunningScript { // Script arguments @@ -74,8 +74,8 @@ export class RunningScript { } let logEntry = txt; - if (Settings.EnableTimestamps) { - logEntry = "[" + getTimestamp() + "] " + logEntry; + if (Settings.TimestampsFormat) { + logEntry = "[" + formatTime(Settings.TimestampsFormat) + "] " + logEntry; } this.logs.push(logEntry); diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index f71defd19..58c08d2d9 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -354,7 +354,8 @@ export function Root(props: IProps): React.ReactElement { .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" }]); + for (const symbol of symbols) + l.language.tokenizer.root.unshift(["[^a-zA-Z]" + symbol + "[^a-zA-Z]", { 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" }])); diff --git a/src/Settings/Settings.ts b/src/Settings/Settings.ts index 4f9dc01cc..50fda14cf 100644 --- a/src/Settings/Settings.ts +++ b/src/Settings/Settings.ts @@ -44,9 +44,9 @@ interface IDefaultSettings { EnableBashHotkeys: boolean; /** - * Enable timestamps + * Timestamps format */ - EnableTimestamps: boolean; + TimestampsFormat: string; /** * Locale used for display numbers @@ -166,7 +166,7 @@ export const defaultSettings: IDefaultSettings = { DisableHotkeys: false, DisableTextEffects: false, EnableBashHotkeys: false, - EnableTimestamps: false, + TimestampsFormat: "YYYY-MM-DD HH:MM:SS", Locale: "en", MaxLogCapacity: 50, MaxPortCapacity: 50, @@ -225,7 +225,7 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = { DisableHotkeys: defaultSettings.DisableHotkeys, DisableTextEffects: defaultSettings.DisableTextEffects, EnableBashHotkeys: defaultSettings.EnableBashHotkeys, - EnableTimestamps: defaultSettings.EnableTimestamps, + TimestampsFormat: defaultSettings.TimestampsFormat, Locale: "en", MaxLogCapacity: defaultSettings.MaxLogCapacity, MaxPortCapacity: defaultSettings.MaxPortCapacity, @@ -282,5 +282,6 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = { Object.assign(Settings.theme, save.theme); delete save.theme; Object.assign(Settings, save); + console.log(Settings.TimestampsFormat); }, }; diff --git a/src/Terminal/ITerminal.tsx b/src/Terminal/ITerminal.tsx index 78e450204..574045ff3 100644 --- a/src/Terminal/ITerminal.tsx +++ b/src/Terminal/ITerminal.tsx @@ -4,7 +4,7 @@ import { Script } from "../Script/Script"; import { IPlayer } from "../PersonObjects/IPlayer"; import { IRouter } from "../ui/Router"; import { Settings } from "../Settings/Settings"; -import { getTimestamp } from "../utils/helpers/getTimestamp"; +import { formatTime } from "../utils/helpers/formatTime"; export class Output { text: string; @@ -13,7 +13,7 @@ export class Output { text: string, color: "inherit" | "initial" | "primary" | "secondary" | "error" | "textPrimary" | "textSecondary" | undefined, ) { - if (Settings.EnableTimestamps) text = "[" + getTimestamp() + "] " + text; + if (Settings.TimestampsFormat) text = "[" + formatTime(Settings.TimestampsFormat) + "] " + text; this.text = text; this.color = color; } @@ -22,10 +22,10 @@ export class Output { export class RawOutput { raw: React.ReactNode; constructor(node: React.ReactNode) { - if (Settings.EnableTimestamps) + if (Settings.TimestampsFormat) node = ( <> - [{getTimestamp()}] {node} + [{formatTime(Settings.TimestampsFormat)}] {node} ); this.raw = node; @@ -36,7 +36,7 @@ export class Link { hostname: string; dashes: string; constructor(dashes: string, hostname: string) { - if (Settings.EnableTimestamps) dashes = "[" + getTimestamp() + "] " + dashes; + if (Settings.TimestampsFormat) dashes = "[" + formatTime(Settings.TimestampsFormat) + "] " + dashes; this.hostname = hostname; this.dashes = dashes; } diff --git a/src/ui/React/GameOptionsRoot.tsx b/src/ui/React/GameOptionsRoot.tsx index e4521be04..e6d1529ba 100644 --- a/src/ui/React/GameOptionsRoot.tsx +++ b/src/ui/React/GameOptionsRoot.tsx @@ -73,7 +73,7 @@ export function GameOptionsRoot(props: IProps): React.ReactElement { const [disableASCIIArt, setDisableASCIIArt] = useState(Settings.DisableASCIIArt); const [disableTextEffects, setDisableTextEffects] = useState(Settings.DisableTextEffects); const [enableBashHotkeys, setEnableBashHotkeys] = useState(Settings.EnableBashHotkeys); - const [enableTimestamps, setEnableTimestamps] = useState(Settings.EnableTimestamps); + const [enableTimestamps, setEnableTimestamps] = useState(!!Settings.TimestampsFormat); const [saveGameOnFileSave, setSaveGameOnFileSave] = useState(Settings.SaveGameOnFileSave); const [locale, setLocale] = useState(Settings.Locale); @@ -156,7 +156,7 @@ export function GameOptionsRoot(props: IProps): React.ReactElement { } function handleEnableTimestampsChange(event: React.ChangeEvent): void { setEnableTimestamps(event.target.checked); - Settings.EnableTimestamps = event.target.checked; + Settings.TimestampsFormat = event.target.checked ? "YYYY-MM-DD HH:MM:SS" : ""; } function handleSaveGameOnFile(event: React.ChangeEvent): void { setSaveGameOnFileSave(event.target.checked); diff --git a/src/utils/helpers/formatTime.ts b/src/utils/helpers/formatTime.ts new file mode 100644 index 000000000..48340ce09 --- /dev/null +++ b/src/utils/helpers/formatTime.ts @@ -0,0 +1,3 @@ +export function formatTime(format: string): string { + return ""; +}