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
+11
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();