mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-12 01:13:19 +01:00
REFACTOR: Handle migration of ActionIdentifier in Bladeburner code instead of GenericReviver (#1799)
This commit is contained in:
parent
3846c69204
commit
22b6458c22
@ -53,6 +53,7 @@ import { resolveTeamCasualties, type OperationTeam } from "./Actions/TeamCasualt
|
|||||||
import { shuffleArray } from "../Infiltration/ui/BribeGame";
|
import { shuffleArray } from "../Infiltration/ui/BribeGame";
|
||||||
import { objectAssert } from "../utils/helpers/typeAssertion";
|
import { objectAssert } from "../utils/helpers/typeAssertion";
|
||||||
import { throwIfReachable } from "../utils/helpers/throwIfReachable";
|
import { throwIfReachable } from "../utils/helpers/throwIfReachable";
|
||||||
|
import { loadActionIdentifier } from "./utils/loadActionIdentifier";
|
||||||
|
|
||||||
export const BladeburnerPromise: PromisePair<number> = { promise: null, resolve: null };
|
export const BladeburnerPromise: PromisePair<number> = { promise: null, resolve: null };
|
||||||
|
|
||||||
@ -1427,6 +1428,25 @@ export class Bladeburner implements OperationTeam {
|
|||||||
const contractsData = value.data.contracts;
|
const contractsData = value.data.contracts;
|
||||||
const operationsData = value.data.operations;
|
const operationsData = value.data.operations;
|
||||||
const bladeburner = Generic_fromJSON(Bladeburner, value.data, Bladeburner.keysToLoad);
|
const bladeburner = Generic_fromJSON(Bladeburner, value.data, Bladeburner.keysToLoad);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle migration from pre-v2.6.1 versions:
|
||||||
|
* - pre-v2.6.1:
|
||||||
|
* - action is an instance of the ActionIdentifier class. It cannot be null.
|
||||||
|
* - action.type is a number.
|
||||||
|
* - 2.6.1:
|
||||||
|
* - action is a nullable plain object. ActionIdentifier is a "type".
|
||||||
|
* - action.type is a string.
|
||||||
|
*/
|
||||||
|
if (bladeburner.action && typeof bladeburner.action.type === "number") {
|
||||||
|
bladeburner.action = loadActionIdentifier(bladeburner.action);
|
||||||
|
if (bladeburner.automateActionHigh) {
|
||||||
|
bladeburner.automateActionHigh = loadActionIdentifier(bladeburner.automateActionHigh);
|
||||||
|
}
|
||||||
|
if (bladeburner.automateActionLow) {
|
||||||
|
bladeburner.automateActionLow = loadActionIdentifier(bladeburner.automateActionLow);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Loading this way allows better typesafety and also allows faithfully reconstructing contracts/operations
|
// Loading this way allows better typesafety and also allows faithfully reconstructing contracts/operations
|
||||||
// even from save data that is missing a lot of static info about the objects.
|
// even from save data that is missing a lot of static info about the objects.
|
||||||
loadContractsData(contractsData, bladeburner.contracts);
|
loadContractsData(contractsData, bladeburner.contracts);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { loadActionIdentifier } from "../Bladeburner/utils/loadActionIdentifier";
|
|
||||||
import { constructorsForReviver, isReviverValue } from "./JSONReviver";
|
import { constructorsForReviver, isReviverValue } from "./JSONReviver";
|
||||||
import { validateObject } from "./Validator";
|
import { validateObject } from "./Validator";
|
||||||
|
|
||||||
@ -21,10 +20,9 @@ export function Reviver(_key: string, value: unknown): any {
|
|||||||
case "Employee": // Entire object removed from game in v2.2.0 (employees abstracted)
|
case "Employee": // Entire object removed from game in v2.2.0 (employees abstracted)
|
||||||
case "Company": // Reviver removed in v2.6.1
|
case "Company": // Reviver removed in v2.6.1
|
||||||
case "Faction": // Reviver removed in v2.6.1
|
case "Faction": // Reviver removed in v2.6.1
|
||||||
|
case "ActionIdentifier": // No longer a class as of v2.6.1
|
||||||
console.warn(`Legacy load type ${value.ctor} converted to expected format while loading.`);
|
console.warn(`Legacy load type ${value.ctor} converted to expected format while loading.`);
|
||||||
return value.data;
|
return value.data;
|
||||||
case "ActionIdentifier": // No longer a class as of v2.6.1
|
|
||||||
return loadActionIdentifier(value.data);
|
|
||||||
}
|
}
|
||||||
// Missing constructor with no special handling. Throw error.
|
// Missing constructor with no special handling. Throw error.
|
||||||
throw new Error(`Could not locate constructor named ${value.ctor}. If the save data is valid, this is a bug.`);
|
throw new Error(`Could not locate constructor named ${value.ctor}. If the save data is valid, this is a bug.`);
|
||||||
|
Loading…
Reference in New Issue
Block a user