Print an error if decorator is missing required property

This commit is contained in:
Seth Posner 2023-04-19 18:21:00 -07:00
parent 6043d0c414
commit 24fcd3468e
2 changed files with 9 additions and 4 deletions

View file

@ -58,6 +58,11 @@ export type GenericBonusCompletionsFeature = Replace<
* }), bonusAmountDecorator) as GenericRepeatable & GenericBonusAmountFeature
*/
export const bonusAmountDecorator: Decorator<BonusAmountFeatureOptions, BaseBonusAmountFeature, GenericBonusAmountFeature> = {
preConstruct(feature) {
if (feature.amount === undefined) {
console.error(`Decorated feature ${feature.id} does not contain the required 'amount' property"`);
}
},
postConstruct(feature) {
processComputable(feature, "bonusAmount");
if (feature.totalAmount === undefined) {

View file

@ -2,11 +2,11 @@ import { Replace, OptionsObject } from "../feature";
import { Computable, GetComputableType, processComputable, ProcessedComputable } from "util/computed";
import { Persistent, State } from "game/persistence";
export type Decorator<FeatureOptions, BaseFeature = Object, GenericFeature = BaseFeature, S extends State = State> = {
export type Decorator<FeatureOptions, BaseFeature = object, GenericFeature = BaseFeature, S extends State = State> = {
getPersistentData?(): Record<string, Persistent<S>>;
preConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature,GenericFeature>): void;
postConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature,GenericFeature>): void;
getGatheredProps?(feature: OptionsObject<FeatureOptions,BaseFeature,GenericFeature>): Partial<OptionsObject<FeatureOptions,BaseFeature,GenericFeature>>
preConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): void;
postConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): void;
getGatheredProps?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): Partial<OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>>
}
export type GenericDecorator = Decorator<unknown>;