mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 12:45:45 +01:00
More hotfixes...
* Script editor theme could be corrupted leading to a recovery screen, this should fix that. * Because script filepath changes were moved before the detection of .ns files, a check was added for .ns files in BaseServer so they get the better name.
This commit is contained in:
parent
1aa53739cc
commit
b65bd62345
@ -480,12 +480,6 @@ function evaluateVersionCompatibility(ver: string | number): void {
|
||||
if (ver < 23) {
|
||||
anyPlayer.currentWork = null;
|
||||
}
|
||||
if (ver < 24) {
|
||||
// Assert the relevant type that was in effect at this version.
|
||||
(Player.getHomeComputer().scripts as unknown as { filename: string }[]).forEach(
|
||||
(s) => s.filename.endsWith(".ns") && (s.filename += ".js"),
|
||||
);
|
||||
}
|
||||
if (ver < 25) {
|
||||
const removePlayerFields = [
|
||||
"hacking_chance_mult",
|
||||
|
@ -1,4 +1,6 @@
|
||||
import type { editor } from "monaco-editor";
|
||||
import { getRecordKeys } from "../../Types/Record";
|
||||
import { Settings } from "../../Settings/Settings";
|
||||
type DefineThemeFn = typeof editor.defineTheme;
|
||||
|
||||
export interface IScriptEditorTheme {
|
||||
@ -72,8 +74,13 @@ const colorRegExp = /^#?([0-9A-Fa-f]{6})([0-9A-Fa-f]{2})?$/;
|
||||
// Recursively sanitize the theme data to prevent errors
|
||||
// Invalid data will be replaced with FF0000 (bright red)
|
||||
export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
|
||||
for (const [k, v] of Object.entries(theme)) {
|
||||
switch (k) {
|
||||
if (typeof theme !== "object") {
|
||||
Settings.EditorTheme = defaultMonacoTheme;
|
||||
return;
|
||||
}
|
||||
for (const themeKey of getRecordKeys(theme)) {
|
||||
if (typeof theme[themeKey] !== "object") delete theme[themeKey];
|
||||
switch (themeKey) {
|
||||
case "base":
|
||||
if (!["vs-dark", "vs"].includes(theme.base)) theme.base = "vs-dark";
|
||||
continue;
|
||||
@ -82,14 +89,17 @@ export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
|
||||
continue;
|
||||
}
|
||||
|
||||
const repairBlock = (block: Record<string, object | string>): void => {
|
||||
for (const [k, v] of Object.entries(block)) {
|
||||
if (typeof v === "object") {
|
||||
repairBlock(v as Record<string, string>);
|
||||
} else if (!v.match(colorRegExp)) block[k] = "FF0000";
|
||||
const block = theme[themeKey];
|
||||
function repairBlock<T extends Record<string, unknown>>(block: T) {
|
||||
for (const [blockKey, blockValue] of Object.entries(block) as [keyof T, unknown][]) {
|
||||
if (!blockValue || (typeof blockValue !== "string" && typeof blockValue !== "object"))
|
||||
(block[blockKey] as string) = "FF0000";
|
||||
else if (typeof blockValue === "object") repairBlock(block);
|
||||
else if (!blockValue.match(colorRegExp)) (block[blockKey] as string) = "FF0000";
|
||||
}
|
||||
};
|
||||
repairBlock(v);
|
||||
}
|
||||
// Type assertion is to something less specific.
|
||||
repairBlock(block);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -333,6 +333,8 @@ export abstract class BaseServer implements IServer {
|
||||
server.scripts = new JSONMap();
|
||||
// In case somehow there are previously valid filenames that can't be sanitized, they will go in a new directory with a note.
|
||||
for (const script of oldScripts) {
|
||||
// We're about to do type validation on the filename anyway.
|
||||
if (script.filename.endsWith(".ns")) script.filename = (script.filename + ".js") as any;
|
||||
let newFilePath = resolveScriptFilePath(script.filename);
|
||||
if (!newFilePath) {
|
||||
newFilePath = `${newDirectory}script${++invalidScriptCount}.js` as ScriptFilePath;
|
||||
|
Loading…
Reference in New Issue
Block a user