Merge pull request #2077 from MartinFournier/feature/get-theme

Add ns.ui.getTheme() api function
This commit is contained in:
hydroflame 2021-12-21 10:57:58 -05:00 committed by GitHub
commit 26106fa71d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 154 additions and 5 deletions

@ -66,6 +66,7 @@
| [StockOrder](./bitburner.stockorder.md) | Return value of [getOrders](./bitburner.tix.getorders.md) | | [StockOrder](./bitburner.stockorder.md) | Return value of [getOrders](./bitburner.tix.getorders.md) |
| [StockOrderObject](./bitburner.stockorderobject.md) | Value in map of [StockOrder](./bitburner.stockorder.md) | | [StockOrderObject](./bitburner.stockorderobject.md) | Value in map of [StockOrder](./bitburner.stockorder.md) |
| [TIX](./bitburner.tix.md) | Stock market API | | [TIX](./bitburner.tix.md) | Stock market API |
| [UserInterface](./bitburner.userinterface.md) | User Interface API. |
| [Warehouse](./bitburner.warehouse.md) | Warehouse for a division in a city | | [Warehouse](./bitburner.warehouse.md) | Warehouse for a division in a city |
| [WarehouseAPI](./bitburner.warehouseapi.md) | Corporation Warehouse API | | [WarehouseAPI](./bitburner.warehouseapi.md) | Corporation Warehouse API |

