diff --git a/src/features/decorators/common.ts b/src/features/decorators/common.ts index 8d76b37..07783bb 100644 --- a/src/features/decorators/common.ts +++ b/src/features/decorators/common.ts @@ -27,8 +27,8 @@ export type Decorator< export type GenericDecorator = Decorator; -export interface EffectFeatureOptions { - effect: Computable; +export interface EffectFeatureOptions { + effect: Computable; } export type EffectFeature = Replace< @@ -36,9 +36,9 @@ export type EffectFeature = Replace< { effect: GetComputableType } >; -export type GenericEffectFeature = Replace< +export type GenericEffectFeature = Replace< EffectFeature, - { effect: ProcessedComputable } + { effect: ProcessedComputable } >; /** diff --git a/src/util/proxies.ts b/src/util/proxies.ts index 6e7a6f1..f712470 100644 --- a/src/util/proxies.ts +++ b/src/util/proxies.ts @@ -36,8 +36,13 @@ export function createLazyProxy( ): T { const obj: S & Partial = baseObject; let calculated = false; + let calculating = false; function calculateObj(): T { if (!calculated) { + if (calculating) { + throw new Error("Cyclical dependency detected. Cannot evaluate lazy proxy."); + } + calculating = true; Object.assign(obj, objectFunc.call(obj, obj)); calculated = true; } diff --git a/tests/game/requirements.test.ts b/tests/game/requirements.test.ts index 2f42414..f6143ca 100644 --- a/tests/game/requirements.test.ts +++ b/tests/game/requirements.test.ts @@ -187,19 +187,9 @@ describe("Creating cost requirement", () => { unref( createCostRequirement(() => ({ resource, - cost: Formula.variable(resource).times(0), - maxBulkAmount: 10 - })).requirementMet - ) - ).compare_tolerance(10)); - - test("Direct sum respected", () => - expect( - unref( - createCostRequirement(() => ({ - resource, - cost: Formula.variable(resource).times(0), - maxBulkAmount: 10 + cost: Formula.variable(resource).times(0.0001), + maxBulkAmount: 10, + cumulativeCost: false })).requirementMet ) ).compare_tolerance(10));