forked from profectus/Profectus
Print an error if decorator is missing required property
This commit is contained in:
parent
6043d0c414
commit
24fcd3468e
2 changed files with 9 additions and 4 deletions
|
@ -58,6 +58,11 @@ export type GenericBonusCompletionsFeature = Replace<
|
||||||
* }), bonusAmountDecorator) as GenericRepeatable & GenericBonusAmountFeature
|
* }), bonusAmountDecorator) as GenericRepeatable & GenericBonusAmountFeature
|
||||||
*/
|
*/
|
||||||
export const bonusAmountDecorator: Decorator<BonusAmountFeatureOptions, BaseBonusAmountFeature, 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) {
|
postConstruct(feature) {
|
||||||
processComputable(feature, "bonusAmount");
|
processComputable(feature, "bonusAmount");
|
||||||
if (feature.totalAmount === undefined) {
|
if (feature.totalAmount === undefined) {
|
||||||
|
|
|
@ -2,11 +2,11 @@ import { Replace, OptionsObject } from "../feature";
|
||||||
import { Computable, GetComputableType, processComputable, ProcessedComputable } from "util/computed";
|
import { Computable, GetComputableType, processComputable, ProcessedComputable } from "util/computed";
|
||||||
import { Persistent, State } from "game/persistence";
|
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>>;
|
getPersistentData?(): Record<string, Persistent<S>>;
|
||||||
preConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature,GenericFeature>): void;
|
preConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): void;
|
||||||
postConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature,GenericFeature>): void;
|
postConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): void;
|
||||||
getGatheredProps?(feature: OptionsObject<FeatureOptions,BaseFeature,GenericFeature>): Partial<OptionsObject<FeatureOptions,BaseFeature,GenericFeature>>
|
getGatheredProps?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): Partial<OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GenericDecorator = Decorator<unknown>;
|
export type GenericDecorator = Decorator<unknown>;
|
||||||
|
|
Loading…
Reference in a new issue