mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2024-11-24 01:11:45 +00:00
Merge remote-tracking branch 'template/feature/requirements-refactor'
This commit is contained in:
commit
f8e08879df
3 changed files with 12 additions and 17 deletions
|
@ -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> }
|
||||
>;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue