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) {
|
if (ver < 23) {
|
||||||
anyPlayer.currentWork = null;
|
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) {
|
if (ver < 25) {
|
||||||
const removePlayerFields = [
|
const removePlayerFields = [
|
||||||
"hacking_chance_mult",
|
"hacking_chance_mult",
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import type { editor } from "monaco-editor";
|
import type { editor } from "monaco-editor";
|
||||||
|
import { getRecordKeys } from "../../Types/Record";
|
||||||
|
import { Settings } from "../../Settings/Settings";
|
||||||
type DefineThemeFn = typeof editor.defineTheme;
|
type DefineThemeFn = typeof editor.defineTheme;
|
||||||
|
|
||||||
export interface IScriptEditorTheme {
|
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
|
// Recursively sanitize the theme data to prevent errors
|
||||||
// Invalid data will be replaced with FF0000 (bright red)
|
// Invalid data will be replaced with FF0000 (bright red)
|
||||||
export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
|
export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
|
||||||
for (const [k, v] of Object.entries(theme)) {
|
if (typeof theme !== "object") {
|
||||||
switch (k) {
|
Settings.EditorTheme = defaultMonacoTheme;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const themeKey of getRecordKeys(theme)) {
|
||||||
|
if (typeof theme[themeKey] !== "object") delete theme[themeKey];
|
||||||
|
switch (themeKey) {
|
||||||
case "base":
|
case "base":
|
||||||
if (!["vs-dark", "vs"].includes(theme.base)) theme.base = "vs-dark";
|
if (!["vs-dark", "vs"].includes(theme.base)) theme.base = "vs-dark";
|
||||||
continue;
|
continue;
|
||||||
@ -82,14 +89,17 @@ export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const repairBlock = (block: Record<string, object | string>): void => {
|
const block = theme[themeKey];
|
||||||
for (const [k, v] of Object.entries(block)) {
|
function repairBlock<T extends Record<string, unknown>>(block: T) {
|
||||||
if (typeof v === "object") {
|
for (const [blockKey, blockValue] of Object.entries(block) as [keyof T, unknown][]) {
|
||||||
repairBlock(v as Record<string, string>);
|
if (!blockValue || (typeof blockValue !== "string" && typeof blockValue !== "object"))
|
||||||
} else if (!v.match(colorRegExp)) block[k] = "FF0000";
|
(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();
|
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.
|
// 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) {
|
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);
|
let newFilePath = resolveScriptFilePath(script.filename);
|
||||||
if (!newFilePath) {
|
if (!newFilePath) {
|
||||||
newFilePath = `${newDirectory}script${++invalidScriptCount}.js` as ScriptFilePath;
|
newFilePath = `${newDirectory}script${++invalidScriptCount}.js` as ScriptFilePath;
|
||||||
|
Loading…
Reference in New Issue
Block a user