From ac0e4d6368da3bad898d90137e8eb2780372be2b Mon Sep 17 00:00:00 2001 From: JPMeehan Date: Thu, 14 Dec 2023 13:55:08 -0800 Subject: [PATCH 1/2] Improved types --- .../core/containers/cached-container.d.ts | 8 +- .../client/pixi/core/containers/quadtree.d.ts | 2 +- .../pixi/core/containers/sprite-mesh.d.ts | 9 +- .../core/interaction/canvas-animation.d.ts | 125 ++++-------------- src/foundry/client/pixi/placeables/token.d.ts | 15 --- 5 files changed, 30 insertions(+), 129 deletions(-) diff --git a/src/foundry/client/pixi/core/containers/cached-container.d.ts b/src/foundry/client/pixi/core/containers/cached-container.d.ts index 7a768cea0..4f66caf01 100644 --- a/src/foundry/client/pixi/core/containers/cached-container.d.ts +++ b/src/foundry/client/pixi/core/containers/cached-container.d.ts @@ -74,11 +74,9 @@ declare global { */ clear(destroy?: boolean): CachedContainer; - /** {@inheritdoc} */ - destroy(options?: Parameters[0]): ReturnType; + override destroy(options?: boolean | PIXI.IDestroyOptions): void; - /** {@inheritdoc} */ - render(renderer: Parameters[0]): void; + override render(renderer: PIXI.Renderer): void; /** * Resize a render texture passed as a parameter with the renderer. @@ -91,7 +89,7 @@ declare global { namespace CachedContainer { type RenderOptions = { /** Render function that will be called to render into the RT. */ - renderFunction?: (...args: any[]) => any; + renderFunction?: (renderer: PIXI.Renderer) => void; /** An optional clear color to clear the RT before rendering into it. */ clearColor?: number[]; }; diff --git a/src/foundry/client/pixi/core/containers/quadtree.d.ts b/src/foundry/client/pixi/core/containers/quadtree.d.ts index 6586a19e9..62558da65 100644 --- a/src/foundry/client/pixi/core/containers/quadtree.d.ts +++ b/src/foundry/client/pixi/core/containers/quadtree.d.ts @@ -60,7 +60,7 @@ declare global { /** * A constant that enumerates the index order of the quadtree nodes from top-left to bottom-right. */ - static INDICES: { + static readonly INDICES: { tl: 0; tr: 1; bl: 2; diff --git a/src/foundry/client/pixi/core/containers/sprite-mesh.d.ts b/src/foundry/client/pixi/core/containers/sprite-mesh.d.ts index 5b42e083d..982d980b5 100644 --- a/src/foundry/client/pixi/core/containers/sprite-mesh.d.ts +++ b/src/foundry/client/pixi/core/containers/sprite-mesh.d.ts @@ -1,6 +1,3 @@ -import { IBaseTextureOptions } from "@pixi/core"; -import { IPointData } from "@pixi/math"; - export {}; declare global { @@ -145,9 +142,9 @@ declare global { override getLocalBounds(rect: PIXI.Rectangle): PIXI.Rectangle; - override containsPoint(point: IPointData): boolean; + override containsPoint(point: PIXI.IPointData): boolean; - override destroy(...args: any[]): void; + override destroy(options: PIXI.IDestroyOptions | boolean): void; /** * Create a SpriteMesh from another source. @@ -158,7 +155,7 @@ declare global { */ static from( source: string | PIXI.Texture | HTMLCanvasElement | HTMLVideoElement, - textureOptions?: IBaseTextureOptions, + textureOptions?: PIXI.IBaseTextureOptions, shaderCls?: typeof AbstractBaseShader, ): SpriteMesh; } diff --git a/src/foundry/client/pixi/core/interaction/canvas-animation.d.ts b/src/foundry/client/pixi/core/interaction/canvas-animation.d.ts index deec5f7e2..186777077 100644 --- a/src/foundry/client/pixi/core/interaction/canvas-animation.d.ts +++ b/src/foundry/client/pixi/core/interaction/canvas-animation.d.ts @@ -114,36 +114,6 @@ declare global { { context, name, duration, easing, ontick, priority }?: CanvasAnimationOptions, ): Promise; - /** - * Apply a linear animation from the current value of some attribute to a new value - * Resolve a Promise once the animation has concluded and the attributes have reached their new target - * @param attributes - An array of attributes to animate. Structure of the Array is shown in the example - * @param options - Additional options which customize the animation - * (default: `{}`) - * @returns A Promise which resolves once the linear animation has concluded - * - * @example - * ```typescript - * let animation = [ - * { - * parent: token, - * attribute: x, - * to: 1000 - * }, - * { - * parent: token, - * attribute: y, - * to: 2000 - * } - * ]; - * CanvasAnimation.animateLinear(attributes, {duration:500, ontick: console.log("ticking")}); - * ``` - */ - static animateLinear( - attributes: CanvasAnimation.Attribute[], - options?: InexactPartial, - ): Promise; - /** * Retrieve an animation currently in progress by its name * @param name - The animation name to retrieve @@ -158,82 +128,33 @@ declare global { static terminateAnimation(name: string): void; /** - * Asynchronously animate a transition function and resolve a Promise once the animation has completed - * @param fn - A suitable transition function. See PIXI.Ticker for details - * @param context - The Canvas container providing scope for the transition - * @param name - Provide a unique animation name which may be referenced later - * @param attributes - The attributes being animated by the function - * @param duration - The duration in milliseconds over which the animation should occur - * @param ontick - A function which defines additional behaviors to apply every animation frame - * @returns A Promise which resolves once the animation has completed + * Cosine based easing with smooth in-out. + * @param pt - The proportional animation timing on [0,1] + * @returns The eased animation progress on [0,1] */ - protected static _animatePromise( - fn: TransitionFunction, - context: PIXI.Container, - name: string, - attributes: CanvasAnimation.Attribute[], - duration: number, - ontick: TickFunction | undefined, - ): Promise; + static easeInOutCosine(pt: number): number; /** - * Generic ticker function to implement the animation. - * This animation wrapper executes once per frame for the duration of the animation event. - * Once the animated attributes have converged to their targets, it resolves the original Promise. - * The user-provided ontick function runs each frame update to apply additional behaviors. + * Shallow ease out. + * @param pt - The proportional animation timing on [0,1] + * @returns The eased animation progress on [0,1] */ - protected static _animateFrame( - deltaTime: number, - resolve: CanvasAnimationData["resolve"], - reject: (reason?: any) => void, - attributes: CanvasAnimation.Attribute[], - duration: number, - ontick: TickFunction | undefined, - ): void; - } + static easeOutCircle(pt: number): number; - namespace CanvasAnimation { - interface Attribute { - attribute: string; - d?: number; - delta?: number; - done?: number; - parent: any; - remaining?: number; - to: number; - } - } -} - -interface LinearAnimationOptions { - /** - * An animation context to use which defines scope - */ - context: PIXI.DisplayObject; - - /** - * Provide a unique animation name which may be referenced later - */ - name: string; - - /** - * The duration in milliseconds over which the animation should occur - * @defaultValue `1000` - */ - duration: number; + /** + * Shallow ease in. + * @param pt - The proportional animation timing on [0,1] + * @returns The eased animation progress on [0,1] + */ + static easeInCircle(pt: number): number; - /** - * A function which defines additional behaviors to apply every animation frame - */ - ontick: TickFunction; + /** + * @deprecated since v10, will be removed in v12 + * @remarks "You are calling CanvasAnimation.animateLinear which is deprecated in favor of CanvasAnimation.animate" + */ + static animateLinear( + attributes: CanvasAnimationAttribute[], + options: CanvasAnimationOptions, + ): Promise; + } } - -type TickFunction = (dt: number, attributes: CanvasAnimation.Attribute[]) => void; -type TransitionFunction = ( - dt: number, - resolve: CanvasAnimationData["resolve"], - reject: (reason?: any) => void, - attributes: CanvasAnimation.Attribute[], - duration: number, - ontick?: TickFunction, -) => void; diff --git a/src/foundry/client/pixi/placeables/token.d.ts b/src/foundry/client/pixi/placeables/token.d.ts index 9722b22ca..c910d8294 100644 --- a/src/foundry/client/pixi/placeables/token.d.ts +++ b/src/foundry/client/pixi/placeables/token.d.ts @@ -357,21 +357,6 @@ declare global { */ animateMovement(ray: Ray): Promise; - /** - * Animate the continual revealing of Token vision during a movement animation - * @internal - */ - protected _onMovementFrame( - dt: number, - anim: Array<{ - context: unknown; - name: string | null; - duration: number; - ontick: (dt: number, attributes: CanvasAnimation.Attribute[]) => void; - }>, - config: { fog?: boolean; sound?: boolean; source?: boolean }, - ): void; - /** * Update perception each frame depending on the animation configuration * @param source - (default: `false`) From 79320b0edd92a7f6ab29d490e0e7621d5af67066 Mon Sep 17 00:00:00 2001 From: JPMeehan Date: Thu, 14 Dec 2023 14:19:55 -0800 Subject: [PATCH 2/2] Type improvements --- src/foundry/client/pixi/core/interaction/control-icon.d.ts | 2 +- src/foundry/client/pixi/core/interaction/targets.d.ts | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/foundry/client/pixi/core/interaction/control-icon.d.ts b/src/foundry/client/pixi/core/interaction/control-icon.d.ts index e14591c9a..35664bb8c 100644 --- a/src/foundry/client/pixi/core/interaction/control-icon.d.ts +++ b/src/foundry/client/pixi/core/interaction/control-icon.d.ts @@ -35,7 +35,7 @@ declare class ControlIcon extends PIXI.Container { /** * @defaultValue `static` */ - eventMode: "none" | "passive" | "auto" | "static" | "dynamic"; + override eventMode: "none" | "passive" | "auto" | "static" | "dynamic"; /** * @defaultValue `false` diff --git a/src/foundry/client/pixi/core/interaction/targets.d.ts b/src/foundry/client/pixi/core/interaction/targets.d.ts index 5167ca989..88c53de91 100644 --- a/src/foundry/client/pixi/core/interaction/targets.d.ts +++ b/src/foundry/client/pixi/core/interaction/targets.d.ts @@ -42,10 +42,5 @@ declare global { * @remarks Returns void, but Set.delete returns boolean */ override delete(token: InstanceType>): void; - - /** - * Dispatch the targetToken hook whenever the user's target set changes - */ - protected _hook(token: InstanceType>, targeted: boolean): void; } }