From 56d14e70ce91a377f30a18b4f326b1b4452026dc Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 15 Dec 2024 11:02:46 -0800 Subject: [PATCH 01/22] start of BES --- .../canvas/sources/base-effect-source.d.mts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 4ea04f286..a3a0254d3 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 @@ -1,4 +1,4 @@ -import type { InexactPartial } from "../../../../types/utils.d.mts"; +import type { InexactPartial, NullishProps } from "../../../../types/utils.d.mts"; /** * TODO - Re-document after ESM refactor. @@ -14,15 +14,17 @@ import type { InexactPartial } from "../../../../types/utils.d.mts"; * ``` * @privateRemarks The TODO is foundry's */ -declare class BaseEffectSource< +declare abstract class BaseEffectSource< SourceData extends BaseEffectSource.BaseEffectSourceData, SourceShape extends PIXI.Polygon, > { /** * An effect source is constructed by providing configuration options. * @param options - Options which modify the base effect source instance + * @remarks Passing a PlaceableObject is deprecated, and will be removed in v13 */ - constructor(options?: BaseEffectSource.BaseEffectSourceOptions); + constructor(options?: PlaceableObject); + constructor(options?: BaseEffectSource.BaseEffectSourceOptions | PlaceableObject); /** * The type of source represented by this data structure. @@ -56,8 +58,9 @@ declare class BaseEffectSource< /** * The source id linked to this effect source. + * @remarks Foundry types this as Readonly, but does nothing to that effect at runtime */ - readonly sourceId: string; + sourceId: string; /** * The data of this source. @@ -130,13 +133,13 @@ declare class BaseEffectSource< */ initialize( data?: InexactPartial, - options?: InexactPartial<{ + options?: NullishProps<{ // The type def references a behaviors object that is not even passed into the function /** * Should source data be reset to default values before applying changes? * @defaultValue `false` */ - reset?: boolean; + reset: boolean; }>, ): this; From 996c5943e5a9ce69b2b7778a758a082743e2cd7d Mon Sep 17 00:00:00 2001 From: esheyw Date: Mon, 16 Dec 2024 20:15:32 -0800 Subject: [PATCH 02/22] more BES work --- .../canvas/sources/base-effect-source.d.mts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 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 a3a0254d3..addf92db5 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 @@ -1,4 +1,5 @@ -import type { InexactPartial, NullishProps } from "../../../../types/utils.d.mts"; +import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; +import type { NullishProps } from "../../../../types/utils.d.mts"; /** * TODO - Re-document after ESM refactor. @@ -24,6 +25,7 @@ declare abstract class BaseEffectSource< * @remarks Passing a PlaceableObject is deprecated, and will be removed in v13 */ constructor(options?: PlaceableObject); + constructor(options?: BaseEffectSource.BaseEffectSourceOptions); constructor(options?: BaseEffectSource.BaseEffectSourceOptions | PlaceableObject); /** @@ -132,9 +134,9 @@ declare abstract class BaseEffectSource< * @returns The initialized source */ initialize( - data?: InexactPartial, + data?: NullishProps, + /** @privateRemarks Foundry describes an `options.behaviors` key, but it is neither checked for nor used at runtime */ options?: NullishProps<{ - // The type def references a behaviors object that is not even passed into the function /** * Should source data be reset to default values before applying changes? * @defaultValue `false` @@ -147,7 +149,10 @@ declare abstract class BaseEffectSource< * Subclass specific data initialization steps. * @param data - Provided data for configuration */ - _initialize(data: Partial): void; + _initialize( + /** @remarks IntentionalPartial because `this.initialize` has filtered invalid keys and replaced any nullish values before calling this */ + data: IntentionalPartial, + ): void; /** * Create the polygon shape (or shapes) for this source using configured data. @@ -214,16 +219,20 @@ declare abstract class BaseEffectSource< declare namespace BaseEffectSource { type AnyConstructor = typeof AnyBaseEffectSource; - interface BaseEffectSourceOptions { + /** @internal Intermediary type to simplify use of optionality- and nullish-permissiveness-modifiying helpers */ + type _BaseEffectSourceOptions = NullishProps<{ /** * An optional PlaceableObject which is responsible for this source */ - object?: PlaceableObject | undefined; + object: PlaceableObject; + }>; + + interface BaseEffectSourceOptions extends _BaseEffectSourceOptions { /** * A unique ID for this source. This will be set automatically if an * object is provided, otherwise is required. */ - sourceId?: string | undefined; + sourceId?: string; } interface BaseEffectSourceData { From 2da1fe70462a4db08cdbb5ac5944f5cdaa9bff42 Mon Sep 17 00:00:00 2001 From: esheyw Date: Tue, 17 Dec 2024 11:01:45 -0800 Subject: [PATCH 03/22] BES done --- .../canvas/sources/base-effect-source.d.mts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 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 addf92db5..83fc216fc 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 @@ -24,8 +24,6 @@ declare abstract class BaseEffectSource< * @param options - Options which modify the base effect source instance * @remarks Passing a PlaceableObject is deprecated, and will be removed in v13 */ - constructor(options?: PlaceableObject); - constructor(options?: BaseEffectSource.BaseEffectSourceOptions); constructor(options?: BaseEffectSource.BaseEffectSourceOptions | PlaceableObject); /** @@ -62,7 +60,7 @@ declare abstract class BaseEffectSource< * The source id linked to this effect source. * @remarks Foundry types this as Readonly, but does nothing to that effect at runtime */ - sourceId: string; + sourceId: string | undefined; /** * The data of this source. @@ -163,8 +161,9 @@ declare abstract class BaseEffectSource< * Subclass specific configuration steps. Occurs after data initialization and shape computation. * Only called if the source is attached and not disabled. * @param changes - Changes to the source data which were applied + * @remarks This is actually passed *flattened* partial data */ - protected _configure(changes: Partial): void; + protected _configure(changes: IntentionalPartial): void; /** * Refresh the state and uniforms of the source. @@ -219,7 +218,7 @@ declare abstract class BaseEffectSource< declare namespace BaseEffectSource { type AnyConstructor = typeof AnyBaseEffectSource; - /** @internal Intermediary type to simplify use of optionality- and nullish-permissiveness-modifiying helpers */ + /** @internal */ type _BaseEffectSourceOptions = NullishProps<{ /** * An optional PlaceableObject which is responsible for this source @@ -231,6 +230,8 @@ declare namespace BaseEffectSource { /** * A unique ID for this source. This will be set automatically if an * object is provided, otherwise is required. + * @remarks The above is misleading; sourceId will *not* be inferred if you pass in `{object: PlaceableObject}`, + * only if you pass a `PlaceableObject` *instead* of an options object to the constructor. */ sourceId?: string; } From 01c93b12a49a39dffb0f73650f7d6fd63023b273 Mon Sep 17 00:00:00 2001 From: esheyw Date: Tue, 17 Dec 2024 12:49:54 -0800 Subject: [PATCH 04/22] PIXI Enum conversion and interface spacing --- .../canvas/sources/base-light-source.d.mts | 10 ++ .../sources/rendered-effect-source.d.mts | 16 ++- src/types/augments/pixi.d.mts | 102 ++++++++++++++++++ 3 files changed, 124 insertions(+), 4 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts index 2664b4940..8382c273f 100644 --- a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts @@ -113,42 +113,52 @@ declare namespace BaseLightSource { * An opacity for the emitted light, if any */ alpha: number; + /** * The allowed radius of bright vision or illumination */ bright: number; + /** * The coloration technique applied in the shader */ coloration: number; + /** * The amount of contrast this light applies to the background texture */ contrast: number; + /** * The allowed radius of dim vision or illumination */ dim: number; + /** * Strength of the attenuation between bright, dim, and dark */ attenuation: number; + /** * The luminosity applied in the shader */ luminosity: number; + /** * The amount of color saturation this light applies to the background texture */ saturation: number; + /** * The depth of shadows this light applies to the background texture */ shadows: number; + /** * Whether or not this source provides a source of vision */ vision: boolean; + /** * Strength of this source to beat or not negative/positive sources */ diff --git a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts index 0787aaea7..ad06d218e 100644 --- a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts @@ -1,9 +1,6 @@ import type { AnyFunction, InexactPartial } from "../../../../types/utils.d.mts"; import type BaseEffectSource from "./base-effect-source.d.mts"; -// TODO: Remove after shaders are done -type AdaptiveDarknessShader = unknown; - /** * An abstract class which extends the base PointSource to provide common functionality for rendering. * This class is extended by both the LightSource and VisionSource subclasses. @@ -214,14 +211,17 @@ declare namespace RenderedEffectSource { * An animation configuration for the source */ animation: object; + /** * A color applied to the rendered effect */ color: number | null; + /** * An integer seed to synchronize (or de-synchronize) animations */ seed: number | null; + /** * Is this source a temporary preview? */ @@ -253,31 +253,38 @@ declare namespace RenderedEffectSource { * The human-readable (localized) label for the animation */ label?: string | undefined; + /** * The animation function that runs every frame * @privateRemarks TODO: Figure out if there's a better way to define the function */ animation?: AnyFunction | undefined; + /** * A custom illumination shader used by this animation */ illuminationShader?: AdaptiveIlluminationShader | undefined; + /** * A custom coloration shader used by this animation */ colorationShader?: AdaptiveColorationShader | undefined; + /** * A custom background shader used by this animation */ backgroundShader?: AdaptiveBackgroundShader | undefined; + /** * A custom darkness shader used by this animation */ darknessShader?: AdaptiveDarknessShader | undefined; + /** * The animation seed */ seed?: number | undefined; + /** * The animation time */ @@ -312,10 +319,11 @@ declare namespace RenderedEffectSource { * The default shader used by this layer */ defaultShader: AdaptiveLightingShader; + /** * The blend mode used by this layer */ - blendMode: PIXI.BLEND_MODES; + blendMode: keyof typeof PIXI.BLEND_MODES; } // Interface causes errors diff --git a/src/types/augments/pixi.d.mts b/src/types/augments/pixi.d.mts index 99566ab47..29c44a675 100644 --- a/src/types/augments/pixi.d.mts +++ b/src/types/augments/pixi.d.mts @@ -1,6 +1,7 @@ import * as _PIXI from "pixi.js"; import * as pixiParticles from "@pixi/particle-emitter"; import * as graphicsSmooth from "@pixi/graphics-smooth"; +import type { Brand } from "../helperTypes.d.mts"; export * from "pixi.js"; @@ -11,6 +12,107 @@ export as namespace PIXI; declare global { namespace PIXI { + /***************************** + * Enum to Brand conversions * + *****************************/ + type ALPHA_MODES = Brand; + const ALPHA_MODES: Record; + + /** @privateRemarks Merges Foundry's extra keys */ + type BLEND_MODES = Brand; + const BLEND_MODES: Record; + + type BUFFER_BITS = Brand; + const BUFFER_BITS: Record; + + type BUFFER_TYPE = Brand; + const BUFFER_TYPE: Record; + + type CLEAR_MODES = Brand; + const CLEAR_MODES: Record; + + type COLOR_MASK_BITS = Brand; + const COLOR_MASK_BITS: Record; + + type DRAW_MODES = Brand; + const DRAW_MODES: Record; + + type ENV = Brand; + const ENV: Record; + + type ExtensionType = Brand; + const ExtensionType: Record; + + type FORMATS = Brand; + const FORMATS: Record; + + type GC_MODES = Brand; + const GC_MODES: Record; + + type INTERNAL_FORMATS = Brand; + const INTERNAL_FORMATS: Record; + + type LINE_CAP = Brand; + const LINE_CAP: Record; + + type LINE_JOIN = Brand; + const LINE_JOIN: Record; + + type LoaderParserPriority = Brand; + const LoaderParserPriority: Record; + + type MASK_TYPES = Brand; + const MASK_TYPES: Record; + + type MIPMAP_MODES = Brand; + const MIPMAP_MODES: Record; + + type MSAA_QUALITY = Brand; + const MSAA_QUALITY: Record; + + type PRECISION = Brand; + const PRECISION: Record; + + type RENDERER_TYPE = Brand; + const RENDERER_TYPE: Record; + + type SAMPLER_TYPES = Brand; + const SAMPLER_TYPES: Record; + + type SCALE_MODES = Brand; + const SCALE_MODES: Record; + + type SHAPES = Brand; + const SHAPES: Record; + + type TARGETS = Brand; + const TARGET: Record; + + type TEXT_GRADIENT = Brand; + const TEXT_GRADIENT: Record; + + type UPDATE_PRIORITY = Brand; + const UPDATE_PRIORITY: Record; + + type WRAP_MODES = Brand; + const WRAP_MODES: Record; + + //TODO: Figure out how to make this not break + // namespace particles { + // namespace behaviors { + // type BehaviorOrder = Brand; + // const BehaviorOrder: Record; + // } + // } + + // namespace smooth { + // type JOINT_TYPE = Brand; + // const JOINT_TYPE: Record; + + // type LINE_SCALE_MODE = Brand; + // const LINE_SCALE_MODE: Record; + // } + export import smooth = graphicsSmooth; export import particles = pixiParticles; From 905d80827fab415980d9a3c2a25f7e5d860f9ef7 Mon Sep 17 00:00:00 2001 From: Luke Abby Date: Tue, 17 Dec 2024 17:24:25 -0800 Subject: [PATCH 05/22] Fix merging of PIXI.smooth and PIXI.graphics --- src/types/augments/particles.d.mts | 11 +++++++++++ src/types/augments/pixi.d.mts | 31 +++++++++++------------------- src/types/augments/smooth.d.mts | 11 +++++++++++ 3 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 src/types/augments/particles.d.mts create mode 100644 src/types/augments/smooth.d.mts diff --git a/src/types/augments/particles.d.mts b/src/types/augments/particles.d.mts new file mode 100644 index 000000000..9bb161195 --- /dev/null +++ b/src/types/augments/particles.d.mts @@ -0,0 +1,11 @@ +/* eslint-disable import/export */ + +import * as pixiParticles from "@pixi/particle-emitter"; +import type { Brand } from "../helperTypes.d.mts"; + +export namespace behaviors { + type BehaviorOrder = Brand; + const BehaviorOrder: Record; +} + +export * from "@pixi/particle-emitter"; diff --git a/src/types/augments/pixi.d.mts b/src/types/augments/pixi.d.mts index 29c44a675..d97124b84 100644 --- a/src/types/augments/pixi.d.mts +++ b/src/types/augments/pixi.d.mts @@ -1,8 +1,15 @@ import * as _PIXI from "pixi.js"; -import * as pixiParticles from "@pixi/particle-emitter"; -import * as graphicsSmooth from "@pixi/graphics-smooth"; import type { Brand } from "../helperTypes.d.mts"; +// Note(LukeAbby): The `smooth.d.mts` and `smooth.d.mts` files exist to make it DRY to selectively tweak PIXI sub-namespaces. +// Each of them write `export * from "..."` and then selectively shadow or augment the exports. + +// eslint-disable-next-line import/extensions +import * as _smooth from "./smooth.mjs"; + +// eslint-disable-next-line import/extensions +import * as _particles from "./particles.mjs"; + export * from "pixi.js"; /** @@ -97,24 +104,8 @@ declare global { type WRAP_MODES = Brand; const WRAP_MODES: Record; - //TODO: Figure out how to make this not break - // namespace particles { - // namespace behaviors { - // type BehaviorOrder = Brand; - // const BehaviorOrder: Record; - // } - // } - - // namespace smooth { - // type JOINT_TYPE = Brand; - // const JOINT_TYPE: Record; - - // type LINE_SCALE_MODE = Brand; - // const LINE_SCALE_MODE: Record; - // } - - export import smooth = graphicsSmooth; - export import particles = pixiParticles; + export import smooth = _smooth; + export import particles = _particles; export class Graphics extends PIXI.smooth.SmoothGraphics {} diff --git a/src/types/augments/smooth.d.mts b/src/types/augments/smooth.d.mts new file mode 100644 index 000000000..658c77a35 --- /dev/null +++ b/src/types/augments/smooth.d.mts @@ -0,0 +1,11 @@ +import type { Brand } from "../helperTypes.d.mts"; +import * as graphicsSmooth from "@pixi/graphics-smooth"; + +type JOINT_TYPE = Brand; +declare const JOINT_TYPE: Record; + +type LINE_SCALE_MODE = Brand; +declare const LINE_SCALE_MODE: Record; + +export * from "@pixi/graphics-smooth"; +export { JOINT_TYPE, LINE_SCALE_MODE }; From 55bc8c9e6de3fabed87e7daaee859cd158c63a00 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 11:54:34 -0800 Subject: [PATCH 06/22] RenderedEffectSource done --- .../sources/rendered-effect-source.d.mts | 72 ++++++++++++------- .../sources/base-effect-source.mjs.test-d.ts | 3 +- .../rendered-effect-source.mjs.test-d.ts | 4 +- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts index ad06d218e..8be500e3c 100644 --- a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts @@ -1,3 +1,4 @@ +import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; import type { AnyFunction, InexactPartial } from "../../../../types/utils.d.mts"; import type BaseEffectSource from "./base-effect-source.d.mts"; @@ -24,7 +25,10 @@ declare class RenderedEffectSource< * Layers handled by this rendered source. * @remarks Keys should match the keys of RenderingLayers */ - protected static get _layers(): Record; + protected static get _layers(): Record< + "background" | "coloration" | "illumination", + RenderedEffectSource.RenderedEffectLayerConfig + >; /** * The offset in pixels applied to create soft edges. @@ -97,29 +101,25 @@ declare class RenderedEffectSource< */ get illumination(): PointSourceMesh; - _initialize(data: Partial): void; + override _initialize(data: IntentionalPartial): void; /** * Decide whether to render soft edges with a blur. */ protected _initializeSoftEdges(): void; - override _configure(changes: Partial): void; + override _configure(changes: IntentionalPartial): void; /** * Configure which shaders are used for each rendered layer. * @privateRemarks Foundry marks this as private then overrides it in `PointVisionSource` */ - protected _configureShaders(): { - background: AdaptiveLightingShader; - coloration: AdaptiveLightingShader; - illumination: AdaptiveLightingShader; - }; + protected _configureShaders(): Record; /** * Specific configuration for a layer. */ - protected _configureLayer(layer: Record, layerId: string): void; + protected _configureLayer(layer: RenderedEffectSource.RenderedEffectSourceLayer, layerId: string): void; /** * Create the geometry for the source shape that is used in shaders and compute its bounds for culling purpose. @@ -131,11 +131,8 @@ declare class RenderedEffectSource< /** * Render the containers used to represent this light source within the LightingLayer */ - drawMeshes(): { - background: PIXI.Mesh; - coloration: PIXI.Mesh; - illumination: PIXI.Mesh; - }; + drawMeshes(): Record; + /** * Create a Mesh for a certain rendered layer of this source. * @param layerId - The layer key in layers to draw @@ -163,9 +160,13 @@ declare class RenderedEffectSource< */ protected _updateIlluminationUniforms(): void; + protected override _destroy(): void; + /** * Animate the PointSource, if an animation is enabled and if it currently has rendered containers. * @param dt - Delta time. + * @privateRemarks In core this will return `void`, as the `this.animation.animation` function will be a {@link LightAnimationFunction} + * such as `RenderedEffectSource#animateTime` below, but it could technically be set to any function */ animate(dt: number): this["animation"]["animation"] extends (...args: any) => infer Return ? Return : void; @@ -174,7 +175,7 @@ declare class RenderedEffectSource< * @param dt - Delta time. * @param options - Options which affect the time animation */ - animateTime(dt: number, options?: InexactPartial): void; + animateTime(dt: number, options?: RenderedEffectSource.AnimationOptions): void; /** * Get corrected level according to level and active vision mode data. @@ -193,12 +194,14 @@ declare class RenderedEffectSource< ): Color; /** - * @deprecated since v11 + * @deprecated since v11, until v13 + * @remarks "The RenderedEffectSource#preview is deprecated. Use RenderedEffectSource#isPreview instead." */ set preview(preview: boolean); /** - * @deprecated since v11 + * @deprecated since v11, until v13 + * @remarks "The RenderedEffectSource#preview is deprecated. Set RenderedEffectSource#preview as part of RenderedEffectSource#initialize instead." */ get preview(): boolean; } @@ -206,6 +209,8 @@ declare class RenderedEffectSource< declare namespace RenderedEffectSource { type Any = RenderedEffectSource; + type AnyConstructor = typeof AnyRenderedEffectSource; + interface RenderedEffectSourceData extends BaseEffectSource.BaseEffectSourceData { /** * An animation configuration for the source @@ -228,25 +233,29 @@ declare namespace RenderedEffectSource { preview: boolean; } - interface AnimationOptions { + type _AnimationOptions = InexactPartial<{ /** * The animation speed, from 0 to 10 * @defaultValue `5` + * @remarks Can't be null due to only having default via signature */ - speed?: number; + speed: number; /** * The animation intensity, from 1 to 10 * @defaultValue `5` + * @remarks Can't be null due to only having default via signature */ - intensity?: number; + intensity: number; /** * Reverse the animation direction * @defaultValue `false` */ - reverse?: boolean; - } + reverse: boolean | null; + }>; + + interface AnimationOptions extends _AnimationOptions {} interface RenderedEffectSourceAnimationConfig { /** @@ -291,34 +300,41 @@ declare namespace RenderedEffectSource { time?: number | undefined; } - interface RenderedEffectSourceLayer { + interface RenderedEffectSourceLayer extends RenderedEffectLayerConfig { /** * Is this layer actively rendered? */ active: boolean; + /** * Do uniforms need to be reset? */ reset: boolean; + /** * Is this layer temporarily suppressed? */ suppressed: boolean; + /** * The rendered mesh for this layer */ - mesh: PointSourceMesh; + mesh: PointSourceMesh | undefined; + /** * The shader instance used for the layer */ - shader: AdaptiveLightingShader; + shader: AdaptiveLightingShader | undefined; + + /** @remarks Foundry does not include this in the typedef but is in the initalization of `RenderedEffectSource#layers` */ + vmUniforms: AbstractBaseShader.Uniforms | undefined; } interface RenderedEffectLayerConfig { /** * The default shader used by this layer */ - defaultShader: AdaptiveLightingShader; + defaultShader: typeof AdaptiveLightingShader; /** * The blend mode used by this layer @@ -335,4 +351,8 @@ declare namespace RenderedEffectSource { }; } +declare abstract class AnyRenderedEffectSource extends RenderedEffectSource { + constructor(arg0: never, ...args: never[]); +} + export default RenderedEffectSource; diff --git a/tests/foundry/client-esm/canvas/sources/base-effect-source.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/base-effect-source.mjs.test-d.ts index dfc93a283..aed36e460 100644 --- a/tests/foundry/client-esm/canvas/sources/base-effect-source.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/base-effect-source.mjs.test-d.ts @@ -1,5 +1,6 @@ import { expectTypeOf } from "vitest"; +import type BaseEffectSource from "../../../../../src/foundry/client-esm/canvas/sources/base-effect-source.d.mts"; -const mySource = new foundry.canvas.sources.BaseEffectSource(); +declare const mySource: BaseEffectSource; expectTypeOf(mySource.active).toEqualTypeOf(); diff --git a/tests/foundry/client-esm/canvas/sources/rendered-effect-source.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/rendered-effect-source.mjs.test-d.ts index 814c1a482..db8d2a527 100644 --- a/tests/foundry/client-esm/canvas/sources/rendered-effect-source.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/rendered-effect-source.mjs.test-d.ts @@ -1,6 +1,6 @@ import { expectTypeOf } from "vitest"; const mySource = new foundry.canvas.sources.RenderedEffectSource(); - +const meshes = mySource.drawMeshes(); expectTypeOf(mySource.active).toEqualTypeOf(); -expectTypeOf(mySource.drawMeshes().background.visible).toEqualTypeOf(); +expectTypeOf(meshes.background?.visible).toEqualTypeOf(); From daa6930a408eb3ae25a901d07f0411a47b09a8f8 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 14:29:45 -0800 Subject: [PATCH 07/22] BaseLightSource before messing with config --- .../canvas/sources/base-light-source.d.mts | 35 +++++++++++---- .../sources/rendered-effect-source.d.mts | 44 +++++++++++++------ .../sources/base-light-source.mjs.test-d.ts | 5 ++- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts index 8382c273f..f555d3751 100644 --- a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts @@ -1,10 +1,11 @@ +import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; import type { InexactPartial } from "../../../../types/utils.d.mts"; import type RenderedEffectSource from "./rendered-effect-source.d.mts"; /** * A specialized subclass of BaseEffectSource which deals with the rendering of light or darkness. */ -declare class BaseLightSource< +declare abstract class BaseLightSource< SourceData extends BaseLightSource.LightSourceData = BaseLightSource.LightSourceData, SourceShape extends PIXI.Polygon = PIXI.Polygon, RenderingLayers extends Record = RenderedEffectSource.Layers, @@ -20,17 +21,20 @@ declare class BaseLightSource< /** * The corresponding lighting levels for dim light. + * @defaultValue `foundry.CONST.LIGHTING_LEVELS.DIM` */ protected static _dimLightingLevel: foundry.CONST.LIGHTING_LEVELS; /** * The corresponding lighting levels for bright light. + * @defaultValue `foundry.CONST.LIGHTING_LEVELS.BRIGHT` */ protected static _brightLightingLevel: foundry.CONST.LIGHTING_LEVELS; /** * The corresponding animation config. */ + //TODO: convert when index signatures are removed from CONFIG protected static get ANIMATIONS(): CONFIG.Canvas.LightSourceAnimationConfig; /** @@ -59,7 +63,7 @@ declare class BaseLightSource< */ ratio: number; - override _initialize(data: Partial): void; + override _initialize(data: IntentionalPartial): void; override _updateColorationUniforms(): void; @@ -74,7 +78,7 @@ declare class BaseLightSource< * @param dt - Delta time * @param options - Additional options which modify the torch animation */ - animateTorch(dt: number, options?: InexactPartial): void; + animateTorch(dt: number, options?: RenderedEffectSource.AnimationFunctionOptions): void; /** * An animation with flickering ratio and light intensity @@ -83,23 +87,28 @@ declare class BaseLightSource< */ animateFlickering( dt: number, - options?: InexactPartial< - RenderedEffectSource.AnimationOptions & { + options?: RenderedEffectSource.AnimationFunctionOptions & + InexactPartial<{ /** * Noise amplification (\>1) or dampening (\<1) * @defaultValue `1` */ amplification: number; - } - >, + }>, ): void; + /** + * @remarks This property will be generated on any class that is `animateFlickering`'s `this` when it is called + * Foundry does not document it. + */ + _noise?: SmoothNoise; + /** * A basic "pulse" animation which expands and contracts. * @param dt - Delta time * @param options - Additional options which modify the pulse animation */ - animatePulse(dt: number, options?: InexactPartial): void; + animatePulse(dt: number, options?: RenderedEffectSource.AnimationFunctionOptions): void; /** * @deprecated since v12 @@ -108,6 +117,12 @@ declare class BaseLightSource< } declare namespace BaseLightSource { + type LightAnimationFunction = ( + this: BaseLightSource, + dt: number, + options?: RenderedEffectSource.AnimationFunctionOptions, + ) => void; + interface LightSourceData extends RenderedEffectSource.RenderedEffectSourceData { /** * An opacity for the emitted light, if any @@ -166,4 +181,8 @@ declare namespace BaseLightSource { } } +declare abstract class AnyBaseLightSource extends BaseLightSource { + constructor(arg0: never, ...args: never[]); +} + export default BaseLightSource; diff --git a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts index 8be500e3c..cb1e59fda 100644 --- a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts @@ -1,5 +1,5 @@ import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; -import type { AnyFunction, InexactPartial } from "../../../../types/utils.d.mts"; +import type { InexactPartial } from "../../../../types/utils.d.mts"; import type BaseEffectSource from "./base-effect-source.d.mts"; /** @@ -175,7 +175,7 @@ declare class RenderedEffectSource< * @param dt - Delta time. * @param options - Options which affect the time animation */ - animateTime(dt: number, options?: RenderedEffectSource.AnimationOptions): void; + animateTime(dt: number, options?: RenderedEffectSource.AnimationFunctionOptions): void; /** * Get corrected level according to level and active vision mode data. @@ -233,7 +233,15 @@ declare namespace RenderedEffectSource { preview: boolean; } - type _AnimationOptions = InexactPartial<{ + type AnimationFunction = ( + this: foundry.canvas.sources.RenderedEffectSource, + /** Delta time */ + dt: number, + options?: AnimationFunctionOptions, + ) => void; + + /** @internal */ + type _AnimationFunctionOptions = InexactPartial<{ /** * The animation speed, from 0 to 10 * @defaultValue `5` @@ -255,51 +263,59 @@ declare namespace RenderedEffectSource { reverse: boolean | null; }>; - interface AnimationOptions extends _AnimationOptions {} + /** Shared options for the {@link LightAnimationFunction}s provided by `_Source` classes */ + interface AnimationFunctionOptions extends _AnimationFunctionOptions {} - interface RenderedEffectSourceAnimationConfig { + /** @internal */ + type _RenderedEffectSourceAnimationConfig = InexactPartial<{ /** * The human-readable (localized) label for the animation */ - label?: string | undefined; + label: string; /** * The animation function that runs every frame * @privateRemarks TODO: Figure out if there's a better way to define the function */ - animation?: AnyFunction | undefined; + animation: RenderedEffectSource.AnimationFunction; /** * A custom illumination shader used by this animation */ - illuminationShader?: AdaptiveIlluminationShader | undefined; + illuminationShader: typeof AdaptiveIlluminationShader; /** * A custom coloration shader used by this animation */ - colorationShader?: AdaptiveColorationShader | undefined; + colorationShader: typeof AdaptiveColorationShader; /** * A custom background shader used by this animation */ - backgroundShader?: AdaptiveBackgroundShader | undefined; + backgroundShader: typeof AdaptiveBackgroundShader; /** * A custom darkness shader used by this animation */ - darknessShader?: AdaptiveDarknessShader | undefined; + darknessShader: typeof AdaptiveDarknessShader; /** * The animation seed */ - seed?: number | undefined; + seed: number; /** * The animation time */ - time?: number | undefined; - } + time: number; + }>; + interface RenderedEffectSourceAnimationConfig extends _RenderedEffectSourceAnimationConfig {} + + /** + * @remarks `mesh` and `shader` are given values during initialization *if* the Source has a valid `Placeable` as its `object`. + * `vmUniforms` is only provided for `PointVisionSource` layers. + */ interface RenderedEffectSourceLayer extends RenderedEffectLayerConfig { /** * Is this layer actively rendered? diff --git a/tests/foundry/client-esm/canvas/sources/base-light-source.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/base-light-source.mjs.test-d.ts index c9766a0d3..8f7060de0 100644 --- a/tests/foundry/client-esm/canvas/sources/base-light-source.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/base-light-source.mjs.test-d.ts @@ -1,7 +1,8 @@ import { expectTypeOf } from "vitest"; +import type BaseLightSource from "../../../../../src/foundry/client-esm/canvas/sources/base-light-source.d.mts"; -const mySource = new foundry.canvas.sources.BaseLightSource(); +declare const mySource: BaseLightSource; expectTypeOf(mySource.active).toEqualTypeOf(); -expectTypeOf(mySource.drawMeshes().background.visible).toEqualTypeOf(); +expectTypeOf(mySource.drawMeshes().background?.visible).toEqualTypeOf(); expectTypeOf(mySource.animateTorch(5)).toEqualTypeOf(); From dfe770e0b2d815e787014b78672305e64e2a3303 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 14:46:39 -0800 Subject: [PATCH 08/22] remove `LightAnimationFunction` from config and update `lightAnimations` typing --- .../sources/rendered-effect-source.d.mts | 8 +- src/foundry/client/config.d.mts | 119 +++++++++--------- 2 files changed, 61 insertions(+), 66 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts index cb1e59fda..1a561fc03 100644 --- a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts @@ -165,8 +165,8 @@ declare class RenderedEffectSource< /** * Animate the PointSource, if an animation is enabled and if it currently has rendered containers. * @param dt - Delta time. - * @privateRemarks In core this will return `void`, as the `this.animation.animation` function will be a {@link LightAnimationFunction} - * such as `RenderedEffectSource#animateTime` below, but it could technically be set to any function + * @privateRemarks In core this will return `void`, as the `this.animation.animation` function will be a {@link BaseLightSource.LightAnimationFunction} + * and in fact most of the time will be `RenderedEffectSource#animateTime`, but it could technically be set to any function */ animate(dt: number): this["animation"]["animation"] extends (...args: any) => infer Return ? Return : void; @@ -234,7 +234,7 @@ declare namespace RenderedEffectSource { } type AnimationFunction = ( - this: foundry.canvas.sources.RenderedEffectSource, + this: RenderedEffectSource, /** Delta time */ dt: number, options?: AnimationFunctionOptions, @@ -263,7 +263,7 @@ declare namespace RenderedEffectSource { reverse: boolean | null; }>; - /** Shared options for the {@link LightAnimationFunction}s provided by `_Source` classes */ + /** Shared options for the {@link AnimationFunction}s provided by `_Source` classes */ interface AnimationFunctionOptions extends _AnimationFunctionOptions {} /** @internal */ diff --git a/src/foundry/client/config.d.mts b/src/foundry/client/config.d.mts index f8d2b5b45..ac5e9b169 100644 --- a/src/foundry/client/config.d.mts +++ b/src/foundry/client/config.d.mts @@ -1,8 +1,8 @@ import type { GetKey } from "../../types/helperTypes.d.mts"; import type * as CONST from "../common/constants.d.mts"; import type { DataModel, Document } from "../common/abstract/module.d.mts"; -import type PointLightSource from "../client-esm/canvas/sources/point-light-source.d.mts"; import type { AnyObject, HandleEmptyObject, MaybePromise } from "../../types/utils.d.mts"; +import type BaseLightSource from "../client-esm/canvas/sources/base-light-source.d.mts"; declare global { namespace CONFIG { @@ -1028,13 +1028,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateFlickering` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `FlameIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `FlameColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; torch: { @@ -1042,13 +1042,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTorch` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `TorchIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `TorchColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; revolving: { @@ -1056,10 +1056,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `RevolvingColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; siren: { @@ -1067,13 +1067,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTorch` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `SirenIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `SirenIlluminationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; pulse: { @@ -1081,13 +1081,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animatePulse` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `PulseIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `PulseColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; chroma: { @@ -1095,10 +1095,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `ChromaColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; wave: { @@ -1106,13 +1106,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `WaveIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `WaveColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; fog: { @@ -1120,10 +1120,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `FogColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; sunburst: { @@ -1131,13 +1131,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `SunburstIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `SunburstColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; dome: { @@ -1145,10 +1145,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `LightDomeColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; emanation: { @@ -1156,10 +1156,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `EmanationColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; hexa: { @@ -1167,10 +1167,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `HexaDomeColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; ghost: { @@ -1178,13 +1178,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `GhostLightIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `GhostLightColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; energy: { @@ -1192,10 +1192,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `EnergyFieldColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; vortex: { @@ -1203,13 +1203,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `VortexIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `VortexColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; witchwave: { @@ -1217,13 +1217,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `BewitchingWaveIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `BewitchingWaveColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; rainbowswirl: { @@ -1231,10 +1231,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `SwirlingRainbowColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; radialrainbow: { @@ -1242,10 +1242,10 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `RadialRainbowColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; fairy: { @@ -1253,13 +1253,13 @@ declare global { label: string; /** @defaultValue `foundry.canvas.sources.LightSource.prototype.animateTime` */ - animation: CONFIG.Canvas.LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; /** @defaultValue `FairyLightIlluminationShader` */ - illuminationShader: typeof AbstractBaseShader; + illuminationShader: typeof AdaptiveIlluminationShader; /** @defaultValue `FairyLightColorationShader` */ - colorationShader: typeof AbstractBaseShader; + colorationShader: typeof AdaptiveColorationShader; }; }; @@ -2991,10 +2991,10 @@ declare global { string, { label: string; - animation: LightAnimationFunction; + animation: BaseLightSource.LightAnimationFunction; backgroundShader?: typeof AdaptiveBackgroundShader; - illuminationShader?: typeof AbstractBaseShader; - colorationShader?: typeof AbstractBaseShader; + illuminationShader?: typeof AdaptiveIlluminationShader; + colorationShader?: typeof AdaptiveColorationShader; } >; @@ -3003,18 +3003,13 @@ declare global { */ type DarknessSourceAnimationConfig = Record< string, - { label: string; animation: LightAnimationFunction; darknessShader: typeof AdaptiveDarknessShader } + { + label: string; + animation: BaseLightSource.LightAnimationFunction; + darknessShader: typeof AdaptiveDarknessShader; + } >; - type LightAnimationFunction = ( - // `this` is technically not a `PointLightSource`. - // Instead it is `foundry.canvas.sources.Pointfoundry.canvas.sources.LightSource.prototype`. - // However differentiating this would be a lot of work for little gain as nothing critical happens in the constructor. - this: PointLightSource, - dt: number, - properties?: { speed?: number; intensity?: number; reverse?: false }, - ) => void; - namespace Pings { interface Style { class: unknown; From cae430ce96d71a4c89eeea219ff301cfa5d9bf54 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 14:48:41 -0800 Subject: [PATCH 09/22] rename `BaseLightSource.LightSourceData` to `.BaseLightSourceData` --- .../client-esm/canvas/sources/base-light-source.d.mts | 6 +++--- .../client-esm/canvas/sources/global-light-source.d.mts | 2 +- .../client-esm/canvas/sources/point-darkness-source.d.mts | 2 +- .../client-esm/canvas/sources/point-light-source.d.mts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts index f555d3751..fb7852b63 100644 --- a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts @@ -6,7 +6,7 @@ import type RenderedEffectSource from "./rendered-effect-source.d.mts"; * A specialized subclass of BaseEffectSource which deals with the rendering of light or darkness. */ declare abstract class BaseLightSource< - SourceData extends BaseLightSource.LightSourceData = BaseLightSource.LightSourceData, + SourceData extends BaseLightSource.BaseLightSourceData = BaseLightSource.BaseLightSourceData, SourceShape extends PIXI.Polygon = PIXI.Polygon, RenderingLayers extends Record = RenderedEffectSource.Layers, > extends RenderedEffectSource { @@ -56,7 +56,7 @@ declare abstract class BaseLightSource< * } * ``` */ - static override defaultData: RenderedEffectSource.RenderedEffectSourceData; + static override defaultData: BaseLightSource.BaseLightSourceData; /** * A ratio of dim:bright as part of the source radius @@ -123,7 +123,7 @@ declare namespace BaseLightSource { options?: RenderedEffectSource.AnimationFunctionOptions, ) => void; - interface LightSourceData extends RenderedEffectSource.RenderedEffectSourceData { + interface BaseLightSourceData extends RenderedEffectSource.RenderedEffectSourceData { /** * An opacity for the emitted light, if any */ diff --git a/src/foundry/client-esm/canvas/sources/global-light-source.d.mts b/src/foundry/client-esm/canvas/sources/global-light-source.d.mts index aef6f5e5e..cd07b0b4f 100644 --- a/src/foundry/client-esm/canvas/sources/global-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/global-light-source.d.mts @@ -26,7 +26,7 @@ export default class GlobalLightSource extends BaseLightSource { * } * ``` */ - static override defaultData: BaseLightSource.LightSourceData; + static override defaultData: BaseLightSource.BaseLightSourceData; /** * Name of this global light source. 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 3f436d081..b13724503 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 @@ -2,7 +2,7 @@ import type BaseLightSource from "./base-light-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; import type RenderedEffectSource from "./rendered-effect-source.d.mts"; -type DarknessSourceData = BaseLightSource.LightSourceData & PointEffectSourceMixin.PointEffectSourceData; +type DarknessSourceData = BaseLightSource.BaseLightSourceData & PointEffectSourceMixin.PointEffectSourceData; // Interface causes errors // eslint-disable-next-line @typescript-eslint/consistent-type-definitions 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 83f22e259..2787f8f73 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,7 +1,7 @@ import type BaseLightSource from "./base-light-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; -type LightSourceData = PointEffectSourceMixin.PointEffectSourceData & BaseLightSource.LightSourceData; +type LightSourceData = PointEffectSourceMixin.PointEffectSourceData & BaseLightSource.BaseLightSourceData; /** * A specialized subclass of the BaseLightSource which renders a source of light as a point-based effect. From 9e2cae4adc2ffdc2a234939071e67a441a11576d Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 14:56:41 -0800 Subject: [PATCH 10/22] BaseLightSource done --- .../canvas/sources/base-light-source.d.mts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts index fb7852b63..cd18d39a7 100644 --- a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts @@ -73,6 +73,12 @@ declare abstract class BaseLightSource< override _updateCommonUniforms(shader: AbstractBaseShader): void; + /** @remarks This property is undocumented, and only defined during `_updateCommonUniforms` */ + cachededAttentuation?: number; + + /** @remarks This property is undocumented, and only defined during `_updateCommonUniforms` */ + computedAttentuation?: number; + /** * An animation with flickering ratio and light intensity. * @param dt - Delta time @@ -98,7 +104,7 @@ declare abstract class BaseLightSource< ): void; /** - * @remarks This property will be generated on any class that is `animateFlickering`'s `this` when it is called + * @remarks This property will be generated on any class that is `animateFlickering`'s `this` when it is called. * Foundry does not document it. */ _noise?: SmoothNoise; @@ -111,12 +117,15 @@ declare abstract class BaseLightSource< animatePulse(dt: number, options?: RenderedEffectSource.AnimationFunctionOptions): void; /** - * @deprecated since v12 + * @deprecated since v12, until v14 + * @remarks "BaseLightSource#isDarkness is now obsolete. Use DarknessSource instead." */ - get isDarkness(): boolean; + get isDarkness(): false; } declare namespace BaseLightSource { + type AnyConstructor = typeof AnyBaseLightSource; + type LightAnimationFunction = ( this: BaseLightSource, dt: number, From 4571f56ea4f6fa434fe43584ab70a32ecd40c501 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 15:04:45 -0800 Subject: [PATCH 11/22] GlobalLightSource done --- .../client-esm/canvas/sources/global-light-source.d.mts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/foundry/client-esm/canvas/sources/global-light-source.d.mts b/src/foundry/client-esm/canvas/sources/global-light-source.d.mts index cd07b0b4f..0c0f926cb 100644 --- a/src/foundry/client-esm/canvas/sources/global-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/global-light-source.d.mts @@ -30,12 +30,14 @@ export default class GlobalLightSource extends BaseLightSource { /** * Name of this global light source. - * @defaultValue GlobalLightSource.sourceType + * @defaultValue `GlobalLightSource.sourceType` */ name: string; /** * A custom polygon placeholder. + * @defaultValue `null` + * @remarks This is not set anywhere in Foundry code, so will always be null barring system/module/user action */ customPolygon: PIXI.Polygon | number[] | null; @@ -44,4 +46,6 @@ export default class GlobalLightSource extends BaseLightSource { override _initializeSoftEdges(): void; override _updateGeometry(): void; + + override _updateCommonUniforms(shader: AbstractBaseShader): void; } From 939b17725355a740b9c26b914ea28e9bb8ddf7f6 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 22:15:40 -0800 Subject: [PATCH 12/22] simplify interface names --- .../canvas/sources/base-effect-source.d.mts | 12 ++++---- .../canvas/sources/base-light-source.d.mts | 8 +++--- .../canvas/sources/global-light-source.d.mts | 2 +- .../sources/point-darkness-source.d.mts | 6 ++-- .../canvas/sources/point-effect-source.d.mts | 6 ++-- .../canvas/sources/point-light-source.d.mts | 2 +- .../sources/point-movement-source.d.mts | 2 +- .../canvas/sources/point-sound-source.d.mts | 2 +- .../canvas/sources/point-vision-source.d.mts | 9 ++---- .../sources/rendered-effect-source.d.mts | 28 +++++++++---------- .../sources/base-effect-source.mjs.test-d.ts | 2 +- 11 files changed, 38 insertions(+), 41 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 83fc216fc..f64507a87 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 @@ -16,7 +16,7 @@ import type { NullishProps } from "../../../../types/utils.d.mts"; * @privateRemarks The TODO is foundry's */ declare abstract class BaseEffectSource< - SourceData extends BaseEffectSource.BaseEffectSourceData, + SourceData extends BaseEffectSource.SourceData, SourceShape extends PIXI.Polygon, > { /** @@ -24,7 +24,7 @@ declare abstract class BaseEffectSource< * @param options - Options which modify the base effect source instance * @remarks Passing a PlaceableObject is deprecated, and will be removed in v13 */ - constructor(options?: BaseEffectSource.BaseEffectSourceOptions | PlaceableObject); + constructor(options?: BaseEffectSource.SourceOptions | PlaceableObject); /** * The type of source represented by this data structure. @@ -49,7 +49,7 @@ declare abstract class BaseEffectSource< * } * ``` */ - static defaultData: BaseEffectSource.BaseEffectSourceData; + static defaultData: BaseEffectSource.SourceData; /** * Some other object which is responsible for this source. @@ -219,14 +219,14 @@ declare namespace BaseEffectSource { type AnyConstructor = typeof AnyBaseEffectSource; /** @internal */ - type _BaseEffectSourceOptions = NullishProps<{ + type _SourceOptions = NullishProps<{ /** * An optional PlaceableObject which is responsible for this source */ object: PlaceableObject; }>; - interface BaseEffectSourceOptions extends _BaseEffectSourceOptions { + interface SourceOptions extends _SourceOptions { /** * A unique ID for this source. This will be set automatically if an * object is provided, otherwise is required. @@ -236,7 +236,7 @@ declare namespace BaseEffectSource { sourceId?: string; } - interface BaseEffectSourceData { + interface SourceData { /** * The x-coordinate of the source location */ diff --git a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts index cd18d39a7..77495acb1 100644 --- a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts @@ -6,9 +6,9 @@ import type RenderedEffectSource from "./rendered-effect-source.d.mts"; * A specialized subclass of BaseEffectSource which deals with the rendering of light or darkness. */ declare abstract class BaseLightSource< - SourceData extends BaseLightSource.BaseLightSourceData = BaseLightSource.BaseLightSourceData, + SourceData extends BaseLightSource.SourceData = BaseLightSource.SourceData, SourceShape extends PIXI.Polygon = PIXI.Polygon, - RenderingLayers extends Record = RenderedEffectSource.Layers, + RenderingLayers extends Record = RenderedEffectSource.Layers, > extends RenderedEffectSource { /** @defaultValue `"light"` */ static override sourceType: string; @@ -56,7 +56,7 @@ declare abstract class BaseLightSource< * } * ``` */ - static override defaultData: BaseLightSource.BaseLightSourceData; + static override defaultData: BaseLightSource.SourceData; /** * A ratio of dim:bright as part of the source radius @@ -132,7 +132,7 @@ declare namespace BaseLightSource { options?: RenderedEffectSource.AnimationFunctionOptions, ) => void; - interface BaseLightSourceData extends RenderedEffectSource.RenderedEffectSourceData { + interface SourceData extends RenderedEffectSource.SourceData { /** * An opacity for the emitted light, if any */ diff --git a/src/foundry/client-esm/canvas/sources/global-light-source.d.mts b/src/foundry/client-esm/canvas/sources/global-light-source.d.mts index 0c0f926cb..53987b285 100644 --- a/src/foundry/client-esm/canvas/sources/global-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/global-light-source.d.mts @@ -26,7 +26,7 @@ export default class GlobalLightSource extends BaseLightSource { * } * ``` */ - static override defaultData: BaseLightSource.BaseLightSourceData; + static override defaultData: BaseLightSource.SourceData; /** * Name of this global light source. 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 b13724503..1c1241dc6 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 @@ -2,12 +2,12 @@ import type BaseLightSource from "./base-light-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; import type RenderedEffectSource from "./rendered-effect-source.d.mts"; -type DarknessSourceData = BaseLightSource.BaseLightSourceData & PointEffectSourceMixin.PointEffectSourceData; +type DarknessSourceData = BaseLightSource.SourceData & PointEffectSourceMixin.SourceData; // Interface causes errors // eslint-disable-next-line @typescript-eslint/consistent-type-definitions type DarknessLayers = { - darkness: RenderedEffectSource.RenderedEffectSourceLayer; + darkness: RenderedEffectSource.SourceLayer; }; /** @@ -29,7 +29,7 @@ export default class PointDarknessSource< /** @defaultValue `CONFIG.Canvas.darknessAnimations` */ static get ANIMATIONS(): CONFIG.Canvas.LightSourceAnimationConfig; - static override get _layers(): Record; + static override get _layers(): Record; /** * The optional geometric shape is solely utilized for visual representation regarding darkness sources. 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 8596ab9c5..295975fac 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 @@ -18,14 +18,14 @@ declare class PointEffectSource { * } * ``` */ - static defaultData: PointEffectSourceMixin.PointEffectSourceData; + static defaultData: PointEffectSourceMixin.SourceData; /** * A convenience reference to the radius of the source. */ get radius(): number; - _initialize(data: Partial): void; + _initialize(data: Partial): void; _initializeSoftEdges(): void; @@ -66,7 +66,7 @@ declare function PointEffectSourceMixin>; - interface PointEffectSourceData extends BaseEffectSource.BaseEffectSourceData { + interface SourceData extends BaseEffectSource.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 2787f8f73..747de8e84 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,7 +1,7 @@ import type BaseLightSource from "./base-light-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; -type LightSourceData = PointEffectSourceMixin.PointEffectSourceData & BaseLightSource.BaseLightSourceData; +type LightSourceData = PointEffectSourceMixin.SourceData & BaseLightSource.SourceData; /** * A specialized subclass of the BaseLightSource which renders a source of light as a point-based effect. 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 345cdb386..e586d7246 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,7 +1,7 @@ import type BaseEffectSource from "./base-effect-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; -type MovementSourceData = PointEffectSourceMixin.PointEffectSourceData & BaseEffectSource.BaseEffectSourceData; +type MovementSourceData = PointEffectSourceMixin.SourceData & BaseEffectSource.SourceData; /** * A specialized subclass of the BaseEffectSource which describes a movement-based source. 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 dc92ef944..68f68dd77 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,7 +1,7 @@ import type BaseEffectSource from "./base-effect-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; -type SoundSourceData = PointEffectSourceMixin.PointEffectSourceData & BaseEffectSource.BaseEffectSourceData; +type SoundSourceData = PointEffectSourceMixin.SourceData & BaseEffectSource.SourceData; /** * A specialized subclass of the BaseEffectSource which describes a point-based source of sound. 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 3ad52368c..1de40f614 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 @@ -47,7 +47,7 @@ declare class PointVisionSource< */ static override defaultData: PointVisionSourceData; - static get _layers(): Record; + static get _layers(): Record; /** * The vision mode linked to this VisionSource @@ -166,9 +166,7 @@ declare class PointVisionSource< declare namespace PointVisionSource { type Any = PointVisionSource; - interface VisionSourceData - extends RenderedEffectSource.RenderedEffectSourceData, - PointEffectSourceMixin.PointEffectSourceData { + interface VisionSourceData extends RenderedEffectSource.SourceData, PointEffectSourceMixin.SourceData { /** * The amount of contrast */ @@ -206,7 +204,6 @@ declare namespace PointVisionSource { } } -type PointVisionSourceData = PointEffectSourceMixin.PointEffectSourceData & - RenderedEffectSource.RenderedEffectSourceData; +type PointVisionSourceData = PointEffectSourceMixin.SourceData & RenderedEffectSource.SourceData; export default PointVisionSource; diff --git a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts index 1a561fc03..44bb2b6a6 100644 --- a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts @@ -7,9 +7,9 @@ import type BaseEffectSource from "./base-effect-source.d.mts"; * This class is extended by both the LightSource and VisionSource subclasses. */ declare class RenderedEffectSource< - SourceData extends RenderedEffectSource.RenderedEffectSourceData = RenderedEffectSource.RenderedEffectSourceData, + SourceData extends RenderedEffectSource.SourceData = RenderedEffectSource.SourceData, SourceShape extends PIXI.Polygon = PIXI.Polygon, - RenderingLayers extends Record = RenderedEffectSource.Layers, + RenderingLayers extends Record = RenderedEffectSource.Layers, > extends BaseEffectSource { /** * Keys of the data object which require shaders to be re-initialized. @@ -27,7 +27,7 @@ declare class RenderedEffectSource< */ protected static get _layers(): Record< "background" | "coloration" | "illumination", - RenderedEffectSource.RenderedEffectLayerConfig + RenderedEffectSource.LayerConfig >; /** @@ -48,13 +48,13 @@ declare class RenderedEffectSource< * } * ``` */ - static defaultData: RenderedEffectSource.RenderedEffectSourceData; + static defaultData: RenderedEffectSource.SourceData; /** * The animation configuration applied to this source * @defaultValue `{}` */ - animation: RenderedEffectSource.RenderedEffectSourceAnimationConfig; + animation: RenderedEffectSource.AnimationConfig; /** * Track the status of rendering layers @@ -119,7 +119,7 @@ declare class RenderedEffectSource< /** * Specific configuration for a layer. */ - protected _configureLayer(layer: RenderedEffectSource.RenderedEffectSourceLayer, layerId: string): void; + protected _configureLayer(layer: RenderedEffectSource.SourceLayer, layerId: string): void; /** * Create the geometry for the source shape that is used in shaders and compute its bounds for culling purpose. @@ -211,7 +211,7 @@ declare namespace RenderedEffectSource { type AnyConstructor = typeof AnyRenderedEffectSource; - interface RenderedEffectSourceData extends BaseEffectSource.BaseEffectSourceData { + interface SourceData extends BaseEffectSource.SourceData { /** * An animation configuration for the source */ @@ -267,7 +267,7 @@ declare namespace RenderedEffectSource { interface AnimationFunctionOptions extends _AnimationFunctionOptions {} /** @internal */ - type _RenderedEffectSourceAnimationConfig = InexactPartial<{ + type _AnimationConfig = InexactPartial<{ /** * The human-readable (localized) label for the animation */ @@ -310,13 +310,13 @@ declare namespace RenderedEffectSource { time: number; }>; - interface RenderedEffectSourceAnimationConfig extends _RenderedEffectSourceAnimationConfig {} + interface AnimationConfig extends _AnimationConfig {} /** * @remarks `mesh` and `shader` are given values during initialization *if* the Source has a valid `Placeable` as its `object`. * `vmUniforms` is only provided for `PointVisionSource` layers. */ - interface RenderedEffectSourceLayer extends RenderedEffectLayerConfig { + interface SourceLayer extends LayerConfig { /** * Is this layer actively rendered? */ @@ -346,7 +346,7 @@ declare namespace RenderedEffectSource { vmUniforms: AbstractBaseShader.Uniforms | undefined; } - interface RenderedEffectLayerConfig { + interface LayerConfig { /** * The default shader used by this layer */ @@ -361,9 +361,9 @@ declare namespace RenderedEffectSource { // Interface causes errors // eslint-disable-next-line @typescript-eslint/consistent-type-definitions type Layers = { - background: RenderedEffectSource.RenderedEffectSourceLayer; - coloration: RenderedEffectSource.RenderedEffectSourceLayer; - illumination: RenderedEffectSource.RenderedEffectSourceLayer; + background: RenderedEffectSource.SourceLayer; + coloration: RenderedEffectSource.SourceLayer; + illumination: RenderedEffectSource.SourceLayer; }; } diff --git a/tests/foundry/client-esm/canvas/sources/base-effect-source.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/base-effect-source.mjs.test-d.ts index aed36e460..c3b7c1554 100644 --- a/tests/foundry/client-esm/canvas/sources/base-effect-source.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/base-effect-source.mjs.test-d.ts @@ -1,6 +1,6 @@ import { expectTypeOf } from "vitest"; import type BaseEffectSource from "../../../../../src/foundry/client-esm/canvas/sources/base-effect-source.d.mts"; -declare const mySource: BaseEffectSource; +declare const mySource: BaseEffectSource; expectTypeOf(mySource.active).toEqualTypeOf(); From 495a4084a19531116115183065f0feb1930c0efb Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 22:58:22 -0800 Subject: [PATCH 13/22] Start of PointDarknessSource --- .../canvas/sources/base-light-source.d.mts | 4 +- .../sources/point-darkness-source.d.mts | 45 ++++++++++++------- .../canvas/sources/point-effect-source.d.mts | 8 +++- .../point-darkness-sources.mjs.test-d.ts | 5 +++ 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts index 77495acb1..425b24894 100644 --- a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts @@ -33,9 +33,9 @@ declare abstract class BaseLightSource< /** * The corresponding animation config. + * @remarks More broad than it should be to accomodate {@link foundry.canvas.sources.PointDarknessSource} */ - //TODO: convert when index signatures are removed from CONFIG - protected static get ANIMATIONS(): CONFIG.Canvas.LightSourceAnimationConfig; + protected static get ANIMATIONS(): typeof CONFIG.Canvas.lightAnimations | typeof CONFIG.Canvas.darknessAnimations; /** * @defaultValue 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 1c1241dc6..5e3fcf9a9 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 @@ -2,40 +2,35 @@ import type BaseLightSource from "./base-light-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; import type RenderedEffectSource from "./rendered-effect-source.d.mts"; -type DarknessSourceData = BaseLightSource.SourceData & PointEffectSourceMixin.SourceData; - -// Interface causes errors -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -type DarknessLayers = { - darkness: RenderedEffectSource.SourceLayer; -}; - /** * A specialized subclass of the BaseLightSource which renders a source of darkness as a point-based effect. */ -export default class PointDarknessSource< - SourceData extends DarknessSourceData = DarknessSourceData, +declare class PointDarknessSource< + SourceData extends PointDarknessSource.SourceData = PointDarknessSource.SourceData, SourceShape extends PointSourcePolygon = PointSourcePolygon, -> extends PointEffectSourceMixin(BaseLightSource) { +> extends PointEffectSourceMixin(BaseLightSource) { /** @defaultValue `"darknessSources"` */ static override effectsCollection: string; - /** @defaultValue `LIGHTING_LEVELS.HALFDARK` */ + /** @defaultValue `foundry.CONST.LIGHTING_LEVELS.HALFDARK` */ static override _dimLightingLevel: foundry.CONST.LIGHTING_LEVELS; - /** @defaultValue `LIGHTING_LEVELS.DARKNESS` */ + /** @defaultValue `foundry.CONST.LIGHTING_LEVELS.DARKNESS` */ static override _brightLightingLevel: foundry.CONST.LIGHTING_LEVELS; /** @defaultValue `CONFIG.Canvas.darknessAnimations` */ - static get ANIMATIONS(): CONFIG.Canvas.LightSourceAnimationConfig; + static get ANIMATIONS(): typeof CONFIG.Canvas.darknessAnimations; + + static override get _layers(): Record<"darkness", foundry.canvas.sources.RenderedEffectSource.LayerConfig>; - static override get _layers(): Record; + /** @privateRemarks This is not in Foundry's code, but accounts for the mixin class's static property's inability to be generic */ + static override defaultData: PointDarknessSource.SourceData; /** * The optional geometric shape is solely utilized for visual representation regarding darkness sources. * Used only when an additional radius is added for visuals. */ - protected _visualShape: SourceShape; + protected _visualShape: SourceShape | null; /** * Padding applied on the darkness source shape for visual appearance only. @@ -72,3 +67,21 @@ export default class PointDarknessSource< */ get darkness(): PointSourceMesh; } + +declare namespace PointDarknessSource { + type AnyConstructor = typeof AnyPointDarknessSource; + + type SourceData = BaseLightSource.SourceData & PointEffectSourceMixin.SourceData; + + // Interface causes errors + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions + type DarknessLayers = { + darkness: RenderedEffectSource.SourceLayer; + }; +} + +declare abstract class AnyPointDarknessSource extends PointDarknessSource { + constructor(arg0: never, ...args: never[]); +} + +export default PointDarknessSource; 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 295975fac..3c8522dfa 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 @@ -1,3 +1,4 @@ +import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; import type { Mixin } from "../../../../types/utils.d.mts"; import type BaseEffectSource from "./base-effect-source.d.mts"; @@ -17,21 +18,24 @@ declare class PointEffectSource { * walls: true * } * ``` + * @privateRemarks This will only be accurate for classes extending `PointEffectSourceMixin(BaseEffectSource)`. + * Other subclasses must override this. */ - static defaultData: PointEffectSourceMixin.SourceData; + static defaultData: PointEffectSourceMixin.SourceData & BaseEffectSource.SourceData; /** * A convenience reference to the radius of the source. */ get radius(): number; - _initialize(data: Partial): void; + _initialize(data: IntentionalPartial): void; _initializeSoftEdges(): void; /** * Configure the parameters of the polygon that is generated for this source. */ + //TODO: Make sure this is accurate as part of work on "pixi leftovers" protected _getPolygonConfiguration(): PointSourcePolygonConfig; _createShapes(): void; diff --git a/tests/foundry/client-esm/canvas/sources/point-darkness-sources.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/point-darkness-sources.mjs.test-d.ts index e277f89f3..dc5ac2152 100644 --- a/tests/foundry/client-esm/canvas/sources/point-darkness-sources.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/point-darkness-sources.mjs.test-d.ts @@ -2,9 +2,14 @@ import { expectTypeOf } from "vitest"; const mySource = new foundry.canvas.sources.PointDarknessSource(); +expectTypeOf(mySource.data).toEqualTypeOf(); expectTypeOf(mySource.active).toEqualTypeOf(); expectTypeOf(mySource.drawMeshes().background.visible).toEqualTypeOf(); expectTypeOf(mySource.animateTorch(5)).toEqualTypeOf(); expectTypeOf(mySource.add()).toEqualTypeOf(); expectTypeOf(mySource.shape).toEqualTypeOf(); expectTypeOf(mySource.layers.darkness.suppressed).toEqualTypeOf(); + +expectTypeOf( + foundry.canvas.sources.PointDarknessSource.defaultData, +).toEqualTypeOf(); From 542d57bea56a9919788f04e52afa7b814cd2e3d8 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sat, 21 Dec 2024 22:59:43 -0800 Subject: [PATCH 14/22] PointDarknessSource done --- .../canvas/sources/base-effect-source.d.mts | 2 +- .../canvas/sources/base-light-source.d.mts | 7 +++++- .../sources/point-darkness-source.d.mts | 22 +++++++++++++------ .../canvas/sources/point-vision-source.d.mts | 14 +++++------- .../sources/rendered-effect-source.d.mts | 16 +++++--------- .../point-darkness-sources.mjs.test-d.ts | 7 ++---- 6 files changed, 34 insertions(+), 34 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 f64507a87..58df56e6c 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 @@ -70,7 +70,7 @@ declare abstract class BaseEffectSource< /** * The geometric shape of the effect source which is generated later. */ - shape: SourceShape; + shape: SourceShape | undefined; /** * A collection of boolean flags which control rendering and refresh behavior for the source. diff --git a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts index 425b24894..b9c9b589d 100644 --- a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts @@ -34,6 +34,7 @@ declare abstract class BaseLightSource< /** * The corresponding animation config. * @remarks More broad than it should be to accomodate {@link foundry.canvas.sources.PointDarknessSource} + * TODO: Reevaluate after CONFIG has been gone over */ protected static get ANIMATIONS(): typeof CONFIG.Canvas.lightAnimations | typeof CONFIG.Canvas.darknessAnimations; @@ -120,12 +121,16 @@ declare abstract class BaseLightSource< * @deprecated since v12, until v14 * @remarks "BaseLightSource#isDarkness is now obsolete. Use DarknessSource instead." */ - get isDarkness(): false; + get isDarkness(): boolean; } declare namespace BaseLightSource { type AnyConstructor = typeof AnyBaseLightSource; + /** + * @privateRemarks This `this` is a concession to practicality (could really be a `RenderedEffectSource`, + * technically) but I didn't want to move the typing of `_noise` + */ type LightAnimationFunction = ( this: BaseLightSource, dt: number, 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 5e3fcf9a9..68c8f7bb2 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 @@ -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"; import type RenderedEffectSource from "./rendered-effect-source.d.mts"; @@ -8,7 +9,7 @@ import type RenderedEffectSource from "./rendered-effect-source.d.mts"; declare class PointDarknessSource< SourceData extends PointDarknessSource.SourceData = PointDarknessSource.SourceData, SourceShape extends PointSourcePolygon = PointSourcePolygon, -> extends PointEffectSourceMixin(BaseLightSource) { +> extends PointEffectSourceMixin(BaseLightSource) { /** @defaultValue `"darknessSources"` */ static override effectsCollection: string; @@ -21,7 +22,7 @@ declare class PointDarknessSource< /** @defaultValue `CONFIG.Canvas.darknessAnimations` */ static get ANIMATIONS(): typeof CONFIG.Canvas.darknessAnimations; - static override get _layers(): Record<"darkness", foundry.canvas.sources.RenderedEffectSource.LayerConfig>; + static override get _layers(): Record; /** @privateRemarks This is not in Foundry's code, but accounts for the mixin class's static property's inability to be generic */ static override defaultData: PointDarknessSource.SourceData; @@ -35,6 +36,7 @@ declare class PointDarknessSource< /** * 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. + * @defaultValue `(CONFIG.Canvas.darknessSourcePaddingMultiplier ?? 0) * canvas.grid.size` */ protected _padding: number; @@ -43,9 +45,16 @@ declare class PointDarknessSource< */ edges: foundry.canvas.edges.Edge[]; + /** + * A convenience accessor to the darkness layer mesh. + */ + get darkness(): this["layers"]["darkness"]["mesh"]; + + override _initialize(data: IntentionalPartial): void; + override _createShapes(): void; - override _configure(changes: Partial): void; + override _configure(changes: IntentionalPartial): void; override _getPolygonConfiguration(): PointSourcePolygonConfig; @@ -61,11 +70,10 @@ declare class PointDarknessSource< override _destroy(): void; /** - * A convenience accessor to the darkness layer mesh. * @deprecated since v12, until v14 * @remarks `"BaseLightSource#isDarkness is now obsolete. Use DarknessSource instead."` */ - get darkness(): PointSourceMesh; + get isDarkness(): boolean; } declare namespace PointDarknessSource { @@ -73,9 +81,9 @@ declare namespace PointDarknessSource { type SourceData = BaseLightSource.SourceData & PointEffectSourceMixin.SourceData; - // Interface causes errors + // Interface would require `RenderingLayers extends ... = InterfaceToObject` in every subclass signature // eslint-disable-next-line @typescript-eslint/consistent-type-definitions - type DarknessLayers = { + type Layers = { darkness: RenderedEffectSource.SourceLayer; }; } 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 1de40f614..733cadf6f 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 @@ -6,7 +6,9 @@ import type PointEffectSourceMixin from "./point-effect-source.d.mts"; */ declare class PointVisionSource< SourceData extends PointVisionSource.VisionSourceData = PointVisionSource.VisionSourceData, -> extends PointEffectSourceMixin(RenderedEffectSource) { + SourceShape extends PointSourcePolygon = PointSourcePolygon, + RenderingLayers extends RenderedEffectSource.Layers = RenderedEffectSource.Layers, +> extends PointEffectSourceMixin(RenderedEffectSource) { /** @defaultValue `"sight"` */ static override sourceType: string; @@ -112,8 +114,6 @@ declare class PointVisionSource< override _createShapes(): void; - override shape: PointSourcePolygon; - /** * Responsible for assigning the Vision Mode and calling the activation and deactivation handlers. */ @@ -121,7 +121,7 @@ declare class PointVisionSource< override _configure(changes: Partial): void; - override _configureLayer(layer: Record, layerId: string): void; + override _configureLayer(layer: RenderedEffectSource.SourceLayer, layerId: string): void; override _getPolygonConfiguration(): PointSourcePolygonConfig; @@ -141,11 +141,7 @@ declare class PointVisionSource< */ protected _createRestrictedPolygon(): PointSourcePolygon; - override _configureShaders(): { - background: AdaptiveLightingShader; - coloration: AdaptiveLightingShader; - illumination: AdaptiveLightingShader; - }; + override _configureShaders(): Record; override _updateColorationUniforms(): void; diff --git a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts index 44bb2b6a6..ccdf3b7fa 100644 --- a/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts @@ -25,10 +25,7 @@ declare class RenderedEffectSource< * Layers handled by this rendered source. * @remarks Keys should match the keys of RenderingLayers */ - protected static get _layers(): Record< - "background" | "coloration" | "illumination", - RenderedEffectSource.LayerConfig - >; + protected static get _layers(): Record; /** * The offset in pixels applied to create soft edges. @@ -266,8 +263,7 @@ declare namespace RenderedEffectSource { /** Shared options for the {@link AnimationFunction}s provided by `_Source` classes */ interface AnimationFunctionOptions extends _AnimationFunctionOptions {} - /** @internal */ - type _AnimationConfig = InexactPartial<{ + type AnimationConfig = InexactPartial<{ /** * The human-readable (localized) label for the animation */ @@ -310,11 +306,9 @@ declare namespace RenderedEffectSource { time: number; }>; - interface AnimationConfig extends _AnimationConfig {} - /** - * @remarks `mesh` and `shader` are given values during initialization *if* the Source has a valid `Placeable` as its `object`. - * `vmUniforms` is only provided for `PointVisionSource` layers. + * @remarks The properties `mesh` and `shader` from `LayerConfig` are not documented as being part of the typedef. They are given values + * during initialization *if* the Source has a valid `Placeable` as its `object`. `vmUniforms` is only provided a value for `PointVisionSource` layers. */ interface SourceLayer extends LayerConfig { /** @@ -358,7 +352,7 @@ declare namespace RenderedEffectSource { blendMode: keyof typeof PIXI.BLEND_MODES; } - // Interface causes errors + // Interface would require `RenderingLayers extends ... = InterfaceToObject` in every subclass signature // eslint-disable-next-line @typescript-eslint/consistent-type-definitions type Layers = { background: RenderedEffectSource.SourceLayer; diff --git a/tests/foundry/client-esm/canvas/sources/point-darkness-sources.mjs.test-d.ts b/tests/foundry/client-esm/canvas/sources/point-darkness-sources.mjs.test-d.ts index dc5ac2152..df2386ba3 100644 --- a/tests/foundry/client-esm/canvas/sources/point-darkness-sources.mjs.test-d.ts +++ b/tests/foundry/client-esm/canvas/sources/point-darkness-sources.mjs.test-d.ts @@ -4,12 +4,9 @@ const mySource = new foundry.canvas.sources.PointDarknessSource(); expectTypeOf(mySource.data).toEqualTypeOf(); expectTypeOf(mySource.active).toEqualTypeOf(); -expectTypeOf(mySource.drawMeshes().background.visible).toEqualTypeOf(); +expectTypeOf(mySource.drawMeshes().darkness).toEqualTypeOf(); +expectTypeOf(mySource.drawMeshes().darkness?.visible).toEqualTypeOf(); expectTypeOf(mySource.animateTorch(5)).toEqualTypeOf(); expectTypeOf(mySource.add()).toEqualTypeOf(); expectTypeOf(mySource.shape).toEqualTypeOf(); expectTypeOf(mySource.layers.darkness.suppressed).toEqualTypeOf(); - -expectTypeOf( - foundry.canvas.sources.PointDarknessSource.defaultData, -).toEqualTypeOf(); From 8ad332174085d520d565b2a9884d9365089ecfa2 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 00:18:36 -0800 Subject: [PATCH 15/22] 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(); From babad8c0d7aba74248e21900af41cc90cfd5981e Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 01:12:11 -0800 Subject: [PATCH 16/22] 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(); From bf1de40ced558996c7a42b045514d04ae2f17cca Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 10:51:56 -0800 Subject: [PATCH 17/22] canvas test fixes, and one improvement to the actual class --- src/foundry/client/pixi/board.d.mts | 2 +- tests/foundry/client/pixi/board.test-d.ts | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/foundry/client/pixi/board.d.mts b/src/foundry/client/pixi/board.d.mts index 9fe51fce6..35c47cbc7 100644 --- a/src/foundry/client/pixi/board.d.mts +++ b/src/foundry/client/pixi/board.d.mts @@ -167,7 +167,7 @@ declare global { /** * The singleton FogManager instance. */ - fog: FogManager; + fog: InstanceType; /** * A perception manager interface for batching lighting, sight, and sound updates diff --git a/tests/foundry/client/pixi/board.test-d.ts b/tests/foundry/client/pixi/board.test-d.ts index 69dbfbdb6..12f76db69 100644 --- a/tests/foundry/client/pixi/board.test-d.ts +++ b/tests/foundry/client/pixi/board.test-d.ts @@ -14,19 +14,21 @@ expectTypeOf(myCanvas.getLayerByEmbeddedName("Token")).toEqualTypeOf(); expectTypeOf(myCanvas.getLayerByEmbeddedName("any-string")).toEqualTypeOf(); -expectTypeOf(myCanvas.animatePan()).toEqualTypeOf>(); -expectTypeOf(myCanvas.animatePan({})).toEqualTypeOf>(); -expectTypeOf(myCanvas.animatePan({ x: 100, y: 100, scale: 1, duration: 250, speed: 10 })).toEqualTypeOf< - Promise +expectTypeOf(myCanvas.animatePan({})).toEqualTypeOf>(); +expectTypeOf( + myCanvas.animatePan({ x: 100, y: 100, scale: 1, duration: 250, easing: (pt: number) => pt }), +).toEqualTypeOf>(); +expectTypeOf(myCanvas.animatePan({ x: 500, y: 500, scale: 10, speed: 6, easing: "easeInCircle" })).toEqualTypeOf< + Promise >(); -expectTypeOf(myCanvas.recenter()).toEqualTypeOf>(); -expectTypeOf(myCanvas.recenter({})).toEqualTypeOf>(); -expectTypeOf(myCanvas.recenter({ x: null, y: null, scale: null })).toEqualTypeOf>(); -expectTypeOf(myCanvas.recenter({ x: 100, y: 100, scale: 1 })).toEqualTypeOf>(); +expectTypeOf(myCanvas.recenter()).toEqualTypeOf>(); +expectTypeOf(myCanvas.recenter({})).toEqualTypeOf>(); +expectTypeOf(myCanvas.recenter({ x: null, y: null, scale: null })).toEqualTypeOf>(); +expectTypeOf(myCanvas.recenter({ x: 100, y: 100, scale: 1 })).toEqualTypeOf>(); myCanvas.pendingRenderFlags.OBJECTS.add(myCanvas.perception); expectTypeOf(myCanvas.hidden).toEqualTypeOf(); -expectTypeOf(myCanvas.rendered).toEqualTypeOf(); -expectTypeOf(myCanvas.environment).toEqualTypeOf(); +expectTypeOf(myCanvas.rendered).toEqualTypeOf(); +expectTypeOf(myCanvas.environment).toEqualTypeOf(); From 78e4e7c9d90a7c2bc2074a15d28edcd5cc3f6c53 Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 11:16:16 -0800 Subject: [PATCH 18/22] more test and random error fixes --- .../pixi/core/interaction/render-flags.d.mts | 2 +- src/foundry/common/grid/_module.d.mts | 2 +- .../layers/base/placeables-layer.test-d.ts | 4 ++-- .../client/pixi/layers/grid/grid.test-d.ts | 22 ------------------- .../client/pixi/layers/grid/hex.test-d.ts | 7 ------ .../client/pixi/layers/grid/square.test-d.ts | 22 ------------------- tests/foundry/common/grid/hex.test-d.ts | 10 +++++++++ tests/foundry/common/grid/square.test-d.ts | 16 ++++++++++++++ 8 files changed, 30 insertions(+), 55 deletions(-) delete mode 100644 tests/foundry/client/pixi/layers/grid/grid.test-d.ts delete mode 100644 tests/foundry/client/pixi/layers/grid/hex.test-d.ts delete mode 100644 tests/foundry/client/pixi/layers/grid/square.test-d.ts create mode 100644 tests/foundry/common/grid/hex.test-d.ts create mode 100644 tests/foundry/common/grid/square.test-d.ts diff --git a/src/foundry/client/pixi/core/interaction/render-flags.d.mts b/src/foundry/client/pixi/core/interaction/render-flags.d.mts index 660b22f91..c1c20421e 100644 --- a/src/foundry/client/pixi/core/interaction/render-flags.d.mts +++ b/src/foundry/client/pixi/core/interaction/render-flags.d.mts @@ -86,7 +86,7 @@ declare global { * Valid options are OBJECTS or PERCEPTION. * @defaultValue `PIXI.UPDATE_PRIORITY.OBJECTS` */ - priority?: PIXI.UPDATE_PRIORITY.OBJECTS | PIXI.UPDATE_PRIORITY.PERCEPTION; + priority?: PIXI.UPDATE_PRIORITY; }, ); diff --git a/src/foundry/common/grid/_module.d.mts b/src/foundry/common/grid/_module.d.mts index acfbdc7cd..eb793d528 100644 --- a/src/foundry/common/grid/_module.d.mts +++ b/src/foundry/common/grid/_module.d.mts @@ -7,4 +7,4 @@ export { default as BaseGrid } from "./base.mjs"; export { default as GridHex } from "./grid-hex.mjs"; export { default as GridlessGrid } from "./gridless.mjs"; export { default as HexagonalGrid } from "./hexagonal.mjs"; -export { default as SquareHex } from "./square.mjs"; +export { default as SquareGrid } from "./square.mjs"; diff --git a/tests/foundry/client/pixi/layers/base/placeables-layer.test-d.ts b/tests/foundry/client/pixi/layers/base/placeables-layer.test-d.ts index eaa619ae9..32b0cc244 100644 --- a/tests/foundry/client/pixi/layers/base/placeables-layer.test-d.ts +++ b/tests/foundry/client/pixi/layers/base/placeables-layer.test-d.ts @@ -64,11 +64,11 @@ expectTypeOf(layer.rotateMany({ angle: 10, delta: 20, snap: 20, ids: ["abc", "de >(); expectTypeOf(layer.moveMany()).toEqualTypeOf | undefined>(); expectTypeOf(layer.moveMany({})).toEqualTypeOf | undefined>(); -expectTypeOf(layer.moveMany({ dx: 100, dy: 100, rotate: true, ids: ["abc", "def"] })).toEqualTypeOf< +expectTypeOf(layer.moveMany({ dx: 1, dy: -1, rotate: true, ids: ["abc", "def"] })).toEqualTypeOf< Promise | undefined >(); expectTypeOf(layer.undoHistory()).toEqualTypeOf>(); -expectTypeOf(layer.deleteAll()).toEqualTypeOf>(); +expectTypeOf(layer.deleteAll()).toEqualTypeOf>(); expectTypeOf(layer.storeHistory("create", new AmbientLightDocument()["_source"])).toEqualTypeOf(); expectTypeOf(layer.storeHistory("update", new AmbientLightDocument()["_source"])).toEqualTypeOf(); expectTypeOf(layer.storeHistory("delete", new AmbientLightDocument()["_source"])).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/grid/grid.test-d.ts b/tests/foundry/client/pixi/layers/grid/grid.test-d.ts deleted file mode 100644 index 4260a0052..000000000 --- a/tests/foundry/client/pixi/layers/grid/grid.test-d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { expectTypeOf } from "vitest"; - -const myGrid = new foundry.grid.BaseGrid({ - dimensions: { - width: 1, - height: 2, - sceneHeight: 3, - sceneRect: { x: 1, y: 2, width: 3, height: 4 }, - sceneWidth: 5, - sceneX: 6, - sceneY: 7, - size: 8, - rect: { x: 1, y: 2, width: 3, height: 4 }, - distance: 9, - maxR: 10, - ratio: 11, - }, - color: "0x000000", - alpha: 3, -}); - -expectTypeOf(myGrid.draw()).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/grid/hex.test-d.ts b/tests/foundry/client/pixi/layers/grid/hex.test-d.ts deleted file mode 100644 index 2b1c290fb..000000000 --- a/tests/foundry/client/pixi/layers/grid/hex.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectTypeOf } from "vitest"; - -HexagonalGrid.pixelsToOffset({ x: 3, y: 2 }, { columns: true, even: false, size: 4 }, "floor"); - -const myGrid = new HexagonalGrid({ columns: true, even: false, size: 4 }); - -expectTypeOf(myGrid.draw()).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/grid/square.test-d.ts b/tests/foundry/client/pixi/layers/grid/square.test-d.ts deleted file mode 100644 index 94697e4e4..000000000 --- a/tests/foundry/client/pixi/layers/grid/square.test-d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { expectTypeOf } from "vitest"; - -const myGrid = new SquareGrid({ - dimensions: { - width: 1, - height: 2, - sceneHeight: 3, - sceneRect: { x: 1, y: 2, width: 3, height: 4 }, - sceneWidth: 5, - sceneX: 6, - sceneY: 7, - size: 8, - rect: { x: 1, y: 2, width: 3, height: 4 }, - distance: 9, - maxR: 10, - ratio: 11, - }, - color: "0x000000", - alpha: 3, -}); - -expectTypeOf(myGrid.draw()).toEqualTypeOf(); diff --git a/tests/foundry/common/grid/hex.test-d.ts b/tests/foundry/common/grid/hex.test-d.ts new file mode 100644 index 000000000..f555d461b --- /dev/null +++ b/tests/foundry/common/grid/hex.test-d.ts @@ -0,0 +1,10 @@ +import type HexagonalGrid from "src/foundry/common/grid/hexagonal.d.mts"; +import { expectTypeOf } from "vitest"; + +const hexGrid = new foundry.grid.HexagonalGrid({ + columns: false, + even: true, + size: 200, +}); + +expectTypeOf(hexGrid.getOffset({ q: 50, r: 200, s: 500 })).toEqualTypeOf(); diff --git a/tests/foundry/common/grid/square.test-d.ts b/tests/foundry/common/grid/square.test-d.ts new file mode 100644 index 000000000..4d4ee4391 --- /dev/null +++ b/tests/foundry/common/grid/square.test-d.ts @@ -0,0 +1,16 @@ +import type SquareGrid from "src/foundry/common/grid/square.d.mts"; +import { expectTypeOf } from "vitest"; + +const myGrid = new foundry.grid.SquareGrid({ + diagonals: CONST.GRID_DIAGONALS.ALTERNATING_1, + size: 100, + color: "0x000000", + alpha: 3, +}); + +expectTypeOf( + myGrid.getDirectPath([ + { i: 30, j: 200 }, + { x: 2000, y: 2000 }, + ]), +).toEqualTypeOf(); From b56da632aa050c5bc867c3d57ee1dca82840125e Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 14:55:06 -0800 Subject: [PATCH 19/22] update imports and lint --- .../client-esm/canvas/sources/base-light-source.d.mts | 4 ---- .../client-esm/canvas/sources/point-darkness-source.d.mts | 2 +- .../client-esm/canvas/sources/point-light-source.d.mts | 2 +- .../client-esm/canvas/sources/point-sound-source.d.mts | 2 +- .../client-esm/canvas/sources/point-vision-source.d.mts | 2 +- src/foundry/client/pixi/layers/controls/layer.d.mts | 7 ++++++- src/foundry/common/data/data.d.mts | 2 +- src/types/augments/smooth.d.mts | 4 +++- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts index e42853b6e..76322100b 100644 --- a/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +++ b/src/foundry/client-esm/canvas/sources/base-light-source.d.mts @@ -126,10 +126,6 @@ declare abstract class BaseLightSource< declare namespace BaseLightSource { type AnyConstructor = typeof AnyBaseLightSource; - /** - * @privateRemarks This `this` is a concession to practicality (could really be a `RenderedEffectSource`, - * technically) but I didn't want to move the typing of `_noise` - */ type LightAnimationFunction = ( this: BaseLightSource, dt: number, 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 55058cde7..e8a998584 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 @@ -1,4 +1,4 @@ -import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; +import type { IntentionalPartial } from "../../../../utils/index.d.mts"; import type BaseLightSource from "./base-light-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; import type RenderedEffectSource from "./rendered-effect-source.d.mts"; 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 5e7dac3ec..6a88d127c 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,4 +1,4 @@ -import type { IntentionalPartial } from "../../../../types/helperTypes.d.mts"; +import type { IntentionalPartial } from "../../../../utils/index.d.mts"; import type BaseLightSource from "./base-light-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; 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 95336d121..e39328ce9 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,4 +1,4 @@ -import type { NullishProps } from "../../../../types/utils.d.mts"; +import type { NullishProps } from "../../../../utils/index.d.mts"; import type BaseEffectSource from "./base-effect-source.d.mts"; import type PointEffectSourceMixin from "./point-effect-source.d.mts"; 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 fde9ba09a..15cbbc491 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,6 +1,6 @@ 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"; +import type { IntentionalPartial } from "../../../../utils/index.d.mts"; /** * A specialized subclass of RenderedEffectSource which represents a source of point-based vision. diff --git a/src/foundry/client/pixi/layers/controls/layer.d.mts b/src/foundry/client/pixi/layers/controls/layer.d.mts index 235a0a95d..66d675f3d 100644 --- a/src/foundry/client/pixi/layers/controls/layer.d.mts +++ b/src/foundry/client/pixi/layers/controls/layer.d.mts @@ -1,4 +1,9 @@ -import type { IntentionalPartial, InexactPartial, NullishProps, RemoveIndexSignatures } from "../../../../../utils/index.d.mts"; +import type { + IntentionalPartial, + InexactPartial, + NullishProps, + RemoveIndexSignatures, +} from "../../../../../utils/index.d.mts"; import type { LineIntersection } from "../../../../common/utils/geometry.d.mts"; declare global { diff --git a/src/foundry/common/data/data.d.mts b/src/foundry/common/data/data.d.mts index f4c0e7bfd..7300dc103 100644 --- a/src/foundry/common/data/data.d.mts +++ b/src/foundry/common/data/data.d.mts @@ -2,7 +2,7 @@ import type { DatabaseBackend } from "../abstract/module.d.mts"; import type { DataModel } from "../abstract/data.d.mts"; import type { fields } from "./module.d.mts"; import type * as documents from "../documents/_module.d.mts"; -import type { AnyObject, EmptyObject, ToMethod, ValueOf } from "../../../utils/index.d.mts" +import type { AnyObject, EmptyObject, ToMethod, ValueOf } from "../../../utils/index.d.mts"; // TODO: Implement all of the necessary options diff --git a/src/types/augments/smooth.d.mts b/src/types/augments/smooth.d.mts index 658c77a35..7f0ba7ef0 100644 --- a/src/types/augments/smooth.d.mts +++ b/src/types/augments/smooth.d.mts @@ -1,4 +1,4 @@ -import type { Brand } from "../helperTypes.d.mts"; +import type { Brand } from "src/utils/index.d.mts"; import * as graphicsSmooth from "@pixi/graphics-smooth"; type JOINT_TYPE = Brand; @@ -7,5 +7,7 @@ declare const JOINT_TYPE: Record; declare const LINE_SCALE_MODE: Record; +// eslint-disable-next-line export * from "@pixi/graphics-smooth"; +// eslint-disable-next-line export { JOINT_TYPE, LINE_SCALE_MODE }; From 3fc57f8cdb07ab62dee21a4e6e136a9f867ca88f Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 14:56:56 -0800 Subject: [PATCH 20/22] last helperTypes reference got --- src/types/augments/particles.d.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/augments/particles.d.mts b/src/types/augments/particles.d.mts index 9bb161195..9e904fdae 100644 --- a/src/types/augments/particles.d.mts +++ b/src/types/augments/particles.d.mts @@ -1,7 +1,7 @@ /* eslint-disable import/export */ import * as pixiParticles from "@pixi/particle-emitter"; -import type { Brand } from "../helperTypes.d.mts"; +import type { Brand } from "src/utils/index.d.mts"; export namespace behaviors { type BehaviorOrder = Brand; From 526a3c747d76c1b2f61221ec56ed1e132b5e416e Mon Sep 17 00:00:00 2001 From: esheyw Date: Sun, 22 Dec 2024 14:59:12 -0800 Subject: [PATCH 21/22] more lint fixes --- .../client-esm/applications/api/application.d.mts | 9 ++++++++- src/foundry/client-esm/dice/terms/dice.d.mts | 5 ++++- src/foundry/client/data/abstract/client-document.d.mts | 5 ++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/foundry/client-esm/applications/api/application.d.mts b/src/foundry/client-esm/applications/api/application.d.mts index a82571399..9873ef904 100644 --- a/src/foundry/client-esm/applications/api/application.d.mts +++ b/src/foundry/client-esm/applications/api/application.d.mts @@ -1,4 +1,11 @@ -import type { MustConform, AnyObject, DeepPartial, EmptyObject, InexactPartial, MaybePromise } from "../../../../utils/index.d.mts"; +import type { + MustConform, + AnyObject, + DeepPartial, + EmptyObject, + InexactPartial, + MaybePromise, +} from "../../../../utils/index.d.mts"; import type EventEmitterMixin from "../../../common/utils/event-emitter.d.mts"; // TODO: Investigate use of DeepPartial vs Partial vs InexactPartial diff --git a/src/foundry/client-esm/dice/terms/dice.d.mts b/src/foundry/client-esm/dice/terms/dice.d.mts index 16b8887ab..ceb46bc3c 100644 --- a/src/foundry/client-esm/dice/terms/dice.d.mts +++ b/src/foundry/client-esm/dice/terms/dice.d.mts @@ -315,7 +315,10 @@ declare abstract class DiceTerm extends RollTerm { /* Serialization & Loading */ /* -------------------------------------------- */ - protected static _fromData(this: T, data: Record): InstanceType; + protected static _fromData( + this: T, + data: Record, + ): InstanceType; override toJSON(): Record; } diff --git a/src/foundry/client/data/abstract/client-document.d.mts b/src/foundry/client/data/abstract/client-document.d.mts index e1da94775..4b65bd830 100644 --- a/src/foundry/client/data/abstract/client-document.d.mts +++ b/src/foundry/client/data/abstract/client-document.d.mts @@ -88,7 +88,10 @@ declare class ClientDocument Date: Sun, 22 Dec 2024 15:01:18 -0800 Subject: [PATCH 22/22] actual last helperType reference --- src/types/augments/pixi.d.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/augments/pixi.d.mts b/src/types/augments/pixi.d.mts index d97124b84..d162145c1 100644 --- a/src/types/augments/pixi.d.mts +++ b/src/types/augments/pixi.d.mts @@ -1,5 +1,5 @@ import * as _PIXI from "pixi.js"; -import type { Brand } from "../helperTypes.d.mts"; +import type { Brand } from "src/utils/index.d.mts"; // Note(LukeAbby): The `smooth.d.mts` and `smooth.d.mts` files exist to make it DRY to selectively tweak PIXI sub-namespaces. // Each of them write `export * from "..."` and then selectively shadow or augment the exports.