Skip to content

Commit

Permalink
API: Add getSaveData API (bitburner-official#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg authored Jan 30, 2025
1 parent 934687d commit 956e387
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions markdown/bitburner.singularity.getsavedata.md
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions markdown/bitburner.singularity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
1 change: 1 addition & 0 deletions src/Netscript/RamCostGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions src/NetscriptFunctions/Singularity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/ScriptEditor/NetscriptDefinitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 956e387

Please sign in to comment.