mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 11:27:04 +02:00
GRAFTING: Add new api for checking ongoing grafting (#1435)
This commit is contained in:
@@ -10,6 +10,8 @@ import { dialogBoxCreate } from "../ui/React/DialogBox";
|
||||
import { constructorsForReviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
|
||||
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
|
||||
import { Augmentations } from "../Augmentation/Augmentations";
|
||||
import { PromisePair } from "../Types/Promises";
|
||||
import { getKeyList } from "../utils/helpers/getKeyList";
|
||||
|
||||
export const isGraftingWork = (w: Work | null): w is GraftingWork => w !== null && w.type === WorkType.GRAFTING;
|
||||
|
||||
@@ -22,6 +24,14 @@ export class GraftingWork extends Work {
|
||||
augmentation: AugmentationName;
|
||||
unitCompleted: number;
|
||||
unitRate: number;
|
||||
completionPromisePair: PromisePair<void> = { promise: null, resolve: null };
|
||||
|
||||
get completion(): Promise<void> {
|
||||
if (!this.completionPromisePair.promise) {
|
||||
this.completionPromisePair.promise = new Promise((r) => (this.completionPromisePair.resolve = r));
|
||||
}
|
||||
return this.completionPromisePair.promise;
|
||||
}
|
||||
|
||||
constructor(params?: GraftingWorkParams) {
|
||||
super(WorkType.GRAFTING, params?.singularity ?? true);
|
||||
@@ -79,6 +89,12 @@ export class GraftingWork extends Work {
|
||||
(CONSTANTS.IntelligenceGraftBaseExpGain * this.cyclesWorked * CONSTANTS.MilliPerCycle) / 10000,
|
||||
);
|
||||
}
|
||||
|
||||
if (this.completionPromisePair.resolve) {
|
||||
this.completionPromisePair.resolve();
|
||||
this.completionPromisePair.resolve = null;
|
||||
this.completionPromisePair.promise = null;
|
||||
}
|
||||
}
|
||||
|
||||
APICopy() {
|
||||
@@ -86,17 +102,20 @@ export class GraftingWork extends Work {
|
||||
type: WorkType.GRAFTING as const,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
augmentation: this.augmentation,
|
||||
completion: this.completion,
|
||||
};
|
||||
}
|
||||
|
||||
static savedKeys = getKeyList(GraftingWork, { removedKeys: ["completionPromisePair"] });
|
||||
|
||||
/** Serialize the current object to a JSON save state. */
|
||||
toJSON(): IReviverValue {
|
||||
return Generic_toJSON("GraftingWork", this);
|
||||
return Generic_toJSON("GraftingWork", this, GraftingWork.savedKeys);
|
||||
}
|
||||
|
||||
/** Initializes a GraftingWork object from a JSON save state. */
|
||||
static fromJSON(value: IReviverValue): GraftingWork {
|
||||
return Generic_fromJSON(GraftingWork, value.data);
|
||||
return Generic_fromJSON(GraftingWork, value.data, GraftingWork.savedKeys);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user