mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
MISC: Remove APIs that were deprecated a long time ago (#2088)
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [getTimeSinceLastAug](./bitburner.ns.gettimesincelastaug.md)
|
||||
|
||||
## NS.getTimeSinceLastAug() method
|
||||
|
||||
Returns the amount of time in milliseconds that have passed since you last installed Augmentations.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
getTimeSinceLastAug(): number;
|
||||
```
|
||||
**Returns:**
|
||||
|
||||
number
|
||||
|
||||
Time in milliseconds that have passed since you last installed Augmentations.
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0.05 GB
|
||||
|
||||
@@ -113,7 +113,6 @@ export async function main(ns) {
|
||||
| [getServerSecurityLevel(host)](./bitburner.ns.getserversecuritylevel.md) | Get server security level. |
|
||||
| [getServerUsedRam(host)](./bitburner.ns.getserverusedram.md) | Get the used RAM on a server. |
|
||||
| [getSharePower()](./bitburner.ns.getsharepower.md) | Share power has a multiplicative effect on rep/second while doing work for a faction. Share power increases incrementally for every thread of share running on your server network, but at a sharply decreasing rate. |
|
||||
| [getTimeSinceLastAug()](./bitburner.ns.gettimesincelastaug.md) | Returns the amount of time in milliseconds that have passed since you last installed Augmentations. |
|
||||
| [getTotalScriptExpGain()](./bitburner.ns.gettotalscriptexpgain.md) | Get the exp gain of all scripts. |
|
||||
| [getTotalScriptIncome()](./bitburner.ns.gettotalscriptincome.md) | Get the income of all scripts. |
|
||||
| [getWeakenTime(host)](./bitburner.ns.getweakentime.md) | Get the execution time of a weaken() call. |
|
||||
@@ -137,7 +136,6 @@ export async function main(ns) {
|
||||
| [moveTail(x, y, pid)](./bitburner.ns.movetail.md) | Move a tail window. This function is deprecated and will be removed in a later version. |
|
||||
| [mv(host, source, destination)](./bitburner.ns.mv.md) | Move a file on the target server. |
|
||||
| [nextPortWrite(port)](./bitburner.ns.nextportwrite.md) | Listen for a port write. |
|
||||
| [nFormat(n, format)](./bitburner.ns.nformat.md) | Format a number using the numeral library. This function is deprecated and will be removed in a later version. |
|
||||
| [nuke(host)](./bitburner.ns.nuke.md) | Runs NUKE.exe on a server. |
|
||||
| [peek(portNumber)](./bitburner.ns.peek.md) | Get a copy of the data from a port without popping it. |
|
||||
| [print(args)](./bitburner.ns.print.md) | Prints one or more values or variables to the script’s logs. |
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [nFormat](./bitburner.ns.nformat.md)
|
||||
|
||||
## NS.nFormat() method
|
||||
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> Use alternatives:
|
||||
>
|
||||
> - NS APIs: ns.formatNumber, ns.formatRam, ns.formatPercent
|
||||
>
|
||||
> - JS built-in objects/functions: Intl.NumberFormat, Intl.PluralRules, Intl.Locale, etc.
|
||||
>
|
||||
|
||||
Format a number using the numeral library. This function is deprecated and will be removed in a later version.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
nFormat(n: number, format: string): string;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| n | number | Number to format. |
|
||||
| format | string | Formatting options. See http://numeraljs.com/\#format for valid formats. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
string
|
||||
|
||||
Formatted number.
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
Converts a number into a string with the specified format options. See http://numeraljs.com/\#format for documentation on format strings supported.
|
||||
|
||||
16
package-lock.json
generated
16
package-lock.json
generated
@@ -36,7 +36,6 @@
|
||||
"material-ui-popup-state": "^1.9.3",
|
||||
"monaco-vim": "^0.3.5",
|
||||
"notistack": "^2.0.8",
|
||||
"numeral": "^2.0.6",
|
||||
"prop-types": "^15.8.1",
|
||||
"react": "^17.0.2",
|
||||
"react-beautiful-dnd": "^13.1.1",
|
||||
@@ -65,7 +64,6 @@
|
||||
"@types/jest": "^29.5.5",
|
||||
"@types/jquery": "^3.5.22",
|
||||
"@types/lodash": "^4.14.199",
|
||||
"@types/numeral": "^2.0.3",
|
||||
"@types/react": "^17.0.67",
|
||||
"@types/react-beautiful-dnd": "^13.1.5",
|
||||
"@types/react-dom": "^17.0.21",
|
||||
@@ -5148,12 +5146,6 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/numeral": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/numeral/-/numeral-2.0.3.tgz",
|
||||
"integrity": "sha512-37VDYvFbx/I+Ve1kwcDUq5+qvgNl+uy9YUZhBMJ6YWHBtr2+d6CAgdn4R81NqBlZbTpvLxJOTUhwbki7+90+qQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/parse-json": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
|
||||
@@ -15063,14 +15055,6 @@
|
||||
"url": "https://github.com/fb55/nth-check?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/numeral": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/numeral/-/numeral-2.0.6.tgz",
|
||||
"integrity": "sha512-qaKRmtYPZ5qdw4jWJD6bxEf1FJEqllJrwxCLIm0sQU/A7v2/czigzOb+C2uSiFsa9lBUzeH7M1oK+Q+OLxL3kA==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/nwsapi": {
|
||||
"version": "2.2.7",
|
||||
"resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz",
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
"material-ui-popup-state": "^1.9.3",
|
||||
"monaco-vim": "^0.3.5",
|
||||
"notistack": "^2.0.8",
|
||||
"numeral": "^2.0.6",
|
||||
"prop-types": "^15.8.1",
|
||||
"react": "^17.0.2",
|
||||
"react-beautiful-dnd": "^13.1.1",
|
||||
@@ -66,7 +65,6 @@
|
||||
"@types/jest": "^29.5.5",
|
||||
"@types/jquery": "^3.5.22",
|
||||
"@types/lodash": "^4.14.199",
|
||||
"@types/numeral": "^2.0.3",
|
||||
"@types/react": "^17.0.67",
|
||||
"@types/react-beautiful-dnd": "^13.1.5",
|
||||
"@types/react-dom": "^17.0.21",
|
||||
|
||||
@@ -602,9 +602,7 @@ export const RamCosts: RamCostTree<NSFull> = {
|
||||
formatNumber: 0,
|
||||
formatRam: 0,
|
||||
formatPercent: 0,
|
||||
nFormat: 0,
|
||||
tFormat: 0,
|
||||
getTimeSinceLastAug: RamCostConstants.GetHackTime,
|
||||
prompt: 0,
|
||||
wget: 0,
|
||||
getFavorToDonate: RamCostConstants.GetFavorToDonate,
|
||||
|
||||
@@ -97,7 +97,6 @@ import { ScriptDeath } from "./Netscript/ScriptDeath";
|
||||
import { getBitNodeMultipliers } from "./BitNode/BitNode";
|
||||
import { assert, assertArray, assertString, assertObject } from "./utils/TypeAssertion";
|
||||
import { escapeRegExp } from "lodash";
|
||||
import numeral from "numeral";
|
||||
import { clearPort, peekPort, portHandle, readPort, tryWritePort, writePort, nextPortWrite } from "./NetscriptPort";
|
||||
import { FilePath, resolveFilePath } from "./Paths/FilePath";
|
||||
import { hasScriptExtension } from "./Paths/ScriptFilePath";
|
||||
@@ -106,7 +105,7 @@ import { ContentFilePath } from "./Paths/ContentFile";
|
||||
import { hasContractExtension } from "./Paths/ContractFilePath";
|
||||
import { getRamCost } from "./Netscript/RamCostGenerator";
|
||||
import { getEnumHelper } from "./utils/EnumHelper";
|
||||
import { setDeprecatedProperties, deprecationWarning } from "./utils/DeprecationHelper";
|
||||
import { deprecationWarning } from "./utils/DeprecationHelper";
|
||||
import { ServerConstants } from "./Server/data/Constants";
|
||||
import { assertFunctionWithNSContext } from "./Netscript/TypeAssertion";
|
||||
import { Router } from "./ui/GameRoot";
|
||||
@@ -1637,30 +1636,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
const multStart = helpers.number(ctx, "multStart", _multStart);
|
||||
return formatPercent(n, fractionalDigits, multStart);
|
||||
},
|
||||
// Todo: Remove function for real though in 2.4. Until then it just directly wraps numeral.
|
||||
nFormat: (ctx) => (_n, _format) => {
|
||||
deprecationWarning(
|
||||
"ns.nFormat",
|
||||
"Use ns.formatNumber, ns.formatRam, ns.formatPercent, or JS built-in objects/functions (e.g., Intl namespace) instead. " +
|
||||
"Check the NS API documentation for details.",
|
||||
);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const format = helpers.string(ctx, "format", _format);
|
||||
return numeral(n).format(format);
|
||||
},
|
||||
tFormat: (ctx) => (_milliseconds, _milliPrecision) => {
|
||||
const milliseconds = helpers.number(ctx, "milliseconds", _milliseconds);
|
||||
const milliPrecision = !!_milliPrecision;
|
||||
return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision);
|
||||
},
|
||||
getTimeSinceLastAug: () => () => {
|
||||
deprecationWarning(
|
||||
"ns.getTimeSinceLastAug()",
|
||||
"Use `Date.now() - ns.getResetInfo().lastAugReset` instead. Please note that ns.getResetInfo().lastAugReset does NOT return the " +
|
||||
"same value as ns.getTimeSinceLastAug(). Check the NS API documentation for details.",
|
||||
);
|
||||
return Player.playtimeSinceLastAug;
|
||||
},
|
||||
alert: (ctx) => (_message) => {
|
||||
const message = helpers.string(ctx, "message", _message);
|
||||
dialogBoxCreate(message, { html: true, canBeDismissedEasily: true });
|
||||
@@ -1769,23 +1749,6 @@ export const ns: InternalAPI<NSFull> = {
|
||||
entropy: Player.entropy,
|
||||
karma: Player.karma,
|
||||
};
|
||||
setDeprecatedProperties(data, {
|
||||
playtimeSinceLastAug: {
|
||||
identifier: "ns.getPlayer().playtimeSinceLastAug",
|
||||
message: "Use ns.getResetInfo().lastAugReset instead. This is a static timestamp instead of an elapsed time.",
|
||||
value: Player.playtimeSinceLastAug,
|
||||
},
|
||||
playtimeSinceLastBitnode: {
|
||||
identifier: "ns.getPlayer().playtimeSinceLastBitnode",
|
||||
message: "Use ns.getResetInfo().lastNodeReset instead. This is a static timestamp instead of an elapsed time.",
|
||||
value: Player.playtimeSinceLastBitnode,
|
||||
},
|
||||
bitNodeN: {
|
||||
identifier: "ns.getPlayer().bitNodeN",
|
||||
message: "Use ns.getResetInfo().currentNode instead",
|
||||
value: Player.bitNodeN,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
},
|
||||
getMoneySources: () => () => ({
|
||||
@@ -1870,6 +1833,14 @@ export const ns: InternalAPI<NSFull> = {
|
||||
// Removed functions
|
||||
setRemovedFunctions(ns, {
|
||||
getServerRam: { version: "2.2.0", replacement: "getServerMaxRam and getServerUsedRam" },
|
||||
nFormat: {
|
||||
version: "3.0.0",
|
||||
replacement: "ns.formatNumber, ns.formatRam, ns.formatPercent, or JS built-in objects/functions",
|
||||
},
|
||||
getTimeSinceLastAug: {
|
||||
version: "3.0.0",
|
||||
replacement: "Date.now() - ns.getResetInfo().lastAugReset",
|
||||
},
|
||||
});
|
||||
|
||||
export function NetscriptFunctions(ws: WorkerScript): NSFull {
|
||||
|
||||
@@ -7,7 +7,6 @@ import { Warehouse } from "../Corporation/Warehouse";
|
||||
import { Division } from "../Corporation/Division";
|
||||
import { Corporation, CorporationPromise } from "../Corporation/Corporation";
|
||||
import { omit } from "lodash";
|
||||
import { setDeprecatedProperties } from "../utils/DeprecationHelper";
|
||||
import {
|
||||
Corporation as NSCorporation,
|
||||
Division as NSDivision,
|
||||
@@ -711,13 +710,6 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
divisions: [...corporation.divisions.keys()],
|
||||
valuation: corporation.valuation,
|
||||
};
|
||||
setDeprecatedProperties(data, {
|
||||
state: {
|
||||
identifier: "ns.corporation.getCorporation().state",
|
||||
message: "Use ns.corporation.getCorporation().nextState instead.",
|
||||
value: corporation.state.nextName,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
},
|
||||
hasUnlock: (ctx) => (_unlockName) => {
|
||||
|
||||
31
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
31
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -7962,14 +7962,6 @@ export interface NS {
|
||||
*/
|
||||
getScriptExpGain(script: string, host: string, ...args: ScriptArg[]): number;
|
||||
|
||||
/**
|
||||
* Returns the amount of time in milliseconds that have passed since you last installed Augmentations.
|
||||
*
|
||||
* @remarks RAM cost: 0.05 GB
|
||||
* @returns Time in milliseconds that have passed since you last installed Augmentations.
|
||||
*/
|
||||
getTimeSinceLastAug(): number;
|
||||
|
||||
/**
|
||||
* Format a string.
|
||||
*
|
||||
@@ -8057,29 +8049,6 @@ export interface NS {
|
||||
*/
|
||||
formatPercent(n: number, fractionalDigits?: number, suffixStart?: number): string;
|
||||
|
||||
/**
|
||||
* Format a number using the numeral library. This function is deprecated and will be removed in a later version.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* Use alternatives:
|
||||
*
|
||||
* - NS APIs: ns.formatNumber, ns.formatRam, ns.formatPercent
|
||||
*
|
||||
* - JS built-in objects/functions: Intl.NumberFormat, Intl.PluralRules, Intl.Locale, etc.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Converts a number into a string with the specified format options.
|
||||
* See http://numeraljs.com/#format for documentation on format strings supported.
|
||||
*
|
||||
* @param n - Number to format.
|
||||
* @param format - Formatting options. See http://numeraljs.com/#format for valid formats.
|
||||
* @returns Formatted number.
|
||||
*/
|
||||
nFormat(n: number, format: string): string;
|
||||
|
||||
/**
|
||||
* Format time to a readable string.
|
||||
* @remarks
|
||||
|
||||
@@ -2,19 +2,20 @@ import { APIBreakInfo } from "./APIBreak";
|
||||
|
||||
export const breakInfos261: APIBreakInfo[] = [
|
||||
{
|
||||
brokenFunctions: ["ns.bladeburner.getCurrentAction"],
|
||||
brokenAPIs: [{ name: "ns.bladeburner.getCurrentAction" }],
|
||||
info:
|
||||
"ns.bladeburner.getCurrentAction:\n" +
|
||||
'When not performing a bladeburner action, previously returned {type: "Idle", name: ""}, now returns null.\n' +
|
||||
"Because of this change, the null case now needs to be dealt with prior to accessing properties on the return of getCurrentAction, including destructuring.\n" +
|
||||
"Additionally, any existing code for filtering out the Idle case will need to be adjusted.\n\n" +
|
||||
"See https://github.com/bitburner-official/bitburner-src/issues/1249 or PR https://github.com/bitburner-official/bitburner-src/pull/1248 for more details.",
|
||||
showPopUp: true,
|
||||
},
|
||||
{
|
||||
brokenFunctions: [
|
||||
"ns.bladeburner.getActionCountRemaining",
|
||||
"ns.bladeburner.getActionEstimatedSuccessChance",
|
||||
"ns.bladeburner.getActionTime",
|
||||
brokenAPIs: [
|
||||
{ name: "ns.bladeburner.getActionCountRemaining" },
|
||||
{ name: "ns.bladeburner.getActionEstimatedSuccessChance" },
|
||||
{ name: "ns.bladeburner.getActionTime" },
|
||||
],
|
||||
info:
|
||||
"ns.bladeburner.getActionCountRemaining:\n" +
|
||||
@@ -25,5 +26,6 @@ export const breakInfos261: APIBreakInfo[] = [
|
||||
'Previously returned -1 when called with type "Idle" and name "". This is no longer valid usage and will result in an error.\n\n' +
|
||||
"See the related changes for ns.bladeburner.getCurrentAction, which were shown earlier in these API break details.\n" +
|
||||
"In most cases, the fixes for ns.bladeburner.getCurrentAction will fix this group of issues as well.",
|
||||
showPopUp: true,
|
||||
},
|
||||
];
|
||||
|
||||
63
src/utils/APIBreaks/3.0.0.ts
Normal file
63
src/utils/APIBreaks/3.0.0.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { APIBreakInfo } from "./APIBreak";
|
||||
|
||||
export const breakInfos300: APIBreakInfo[] = [
|
||||
{
|
||||
brokenAPIs: [{ name: "ns.nFormat" }],
|
||||
info:
|
||||
"ns.nFormat() was removed.\n" +
|
||||
"Use ns.formatNumber, ns.formatRam, ns.formatPercent, or JS built-in objects/functions (e.g., Intl.NumberFormat, " +
|
||||
"Intl.PluralRules, Intl.Locale) instead.",
|
||||
showPopUp: true,
|
||||
},
|
||||
{
|
||||
brokenAPIs: [
|
||||
{
|
||||
name: "ns.getTimeSinceLastAug",
|
||||
migration: {
|
||||
searchValue: "ns.getTimeSinceLastAug()",
|
||||
replaceValue: "(Date.now() - ns.getResetInfo().lastAugReset)",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ns.getPlayer().playtimeSinceLastAug",
|
||||
migration: {
|
||||
searchValue: "ns.getPlayer().playtimeSinceLastAug",
|
||||
replaceValue: "(Date.now() - ns.getResetInfo().lastAugReset)",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ns.getPlayer().playtimeSinceLastBitnode",
|
||||
migration: {
|
||||
searchValue: "ns.getPlayer().playtimeSinceLastBitnode",
|
||||
replaceValue: "(Date.now() - ns.getResetInfo().lastNodeReset)",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ns.getPlayer().bitNodeN",
|
||||
migration: {
|
||||
searchValue: "ns.getPlayer().bitNodeN",
|
||||
replaceValue: "ns.getResetInfo().currentNode",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ns.corporation.getCorporation().state",
|
||||
migration: {
|
||||
searchValue: "ns.corporation.getCorporation().state",
|
||||
replaceValue: "ns.corporation.getCorporation().nextState",
|
||||
},
|
||||
},
|
||||
],
|
||||
info:
|
||||
"ns.getTimeSinceLastAug was removed.\n" +
|
||||
'It has been automatically replaced with "Date.now() - ns.getResetInfo().lastAugReset".\n\n' +
|
||||
"ns.getPlayer().playtimeSinceLastAug was removed.\n" +
|
||||
'It has been automatically replaced with "Date.now() - ns.getResetInfo().lastAugReset".\n\n' +
|
||||
"ns.getPlayer().playtimeSinceLastBitnode was removed.\n" +
|
||||
'It has been automatically replaced with "Date.now() - ns.getResetInfo().lastNodeReset".\n\n' +
|
||||
"ns.getPlayer().bitNodeN was removed.\n" +
|
||||
'It has been automatically replaced with "ns.getResetInfo().currentNode"\n\n' +
|
||||
"ns.corporation.getCorporation().state was removed.\n" +
|
||||
'It has been automatically replaced with "ns.corporation.getCorporation().nextState"',
|
||||
showPopUp: false,
|
||||
},
|
||||
];
|
||||
@@ -10,7 +10,8 @@ import { Terminal } from "../../Terminal";
|
||||
import { pluralize } from "../I18nUtils";
|
||||
|
||||
// Temporary until fixing alerts manager to store alerts outside of react scope
|
||||
const dialogBoxCreate = (text: string) => setTimeout(() => dialogBoxCreateOriginal(text), 2000);
|
||||
const dialogBoxCreate = (text: string) =>
|
||||
setTimeout(() => dialogBoxCreateOriginal(text, { html: false, canBeDismissedEasily: false }), 2000);
|
||||
|
||||
/** For a single server, map of script filepath to an array of line numbers where impacted functions were detected */
|
||||
type ScriptImpactMap = Map<ScriptFilePath, number[]>;
|
||||
@@ -20,44 +21,74 @@ type ImpactMap = Map<string, ScriptImpactMap>;
|
||||
|
||||
export interface APIBreakInfo {
|
||||
/** The API functions impacted by the API break */
|
||||
brokenFunctions: string[];
|
||||
brokenAPIs: {
|
||||
name: string;
|
||||
migration?: {
|
||||
/** We may need to use a custom search value instead of name */
|
||||
searchValue: string | RegExp;
|
||||
replaceValue: string;
|
||||
};
|
||||
}[];
|
||||
/** Info that should be shown to the player, alongside the list of impacted scripts */
|
||||
info: string;
|
||||
/** If broken APIs can be safely migrated, we can skip displaying the notification popup */
|
||||
showPopUp: boolean;
|
||||
}
|
||||
|
||||
function getImpactedLines(script: Script, brokenFunctions: string[]): number[] | null {
|
||||
function detectImpactAndMigrateLines(script: Script, brokenFunctions: APIBreakInfo["brokenAPIs"]): number[] | null {
|
||||
const impactedLines: number[] = [];
|
||||
script.content.split("\n").forEach((line, i) => {
|
||||
const lines = script.content.split("\n");
|
||||
for (let i = 0; i < lines.length; ++i) {
|
||||
for (const brokenFunction of brokenFunctions) {
|
||||
if (line.includes(brokenFunction)) return impactedLines.push(i + 1);
|
||||
if (!lines[i].includes(brokenFunction.name)) {
|
||||
continue;
|
||||
}
|
||||
impactedLines.push(i + 1);
|
||||
if (brokenFunction.migration) {
|
||||
lines[i] = lines[i].replaceAll(brokenFunction.migration.searchValue, brokenFunction.migration.replaceValue);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
script.content = lines.join("\n");
|
||||
return impactedLines.length ? impactedLines : null;
|
||||
}
|
||||
|
||||
/** Returns a map keyed by all ser */
|
||||
function getImpactMap(brokenFunctions: string[]): ImpactMap | null {
|
||||
/** Returns a map keyed by hostname */
|
||||
function detectImpactAndMigrate(brokenFunctions: APIBreakInfo["brokenAPIs"]): ImpactMap | null {
|
||||
const returnMap = new Map<string, ScriptImpactMap>();
|
||||
for (const server of GetAllServers()) {
|
||||
const impactedScripts = new Map<ScriptFilePath, number[]>();
|
||||
for (const [filename, script] of server.scripts) {
|
||||
const impactedLines = getImpactedLines(script, brokenFunctions);
|
||||
if (impactedLines) impactedScripts.set(filename, impactedLines);
|
||||
const impactedLines = detectImpactAndMigrateLines(script, brokenFunctions);
|
||||
if (impactedLines) {
|
||||
impactedScripts.set(filename, impactedLines);
|
||||
}
|
||||
}
|
||||
if (impactedScripts.size) {
|
||||
returnMap.set(server.hostname, impactedScripts);
|
||||
}
|
||||
if (impactedScripts.size) returnMap.set(server.hostname, impactedScripts);
|
||||
}
|
||||
return returnMap.size ? returnMap : null;
|
||||
}
|
||||
|
||||
/** Show the player a dialog for their API breaks, and save an info file for the player to review later */
|
||||
export function showAPIBreaks(version: string, ...breakInfos: APIBreakInfo[]) {
|
||||
const details = [];
|
||||
const details: {
|
||||
text: string;
|
||||
showPopUp: boolean;
|
||||
}[] = [];
|
||||
let numberOfPopUps = 0;
|
||||
for (const breakInfo of breakInfos) {
|
||||
const impactMap = getImpactMap(breakInfo.brokenFunctions);
|
||||
if (!impactMap) continue;
|
||||
details.push(
|
||||
breakInfo.info +
|
||||
`\n\nUsage of the following functions may have been affected:\n${breakInfo.brokenFunctions.join("\n")}\n\n` +
|
||||
const impactMap = detectImpactAndMigrate(breakInfo.brokenAPIs);
|
||||
if (!impactMap) {
|
||||
continue;
|
||||
}
|
||||
details.push({
|
||||
text:
|
||||
breakInfo.info +
|
||||
`\n\nUsage of the following functions may have been affected:\n${breakInfo.brokenAPIs
|
||||
.map((func) => func.name)
|
||||
.join("\n")}\n\n` +
|
||||
[...impactMap]
|
||||
.map(
|
||||
([hostname, scriptImpactMap]) =>
|
||||
@@ -72,14 +103,22 @@ export function showAPIBreaks(version: string, ...breakInfos: APIBreakInfo[]) {
|
||||
.join("\n"),
|
||||
)
|
||||
.join("\n\n"),
|
||||
);
|
||||
showPopUp: breakInfo.showPopUp,
|
||||
});
|
||||
if (breakInfo.showPopUp) {
|
||||
++numberOfPopUps;
|
||||
}
|
||||
}
|
||||
if (!details.length) {
|
||||
return;
|
||||
}
|
||||
if (!details.length) return;
|
||||
const textFileName = resolveTextFilePath(`APIBreakInfo-${version}.txt`);
|
||||
if (!textFileName) throw new Error("Version string created an invalid API break file name");
|
||||
if (!textFileName) {
|
||||
throw new Error("Version string created an invalid API break file name");
|
||||
}
|
||||
Player.getHomeComputer().writeToTextFile(
|
||||
textFileName,
|
||||
`API BREAK INFO FOR ${version}\n\n${details.join("\n\n\n\n")}`,
|
||||
`API BREAK INFO FOR ${version}\n\n${details.map((detail) => detail.text).join("\n\n\n\n")}`,
|
||||
);
|
||||
Terminal.warn(`AN API BREAK FROM VERSION ${version} MAY HAVE AFFECTED SOME OF YOUR SCRIPTS.`);
|
||||
Terminal.warn(`INFORMATION ABOUT THIS POTENTIAL IMPACT HAS BEEN LOGGED IN ${textFileName} ON YOUR HOME COMPUTER.`);
|
||||
@@ -88,7 +127,12 @@ export function showAPIBreaks(version: string, ...breakInfos: APIBreakInfo[]) {
|
||||
"The following dialog boxes will provide details of the potential impact to your scripts.\n" +
|
||||
`A file with these details has also been saved on your home computer under filename ${textFileName}.`,
|
||||
);
|
||||
details.forEach((detail, i) => {
|
||||
dialogBoxCreate(`API BREAK VERSION ${version} DETAILS ${i + 1} of ${details.length}\n\n${detail}`);
|
||||
});
|
||||
let popUpIndex = 0;
|
||||
for (const detail of details) {
|
||||
if (!detail.showPopUp) {
|
||||
continue;
|
||||
}
|
||||
dialogBoxCreate(`API BREAK VERSION ${version} DETAILS ${popUpIndex + 1} of ${numberOfPopUps}\n\n${detail.text}`);
|
||||
++popUpIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import { exportMaterial } from "../Corporation/Actions";
|
||||
import { getGoSave, loadGo } from "../Go/SaveLoad";
|
||||
import { showAPIBreaks } from "./APIBreaks/APIBreak";
|
||||
import { breakInfos261 } from "./APIBreaks/2.6.1";
|
||||
import { breakInfos300 } from "./APIBreaks/3.0.0";
|
||||
|
||||
/** Function for performing a series of defined replacements. See 0.58.0 for usage */
|
||||
function convert(code: string, changes: [RegExp, string][]): string {
|
||||
@@ -545,4 +546,7 @@ Error: ${e}`,
|
||||
}
|
||||
if (found) Terminal.error("Filenames with whitespace found and corrected, see console for details.");
|
||||
}
|
||||
if (ver < 44) {
|
||||
showAPIBreaks("3.0.0", ...breakInfos300);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user