Merge remote-tracking branch 'template/feature/requirements-refactor'

This commit is contained in:
thepaperpilot 2023-05-15 21:32:23 -05:00
commit f8e08879df
3 changed files with 12 additions and 17 deletions

View file

@ -27,8 +27,8 @@ export type Decorator<
export type GenericDecorator = Decorator<unknown>;
export interface EffectFeatureOptions {
effect: Computable<unknown>;
export interface EffectFeatureOptions<T = unknown> {
effect: Computable<T>;
}
export type EffectFeature<T extends EffectFeatureOptions> = Replace<
@ -36,9 +36,9 @@ export type EffectFeature<T extends EffectFeatureOptions> = Replace<
{ effect: GetComputableType<T["effect"]> }
>;
export type GenericEffectFeature = Replace<
export type GenericEffectFeature<T = unknown> = Replace<
EffectFeature<EffectFeatureOptions>,
{ effect: ProcessedComputable<unknown> }
{ effect: ProcessedComputable<T> }
>;
/**

View file

@ -36,8 +36,13 @@ export function createLazyProxy<T extends object, S extends T>(
): T {
const obj: S & Partial<T> = 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;
}

View file

@ -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));