mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
NETSCRIPT: Moved formatting functions to their own interface (#1635)
This commit is contained in:
@@ -29,8 +29,8 @@ The amount of real time spent asleep between updates can vary due to "bonus time
|
||||
```js
|
||||
while (true) {
|
||||
const duration = await ns.bladeburner.nextUpdate();
|
||||
ns.print(`Bladeburner Division completed ${ns.tFormat(duration)} of actions.`);
|
||||
ns.print(`Bonus time remaining: ${ns.tFormat(ns.bladeburner.getBonusTime())}`);
|
||||
ns.print(`Bladeburner Division completed ${ns.format.time(duration)} of actions.`);
|
||||
ns.print(`Bonus time remaining: ${ns.format.time(ns.bladeburner.getBonusTime())}`);
|
||||
// Manage the Bladeburner division
|
||||
}
|
||||
```
|
||||
|
||||
@@ -36,5 +36,6 @@ type CodingContractNameEnumType = {
|
||||
EncryptionICaesarCipher: "Encryption I: Caesar Cipher";
|
||||
EncryptionIIVigenereCipher: "Encryption II: Vigenère Cipher";
|
||||
SquareRoot: "Square Root";
|
||||
TotalPrimesInRange: "Total Number of Primes";
|
||||
};
|
||||
```
|
||||
|
||||
@@ -36,5 +36,6 @@ export type CodingContractSignatures = {
|
||||
"Encryption I: Caesar Cipher": [[string, number], string];
|
||||
"Encryption II: Vigenère Cipher": [[string, string], string];
|
||||
"Square Root": [bigint, bigint, [string, string]];
|
||||
"Total Number of Primes": [number[], number];
|
||||
};
|
||||
```
|
||||
|
||||
23
markdown/bitburner.format.md
Normal file
23
markdown/bitburner.format.md
Normal file
@@ -0,0 +1,23 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md)
|
||||
|
||||
## Format interface
|
||||
|
||||
Format API
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
export interface Format
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
| Method | Description |
|
||||
| --- | --- |
|
||||
| [number(n, fractionalDigits, suffixStart, isInteger)](./bitburner.format.number.md) | Format a number. |
|
||||
| [percent(n, fractionalDigits, suffixStart)](./bitburner.format.percent.md) | Format a number as a percentage. |
|
||||
| [ram(n, fractionalDigits)](./bitburner.format.ram.md) | Format a number as an amount of ram. |
|
||||
| [time(milliseconds, milliPrecision)](./bitburner.format.time.md) | Format time to a readable string. |
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [formatNumber](./bitburner.ns.formatnumber.md)
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) > [number](./bitburner.format.number.md)
|
||||
|
||||
## NS.formatNumber() method
|
||||
## Format.number() method
|
||||
|
||||
Format a number.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
formatNumber(n: number, fractionalDigits?: number, suffixStart?: number, isInteger?: boolean): string;
|
||||
number(n: number, fractionalDigits?: number, suffixStart?: number, isInteger?: boolean): string;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@@ -18,7 +18,7 @@ formatNumber(n: number, fractionalDigits?: number, suffixStart?: number, isInteg
|
||||
| --- | --- | --- |
|
||||
| n | number | Number to format. |
|
||||
| fractionalDigits | number | _(Optional)_ Number of digits to show in the fractional part of the decimal number. Optional, defaults to 3. |
|
||||
| suffixStart | number | _(Optional)_ How high a number must be before a suffix will be added. Optional, defaults to 1000. Must be greater than or equal to 1000 if specified. |
|
||||
| suffixStart | number | _(Optional)_ How high a number must be before a suffix will be added. Optional, defaults to 1000. |
|
||||
| isInteger | boolean | _(Optional)_ Whether the number represents an integer. Integers do not display fractional digits until a suffix is present. Optional, defaults to false. |
|
||||
|
||||
**Returns:**
|
||||
@@ -31,7 +31,7 @@ Formatted number.
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
Converts a number into a numeric string with the specified format options. This is the same function that the game itself uses to display numbers. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format ram or percentages, see [formatRam](./bitburner.ns.formatram.md) and [formatPercent](./bitburner.ns.formatpercent.md)<!-- -->.
|
||||
Converts a number into a numeric string with the specified format options. This is the same function that the game itself uses to display numbers. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format ram or percentages, see [format.ram](./bitburner.format.ram.md) and [format.percent](./bitburner.format.percent.md)
|
||||
|
||||
This function has some quirky undocumented behaviors. This is a non-exhaustive list of those behaviors:
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [formatPercent](./bitburner.ns.formatpercent.md)
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) > [percent](./bitburner.format.percent.md)
|
||||
|
||||
## NS.formatPercent() method
|
||||
## Format.percent() method
|
||||
|
||||
Format a number as a percentage.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
formatPercent(n: number, fractionalDigits?: number, suffixStart?: number): string;
|
||||
percent(n: number, fractionalDigits?: number, suffixStart?: number): string;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@@ -30,5 +30,5 @@ Formatted percentage.
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
Converts a number into a percentage string with the specified number of fractional digits. This is the same function that the game itself uses to display percentages. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format plain numbers or ram, see [formatNumber](./bitburner.ns.formatnumber.md) and [formatRam](./bitburner.ns.formatram.md)
|
||||
Converts a number into a percentage string with the specified number of fractional digits. This is the same function that the game itself uses to display percentages. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format plain numbers or ram, see [format.number](./bitburner.format.number.md) and [format.ram](./bitburner.format.ram.md)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [formatRam](./bitburner.ns.formatram.md)
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) > [ram](./bitburner.format.ram.md)
|
||||
|
||||
## NS.formatRam() method
|
||||
## Format.ram() method
|
||||
|
||||
Format a number as an amount of ram.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
formatRam(n: number, fractionalDigits?: number): string;
|
||||
ram(n: number, fractionalDigits?: number): string;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@@ -29,5 +29,5 @@ Formatted ram amount.
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
Converts a number into a ram string with the specified number of fractional digits. This is the same function that the game itself uses to display ram. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format plain numbers or percentages, see [formatNumber](./bitburner.ns.formatnumber.md) and [formatPercent](./bitburner.ns.formatpercent.md)
|
||||
Converts a number into a ram string with the specified number of fractional digits. This is the same function that the game itself uses to display ram. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format plain numbers or percentages, see [format.number](./bitburner.format.number.md) and [format.percent](./bitburner.format.percent.md)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [tFormat](./bitburner.ns.tformat.md)
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) > [time](./bitburner.format.time.md)
|
||||
|
||||
## NS.tFormat() method
|
||||
## Format.time() method
|
||||
|
||||
Format time to a readable string.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
tFormat(milliseconds: number, milliPrecision?: boolean): string;
|
||||
time(milliseconds: number, milliPrecision?: boolean): string;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@@ -29,8 +29,8 @@ The amount of real time spent asleep between updates can vary due to "bonus time
|
||||
```js
|
||||
while (true) {
|
||||
const duration = await ns.gang.nextUpdate();
|
||||
ns.print(`Gang completed ${ns.tFormat(duration)} of activity.`);
|
||||
ns.print(`Bonus time remaining: ${ns.tFormat(ns.gang.getBonusTime())}`);
|
||||
ns.print(`Gang completed ${ns.format.time(duration)} of activity.`);
|
||||
ns.print(`Bonus time remaining: ${ns.format.time(ns.gang.getBonusTime())}`);
|
||||
// Manage the Gang
|
||||
}
|
||||
```
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
| [Export](./bitburner.export.md) | Export order for a material |
|
||||
| [FactionWorkTask](./bitburner.factionworktask.md) | Faction Work |
|
||||
| [FileRequirement](./bitburner.filerequirement.md) | Player must have a specific Literature or Message file on their home computer. |
|
||||
| [Format](./bitburner.format.md) | Format API |
|
||||
| [Formulas](./bitburner.formulas.md) | Formulas API |
|
||||
| [Fragment](./bitburner.fragment.md) | |
|
||||
| [GameInfo](./bitburner.gameinfo.md) | Game Information |
|
||||
|
||||
18
markdown/bitburner.ns.format.md
Normal file
18
markdown/bitburner.ns.format.md
Normal file
@@ -0,0 +1,18 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [format](./bitburner.ns.format.md)
|
||||
|
||||
## NS.format property
|
||||
|
||||
Namespace for formatting functions.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
readonly format: Format;
|
||||
```
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
@@ -36,6 +36,6 @@ Returns the cost to purchase a server with the specified amount of ram.
|
||||
```js
|
||||
const ram = 2 ** 20;
|
||||
const cost = ns.getPurchasedServerCost(ram);
|
||||
ns.tprint(`A purchased server with ${ns.formatRam(ram)} costs $${ns.formatNumber(cost)}`);
|
||||
ns.tprint(`A purchased server with ${ns.format.ram(ram)} costs $${ns.format.number(cost)}`);
|
||||
```
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ export async function main(ns) {
|
||||
| [codingcontract](./bitburner.ns.codingcontract.md) | <code>readonly</code> | [CodingContract](./bitburner.codingcontract.md) | Namespace for codingcontract functions. |
|
||||
| [corporation](./bitburner.ns.corporation.md) | <code>readonly</code> | [Corporation](./bitburner.corporation.md) | Namespace for corporation functions. Contains spoilers. |
|
||||
| [enums](./bitburner.ns.enums.md) | | [NSEnums](./bitburner.nsenums.md) | |
|
||||
| [format](./bitburner.ns.format.md) | <code>readonly</code> | [Format](./bitburner.format.md) | Namespace for formatting functions. |
|
||||
| [formulas](./bitburner.ns.formulas.md) | <code>readonly</code> | [Formulas](./bitburner.formulas.md) | Namespace for formulas functions. |
|
||||
| [gang](./bitburner.ns.gang.md) | <code>readonly</code> | [Gang](./bitburner.gang.md) | Namespace for gang functions. Contains spoilers. |
|
||||
| [go](./bitburner.ns.go.md) | <code>readonly</code> | [Go](./bitburner.go.md) | Namespace for Go functions. |
|
||||
@@ -71,9 +72,6 @@ export async function main(ns) {
|
||||
| [exit()](./bitburner.ns.exit.md) | Terminates the current script immediately. |
|
||||
| [fileExists(filename, host)](./bitburner.ns.fileexists.md) | Check if a file exists. |
|
||||
| [flags(schema)](./bitburner.ns.flags.md) | Parse command line flags. |
|
||||
| [formatNumber(n, fractionalDigits, suffixStart, isInteger)](./bitburner.ns.formatnumber.md) | Format a number. |
|
||||
| [formatPercent(n, fractionalDigits, suffixStart)](./bitburner.ns.formatpercent.md) | Format a number as a percentage. |
|
||||
| [formatRam(n, fractionalDigits)](./bitburner.ns.formatram.md) | Format a number as an amount of ram. |
|
||||
| [ftpcrack(host)](./bitburner.ns.ftpcrack.md) | Runs FTPCrack.exe on a server. |
|
||||
| [getBitNodeMultipliers(n, lvl)](./bitburner.ns.getbitnodemultipliers.md) | Get the current BitNode multipliers. |
|
||||
| [getFavorToDonate()](./bitburner.ns.getfavortodonate.md) | Returns the amount of Faction favor required to be able to donate to a faction. |
|
||||
@@ -165,7 +163,6 @@ export async function main(ns) {
|
||||
| [sprintf(format, args)](./bitburner.ns.sprintf.md) | Format a string. |
|
||||
| [sqlinject(host)](./bitburner.ns.sqlinject.md) | Runs SQLInject.exe on a server. |
|
||||
| [tail(fn, host, args)](./bitburner.ns.tail.md) | Open the tail window of a script. This function is deprecated and will be removed in a later version. |
|
||||
| [tFormat(milliseconds, milliPrecision)](./bitburner.ns.tformat.md) | Format time to a readable string. |
|
||||
| [toast(msg, variant, duration)](./bitburner.ns.toast.md) | Queue a toast (bottom-right notification). |
|
||||
| [tprint(args)](./bitburner.ns.tprint.md) | Prints one or more values or variables to the Terminal. |
|
||||
| [tprintf(format, values)](./bitburner.ns.tprintf.md) | Prints a raw value or a variable to the Terminal. |
|
||||
|
||||
@@ -38,6 +38,6 @@ If the program does not exist, an error is thrown.
|
||||
```js
|
||||
const programName = "BruteSSH.exe";
|
||||
const cost = ns.singularity.getDarkwebProgramCost(programName);
|
||||
if (cost > 0) ns.tprint(`${programName} costs $${ns.formatNumber(cost)}`);
|
||||
if (cost > 0) ns.tprint(`${programName} costs $${ns.format.number(cost)}`);
|
||||
```
|
||||
|
||||
|
||||
@@ -224,6 +224,13 @@ const singularity = {
|
||||
getCurrentWork: SF4Cost(0.5),
|
||||
} as const;
|
||||
|
||||
const format = {
|
||||
number: 0,
|
||||
ram: 0,
|
||||
percent: 0,
|
||||
time: 0,
|
||||
} as const;
|
||||
|
||||
// Gang API
|
||||
const gang = {
|
||||
createGang: RamCostConstants.GangApiBase / 4,
|
||||
@@ -490,6 +497,7 @@ export const RamCosts: RamCostTree<NSFull> = {
|
||||
hacknet,
|
||||
stock,
|
||||
singularity,
|
||||
format,
|
||||
gang,
|
||||
go,
|
||||
bladeburner,
|
||||
@@ -599,10 +607,6 @@ export const RamCosts: RamCostTree<NSFull> = {
|
||||
getScriptExpGain: RamCostConstants.GetScript,
|
||||
getRunningScript: RamCostConstants.GetRunningScript,
|
||||
ramOverride: 0,
|
||||
formatNumber: 0,
|
||||
formatRam: 0,
|
||||
formatPercent: 0,
|
||||
tFormat: 0,
|
||||
prompt: 0,
|
||||
wget: 0,
|
||||
getFavorToDonate: RamCostConstants.GetFavorToDonate,
|
||||
|
||||
@@ -62,7 +62,6 @@ import {
|
||||
formatRam,
|
||||
formatSecurity,
|
||||
formatThreads,
|
||||
formatNumber,
|
||||
} from "./ui/formatNumber";
|
||||
import { convertTimeMsToTimeElapsedString } from "./utils/StringHelperFunctions";
|
||||
import { roundToTwo } from "./utils/helpers/roundToTwo";
|
||||
@@ -114,6 +113,7 @@ import { canAccessBitNodeFeature, validBitNodes } from "./BitNode/BitNodeUtils";
|
||||
import { isIPAddress } from "./Types/strings";
|
||||
import { compile } from "./NetscriptJSEvaluator";
|
||||
import { Script } from "./Script/Script";
|
||||
import { NetscriptFormat } from "./NetscriptFunctions/Format";
|
||||
|
||||
export const enums: NSEnums = {
|
||||
CityName,
|
||||
@@ -136,6 +136,7 @@ export type NSFull = Readonly<Omit<NS & INetscriptExtra, "pid" | "args" | "enums
|
||||
|
||||
export const ns: InternalAPI<NSFull> = {
|
||||
singularity: NetscriptSingularity(),
|
||||
format: NetscriptFormat(),
|
||||
gang: NetscriptGang(),
|
||||
go: NetscriptGo(),
|
||||
bladeburner: NetscriptBladeburner(),
|
||||
@@ -1613,34 +1614,6 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
return runningScript.onlineExpGained / runningScript.onlineRunningTime;
|
||||
},
|
||||
formatNumber:
|
||||
(ctx) =>
|
||||
(_n, _fractionalDigits = 3, _suffixStart = 1000, isInteger) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits);
|
||||
const suffixStart = helpers.number(ctx, "suffixStart", _suffixStart);
|
||||
return formatNumber(n, fractionalDigits, suffixStart, !!isInteger);
|
||||
},
|
||||
formatRam:
|
||||
(ctx) =>
|
||||
(_n, _fractionalDigits = 2) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits);
|
||||
return formatRam(n, fractionalDigits);
|
||||
},
|
||||
formatPercent:
|
||||
(ctx) =>
|
||||
(_n, _fractionalDigits = 2, _multStart = 1e6) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits);
|
||||
const multStart = helpers.number(ctx, "multStart", _multStart);
|
||||
return formatPercent(n, fractionalDigits, multStart);
|
||||
},
|
||||
tFormat: (ctx) => (_milliseconds, _milliPrecision) => {
|
||||
const milliseconds = helpers.number(ctx, "milliseconds", _milliseconds);
|
||||
const milliPrecision = !!_milliPrecision;
|
||||
return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision);
|
||||
},
|
||||
alert: (ctx) => (_message) => {
|
||||
const message = helpers.string(ctx, "message", _message);
|
||||
dialogBoxCreate(message, { html: true, canBeDismissedEasily: true });
|
||||
|
||||
38
src/NetscriptFunctions/Format.ts
Normal file
38
src/NetscriptFunctions/Format.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Format } from "@nsdefs";
|
||||
import { InternalAPI } from "src/Netscript/APIWrapper";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { formatNumber, formatPercent, formatRam } from "../ui/formatNumber";
|
||||
import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions";
|
||||
|
||||
export function NetscriptFormat(): InternalAPI<Format> {
|
||||
return {
|
||||
number:
|
||||
(ctx) =>
|
||||
(_n, _fractionalDigits = 3, _suffixStart = 1000, isInteger) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits);
|
||||
const suffixStart = helpers.number(ctx, "suffixStart", _suffixStart);
|
||||
return formatNumber(n, fractionalDigits, suffixStart, !!isInteger);
|
||||
},
|
||||
ram:
|
||||
(ctx) =>
|
||||
(_n, _fractionalDigits = 2) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits);
|
||||
return formatRam(n, fractionalDigits);
|
||||
},
|
||||
percent:
|
||||
(ctx) =>
|
||||
(_n, _fractionalDigits = 2, _multStart = 1e6) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits);
|
||||
const multStart = helpers.number(ctx, "multStart", _multStart);
|
||||
return formatPercent(n, fractionalDigits, multStart);
|
||||
},
|
||||
time: (ctx) => (_milliseconds, _milliPrecision) => {
|
||||
const milliseconds = helpers.number(ctx, "milliseconds", _milliseconds);
|
||||
const milliPrecision = !!_milliPrecision;
|
||||
return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision);
|
||||
},
|
||||
};
|
||||
}
|
||||
170
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
170
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -2772,7 +2772,7 @@ export interface Singularity {
|
||||
* ```js
|
||||
* const programName = "BruteSSH.exe";
|
||||
* const cost = ns.singularity.getDarkwebProgramCost(programName);
|
||||
* if (cost > 0) ns.tprint(`${programName} costs $${ns.formatNumber(cost)}`);
|
||||
* if (cost > 0) ns.tprint(`${programName} costs $${ns.format.number(cost)}`);
|
||||
* ```
|
||||
* @param programName - Name of program to check the price of
|
||||
* @returns Price of the specified darkweb program
|
||||
@@ -3866,8 +3866,8 @@ export interface Bladeburner {
|
||||
* ```js
|
||||
* while (true) {
|
||||
* const duration = await ns.bladeburner.nextUpdate();
|
||||
* ns.print(`Bladeburner Division completed ${ns.tFormat(duration)} of actions.`);
|
||||
* ns.print(`Bonus time remaining: ${ns.tFormat(ns.bladeburner.getBonusTime())}`);
|
||||
* ns.print(`Bladeburner Division completed ${ns.format.time(duration)} of actions.`);
|
||||
* ns.print(`Bonus time remaining: ${ns.format.time(ns.bladeburner.getBonusTime())}`);
|
||||
* // Manage the Bladeburner division
|
||||
* }
|
||||
* ```
|
||||
@@ -4013,6 +4013,85 @@ export interface CodingContract {
|
||||
getContractTypes(): CodingContractName[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format API
|
||||
* @public
|
||||
*/
|
||||
export interface Format {
|
||||
/**
|
||||
* Format a number.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Converts a number into a numeric string with the specified format options.
|
||||
* This is the same function that the game itself uses to display numbers. The format also depends on the Numeric
|
||||
* Display settings (all options on the "Numeric Display" options page)
|
||||
* To format ram or percentages, see {@link Format.ram | format.ram} and {@link Format.percent | format.percent}
|
||||
*
|
||||
* This function has some quirky undocumented behaviors. This is a non-exhaustive list of those behaviors:
|
||||
*
|
||||
* - "Infinity" and "-Infinity" are returned as "∞" and "-∞", respectively.
|
||||
*
|
||||
* - If you disable the suffix form in the settings page or the absolute value is greater than or equal to 1e33, this
|
||||
* function will use the exponential form. This means that, if Math.abs(n) >= 1e33, the returned value is always in
|
||||
* the exponential form, regardless of the setting.
|
||||
*
|
||||
* Note that the behaviors listed above are "undocumented", in the sense that we don't make any guarantee about
|
||||
* backward compatibility. You must not rely on those behaviors.
|
||||
*
|
||||
* @param n - Number to format.
|
||||
* @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 3.
|
||||
* @param suffixStart - How high a number must be before a suffix will be added. Optional, defaults to 1000.
|
||||
* @param isInteger - Whether the number represents an integer. Integers do not display fractional digits until a suffix is present. Optional, defaults to false.
|
||||
* @returns Formatted number.
|
||||
*/
|
||||
number(n: number, fractionalDigits?: number, suffixStart?: number, isInteger?: boolean): string;
|
||||
|
||||
/**
|
||||
* Format a number as an amount of ram.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Converts a number into a ram string with the specified number of fractional digits.
|
||||
* This is the same function that the game itself uses to display ram. The format also depends on the Numeric Display
|
||||
* settings (all options on the "Numeric Display" options page)
|
||||
* To format plain numbers or percentages, see {@link Format.number | format.number} and {@link Format.percent | format.percent}
|
||||
*
|
||||
* @param n - Number to format as an amount of ram, in base units of GB (or GiB if that Numeric Display option is set).
|
||||
* @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2.
|
||||
* @returns Formatted ram amount.
|
||||
*/
|
||||
ram(n: number, fractionalDigits?: number): string;
|
||||
|
||||
/**
|
||||
* Format a number as a percentage.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Converts a number into a percentage string with the specified number of fractional digits.
|
||||
* This is the same function that the game itself uses to display percentages. The format also depends on the Numeric
|
||||
* Display settings (all options on the "Numeric Display" options page)
|
||||
* To format plain numbers or ram, see {@link Format.number | format.number} and {@link Format.ram | format.ram}
|
||||
*
|
||||
* @param n - Number to format as a percentage.
|
||||
* @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2.
|
||||
* @param suffixStart - When to switch the percentage to a multiplier. Default is 1e6 or x1.00m.
|
||||
* @returns Formatted percentage.
|
||||
*/
|
||||
percent(n: number, fractionalDigits?: number, suffixStart?: number): string;
|
||||
|
||||
/**
|
||||
* Format time to a readable string.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* @param milliseconds - Number of millisecond to format.
|
||||
* @param milliPrecision - Format time with subsecond precision. Defaults to false.
|
||||
* @returns The formatted time.
|
||||
*/
|
||||
time(milliseconds: number, milliPrecision?: boolean): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gang API
|
||||
* @remarks
|
||||
@@ -4341,8 +4420,8 @@ export interface Gang {
|
||||
* ```js
|
||||
* while (true) {
|
||||
* const duration = await ns.gang.nextUpdate();
|
||||
* ns.print(`Gang completed ${ns.tFormat(duration)} of activity.`);
|
||||
* ns.print(`Bonus time remaining: ${ns.tFormat(ns.gang.getBonusTime())}`);
|
||||
* ns.print(`Gang completed ${ns.format.time(duration)} of activity.`);
|
||||
* ns.print(`Bonus time remaining: ${ns.format.time(ns.gang.getBonusTime())}`);
|
||||
* // Manage the Gang
|
||||
* }
|
||||
* ```
|
||||
@@ -6047,6 +6126,12 @@ export interface NS {
|
||||
*/
|
||||
readonly codingcontract: CodingContract;
|
||||
|
||||
/**
|
||||
* Namespace for formatting functions.
|
||||
* @remarks RAM cost: 0 GB
|
||||
*/
|
||||
readonly format: Format;
|
||||
|
||||
/**
|
||||
* Namespace for gang functions. Contains spoilers.
|
||||
* @remarks RAM cost: 0 GB
|
||||
@@ -7528,7 +7613,7 @@ export interface NS {
|
||||
* ```js
|
||||
* const ram = 2 ** 20;
|
||||
* const cost = ns.getPurchasedServerCost(ram);
|
||||
* ns.tprint(`A purchased server with ${ns.formatRam(ram)} costs $${ns.formatNumber(cost)}`);
|
||||
* ns.tprint(`A purchased server with ${ns.format.ram(ram)} costs $${ns.format.number(cost)}`);
|
||||
* ```
|
||||
* @param ram - Amount of RAM of a potential purchased server, in GB. Must be a power of 2 (2, 4, 8, 16, etc.). Maximum value of 1048576 (2^20).
|
||||
* @returns The cost to purchase a server with the specified amount of ram, or returns Infinity if ram is not a valid amount.
|
||||
@@ -7991,79 +8076,6 @@ export interface NS {
|
||||
*/
|
||||
vsprintf(format: string, args: any[]): string;
|
||||
|
||||
/**
|
||||
* Format a number.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Converts a number into a numeric string with the specified format options.
|
||||
* This is the same function that the game itself uses to display numbers. The format also depends on the Numeric
|
||||
* Display settings (all options on the "Numeric Display" options page)
|
||||
* To format ram or percentages, see {@link NS.formatRam | formatRam} and {@link NS.formatPercent | formatPercent}.
|
||||
*
|
||||
* This function has some quirky undocumented behaviors. This is a non-exhaustive list of those behaviors:
|
||||
*
|
||||
* - "Infinity" and "-Infinity" are returned as "∞" and "-∞", respectively.
|
||||
*
|
||||
* - If you disable the suffix form in the settings page or the absolute value is greater than or equal to 1e33, this
|
||||
* function will use the exponential form. This means that, if Math.abs(n) >= 1e33, the returned value is always in
|
||||
* the exponential form, regardless of the setting.
|
||||
*
|
||||
* Note that the behaviors listed above are "undocumented", in the sense that we don't make any guarantee about
|
||||
* backward compatibility. You must not rely on those behaviors.
|
||||
*
|
||||
* @param n - Number to format.
|
||||
* @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 3.
|
||||
* @param suffixStart - How high a number must be before a suffix will be added. Optional, defaults to 1000. Must be greater than or equal to 1000 if specified.
|
||||
* @param isInteger - Whether the number represents an integer. Integers do not display fractional digits until a suffix is present. Optional, defaults to false.
|
||||
* @returns Formatted number.
|
||||
*/
|
||||
formatNumber(n: number, fractionalDigits?: number, suffixStart?: number, isInteger?: boolean): string;
|
||||
|
||||
/**
|
||||
* Format a number as an amount of ram.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Converts a number into a ram string with the specified number of fractional digits.
|
||||
* This is the same function that the game itself uses to display ram. The format also depends on the Numeric Display
|
||||
* settings (all options on the "Numeric Display" options page)
|
||||
* To format plain numbers or percentages, see {@link NS.formatNumber | formatNumber} and {@link NS.formatPercent | formatPercent}
|
||||
*
|
||||
* @param n - Number to format as an amount of ram, in base units of GB (or GiB if that Numeric Display option is set).
|
||||
* @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2.
|
||||
* @returns Formatted ram amount.
|
||||
*/
|
||||
formatRam(n: number, fractionalDigits?: number): string;
|
||||
|
||||
/**
|
||||
* Format a number as a percentage.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Converts a number into a percentage string with the specified number of fractional digits.
|
||||
* This is the same function that the game itself uses to display percentages. The format also depends on the Numeric
|
||||
* Display settings (all options on the "Numeric Display" options page)
|
||||
* To format plain numbers or ram, see {@link NS.formatNumber | formatNumber} and {@link NS.formatRam | formatRam}
|
||||
*
|
||||
* @param n - Number to format as a percentage.
|
||||
* @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2.
|
||||
* @param suffixStart - When to switch the percentage to a multiplier. Default is 1e6 or x1.00m.
|
||||
* @returns Formatted percentage.
|
||||
*/
|
||||
formatPercent(n: number, fractionalDigits?: number, suffixStart?: number): string;
|
||||
|
||||
/**
|
||||
* Format time to a readable string.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* @param milliseconds - Number of millisecond to format.
|
||||
* @param milliPrecision - Format time with subsecond precision. Defaults to false.
|
||||
* @returns The formatted time.
|
||||
*/
|
||||
tFormat(milliseconds: number, milliPrecision?: boolean): string;
|
||||
|
||||
/**
|
||||
* Prompt the player with an input modal.
|
||||
* @remarks
|
||||
|
||||
@@ -60,4 +60,17 @@ export const breakInfos300: APIBreakInfo[] = [
|
||||
'It has been automatically replaced with "ns.corporation.getCorporation().nextState"',
|
||||
showPopUp: false,
|
||||
},
|
||||
{
|
||||
brokenAPIs: [
|
||||
{ name: "ns.formatNumber", migration: { searchValue: "ns.formatNumber", replaceValue: "ns.format.number" } },
|
||||
{ name: "ns.formatRam", migration: { searchValue: "ns.formatRam", replaceValue: "ns.format.ram" } },
|
||||
{ name: "ns.formatPercent", migration: { searchValue: "ns.formatPercent", replaceValue: "ns.format.percent" } },
|
||||
{ name: "ns.tFormat", migration: { searchValue: "ns.tFormat", replaceValue: "ns.format.time" } },
|
||||
],
|
||||
info:
|
||||
"The formatting functions have been moved to their own interface, ns.format.\n" +
|
||||
"Each function has been replaced with their corresponding interface variant.\n" +
|
||||
"Additionally, the naming of ns.tFormat has been changed to ns.format.time.",
|
||||
showPopUp: false,
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user