mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 23:53:48 +01:00
Merge branch 'dev' of github.com:danielyxie/bitburner into dev
This commit is contained in:
commit
efc3992c78
@ -36,7 +36,7 @@ export function printAliases(): void {
|
|||||||
|
|
||||||
// Returns true if successful, false otherwise
|
// Returns true if successful, false otherwise
|
||||||
export function parseAliasDeclaration(dec: string, global = false): boolean {
|
export function parseAliasDeclaration(dec: string, global = false): boolean {
|
||||||
const re = /^([_|\w|!|%|,|@]+)="(.+)"$/;
|
const re = /^([\w|!|%|,|@|-]+)="(.+)"$/;
|
||||||
const matches = dec.match(re);
|
const matches = dec.match(re);
|
||||||
if (matches == null || matches.length != 3) {
|
if (matches == null || matches.length != 3) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
export const validScriptExtensions: Array<string> = [`.js`, `.script`, `.ns`];
|
||||||
|
|
||||||
export function isScriptFilename(f: string): boolean {
|
export function isScriptFilename(f: string): boolean {
|
||||||
return f.endsWith(".js") || f.endsWith(".script") || f.endsWith(".ns");
|
return validScriptExtensions.some((ext) => f.endsWith(ext));
|
||||||
}
|
}
|
||||||
|
@ -16,22 +16,25 @@ import { isValidNumber } from "../utils/helpers/isValidNumber";
|
|||||||
* does not have a duplicate hostname/ip.
|
* does not have a duplicate hostname/ip.
|
||||||
*/
|
*/
|
||||||
export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
|
export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
|
||||||
|
let hostname: string = params.hostname.replace(/ /g, `-`);
|
||||||
|
|
||||||
if (params.ip != null && ipExists(params.ip)) {
|
if (params.ip != null && ipExists(params.ip)) {
|
||||||
params.ip = createUniqueRandomIp();
|
params.ip = createUniqueRandomIp();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetServer(params.hostname) != null) {
|
if (GetServer(hostname) != null) {
|
||||||
|
hostname = `${hostname}-0`;
|
||||||
|
|
||||||
// Use a for loop to ensure that we don't get suck in an infinite loop somehow
|
// Use a for loop to ensure that we don't get suck in an infinite loop somehow
|
||||||
let hostname: string = params.hostname;
|
|
||||||
for (let i = 0; i < 200; ++i) {
|
for (let i = 0; i < 200; ++i) {
|
||||||
hostname = `${params.hostname}-${i}`;
|
hostname = hostname.replace(/-[0-9]+$/, `-${i}`);
|
||||||
if (GetServer(hostname) == null) {
|
if (GetServer(hostname) == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params.hostname = hostname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params.hostname = hostname;
|
||||||
return new Server(params);
|
return new Server(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ export function purchaseServer(hostname: string, ram: number, cost: number, p: I
|
|||||||
|
|
||||||
p.loseMoney(cost, "servers");
|
p.loseMoney(cost, "servers");
|
||||||
|
|
||||||
dialogBoxCreate("Server successfully purchased with hostname " + hostname);
|
dialogBoxCreate("Server successfully purchased with hostname " + newServ.hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually upgrade RAM on home computer (NOT through Netscript)
|
// Manually upgrade RAM on home computer (NOT through Netscript)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { ISelfInitializer, ISelfLoading } from "../types";
|
import { ISelfInitializer, ISelfLoading } from "../types";
|
||||||
import { OwnedAugmentationsOrderSetting, PurchaseAugmentationsOrderSetting } from "./SettingEnums";
|
import { OwnedAugmentationsOrderSetting, PurchaseAugmentationsOrderSetting } from "./SettingEnums";
|
||||||
|
import { defaultTheme, ITheme } from "./Themes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the default settings the player could customize.
|
* Represents the default settings the player could customize.
|
||||||
@ -111,42 +112,7 @@ interface IDefaultSettings {
|
|||||||
/*
|
/*
|
||||||
* Theme colors
|
* Theme colors
|
||||||
*/
|
*/
|
||||||
theme: {
|
theme: ITheme;
|
||||||
[key: string]: string | undefined;
|
|
||||||
primarylight: string;
|
|
||||||
primary: string;
|
|
||||||
primarydark: string;
|
|
||||||
successlight: string;
|
|
||||||
success: string;
|
|
||||||
successdark: string;
|
|
||||||
errorlight: string;
|
|
||||||
error: string;
|
|
||||||
errordark: string;
|
|
||||||
secondarylight: string;
|
|
||||||
secondary: string;
|
|
||||||
secondarydark: string;
|
|
||||||
warninglight: string;
|
|
||||||
warning: string;
|
|
||||||
warningdark: string;
|
|
||||||
infolight: string;
|
|
||||||
info: string;
|
|
||||||
infodark: string;
|
|
||||||
welllight: string;
|
|
||||||
well: string;
|
|
||||||
white: string;
|
|
||||||
black: string;
|
|
||||||
hp: string;
|
|
||||||
money: string;
|
|
||||||
hack: string;
|
|
||||||
combat: string;
|
|
||||||
cha: string;
|
|
||||||
int: string;
|
|
||||||
rep: string;
|
|
||||||
disabled: string;
|
|
||||||
backgroundprimary: string;
|
|
||||||
backgroundsecondary: string;
|
|
||||||
button: string;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -193,41 +159,7 @@ export const defaultSettings: IDefaultSettings = {
|
|||||||
SuppressTIXPopup: false,
|
SuppressTIXPopup: false,
|
||||||
SuppressSavedGameToast: false,
|
SuppressSavedGameToast: false,
|
||||||
|
|
||||||
theme: {
|
theme: defaultTheme,
|
||||||
primarylight: "#0f0",
|
|
||||||
primary: "#0c0",
|
|
||||||
primarydark: "#090",
|
|
||||||
successlight: "#0f0",
|
|
||||||
success: "#0c0",
|
|
||||||
successdark: "#090",
|
|
||||||
errorlight: "#f00",
|
|
||||||
error: "#c00",
|
|
||||||
errordark: "#900",
|
|
||||||
secondarylight: "#AAA",
|
|
||||||
secondary: "#888",
|
|
||||||
secondarydark: "#666",
|
|
||||||
warninglight: "#ff0",
|
|
||||||
warning: "#cc0",
|
|
||||||
warningdark: "#990",
|
|
||||||
infolight: "#69f",
|
|
||||||
info: "#36c",
|
|
||||||
infodark: "#039",
|
|
||||||
welllight: "#444",
|
|
||||||
well: "#222",
|
|
||||||
white: "#fff",
|
|
||||||
black: "#000",
|
|
||||||
hp: "#dd3434",
|
|
||||||
money: "#ffd700",
|
|
||||||
hack: "#adff2f",
|
|
||||||
combat: "#faffdf",
|
|
||||||
cha: "#a671d1",
|
|
||||||
int: "#6495ed",
|
|
||||||
rep: "#faffdf",
|
|
||||||
disabled: "#66cfbc",
|
|
||||||
backgroundprimary: "#000",
|
|
||||||
backgroundsecondary: "#000",
|
|
||||||
button: "#333",
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,41 +194,7 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = {
|
|||||||
MonacoInsertSpaces: false,
|
MonacoInsertSpaces: false,
|
||||||
MonacoFontSize: 20,
|
MonacoFontSize: 20,
|
||||||
|
|
||||||
theme: {
|
theme: { ...defaultTheme },
|
||||||
primarylight: defaultSettings.theme.primarylight,
|
|
||||||
primary: defaultSettings.theme.primary,
|
|
||||||
primarydark: defaultSettings.theme.primarydark,
|
|
||||||
successlight: defaultSettings.theme.successlight,
|
|
||||||
success: defaultSettings.theme.success,
|
|
||||||
successdark: defaultSettings.theme.successdark,
|
|
||||||
errorlight: defaultSettings.theme.errorlight,
|
|
||||||
error: defaultSettings.theme.error,
|
|
||||||
errordark: defaultSettings.theme.errordark,
|
|
||||||
secondarylight: defaultSettings.theme.secondarylight,
|
|
||||||
secondary: defaultSettings.theme.secondary,
|
|
||||||
secondarydark: defaultSettings.theme.secondarydark,
|
|
||||||
warninglight: defaultSettings.theme.warninglight,
|
|
||||||
warning: defaultSettings.theme.warning,
|
|
||||||
warningdark: defaultSettings.theme.warningdark,
|
|
||||||
infolight: defaultSettings.theme.infolight,
|
|
||||||
info: defaultSettings.theme.info,
|
|
||||||
infodark: defaultSettings.theme.infodark,
|
|
||||||
welllight: defaultSettings.theme.welllight,
|
|
||||||
well: defaultSettings.theme.well,
|
|
||||||
white: defaultSettings.theme.white,
|
|
||||||
black: defaultSettings.theme.black,
|
|
||||||
hp: defaultSettings.theme.hp,
|
|
||||||
money: defaultSettings.theme.money,
|
|
||||||
hack: defaultSettings.theme.hack,
|
|
||||||
combat: defaultSettings.theme.combat,
|
|
||||||
cha: defaultSettings.theme.cha,
|
|
||||||
int: defaultSettings.theme.int,
|
|
||||||
rep: defaultSettings.theme.rep,
|
|
||||||
disabled: defaultSettings.theme.disabled,
|
|
||||||
backgroundprimary: defaultSettings.theme.backgroundprimary,
|
|
||||||
backgroundsecondary: defaultSettings.theme.backgroundsecondary,
|
|
||||||
button: defaultSettings.theme.button,
|
|
||||||
},
|
|
||||||
init() {
|
init() {
|
||||||
Object.assign(Settings, defaultSettings);
|
Object.assign(Settings, defaultSettings);
|
||||||
},
|
},
|
||||||
|
110
src/Settings/Themes.ts
Normal file
110
src/Settings/Themes.ts
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
export interface ITheme {
|
||||||
|
[key: string]: string | undefined;
|
||||||
|
primarylight: string;
|
||||||
|
primary: string;
|
||||||
|
primarydark: string;
|
||||||
|
successlight: string;
|
||||||
|
success: string;
|
||||||
|
successdark: string;
|
||||||
|
errorlight: string;
|
||||||
|
error: string;
|
||||||
|
errordark: string;
|
||||||
|
secondarylight: string;
|
||||||
|
secondary: string;
|
||||||
|
secondarydark: string;
|
||||||
|
warninglight: string;
|
||||||
|
warning: string;
|
||||||
|
warningdark: string;
|
||||||
|
infolight: string;
|
||||||
|
info: string;
|
||||||
|
infodark: string;
|
||||||
|
welllight: string;
|
||||||
|
well: string;
|
||||||
|
white: string;
|
||||||
|
black: string;
|
||||||
|
hp: string;
|
||||||
|
money: string;
|
||||||
|
hack: string;
|
||||||
|
combat: string;
|
||||||
|
cha: string;
|
||||||
|
int: string;
|
||||||
|
rep: string;
|
||||||
|
disabled: string;
|
||||||
|
backgroundprimary: string;
|
||||||
|
backgroundsecondary: string;
|
||||||
|
button: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const defaultTheme: ITheme = {
|
||||||
|
primarylight: "#0f0",
|
||||||
|
primary: "#0c0",
|
||||||
|
primarydark: "#090",
|
||||||
|
successlight: "#0f0",
|
||||||
|
success: "#0c0",
|
||||||
|
successdark: "#090",
|
||||||
|
errorlight: "#f00",
|
||||||
|
error: "#c00",
|
||||||
|
errordark: "#900",
|
||||||
|
secondarylight: "#AAA",
|
||||||
|
secondary: "#888",
|
||||||
|
secondarydark: "#666",
|
||||||
|
warninglight: "#ff0",
|
||||||
|
warning: "#cc0",
|
||||||
|
warningdark: "#990",
|
||||||
|
infolight: "#69f",
|
||||||
|
info: "#36c",
|
||||||
|
infodark: "#039",
|
||||||
|
welllight: "#444",
|
||||||
|
well: "#222",
|
||||||
|
white: "#fff",
|
||||||
|
black: "#000",
|
||||||
|
hp: "#dd3434",
|
||||||
|
money: "#ffd700",
|
||||||
|
hack: "#adff2f",
|
||||||
|
combat: "#faffdf",
|
||||||
|
cha: "#a671d1",
|
||||||
|
int: "#6495ed",
|
||||||
|
rep: "#faffdf",
|
||||||
|
disabled: "#66cfbc",
|
||||||
|
backgroundprimary: "#000",
|
||||||
|
backgroundsecondary: "#000",
|
||||||
|
button: "#333",
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface IPredefinedThemes {
|
||||||
|
'Default': ITheme;
|
||||||
|
'Monokai': ITheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getPredefinedThemes = (): IPredefinedThemes => ({
|
||||||
|
'Default': defaultTheme,
|
||||||
|
'Monokai': {
|
||||||
|
...defaultTheme,
|
||||||
|
|
||||||
|
backgroundprimary: '#272822',
|
||||||
|
backgroundsecondary: '#1B1C18',
|
||||||
|
primary: '#F8F8F2',
|
||||||
|
primarylight: '#FFF',
|
||||||
|
primarydark: '#FAFAEB',
|
||||||
|
success: '#A6E22E',
|
||||||
|
successlight: '#ADE146',
|
||||||
|
successdark: '#98E104',
|
||||||
|
error: '#F92672',
|
||||||
|
errorlight: '#FF69A0',
|
||||||
|
errordark: '#D10F56',
|
||||||
|
warning: '#E6DB74',
|
||||||
|
warninglight: '#E1D992',
|
||||||
|
warningdark: '#EDDD54',
|
||||||
|
info: '#66D9EF',
|
||||||
|
infolight: '#92E1F1',
|
||||||
|
infodark: '#31CDED',
|
||||||
|
|
||||||
|
hp: '#F92672',
|
||||||
|
money: '#E6DB74',
|
||||||
|
hack: '#A6E22E',
|
||||||
|
combat: '#75715E',
|
||||||
|
cha: '#AE81FF',
|
||||||
|
int: '#66D9EF',
|
||||||
|
rep: '#E69F66',
|
||||||
|
}
|
||||||
|
});
|
@ -3,7 +3,7 @@ import { IRouter } from "../../ui/Router";
|
|||||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||||
import { BaseServer } from "../../Server/BaseServer";
|
import { BaseServer } from "../../Server/BaseServer";
|
||||||
import { findRunningScript } from "../../Script/ScriptHelpers";
|
import { findRunningScript } from "../../Script/ScriptHelpers";
|
||||||
import { isScriptFilename } from "../../Script/isScriptFilename";
|
import { isScriptFilename, validScriptExtensions } from "../../Script/isScriptFilename";
|
||||||
|
|
||||||
export function check(
|
export function check(
|
||||||
terminal: ITerminal,
|
terminal: ITerminal,
|
||||||
@ -13,19 +13,21 @@ export function check(
|
|||||||
args: (string | number | boolean)[],
|
args: (string | number | boolean)[],
|
||||||
): void {
|
): void {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
terminal.error("Incorrect number of arguments. Usage: check [script] [arg1] [arg2]...");
|
terminal.error(`Incorrect number of arguments. Usage: check [script] [arg1] [arg2]...`);
|
||||||
} else {
|
} else {
|
||||||
const scriptName = terminal.getFilepath(args[0] + "");
|
const scriptName = terminal.getFilepath(args[0] + "");
|
||||||
// Can only tail script files
|
// Can only tail script files
|
||||||
if (!isScriptFilename(scriptName)) {
|
if (!isScriptFilename(scriptName)) {
|
||||||
terminal.error("tail can only be called on .script files (filename must end with .script)");
|
terminal.error(
|
||||||
|
`'check' can only be called on scripts files (filename must end with ${validScriptExtensions.join(", ")})`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the script exists on this machine
|
// Check that the script is running on this machine
|
||||||
const runningScript = findRunningScript(scriptName, args.slice(1), server);
|
const runningScript = findRunningScript(scriptName, args.slice(1), server);
|
||||||
if (runningScript == null) {
|
if (runningScript == null) {
|
||||||
terminal.error("No such script exists");
|
terminal.error(`No script named ${scriptName} is running on the server`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runningScript.displayLog();
|
runningScript.displayLog();
|
||||||
|
@ -27,7 +27,7 @@ export function kill(
|
|||||||
if (res) {
|
if (res) {
|
||||||
terminal.print(`Killing script with PID ${pid}`);
|
terminal.print(`Killing script with PID ${pid}`);
|
||||||
} else {
|
} else {
|
||||||
terminal.error(`Failed to kill script with PID ${pid}. No such script exists`);
|
terminal.error(`Failed to kill script with PID ${pid}. No such script is running`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -17,7 +17,7 @@ export function ls(
|
|||||||
terminal.error("Incorrect usage of ls command. Usage: ls [dir] [| grep pattern]");
|
terminal.error("Incorrect usage of ls command. Usage: ls [dir] [| grep pattern]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numArgs > 5 || numArgs === 3) {
|
if (numArgs > 4 || numArgs === 2) {
|
||||||
return incorrectUsage();
|
return incorrectUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,12 +30,12 @@ export function ls(
|
|||||||
prefix += "/";
|
prefix += "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are 4+ arguments, then the last 3 must be for grep
|
// If there are 3+ arguments, then the last 3 must be for grep
|
||||||
if (numArgs >= 4) {
|
if (numArgs >= 3) {
|
||||||
if (args[numArgs - 1] !== "grep" || args[numArgs - 2] !== "|") {
|
if (args[numArgs - 2] !== "grep" || args[numArgs - 3] !== "|") {
|
||||||
return incorrectUsage();
|
return incorrectUsage();
|
||||||
}
|
}
|
||||||
filter = args[numArgs] + "";
|
filter = args[numArgs - 1] + "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the second argument is not a pipe, then it must be for listing a directory
|
// If the second argument is not a pipe, then it must be for listing a directory
|
||||||
|
@ -29,7 +29,7 @@ export function mem(
|
|||||||
|
|
||||||
const script = terminal.getScript(player, scriptName);
|
const script = terminal.getScript(player, scriptName);
|
||||||
if (script == null) {
|
if (script == null) {
|
||||||
terminal.error("No such script exists!");
|
terminal.error("mem failed. No such script exists!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export function runProgram(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const program of Object.values(Programs)) {
|
for (const program of Object.values(Programs)) {
|
||||||
if (program.name === programName) {
|
if (program.name.toLocaleLowerCase() === programName.toLocaleLowerCase()) {
|
||||||
program.run(
|
program.run(
|
||||||
router,
|
router,
|
||||||
terminal,
|
terminal,
|
||||||
|
@ -90,7 +90,7 @@ export function scp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sourceScript == null) {
|
if (sourceScript == null) {
|
||||||
terminal.error("scp() failed. No such script exists");
|
terminal.error("scp failed. No such script exists");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { IRouter } from "../../ui/Router";
|
|||||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||||
import { BaseServer } from "../../Server/BaseServer";
|
import { BaseServer } from "../../Server/BaseServer";
|
||||||
import { findRunningScriptByPid } from "../../Script/ScriptHelpers";
|
import { findRunningScriptByPid } from "../../Script/ScriptHelpers";
|
||||||
import { isScriptFilename } from "../../Script/isScriptFilename";
|
import { isScriptFilename, validScriptExtensions } from "../../Script/isScriptFilename";
|
||||||
import { compareArrays } from "../../utils/helpers/compareArrays";
|
import { compareArrays } from "../../utils/helpers/compareArrays";
|
||||||
import { LogBoxEvents } from "../../ui/React/LogBoxManager";
|
import { LogBoxEvents } from "../../ui/React/LogBoxManager";
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ export function tail(
|
|||||||
} else if (typeof commandArray[0] === "string") {
|
} else if (typeof commandArray[0] === "string") {
|
||||||
const scriptName = terminal.getFilepath(commandArray[0]);
|
const scriptName = terminal.getFilepath(commandArray[0]);
|
||||||
if (!isScriptFilename(scriptName)) {
|
if (!isScriptFilename(scriptName)) {
|
||||||
terminal.error("tail can only be called on .script, .ns, .js files, or by pid");
|
terminal.error(`tail can only be called on ${validScriptExtensions.join(", ")} files, or by PID`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,11 +66,11 @@ export function tail(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if there's no candidate then we just don't know.
|
// if there's no candidate then we just don't know.
|
||||||
terminal.error("No such script exists.");
|
terminal.error(`No script named ${scriptName} is running on the server`);
|
||||||
} else if (typeof commandArray[0] === "number") {
|
} else if (typeof commandArray[0] === "number") {
|
||||||
const runningScript = findRunningScriptByPid(commandArray[0], server);
|
const runningScript = findRunningScriptByPid(commandArray[0], server);
|
||||||
if (runningScript == null) {
|
if (runningScript == null) {
|
||||||
terminal.error("No such script exists");
|
terminal.error(`No script with PID ${commandArray[0]} is running on the server`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LogBoxEvents.emit(runningScript);
|
LogBoxEvents.emit(runningScript);
|
||||||
|
@ -7,9 +7,11 @@ import Paper from "@mui/material/Paper";
|
|||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import ReplyIcon from "@mui/icons-material/Reply";
|
import ReplyIcon from "@mui/icons-material/Reply";
|
||||||
|
import PaletteSharpIcon from "@mui/icons-material/PaletteSharp";
|
||||||
import { Color, ColorPicker } from "material-ui-color";
|
import { Color, ColorPicker } from "material-ui-color";
|
||||||
import { ThemeEvents } from "./Theme";
|
import { ThemeEvents } from "./Theme";
|
||||||
import { Settings, defaultSettings } from "../../Settings/Settings";
|
import { Settings, defaultSettings } from "../../Settings/Settings";
|
||||||
|
import { ITheme, getPredefinedThemes } from "../../Settings/Themes";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@ -64,11 +66,18 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
|
|||||||
...Settings.theme,
|
...Settings.theme,
|
||||||
});
|
});
|
||||||
|
|
||||||
function resetTheme(): void {
|
const predefinedThemes = getPredefinedThemes();
|
||||||
setCustomTheme({
|
const themes = predefinedThemes && Object.entries(predefinedThemes)
|
||||||
...defaultSettings.theme,
|
.map(([name, templateTheme]) => (
|
||||||
});
|
<Button onClick={() => setTemplateTheme(templateTheme)}
|
||||||
Object.assign(Settings.theme, defaultSettings.theme);
|
startIcon={<PaletteSharpIcon />} key={name} sx={{ mr: 1 }}>
|
||||||
|
<Typography>{name}</Typography>
|
||||||
|
</Button>
|
||||||
|
)) || <></>;
|
||||||
|
|
||||||
|
function setTheme(theme: ITheme): void {
|
||||||
|
setCustomTheme(theme);
|
||||||
|
Object.assign(Settings.theme, theme);
|
||||||
ThemeEvents.emit();
|
ThemeEvents.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,250 +105,262 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
|
|||||||
ThemeEvents.emit();
|
ThemeEvents.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setTemplateTheme(theme: ITheme): void {
|
||||||
|
setTheme(theme);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={props.open} onClose={props.onClose}>
|
<Modal open={props.open} onClose={props.onClose}>
|
||||||
<Paper>
|
<Paper sx={{ px: 1, py: 1, my: 1 }}>
|
||||||
<Tooltip open={true} placement={"top"} title={<Typography>Example tooltip</Typography>}>
|
<Tooltip open={true} placement={"top"} title={<Typography>Example tooltip</Typography>}>
|
||||||
<Button color="primary">primary button</Button>
|
<Button color="primary" size="small">primary button</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Button color="secondary">secondary button</Button>
|
<Button color="secondary" size="small">secondary button</Button>
|
||||||
<Button color="warning">warning button</Button>
|
<Button color="warning" size="small">warning button</Button>
|
||||||
<Button color="info">info button</Button>
|
<Button color="info" size="small">info button</Button>
|
||||||
<Button color="error">error button</Button>
|
<Button color="error" size="small">error button</Button>
|
||||||
<Button disabled>disabled button</Button>
|
<Button disabled size="small">disabled button</Button>
|
||||||
<Typography color="primary">text with primary color</Typography>
|
|
||||||
<Typography color="secondary">text with secondary color</Typography>
|
<br />
|
||||||
<Typography color="error">text with error color</Typography>
|
<Typography color="primary" variant="caption">text with primary color</Typography>
|
||||||
<TextField value={"Text field"} />
|
<Typography color="secondary" variant="caption">text with secondary color</Typography>
|
||||||
|
<Typography color="error" variant="caption">text with error color</Typography>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<TextField value={"Text field"} size="small" />
|
||||||
</Paper>
|
</Paper>
|
||||||
<br />
|
|
||||||
<ColorEditor
|
|
||||||
name="primarylight"
|
|
||||||
onColorChange={onColorChange}
|
|
||||||
color={customTheme["primarylight"]}
|
|
||||||
defaultColor={defaultSettings.theme["primarylight"]}
|
|
||||||
/>
|
|
||||||
<ColorEditor
|
|
||||||
name="primary"
|
|
||||||
onColorChange={onColorChange}
|
|
||||||
color={customTheme["primary"]}
|
|
||||||
defaultColor={defaultSettings.theme["primary"]}
|
|
||||||
/>
|
|
||||||
<ColorEditor
|
|
||||||
name="primarydark"
|
|
||||||
onColorChange={onColorChange}
|
|
||||||
color={customTheme["primarydark"]}
|
|
||||||
defaultColor={defaultSettings.theme["primarydark"]}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<br />
|
<Paper sx={{ py: 1, my: 1 }}>
|
||||||
|
<ColorEditor
|
||||||
|
name="primarylight"
|
||||||
|
onColorChange={onColorChange}
|
||||||
|
color={customTheme["primarylight"]}
|
||||||
|
defaultColor={defaultSettings.theme["primarylight"]}
|
||||||
|
/>
|
||||||
|
<ColorEditor
|
||||||
|
name="primary"
|
||||||
|
onColorChange={onColorChange}
|
||||||
|
color={customTheme["primary"]}
|
||||||
|
defaultColor={defaultSettings.theme["primary"]}
|
||||||
|
/>
|
||||||
|
<ColorEditor
|
||||||
|
name="primarydark"
|
||||||
|
onColorChange={onColorChange}
|
||||||
|
color={customTheme["primarydark"]}
|
||||||
|
defaultColor={defaultSettings.theme["primarydark"]}
|
||||||
|
/>
|
||||||
|
|
||||||
<ColorEditor
|
<br />
|
||||||
name="successlight"
|
<ColorEditor
|
||||||
onColorChange={onColorChange}
|
name="successlight"
|
||||||
color={customTheme["successlight"]}
|
onColorChange={onColorChange}
|
||||||
defaultColor={defaultSettings.theme["successlight"]}
|
color={customTheme["successlight"]}
|
||||||
/>
|
defaultColor={defaultSettings.theme["successlight"]}
|
||||||
<ColorEditor
|
/>
|
||||||
name="success"
|
<ColorEditor
|
||||||
onColorChange={onColorChange}
|
name="success"
|
||||||
color={customTheme["success"]}
|
onColorChange={onColorChange}
|
||||||
defaultColor={defaultSettings.theme["success"]}
|
color={customTheme["success"]}
|
||||||
/>
|
defaultColor={defaultSettings.theme["success"]}
|
||||||
<ColorEditor
|
/>
|
||||||
name="successdark"
|
<ColorEditor
|
||||||
onColorChange={onColorChange}
|
name="successdark"
|
||||||
color={customTheme["successdark"]}
|
onColorChange={onColorChange}
|
||||||
defaultColor={defaultSettings.theme["successdark"]}
|
color={customTheme["successdark"]}
|
||||||
/>
|
defaultColor={defaultSettings.theme["successdark"]}
|
||||||
|
/>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="errorlight"
|
name="errorlight"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["errorlight"]}
|
color={customTheme["errorlight"]}
|
||||||
defaultColor={defaultSettings.theme["errorlight"]}
|
defaultColor={defaultSettings.theme["errorlight"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="error"
|
name="error"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["error"]}
|
color={customTheme["error"]}
|
||||||
defaultColor={defaultSettings.theme["error"]}
|
defaultColor={defaultSettings.theme["error"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="errordark"
|
name="errordark"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["errordark"]}
|
color={customTheme["errordark"]}
|
||||||
defaultColor={defaultSettings.theme["errordark"]}
|
defaultColor={defaultSettings.theme["errordark"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="secondarylight"
|
name="secondarylight"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["secondarylight"]}
|
color={customTheme["secondarylight"]}
|
||||||
defaultColor={defaultSettings.theme["secondarylight"]}
|
defaultColor={defaultSettings.theme["secondarylight"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="secondary"
|
name="secondary"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["secondary"]}
|
color={customTheme["secondary"]}
|
||||||
defaultColor={defaultSettings.theme["secondary"]}
|
defaultColor={defaultSettings.theme["secondary"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="secondarydark"
|
name="secondarydark"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["secondarydark"]}
|
color={customTheme["secondarydark"]}
|
||||||
defaultColor={defaultSettings.theme["secondarydark"]}
|
defaultColor={defaultSettings.theme["secondarydark"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="warninglight"
|
name="warninglight"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["warninglight"]}
|
color={customTheme["warninglight"]}
|
||||||
defaultColor={defaultSettings.theme["warninglight"]}
|
defaultColor={defaultSettings.theme["warninglight"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="warning"
|
name="warning"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["warning"]}
|
color={customTheme["warning"]}
|
||||||
defaultColor={defaultSettings.theme["warning"]}
|
defaultColor={defaultSettings.theme["warning"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="warningdark"
|
name="warningdark"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["warningdark"]}
|
color={customTheme["warningdark"]}
|
||||||
defaultColor={defaultSettings.theme["warningdark"]}
|
defaultColor={defaultSettings.theme["warningdark"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="infolight"
|
name="infolight"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["infolight"]}
|
color={customTheme["infolight"]}
|
||||||
defaultColor={defaultSettings.theme["infolight"]}
|
defaultColor={defaultSettings.theme["infolight"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="info"
|
name="info"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["info"]}
|
color={customTheme["info"]}
|
||||||
defaultColor={defaultSettings.theme["info"]}
|
defaultColor={defaultSettings.theme["info"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="infodark"
|
name="infodark"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["infodark"]}
|
color={customTheme["infodark"]}
|
||||||
defaultColor={defaultSettings.theme["infodark"]}
|
defaultColor={defaultSettings.theme["infodark"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="welllight"
|
name="welllight"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["welllight"]}
|
color={customTheme["welllight"]}
|
||||||
defaultColor={defaultSettings.theme["welllight"]}
|
defaultColor={defaultSettings.theme["welllight"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="well"
|
name="well"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["well"]}
|
color={customTheme["well"]}
|
||||||
defaultColor={defaultSettings.theme["well"]}
|
defaultColor={defaultSettings.theme["well"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="white"
|
name="white"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["white"]}
|
color={customTheme["white"]}
|
||||||
defaultColor={defaultSettings.theme["white"]}
|
defaultColor={defaultSettings.theme["white"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="black"
|
name="black"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["black"]}
|
color={customTheme["black"]}
|
||||||
defaultColor={defaultSettings.theme["black"]}
|
defaultColor={defaultSettings.theme["black"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="backgroundprimary"
|
name="backgroundprimary"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["backgroundprimary"]}
|
color={customTheme["backgroundprimary"]}
|
||||||
defaultColor={defaultSettings.theme["backgroundprimary"]}
|
defaultColor={defaultSettings.theme["backgroundprimary"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="backgroundsecondary"
|
name="backgroundsecondary"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["backgroundsecondary"]}
|
color={customTheme["backgroundsecondary"]}
|
||||||
defaultColor={defaultSettings.theme["backgroundsecondary"]}
|
defaultColor={defaultSettings.theme["backgroundsecondary"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="button"
|
name="button"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["button"]}
|
color={customTheme["button"]}
|
||||||
defaultColor={defaultSettings.theme["button"]}
|
defaultColor={defaultSettings.theme["button"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="hp"
|
name="hp"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["hp"]}
|
color={customTheme["hp"]}
|
||||||
defaultColor={defaultSettings.theme["hp"]}
|
defaultColor={defaultSettings.theme["hp"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="money"
|
name="money"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["money"]}
|
color={customTheme["money"]}
|
||||||
defaultColor={defaultSettings.theme["money"]}
|
defaultColor={defaultSettings.theme["money"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="hack"
|
name="hack"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["hack"]}
|
color={customTheme["hack"]}
|
||||||
defaultColor={defaultSettings.theme["hack"]}
|
defaultColor={defaultSettings.theme["hack"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="combat"
|
name="combat"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["combat"]}
|
color={customTheme["combat"]}
|
||||||
defaultColor={defaultSettings.theme["combat"]}
|
defaultColor={defaultSettings.theme["combat"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="cha"
|
name="cha"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["cha"]}
|
color={customTheme["cha"]}
|
||||||
defaultColor={defaultSettings.theme["cha"]}
|
defaultColor={defaultSettings.theme["cha"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="int"
|
name="int"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["int"]}
|
color={customTheme["int"]}
|
||||||
defaultColor={defaultSettings.theme["int"]}
|
defaultColor={defaultSettings.theme["int"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="rep"
|
name="rep"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["rep"]}
|
color={customTheme["rep"]}
|
||||||
defaultColor={defaultSettings.theme["rep"]}
|
defaultColor={defaultSettings.theme["rep"]}
|
||||||
/>
|
/>
|
||||||
<ColorEditor
|
<ColorEditor
|
||||||
name="disabled"
|
name="disabled"
|
||||||
onColorChange={onColorChange}
|
onColorChange={onColorChange}
|
||||||
color={customTheme["disabled"]}
|
color={customTheme["disabled"]}
|
||||||
defaultColor={defaultSettings.theme["disabled"]}
|
defaultColor={defaultSettings.theme["disabled"]}
|
||||||
/>
|
/>
|
||||||
<br />
|
</Paper>
|
||||||
<br />
|
|
||||||
<TextField
|
<Paper sx={{ px: 1, py: 1, my: 1 }}>
|
||||||
label={"import / export theme"}
|
<TextField
|
||||||
value={JSON.stringify(customTheme)}
|
sx={{ mb: 1 }}
|
||||||
onChange={onThemeChange}
|
multiline
|
||||||
InputProps={{
|
fullWidth
|
||||||
endAdornment: (
|
maxRows={3}
|
||||||
<IconButton onClick={resetTheme} size="large">
|
label={"import / export theme"}
|
||||||
<ReplyIcon />
|
value={JSON.stringify(customTheme)}
|
||||||
</IconButton>
|
onChange={onThemeChange}
|
||||||
),
|
/>
|
||||||
}}
|
<>
|
||||||
/>
|
<Typography sx={{ my: 1 }}>Copy the string above if you want to backup or share your theme with others.</Typography>
|
||||||
|
<Typography sx={{ my: 1 }}>Use the buttons below to replace the current theme with a pre-built template</Typography>
|
||||||
|
{themes}
|
||||||
|
</>
|
||||||
|
</Paper>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user