Skip to content

Commit 956e387

Browse files
authored
API: Add getSaveData API (bitburner-official#1390)
1 parent 934687d commit 956e387

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [Singularity](./bitburner.singularity.md) &gt; [getSaveData](./bitburner.singularity.getsavedata.md)
4+
5+
## Singularity.getSaveData() method
6+
7+
This function returns the save data.
8+
9+
**Signature:**
10+
11+
```typescript
12+
getSaveData(): Promise<Uint8Array>;
13+
```
14+
**Returns:**
15+
16+
Promise&lt;Uint8Array&gt;
17+
18+
## Remarks
19+
20+
RAM cost: 1 GB \* 16/4/1
21+

markdown/bitburner.singularity.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ This API requires Source-File 4 to use. The RAM cost of all these functions is m
5656
| [getFactionWorkTypes(faction)](./bitburner.singularity.getfactionworktypes.md) | Get the work types of a faction. |
5757
| [getOwnedAugmentations(purchased)](./bitburner.singularity.getownedaugmentations.md) | Get a list of owned augmentation. |
5858
| [getOwnedSourceFiles()](./bitburner.singularity.getownedsourcefiles.md) | Get a list of acquired Source-Files. |
59+
| [getSaveData()](./bitburner.singularity.getsavedata.md) | This function returns the save data. |
5960
| [getUpgradeHomeCoresCost()](./bitburner.singularity.getupgradehomecorescost.md) | Get the price of upgrading home cores. |
6061
| [getUpgradeHomeRamCost()](./bitburner.singularity.getupgradehomeramcost.md) | Get the price of upgrading home RAM. |
6162
| [goToLocation(locationName)](./bitburner.singularity.gotolocation.md) | Go to a location. |

src/Netscript/RamCostGenerator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ const singularity = {
215215
installAugmentations: SF4Cost(RamCostConstants.SingularityFn3),
216216
isFocused: SF4Cost(0.1),
217217
setFocus: SF4Cost(0.1),
218+
getSaveData: SF4Cost(RamCostConstants.SingularityFn1 / 2),
218219
exportGame: SF4Cost(RamCostConstants.SingularityFn1 / 2),
219220
exportGameBonus: SF4Cost(RamCostConstants.SingularityFn1 / 4),
220221
b1tflum3: SF4Cost(16),

src/NetscriptFunctions/Singularity.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,17 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
11691169
if (!Player.currentWork) return null;
11701170
return Player.currentWork.APICopy();
11711171
},
1172+
getSaveData: (ctx) => async () => {
1173+
helpers.checkSingularityAccess(ctx);
1174+
const saveData = await saveObject.getSaveData();
1175+
if (typeof saveData === "string") {
1176+
// saveData is the base64-encoded json save string. A base64-encoded string only uses ASCII characters, so it's
1177+
// fine to use new TextEncoder().encode() to encode it to a Uint8Array.
1178+
return new TextEncoder().encode(saveData);
1179+
}
1180+
// saveData is the compressed json save string.
1181+
return saveData;
1182+
},
11721183
exportGame: (ctx) => () => {
11731184
helpers.checkSingularityAccess(ctx);
11741185
onExport();

src/ScriptEditor/NetscriptDefinitions.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,14 @@ export interface BitNodeBooleanOptions {
17931793
* @public
17941794
*/
17951795
export interface Singularity {
1796+
/**
1797+
* This function returns the save data.
1798+
*
1799+
* @remarks
1800+
* RAM cost: 1 GB * 16/4/1
1801+
*/
1802+
getSaveData(): Promise<Uint8Array>;
1803+
17961804
/**
17971805
* Backup game save.
17981806
* @remarks

0 commit comments

Comments
 (0)