mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
API: Add getSaveData API (#1390)
This commit is contained in:
21
markdown/bitburner.singularity.getsavedata.md
Normal file
21
markdown/bitburner.singularity.getsavedata.md
Normal file
@@ -0,0 +1,21 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Singularity](./bitburner.singularity.md) > [getSaveData](./bitburner.singularity.getsavedata.md)
|
||||
|
||||
## Singularity.getSaveData() method
|
||||
|
||||
This function returns the save data.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
getSaveData(): Promise<Uint8Array>;
|
||||
```
|
||||
**Returns:**
|
||||
|
||||
Promise<Uint8Array>
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 1 GB \* 16/4/1
|
||||
|
||||
@@ -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. |
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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();
|
||||
|
||||
8
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
8
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user