From 6b8ae1b3517a6475a6000284e6829b8d664d3500 Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Sun, 19 Feb 2023 15:24:27 -0500 Subject: [PATCH] Change high% display to mult form Also includes some documentation updates from a previous PR (sleeve.setToIdle) --- markdown/bitburner.ns.formatpercent.md | 3 ++- markdown/bitburner.ns.md | 2 +- markdown/bitburner.sleeve.md | 1 + markdown/bitburner.sleeve.settoidle.md | 28 ++++++++++++++++++++++ src/NetscriptFunctions.ts | 6 ++--- src/ScriptEditor/NetscriptDefinitions.d.ts | 4 ++-- src/ui/formatNumber.ts | 6 ++--- 7 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 markdown/bitburner.sleeve.settoidle.md diff --git a/markdown/bitburner.ns.formatpercent.md b/markdown/bitburner.ns.formatpercent.md index 0b09af1a3..611585684 100644 --- a/markdown/bitburner.ns.formatpercent.md +++ b/markdown/bitburner.ns.formatpercent.md @@ -9,7 +9,7 @@ Format a number as a percentage. **Signature:** ```typescript -formatPercent(n: number, fractionalDigits?: number): string; +formatPercent(n: number, fractionalDigits?: number, multStart?: number): string; ``` ## Parameters @@ -18,6 +18,7 @@ formatPercent(n: number, fractionalDigits?: number): string; | --- | --- | --- | | n | number | Number to format as a percentage. | | fractionalDigits | number | _(Optional)_ Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2. | +| multStart | number | _(Optional)_ | **Returns:** diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index a058f67c5..6bcda23f3 100644 --- a/markdown/bitburner.ns.md +++ b/markdown/bitburner.ns.md @@ -77,7 +77,7 @@ export async function main(ns) { | [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)](./bitburner.ns.formatpercent.md) | Format a number as a percentage. | +| [formatPercent(n, fractionalDigits, multStart)](./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. | diff --git a/markdown/bitburner.sleeve.md b/markdown/bitburner.sleeve.md index 17107a3b5..f18c4a79c 100644 --- a/markdown/bitburner.sleeve.md +++ b/markdown/bitburner.sleeve.md @@ -33,6 +33,7 @@ If you are not in BitNode-10, then you must have Source-File 10 in order to use | [setToCompanyWork(sleeveNumber, companyName)](./bitburner.sleeve.settocompanywork.md) | Set a sleeve to work for a company. | | [setToFactionWork(sleeveNumber, factionName, factionWorkType)](./bitburner.sleeve.settofactionwork.md) | Set a sleeve to work for a faction. | | [setToGymWorkout(sleeveNumber, gymName, stat)](./bitburner.sleeve.settogymworkout.md) | Set a sleeve to workout at the gym. | +| [setToIdle(sleeveNumber)](./bitburner.sleeve.settoidle.md) | Set a sleeve to idle. | | [setToShockRecovery(sleeveNumber)](./bitburner.sleeve.settoshockrecovery.md) | Set a sleeve to shock recovery. | | [setToSynchronize(sleeveNumber)](./bitburner.sleeve.settosynchronize.md) | Set a sleeve to synchronize. | | [setToUniversityCourse(sleeveNumber, university, className)](./bitburner.sleeve.settouniversitycourse.md) | Set a sleeve to take a class at a university. | diff --git a/markdown/bitburner.sleeve.settoidle.md b/markdown/bitburner.sleeve.settoidle.md new file mode 100644 index 000000000..3a0df3d09 --- /dev/null +++ b/markdown/bitburner.sleeve.settoidle.md @@ -0,0 +1,28 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [Sleeve](./bitburner.sleeve.md) > [setToIdle](./bitburner.sleeve.settoidle.md) + +## Sleeve.setToIdle() method + +Set a sleeve to idle. + +**Signature:** + +```typescript +setToIdle(sleeveNumber: number): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| sleeveNumber | number | Index of the sleeve to idle. | + +**Returns:** + +void + +## Remarks + +RAM cost: 4 GB + diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 7a0f3767a..40f7a0ac0 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1691,11 +1691,11 @@ export const ns: InternalAPI = { }, formatPercent: (ctx) => - (_n, _fractionalDigits = 2, _suffixStart = 1e7) => { + (_n, _fractionalDigits = 2, _multStart = 1e6) => { const n = helpers.number(ctx, "n", _n); const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits); - const suffixStart = helpers.number(ctx, "suffixStart", _suffixStart); - return formatPercent(n, fractionalDigits, suffixStart); + const multStart = helpers.number(ctx, "multStart", _multStart); + return formatPercent(n, fractionalDigits, multStart); }, // Todo: Remove function in 2.3. Until then it just directly wraps numeral. nFormat: (ctx) => (_n, _format) => { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index dac20d764..04696451c 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6471,10 +6471,10 @@ export interface NS { * * @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 attach a suffix to the percentage. Default is 1e7 which is 1b %. + * @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; + formatPercent(n: number, fractionalDigits?: number, multStart?: number): string; /** * Format a number using the numeral library. This function is deprecated and will be removed in 2.3. diff --git a/src/ui/formatNumber.ts b/src/ui/formatNumber.ts index 167f78ec5..337f1ba16 100644 --- a/src/ui/formatNumber.ts +++ b/src/ui/formatNumber.ts @@ -89,7 +89,7 @@ function formatExponential(n: number) { } // Default suffixing starts at 1e9 % which is 1e7. -export function formatPercent(n: number, fractionalDigits = 2, suffixStart = 1e7) { +export function formatPercent(n: number, fractionalDigits = 2, multStart = 1e6) { // NaN does not get formatted if (Number.isNaN(n)) return "NaN%"; const nAbs = Math.abs(n); @@ -97,8 +97,8 @@ export function formatPercent(n: number, fractionalDigits = 2, suffixStart = 1e7 // Special handling for Infinities if (nAbs * 100 === Infinity) return n < 0 ? "-∞%" : "∞%"; - // Suffix form adds a space to be less visually confusing. Values this high should rarely be seen. - if (nAbs >= suffixStart) return formatNumber(n * 100, fractionalDigits, 0) + " %"; + // Mult form. There are probably some areas in the game this wouldn't make sense, but they hopefully won't ever have huge %. + if (nAbs >= multStart) return "x" + formatNumber(n, fractionalDigits, 0); return getFormatter(fractionalDigits, percentFormats, { style: "percent" }).format(n); }