mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 21:53:50 +01:00
Fix graceful load for type changes
This commit is contained in:
parent
3f850d71ba
commit
6d72861304
@ -1145,11 +1145,24 @@ export class Industry {
|
|||||||
|
|
||||||
/** Initializes a Industry object from a JSON save state. */
|
/** Initializes a Industry object from a JSON save state. */
|
||||||
static fromJSON(value: IReviverValue): Industry {
|
static fromJSON(value: IReviverValue): Industry {
|
||||||
//Gracefully load saves which have old names for industries
|
const matNameMap = { AICores: "AI Cores", RealEstate: "Real Estate" };
|
||||||
if (value.data.type === "RealEstate") value.data.type = IndustryType.RealEstate;
|
const indNameMap = {
|
||||||
if (value.data.type === "Utilities") value.data.type = IndustryType.Utilities;
|
RealEstate: IndustryType.RealEstate,
|
||||||
if (value.data.type === "Computers") value.data.type = IndustryType.Computers;
|
Utilities: IndustryType.Utilities,
|
||||||
if (value.data.type === "Computer") value.data.type = IndustryType.Computers;
|
Computers: IndustryType.Computers,
|
||||||
|
Computer: IndustryType.Computers,
|
||||||
|
};
|
||||||
|
for (const [key, val] of Object.entries(indNameMap)) if (value.data.type === key) value.data.type = val;
|
||||||
|
value.data.prodMats = value.data.prodMats.map((matName: string) => {
|
||||||
|
if (matName in matNameMap) return matNameMap[matName as keyof typeof matNameMap];
|
||||||
|
return matName;
|
||||||
|
});
|
||||||
|
for (const matName of Object.keys(value.data.reqMats)) {
|
||||||
|
if (matName in matNameMap) {
|
||||||
|
value.data.reqMats[matNameMap[matName as keyof typeof matNameMap]] = value.data.reqMats[matName];
|
||||||
|
delete value.data.reqMats[matName];
|
||||||
|
}
|
||||||
|
}
|
||||||
return Generic_fromJSON(Industry, value.data);
|
return Generic_fromJSON(Industry, value.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user