@ -51,6 +51,7 @@ export async function main(ns) {
| [sleeve](./bitburner.ns.sleeve.md) | [Sleeve](./bitburner.sleeve.md) | Namespace for sleeve functions. | | [sleeve](./bitburner.ns.sleeve.md) | [Sleeve](./bitburner.sleeve.md) | Namespace for sleeve functions. |
| [stanek](./bitburner.ns.stanek.md) | [Stanek](./bitburner.stanek.md) | Namespace for stanek functions. RAM cost: 0 GB | | [stanek](./bitburner.ns.stanek.md) | [Stanek](./bitburner.stanek.md) | Namespace for stanek functions. RAM cost: 0 GB |
| [stock](./bitburner.ns.stock.md) | [TIX](./bitburner.tix.md) | Namespace for stock functions. | | [stock](./bitburner.ns.stock.md) | [TIX](./bitburner.tix.md) | Namespace for stock functions. |
| [ui](./bitburner.ns.ui.md) | [UserInterface](./bitburner.userinterface.md) | Namespace for user interface functions. RAM cost: 0 GB |
## Methods ## Methods

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [NS](./bitburner.ns.md) &gt; [ui](./bitburner.ns.ui.md)
## NS.ui property
Namespace for user interface functions. RAM cost: 0 GB
<b>Signature:</b>
```typescript
readonly ui: UserInterface;
```

@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [UserInterface](./bitburner.userinterface.md) &gt; [getTheme](./bitburner.userinterface.gettheme.md)
## UserInterface.getTheme() method
Get the current theme
<b>Signature:</b>
```typescript
getTheme(): UserInterfaceTheme;
```
<b>Returns:</b>
UserInterfaceTheme
An object containing the theme's colors
## Remarks
RAM cost: cost: 0 GB

@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [UserInterface](./bitburner.userinterface.md)
## UserInterface interface
User Interface API.
<b>Signature:</b>
```typescript
interface UserInterface
```
## Methods
| Method | Description |
| --- | --- |
| [getTheme()](./bitburner.userinterface.gettheme.md) | Get the current theme |

@ -348,6 +348,10 @@ export const RamCosts: IMap<any> = {
remove: RamCostConstants.ScriptStanekDeleteAt, remove: RamCostConstants.ScriptStanekDeleteAt,
}, },
ui: {
getTheme: 0,
},
heart: { heart: {
// Easter egg function // Easter egg function
break: 0, break: 0,

@ -64,7 +64,7 @@ import { NetscriptSleeve } from "./NetscriptFunctions/Sleeve";
import { NetscriptExtra } from "./NetscriptFunctions/Extra"; import { NetscriptExtra } from "./NetscriptFunctions/Extra";
import { NetscriptHacknet } from "./NetscriptFunctions/Hacknet"; import { NetscriptHacknet } from "./NetscriptFunctions/Hacknet";
import { NetscriptStanek } from "./NetscriptFunctions/Stanek"; import { NetscriptStanek } from "./NetscriptFunctions/Stanek";
import { NetscriptUserInterface } from './NetscriptFunctions/UserInterface';
import { NetscriptBladeburner } from "./NetscriptFunctions/Bladeburner"; import { NetscriptBladeburner } from "./NetscriptFunctions/Bladeburner";
import { NetscriptCodingContract } from "./NetscriptFunctions/CodingContract"; import { NetscriptCodingContract } from "./NetscriptFunctions/CodingContract";
import { NetscriptCorporation } from "./NetscriptFunctions/Corporation"; import { NetscriptCorporation } from "./NetscriptFunctions/Corporation";
@ -455,6 +455,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
const formulas = NetscriptFormulas(Player, workerScript, helper); const formulas = NetscriptFormulas(Player, workerScript, helper);
const singularity = NetscriptSingularity(Player, workerScript, helper); const singularity = NetscriptSingularity(Player, workerScript, helper);
const stockmarket = NetscriptStockMarket(Player, workerScript, helper); const stockmarket = NetscriptStockMarket(Player, workerScript, helper);
const ui = NetscriptUserInterface(Player, workerScript, helper);
const base: INS = { const base: INS = {
...singularity, ...singularity,
@ -465,7 +466,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
sleeve: sleeve, sleeve: sleeve,
corporation: corporation, corporation: corporation,
stanek: stanek, stanek: stanek,
ui: ui,
formulas: formulas, formulas: formulas,
stock: stockmarket, stock: stockmarket,
args: workerScript.args, args: workerScript.args,

@ -0,0 +1,20 @@
import { INetscriptHelper } from "./INetscriptHelper";
import { WorkerScript } from "../Netscript/WorkerScript";
import { IPlayer } from "../PersonObjects/IPlayer";
import { getRamCost } from "../Netscript/RamCostGenerator";
import { UserInterface as IUserInterface, UserInterfaceTheme } from "../ScriptEditor/NetscriptDefinitions";
import { Settings } from "../Settings/Settings";
export function NetscriptUserInterface(
player: IPlayer,
workerScript: WorkerScript,
helper: INetscriptHelper,
): IUserInterface {
return {
getTheme: function (): UserInterfaceTheme {
helper.updateDynamicRam("getTheme", getRamCost("ui", "getTheme"));
return {...Settings.theme};
},
}
}

@ -194,6 +194,8 @@ async function parseOnlyRamCalculate(
func = workerScript.env.vars.sleeve[ref]; func = workerScript.env.vars.sleeve[ref];
} else if (ref in workerScript.env.vars.stock) { } else if (ref in workerScript.env.vars.stock) {
func = workerScript.env.vars.stock[ref]; func = workerScript.env.vars.stock[ref];
} else if (ref in workerScript.env.vars.ui) {
func = workerScript.env.vars.ui[ref];
} else { } else {
func = workerScript.env.vars[ref]; func = workerScript.env.vars[ref];
} }

@ -3741,6 +3741,21 @@ interface Stanek {
remove(rootX: number, rootY: number): boolean; remove(rootX: number, rootY: number): boolean;
} }
/**
* User Interface API.
* @public
*/
interface UserInterface {
/**
* Get the current theme
* @remarks
* RAM cost: cost: 0 GB
*
* @returns An object containing the theme's colors
*/
getTheme(): UserInterfaceTheme;
}
/** /**
* Collection of all functions passed to scripts * Collection of all functions passed to scripts
* @public * @public
@ -3823,6 +3838,12 @@ export interface NS extends Singularity {
*/ */
readonly corporation: Corporation; readonly corporation: Corporation;
/**
* Namespace for user interface functions.
* RAM cost: 0 GB
*/
readonly ui: UserInterface;
/** /**
* Arguments passed into the script. * Arguments passed into the script.
* *
@ -5890,3 +5911,45 @@ interface Division {
/** Cities in which this division has expanded */ /** Cities in which this division has expanded */
cities: string[]; cities: string[];
} }
/**
* Interface Theme
* @internal
*/
interface UserInterfaceTheme {
[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;
}

@ -11,7 +11,8 @@ 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"; import { getPredefinedThemes } from "../../Settings/Themes";
import { UserInterfaceTheme } from "../../ScriptEditor/NetscriptDefinitions";
interface IProps { interface IProps {
open: boolean; open: boolean;
@ -75,7 +76,7 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
</Button> </Button>
)) || <></>; )) || <></>;
function setTheme(theme: ITheme): void { function setTheme(theme: UserInterfaceTheme): void {
setCustomTheme(theme); setCustomTheme(theme);
Object.assign(Settings.theme, theme); Object.assign(Settings.theme, theme);
ThemeEvents.emit(); ThemeEvents.emit();
@ -105,7 +106,7 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
ThemeEvents.emit(); ThemeEvents.emit();
} }
function setTemplateTheme(theme: ITheme): void { function setTemplateTheme(theme: UserInterfaceTheme): void {
setTheme(theme); setTheme(theme);
} }