This repository has been archived on 2022-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
2021-09-12 13:58:57 -05:00
|
|
|
/// <reference path="./IResource.ts" />
|
|
|
|
|
|
|
|
abstract class Resource implements IResource {
|
2021-09-12 22:27:07 -05:00
|
|
|
public inc?: (state: GameState) => ResourceNumber = undefined;
|
|
|
|
public cost?: (state: GameState) => ResourceNumber = undefined;
|
|
|
|
public max?: (state: GameState) => number = undefined;
|
|
|
|
|
2021-09-12 13:58:57 -05:00
|
|
|
protected rawValue = 0;
|
|
|
|
|
|
|
|
public abstract readonly resourceType: ResourceType;
|
|
|
|
public abstract readonly resourceKey: ResourceKey;
|
|
|
|
|
|
|
|
public abstract readonly label?: string;
|
|
|
|
public abstract readonly singularName: string;
|
|
|
|
public abstract readonly pluralName: string;
|
|
|
|
public abstract readonly description: string;
|
|
|
|
public abstract valueInWholeNumbers: boolean;
|
|
|
|
|
|
|
|
public abstract isUnlocked: (state: GameState) => boolean;
|
|
|
|
|
|
|
|
public get value(): number {
|
|
|
|
return this.valueInWholeNumbers ? Math.floor(this.rawValue) : this.rawValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public addValue = (amount: number, _: GameState): void => {
|
|
|
|
this.rawValue += amount;
|
|
|
|
};
|
|
|
|
|
|
|
|
public restoreConfig = (config: ResourceConfig): void => {
|
|
|
|
this.rawValue = config.value;
|
|
|
|
};
|
|
|
|
}
|