From babad8c0d7aba74248e21900af41cc90cfd5981e Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 01:12:11 -0800 Subject: [PATCH] Sources done? --- .../canvas/sources/point-effect-source.d.mts | 8 +++-- .../canvas/sources/point-light-source.d.mts | 18 ++++++++--- .../sources/point-movement-source.d.mts | 24 +++++++++++--- .../canvas/sources/point-sound-source.d.mts | 32 +++++++++++++++---- .../canvas/sources/point-vision-source.d.mts | 32 ++++++++++++------- .../point-movement-source.mjs.test-d.ts | 7 ++-- .../sources/point-sound-source.mjs.test-d.ts | 7 ++-- .../sources/point-vision-source.mjs.test-d.ts | 6 +++- 8 files changed, 97 insertions(+), 37 deletions(-) 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 00cbe0bb7..808a612e6 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 @@ -21,7 +21,7 @@ declare class PointEffectSource { * @privateRemarks This will only be accurate for classes extending `PointEffectSourceMixin(BaseEffectSource)`. * Other subclasses must override this. */ - static defaultData: PointEffectSourceMixin.SourceData & BaseEffectSource.SourceData; + static defaultData: PointEffectSourceMixin.MixedSourceData; /** @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; @@ -31,7 +31,7 @@ declare class PointEffectSource { */ get radius(): number; - _initialize(data: IntentionalPartial): void; + _initialize(data: IntentionalPartial): void; _initializeSoftEdges(): void; @@ -73,7 +73,9 @@ declare function PointEffectSourceMixin>; - interface SourceData extends BaseEffectSource.SourceData { + type MixedSourceData = SourceData & BaseEffectSource.SourceData; + + interface SourceData { /** * 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 06c0b45c1..5e7dac3ec 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 @@ -2,13 +2,11 @@ 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"; -type LightSourceData = PointEffectSourceMixin.SourceData & BaseLightSource.SourceData; - /** * A specialized subclass of the BaseLightSource which renders a source of light as a point-based effect. */ -export default class PointLightSource< - SourceData extends LightSourceData = LightSourceData, +declare class PointLightSource< + SourceData extends PointLightSource.SourceData = PointLightSource.SourceData, SourceShape extends PointSourcePolygon = PointSourcePolygon, > extends PointEffectSourceMixin(BaseLightSource) { /** @defaultValue `"lightSources"` */ @@ -43,3 +41,15 @@ export default class PointLightSource< */ _canDetectObject(target?: PlaceableObject | null): boolean; } + +declare namespace PointLightSource { + type AnyConstructor = typeof AnyPointLightSource; + + type SourceData = PointEffectSourceMixin.SourceData & BaseLightSource.SourceData; +} + +declare abstract class AnyPointLightSource extends PointLightSource { + constructor(arg0: never, ...args: never[]); +} + +export default PointLightSource; diff --git a/src/foundry/client-esm/canvas/sources/point-movement-source.d.mts b/src/foundry/client-esm/canvas/sources/point-movement-source.d.mts index e586d7246..0bd9111b2 100644 --- a/src/foundry/client-esm/canvas/sources/point-movement-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/point-movement-source.d.mts @@ -1,15 +1,31 @@ import type BaseEffectSource from "./base-effect-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; -type MovementSourceData = PointEffectSourceMixin.SourceData & BaseEffectSource.SourceData; - /** * A specialized subclass of the BaseEffectSource which describes a movement-based source. */ -export default class PointMovementSource< - SourceData extends MovementSourceData = MovementSourceData, +declare class PointMovementSource< + SourceData extends PointMovementSource.SourceData = PointMovementSource.SourceData, SourceShape extends PointSourcePolygon = PointSourcePolygon, > extends PointEffectSourceMixin(BaseEffectSource) { /** @defaultValue `"move"` */ static override sourceType: string; + + /** + * @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; +} + +declare namespace PointMovementSource { + type AnyConstructor = typeof AnyPointMovementSource; + + type SourceData = PointEffectSourceMixin.MixedSourceData; +} + +declare abstract class AnyPointMovementSource extends PointMovementSource { + constructor(arg0: never, ...args: never[]); } + +export default PointMovementSource; diff --git a/src/foundry/client-esm/canvas/sources/point-sound-source.d.mts b/src/foundry/client-esm/canvas/sources/point-sound-source.d.mts index 68f68dd77..95336d121 100644 --- a/src/foundry/client-esm/canvas/sources/point-sound-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/point-sound-source.d.mts @@ -1,18 +1,23 @@ +import type { NullishProps } from "../../../../types/utils.d.mts"; import type BaseEffectSource from "./base-effect-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; -type SoundSourceData = PointEffectSourceMixin.SourceData & BaseEffectSource.SourceData; - /** * A specialized subclass of the BaseEffectSource which describes a point-based source of sound. */ -export default class PointSoundSource< - SourceData extends SoundSourceData = SoundSourceData, +declare class PointSoundSource< + SourceData extends PointSoundSource.SourceData = PointSoundSource.SourceData, SourceShape extends PointSourcePolygon = PointSourcePolygon, > extends PointEffectSourceMixin(BaseEffectSource) { /** @defaultValue `"sound"` */ static override sourceType: string; + /** + * @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 get effectsCollection(): Collection; override _getPolygonConfiguration(): PointSourcePolygonConfig; @@ -22,8 +27,21 @@ export default class PointSoundSource< */ getVolumeMultiplier( listener: Canvas.Point, - options?: { - easing?: boolean | undefined; - }, + options?: NullishProps<{ + /** If no easing, return `1` */ + easing: boolean; + }>, ): number; } + +declare namespace PointSoundSource { + type AnyConstructor = typeof AnyPointSoundSource; + + type SourceData = PointEffectSourceMixin.MixedSourceData; +} + +declare abstract class AnyPointSoundSource extends PointSoundSource { + constructor(arg0: never, ...args: never[]); +} + +export default PointSoundSource; diff --git a/src/foundry/client-esm/canvas/sources/point-vision-source.d.mts b/src/foundry/client-esm/canvas/sources/point-vision-source.d.mts index 733cadf6f..fde9ba09a 100644 --- a/src/foundry/client-esm/canvas/sources/point-vision-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/point-vision-source.d.mts @@ -1,11 +1,12 @@ import type RenderedEffectSource from "./rendered-effect-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; +import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; /** * A specialized subclass of RenderedEffectSource which represents a source of point-based vision. */ declare class PointVisionSource< - SourceData extends PointVisionSource.VisionSourceData = PointVisionSource.VisionSourceData, + SourceData extends PointVisionSource.SourceData = PointVisionSource.SourceData, SourceShape extends PointSourcePolygon = PointSourcePolygon, RenderingLayers extends RenderedEffectSource.Layers = RenderedEffectSource.Layers, > extends PointEffectSourceMixin(RenderedEffectSource) { @@ -20,16 +21,18 @@ declare class PointVisionSource< /** * The corresponding lighting levels for dim light. - * @defaultValue `LIGHTING_LEVELS.DIM` + * @defaultValue `foundry.CONST.LIGHTING_LEVELS.DIM` */ protected static _dimLightingLevel: foundry.CONST.LIGHTING_LEVELS; /** * The corresponding lighting levels for bright light. - * @defaultValue `LIGHTING_LEVELS.BRIGHT` + * @defaultValue `foundry.CONST.LIGHTING_LEVELS.BRIGHT` */ protected static _brightLightingLevel: foundry.CONST.LIGHTING_LEVELS; + static override EDGE_OFFSET: number; + /** @defaultValue `"visionSources"` */ static override effectsCollection: string; @@ -47,8 +50,9 @@ declare class PointVisionSource< * } * ``` */ - static override defaultData: PointVisionSourceData; + static override defaultData: PointVisionSource.SourceData; + /** @remarks Overrides `Adaptive*Shader` references with `*VisionShader` ones */ static get _layers(): Record; /** @@ -80,7 +84,7 @@ declare class PointVisionSource< /** * If this vision source background is rendered into the lighting container. */ - get preferred(): boolean; + get preferred(): boolean | undefined; /** * Is the rendered source animated? @@ -110,7 +114,7 @@ declare class PointVisionSource< */ visionModeOverrides: object; - override _initialize(data: Partial): void; + override _initialize(data: IntentionalPartial): void; override _createShapes(): void; @@ -119,7 +123,7 @@ declare class PointVisionSource< */ protected _updateVisionMode(): void; - override _configure(changes: Partial): void; + override _configure(changes: IntentionalPartial): void; override _configureLayer(layer: RenderedEffectSource.SourceLayer, layerId: string): void; @@ -141,7 +145,7 @@ declare class PointVisionSource< */ protected _createRestrictedPolygon(): PointSourcePolygon; - override _configureShaders(): Record; + override _configureShaders(): Record; override _updateColorationUniforms(): void; @@ -160,9 +164,11 @@ declare class PointVisionSource< } declare namespace PointVisionSource { - type Any = PointVisionSource; + type Any = PointVisionSource; + + type AnyConstructor = typeof AnyPointVisionSource; - interface VisionSourceData extends RenderedEffectSource.SourceData, PointEffectSourceMixin.SourceData { + interface SourceData extends RenderedEffectSource.SourceData, PointEffectSourceMixin.SourceData { /** * The amount of contrast */ @@ -191,7 +197,7 @@ declare namespace PointVisionSource { /** * The range of light perception. */ - lightRadius: number; + lightRadius: number | null; /** * Is this vision source blinded? @@ -200,6 +206,8 @@ declare namespace PointVisionSource { } } -type PointVisionSourceData = PointEffectSourceMixin.SourceData & RenderedEffectSource.SourceData; +declare abstract class AnyPointVisionSource extends PointVisionSource { + constructor(arg0: never, ...args: never[]); +} export default PointVisionSource; diff --git a/tests/foundry/client-esm/canvas/sources/point-movement-source.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/point-movement-source.mjs.test-d.ts index 3dc1d6755..1eec56be1 100644 --- a/tests/foundry/client-esm/canvas/sources/point-movement-source.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/point-movement-source.mjs.test-d.ts @@ -1,8 +1,9 @@ import { expectTypeOf } from "vitest"; +import type PointMovementSource from "../../../../../src/foundry/client-esm/canvas/sources/point-movement-source.d.mts"; const mySource = new foundry.canvas.sources.PointMovementSource(); expectTypeOf(mySource.active).toEqualTypeOf(); -expectTypeOf( - mySource.initialize({ x: 3, y: 5, elevation: 7 }), -).toEqualTypeOf(); +expectTypeOf(mySource.initialize({ x: 3, y: 5, elevation: 7 })).toEqualTypeOf(); +expectTypeOf(mySource.shape).toEqualTypeOf(); +expectTypeOf(mySource.data).toEqualTypeOf(); diff --git a/tests/foundry/client-esm/canvas/sources/point-sound-source.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/point-sound-source.mjs.test-d.ts index 35037e40d..d4374b953 100644 --- a/tests/foundry/client-esm/canvas/sources/point-sound-source.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/point-sound-source.mjs.test-d.ts @@ -1,8 +1,9 @@ import { expectTypeOf } from "vitest"; +import type PointSoundSource from "../../../../../src/foundry/client-esm/canvas/sources/point-sound-source.d.mts"; const mySource = new foundry.canvas.sources.PointSoundSource(); expectTypeOf(mySource.active).toEqualTypeOf(); -expectTypeOf( - mySource.initialize({ radius: 5, walls: true, disabled: false }), -).toEqualTypeOf(); +expectTypeOf(mySource.initialize({ radius: 5, walls: true, disabled: false })).toEqualTypeOf(); +expectTypeOf(mySource.shape).toEqualTypeOf(); +expectTypeOf(mySource.data).toEqualTypeOf(); diff --git a/tests/foundry/client-esm/canvas/sources/point-vision-source.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/point-vision-source.mjs.test-d.ts index bf690de43..510338d67 100644 --- a/tests/foundry/client-esm/canvas/sources/point-vision-source.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/point-vision-source.mjs.test-d.ts @@ -1,6 +1,10 @@ import { expectTypeOf } from "vitest"; +import type PointVisionSource from "../../../../../src/foundry/client-esm/canvas/sources/point-vision-source.d.mts"; const mySource = new foundry.canvas.sources.PointVisionSource(); expectTypeOf(mySource.active).toEqualTypeOf(); -expectTypeOf(mySource.drawMeshes().background.visible).toEqualTypeOf(); +expectTypeOf(mySource.drawMeshes().background?.visible).toEqualTypeOf(); +expectTypeOf(mySource.data).toEqualTypeOf(); +expectTypeOf(mySource.shape).toEqualTypeOf(); +expectTypeOf(mySource._configureShaders().background).toEqualTypeOf();