API: Add getSaveData API (#1390)

This commit is contained in:
catloversg
2025-01-31 01:36:59 +07:00
committed by GitHub
parent 934687d4b5
commit 956e3875e9
5 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [Singularity](./bitburner.singularity.md) &gt; [getSaveData](./bitburner.singularity.getsavedata.md)
## Singularity.getSaveData() method
This function returns the save data.
**Signature:**
```typescript
getSaveData(): Promise<Uint8Array>;
```
**Returns:**
Promise&lt;Uint8Array&gt;
## Remarks
RAM cost: 1 GB \* 16/4/1

View File

@@ -56,6 +56,7 @@ This API requires Source-File 4 to use. The RAM cost of all these functions is m
| [getFactionWorkTypes(faction)](./bitburner.singularity.getfactionworktypes.md) | Get the work types of a faction. |
| [getOwnedAugmentations(purchased)](./bitburner.singularity.getownedaugmentations.md) | Get a list of owned augmentation. |
| [getOwnedSourceFiles()](./bitburner.singularity.getownedsourcefiles.md) | Get a list of acquired Source-Files. |
| [getSaveData()](./bitburner.singularity.getsavedata.md) | This function returns the save data. |
| [getUpgradeHomeCoresCost()](./bitburner.singularity.getupgradehomecorescost.md) | Get the price of upgrading home cores. |
| [getUpgradeHomeRamCost()](./bitburner.singularity.getupgradehomeramcost.md) | Get the price of upgrading home RAM. |
| [goToLocation(locationName)](./bitburner.singularity.gotolocation.md) | Go to a location. |

View File

@@ -215,6 +215,7 @@ const singularity = {
installAugmentations: SF4Cost(RamCostConstants.SingularityFn3),
isFocused: SF4Cost(0.1),
setFocus: SF4Cost(0.1),
getSaveData: SF4Cost(RamCostConstants.SingularityFn1 / 2),
exportGame: SF4Cost(RamCostConstants.SingularityFn1 / 2),
exportGameBonus: SF4Cost(RamCostConstants.SingularityFn1 / 4),
b1tflum3: SF4Cost(16),

View File

@@ -1169,6 +1169,17 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
if (!Player.currentWork) return null;
return Player.currentWork.APICopy();
},
getSaveData: (ctx) => async () => {
helpers.checkSingularityAccess(ctx);
const saveData = await saveObject.getSaveData();
if (typeof saveData === "string") {
// saveData is the base64-encoded json save string. A base64-encoded string only uses ASCII characters, so it's
// fine to use new TextEncoder().encode() to encode it to a Uint8Array.
return new TextEncoder().encode(saveData);
}
// saveData is the compressed json save string.
return saveData;
},
exportGame: (ctx) => () => {
helpers.checkSingularityAccess(ctx);
onExport();

View File

@@ -1793,6 +1793,14 @@ export interface BitNodeBooleanOptions {
* @public
*/
export interface Singularity {
/**
* This function returns the save data.
*
* @remarks
* RAM cost: 1 GB * 16/4/1
*/
getSaveData(): Promise<Uint8Array>;
/**
* Backup game save.
* @remarks