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 type GenericDecorator = Decorator<unknown>;
|
||||||
|
|
||||||
export interface EffectFeatureOptions {
|
export interface EffectFeatureOptions<T = unknown> {
|
||||||
effect: Computable<unknown>;
|
effect: Computable<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EffectFeature<T extends EffectFeatureOptions> = Replace<
|
export type EffectFeature<T extends EffectFeatureOptions> = Replace<
|
||||||
|
@ -36,9 +36,9 @@ export type EffectFeature<T extends EffectFeatureOptions> = Replace<
|
||||||
{ effect: GetComputableType<T["effect"]> }
|
{ effect: GetComputableType<T["effect"]> }
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export type GenericEffectFeature = Replace<
|
export type GenericEffectFeature<T = unknown> = Replace<
|
||||||
EffectFeature<EffectFeatureOptions>,
|
EffectFeature<EffectFeatureOptions>,
|
||||||
{ effect: ProcessedComputable<unknown> }
|
{ effect: ProcessedComputable<T> }
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,8 +36,13 @@ export function createLazyProxy<T extends object, S extends T>(
|
||||||
): T {
|
): T {
|
||||||
const obj: S & Partial<T> = baseObject;
|
const obj: S & Partial<T> = baseObject;
|
||||||
let calculated = false;
|
let calculated = false;
|
||||||
|
let calculating = false;
|
||||||
function calculateObj(): T {
|
function calculateObj(): T {
|
||||||
if (!calculated) {
|
if (!calculated) {
|
||||||
|
if (calculating) {
|
||||||
|
throw new Error("Cyclical dependency detected. Cannot evaluate lazy proxy.");
|
||||||
|
}
|
||||||
|
calculating = true;
|
||||||
Object.assign(obj, objectFunc.call(obj, obj));
|
Object.assign(obj, objectFunc.call(obj, obj));
|
||||||
calculated = true;
|
calculated = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,19 +187,9 @@ describe("Creating cost requirement", () => {
|
||||||
unref(
|
unref(
|
||||||
createCostRequirement(() => ({
|
createCostRequirement(() => ({
|
||||||
resource,
|
resource,
|
||||||
cost: Formula.variable(resource).times(0),
|
cost: Formula.variable(resource).times(0.0001),
|
||||||
maxBulkAmount: 10
|
maxBulkAmount: 10,
|
||||||
})).requirementMet
|
cumulativeCost: false
|
||||||
)
|
|
||||||
).compare_tolerance(10));
|
|
||||||
|
|
||||||
test("Direct sum respected", () =>
|
|
||||||
expect(
|
|
||||||
unref(
|
|
||||||
createCostRequirement(() => ({
|
|
||||||
resource,
|
|
||||||
cost: Formula.variable(resource).times(0),
|
|
||||||
maxBulkAmount: 10
|
|
||||||
})).requirementMet
|
})).requirementMet
|
||||||
)
|
)
|
||||||
).compare_tolerance(10));
|
).compare_tolerance(10));
|
||||||
|
|
Loading…
Reference in a new issue