mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { CorpStateName } from "@nsdefs";
|
|
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../utils/JSONReviver";
|
|
import { stateNames } from "./data/Constants";
|
|
export class CorporationState {
|
|
// Number representing what state the Corporation is in. The number
|
|
// is an index for the array that holds all Corporation States
|
|
state = 0;
|
|
|
|
// Get the name of the current state
|
|
// NOTE: This does NOT return the number stored in the 'state' property,
|
|
// which is just an index for the array of all possible Corporation States.
|
|
getState(): CorpStateName {
|
|
return stateNames[this.state];
|
|
}
|
|
|
|
// Transition to the next state
|
|
nextState(): void {
|
|
if (this.state < 0 || this.state >= stateNames.length) {
|
|
this.state = 0;
|
|
}
|
|
|
|
++this.state;
|
|
if (this.state >= stateNames.length) {
|
|
this.state = 0;
|
|
}
|
|
}
|
|
|
|
// Serialize the current object to a JSON save state.
|
|
toJSON(): IReviverValue {
|
|
return Generic_toJSON("CorporationState", this);
|
|
}
|
|
|
|
// Initializes a CorporationState object from a JSON save state.
|
|
static fromJSON(value: IReviverValue): CorporationState {
|
|
return Generic_fromJSON(CorporationState, value.data);
|
|
}
|
|
}
|
|
|
|
constructorsForReviver.CorporationState = CorporationState;
|