mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 09:13:07 +02:00
prettify, sorry for the big ass commit
This commit is contained in:
@@ -2,59 +2,65 @@
|
||||
* This is an object that is used to keep track of where all of the player's
|
||||
* money is coming from (or going to)
|
||||
*/
|
||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
|
||||
import {
|
||||
Generic_fromJSON,
|
||||
Generic_toJSON,
|
||||
Reviver,
|
||||
} from "../../utils/JSONReviver";
|
||||
|
||||
export class MoneySourceTracker {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
[key: string]: number | Function;
|
||||
|
||||
bladeburner = 0;
|
||||
casino = 0;
|
||||
class = 0;
|
||||
codingcontract = 0;
|
||||
corporation = 0;
|
||||
crime = 0;
|
||||
gang = 0;
|
||||
hacking = 0;
|
||||
hacknetnode = 0;
|
||||
hospitalization = 0;
|
||||
infiltration = 0;
|
||||
sleeves = 0;
|
||||
stock = 0;
|
||||
total = 0;
|
||||
work = 0;
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
[key: string]: number | Function;
|
||||
|
||||
// Record money earned
|
||||
record(amt: number, source: string): void {
|
||||
const sanitizedSource = source.toLowerCase();
|
||||
if (typeof this[sanitizedSource] !== "number") {
|
||||
console.warn(`MoneySourceTracker.record() called with invalid source: ${source}`);
|
||||
return;
|
||||
}
|
||||
bladeburner = 0;
|
||||
casino = 0;
|
||||
class = 0;
|
||||
codingcontract = 0;
|
||||
corporation = 0;
|
||||
crime = 0;
|
||||
gang = 0;
|
||||
hacking = 0;
|
||||
hacknetnode = 0;
|
||||
hospitalization = 0;
|
||||
infiltration = 0;
|
||||
sleeves = 0;
|
||||
stock = 0;
|
||||
total = 0;
|
||||
work = 0;
|
||||
|
||||
(<number> this[sanitizedSource]) += amt;
|
||||
this.total += amt;
|
||||
// Record money earned
|
||||
record(amt: number, source: string): void {
|
||||
const sanitizedSource = source.toLowerCase();
|
||||
if (typeof this[sanitizedSource] !== "number") {
|
||||
console.warn(
|
||||
`MoneySourceTracker.record() called with invalid source: ${source}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the money tracker by setting all stats to 0
|
||||
reset(): void {
|
||||
for (const prop in this) {
|
||||
if (typeof this[prop] === "number") {
|
||||
(this[prop] as number) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
(<number>this[sanitizedSource]) += amt;
|
||||
this.total += amt;
|
||||
}
|
||||
|
||||
// Serialize the current object to a JSON save state.
|
||||
toJSON(): any {
|
||||
return Generic_toJSON("MoneySourceTracker", this);
|
||||
// Reset the money tracker by setting all stats to 0
|
||||
reset(): void {
|
||||
for (const prop in this) {
|
||||
if (typeof this[prop] === "number") {
|
||||
(this[prop] as number) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initiatizes a MoneySourceTracker object from a JSON save state.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
static fromJSON(value: any): MoneySourceTracker {
|
||||
return Generic_fromJSON(MoneySourceTracker, value.data);
|
||||
}
|
||||
// Serialize the current object to a JSON save state.
|
||||
toJSON(): any {
|
||||
return Generic_toJSON("MoneySourceTracker", this);
|
||||
}
|
||||
|
||||
// Initiatizes a MoneySourceTracker object from a JSON save state.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
static fromJSON(value: any): MoneySourceTracker {
|
||||
return Generic_fromJSON(MoneySourceTracker, value.data);
|
||||
}
|
||||
}
|
||||
|
||||
Reviver.constructors.MoneySourceTracker = MoneySourceTracker;
|
||||
|
||||
Reference in New Issue
Block a user