From 8ad332174085d520d565b2a9884d9365089ecfa2 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 00:18:36 -0800 Subject: [PATCH] PointLightSource done --- .../canvas/sources/base-effect-source.d.mts | 1 + .../sources/point-darkness-source.d.mts | 6 ++++++ .../canvas/sources/point-effect-source.d.mts | 3 +++ .../canvas/sources/point-light-source.d.mts | 20 ++++++++++--------- .../pixi/layers/effects/visibility.d.mts | 4 ++++ .../sources/point-light-source.mjs.test-d.ts | 2 +- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/base-effect-source.d.mts b/src/foundry/client-esm/canvas/sources/base-effect-source.d.mts index 58df56e6c..bbd00fa1b 100644 --- a/src/foundry/client-esm/canvas/sources/base-effect-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-effect-source.d.mts @@ -69,6 +69,7 @@ declare abstract class BaseEffectSource< /** * The geometric shape of the effect source which is generated later. + * @remarks This only isn't `undefined` in subclasses implementing `_createShapes()`, usually via {@link PointEffectSourceMixin} */ shape: SourceShape | undefined; diff --git a/src/foundry/client-esm/canvas/sources/point-darkness-source.d.mts b/src/foundry/client-esm/canvas/sources/point-darkness-source.d.mts index 68c8f7bb2..55058cde7 100644 --- a/src/foundry/client-esm/canvas/sources/point-darkness-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/point-darkness-source.d.mts @@ -33,6 +33,12 @@ declare class PointDarknessSource< */ protected _visualShape: SourceShape | null; + /** + * @privateRemarks This is not in foundry's code, but since this class (and its parent) implements `_createShapes`, + * and we are counting what happens in `initialize` as 'the constructor', this gets to be declared never undefined. + */ + override shape: SourceShape; + /** * Padding applied on the darkness source shape for visual appearance only. * Note: for now, padding is increased radius. It might evolve in a future release. diff --git a/src/foundry/client-esm/canvas/sources/point-effect-source.d.mts b/src/foundry/client-esm/canvas/sources/point-effect-source.d.mts index 3c8522dfa..00cbe0bb7 100644 --- a/src/foundry/client-esm/canvas/sources/point-effect-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/point-effect-source.d.mts @@ -23,6 +23,9 @@ declare class PointEffectSource { */ static defaultData: PointEffectSourceMixin.SourceData & BaseEffectSource.SourceData; + /** @privateRemarks This is not in Foundry's code, but the mixin class loses access to the type parameter that would otherwise be here */ + shape: PointSourcePolygon; + /** * A convenience reference to the radius of the source. */ diff --git a/src/foundry/client-esm/canvas/sources/point-light-source.d.mts b/src/foundry/client-esm/canvas/sources/point-light-source.d.mts index 747de8e84..06c0b45c1 100644 --- a/src/foundry/client-esm/canvas/sources/point-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/point-light-source.d.mts @@ -1,3 +1,4 @@ +import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; import type BaseLightSource from "./base-light-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; @@ -13,11 +14,17 @@ export default class PointLightSource< /** @defaultValue `"lightSources"` */ static override effectsCollection: string; - override _initialize(data: Partial): void; + /** + * @privateRemarks This is not in foundry's code, but since this class (and its parent) implements `_createShapes`, + * and we are counting what happens in `initialize` as 'the constructor', this gets to be declared never undefined. + */ + override shape: SourceShape; + + override _initialize(data: IntentionalPartial): void; override _createShapes(): void; - override _configure(changes: Partial): void; + override _configure(changes: IntentionalPartial): void; override _getPolygonConfiguration(): PointSourcePolygonConfig; @@ -26,12 +33,7 @@ export default class PointLightSource< * @param config - The visibility test configuration * @returns Is the target object visible to this source? */ - testVisibility(config: { - /** The sequence of tests to perform */ - tests: CanvasVisibilityTest[]; - /** The target object being tested */ - object: PlaceableObject; - }): boolean; + testVisibility(config?: CanvasVisibilityTestConfig): boolean; /** * Can this LightSource theoretically detect a certain object based on its properties? @@ -39,5 +41,5 @@ export default class PointLightSource< * @param target - The target object being tested * @returns Can the target object theoretically be detected by this vision source? */ - _canDetectObject(target: PlaceableObject): boolean; + _canDetectObject(target?: PlaceableObject | null): boolean; } diff --git a/src/foundry/client/pixi/layers/effects/visibility.d.mts b/src/foundry/client/pixi/layers/effects/visibility.d.mts index ee8102891..5b3ff1add 100644 --- a/src/foundry/client/pixi/layers/effects/visibility.d.mts +++ b/src/foundry/client/pixi/layers/effects/visibility.d.mts @@ -211,11 +211,15 @@ declare global { interface CanvasVisibilityTest { point: PIXI.Point; + elevation: number; los: Map; } interface CanvasVisibilityTestConfig { + /** The target object */ object: PlaceableObject | null; + + /** An array of visibility tests */ tests: CanvasVisibilityTest[]; } } diff --git a/tests/foundry/client-esm/canvas/sources/point-light-source.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/point-light-source.mjs.test-d.ts index 8b399678f..20b959643 100644 --- a/tests/foundry/client-esm/canvas/sources/point-light-source.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/point-light-source.mjs.test-d.ts @@ -3,7 +3,7 @@ import { expectTypeOf } from "vitest"; const mySource = new foundry.canvas.sources.PointLightSource(); expectTypeOf(mySource.active).toEqualTypeOf(); -expectTypeOf(mySource.drawMeshes().background.visible).toEqualTypeOf(); +expectTypeOf(mySource.drawMeshes().background?.visible).toEqualTypeOf(); expectTypeOf(mySource.animateTorch(5)).toEqualTypeOf(); expectTypeOf(mySource.add()).toEqualTypeOf(); expectTypeOf(mySource.shape).toEqualTypeOf();