Add ns.ui.getTheme() api function

This commit is contained in:
Martin Fournier 2021-12-20 13:38:21 -05:00
parent 25f78f2b30
commit 65d0877edc
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) |
| [StockOrderObject](./bitburner.stockorderobject.md) | Value in map of [StockOrder](./bitburner.stockorder.md) |
| [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 |
| [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. |
| [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. |
| [ui](./bitburner.ns.ui.md) | [UserInterface](./bitburner.userinterface.md) | Namespace for user interface functions. RAM cost: 0 GB |
## 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,
},
ui: {
getTheme: 0,
},
heart: {
// Easter egg function
break: 0,

@ -64,7 +64,7 @@ import { NetscriptSleeve } from "./NetscriptFunctions/Sleeve";
import { NetscriptExtra } from "./NetscriptFunctions/Extra";
import { NetscriptHacknet } from "./NetscriptFunctions/Hacknet";
import { NetscriptStanek } from "./NetscriptFunctions/Stanek";
import { NetscriptUserInterface } from './NetscriptFunctions/UserInterface';
import { NetscriptBladeburner } from "./NetscriptFunctions/Bladeburner";
import { NetscriptCodingContract } from "./NetscriptFunctions/CodingContract";
import { NetscriptCorporation } from "./NetscriptFunctions/Corporation";
@ -455,6 +455,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
const formulas = NetscriptFormulas(Player, workerScript, helper);
const singularity = NetscriptSingularity(Player, workerScript, helper);
const stockmarket = NetscriptStockMarket(Player, workerScript, helper);
const ui = NetscriptUserInterface(Player, workerScript, helper);
const base: INS = {
...singularity,
@ -465,7 +466,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
sleeve: sleeve,
corporation: corporation,
stanek: stanek,
ui: ui,
formulas: formulas,
stock: stockmarket,
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];
} else if (ref in workerScript.env.vars.stock) {
func = workerScript.env.vars.stock[ref];
} else if (ref in workerScript.env.vars.ui) {
func = workerScript.env.vars.ui[ref];
} else {
func = workerScript.env.vars[ref];
}

@ -3739,6 +3739,21 @@ interface Stanek {
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
* @public
@ -3821,6 +3836,12 @@ export interface NS extends Singularity {
*/
readonly corporation: Corporation;
/**
* Namespace for user interface functions.
* RAM cost: 0 GB
*/
readonly ui: UserInterface;
/**
* Arguments passed into the script.
*
@ -5882,3 +5903,45 @@ interface Division {
/** Cities in which this division has expanded */
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 { ThemeEvents } from "./Theme";
import { Settings, defaultSettings } from "../../Settings/Settings";
import { ITheme, getPredefinedThemes } from "../../Settings/Themes";
import { getPredefinedThemes } from "../../Settings/Themes";
import { UserInterfaceTheme } from "../../ScriptEditor/NetscriptDefinitions";
interface IProps {
open: boolean;
@ -75,7 +76,7 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
</Button>
)) || <></>;
function setTheme(theme: ITheme): void {
function setTheme(theme: UserInterfaceTheme): void {
setCustomTheme(theme);
Object.assign(Settings.theme, theme);
ThemeEvents.emit();
@ -105,7 +106,7 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
ThemeEvents.emit();
}
function setTemplateTheme(theme: ITheme): void {
function setTemplateTheme(theme: UserInterfaceTheme): void {
setTheme(theme);
}