From 24fcd3468e3b613e904ba2f06ee0ad3e73774fce Mon Sep 17 00:00:00 2001 From: Seth Posner Date: Wed, 19 Apr 2023 18:21:00 -0700 Subject: [PATCH] Print an error if decorator is missing required property --- src/features/decorators/bonusDecorator.ts | 5 +++++ src/features/decorators/common.ts | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/features/decorators/bonusDecorator.ts b/src/features/decorators/bonusDecorator.ts index 1c26b14..b1c38cf 100644 --- a/src/features/decorators/bonusDecorator.ts +++ b/src/features/decorators/bonusDecorator.ts @@ -58,6 +58,11 @@ export type GenericBonusCompletionsFeature = Replace< * }), bonusAmountDecorator) as GenericRepeatable & GenericBonusAmountFeature */ export const bonusAmountDecorator: Decorator = { + 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) { diff --git a/src/features/decorators/common.ts b/src/features/decorators/common.ts index a4656d3..fb084db 100644 --- a/src/features/decorators/common.ts +++ b/src/features/decorators/common.ts @@ -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 = { +export type Decorator = { getPersistentData?(): Record>; - preConstruct?(feature: OptionsObject): void; - postConstruct?(feature: OptionsObject): void; - getGatheredProps?(feature: OptionsObject): Partial> + preConstruct?(feature: OptionsObject): void; + postConstruct?(feature: OptionsObject): void; + getGatheredProps?(feature: OptionsObject): Partial> } export type GenericDecorator = Decorator;