import { AnimationOptions } from '@drincs/pixi-vn/motion'; import { Filter, AlphaFilter, BlurFilter, NoiseFilter, UPDATE_PRIORITY } from '@drincs/pixi-vn/pixi.js'; import { AdjustmentFilter, AdvancedBloomFilter, AsciiFilter, BackdropBlurFilter, BevelFilter, BloomFilter, BulgePinchFilter, ColorGradientFilter, ColorOverlayFilter, ColorReplaceFilter, ConvolutionFilter, CRTFilter, CrossHatchFilter, DotFilter, DropShadowFilter, EmbossFilter, GlitchFilter, GlowFilter, GodrayFilter, GrayscaleFilter, HslAdjustmentFilter, KawaseBlurFilter, MotionBlurFilter, MultiColorReplaceFilter, OldFilmFilter, OutlineFilter, PixelateFilter, RadialBlurFilter, ReflectionFilter, RGBSplitFilter, ShockwaveFilter, SimplexNoiseFilter, TiltShiftFilter, TwistFilter, ZoomBlurFilter } from 'pixi-filters'; /** * Is a decorator that registers a `Filter` class so it can be saved and restored as part of a canvas * element's `.filters`. Required for any custom filter you want to survive a save/restore round-trip - * built-in ones like `PixelateFilter` (and `BlurFilter`) are already registered by Pixi'VN. * @param options.name The id used to identify this filter class in saves (must be unique). Defaults to the class name. * @param options.toMemory Reads a live instance's current parameters into a plain, serializable object. It is passed to the class's constructor (as its single argument) to reconstruct the filter on restore. * @example * ```ts * @filterDecorator({ toMemory: (filter: MyFilter) => ({ amount: filter.amount }) }) * class MyFilter extends Filter { * constructor(args: { amount?: number } = {}) { * super({ ... }); * this.amount = args.amount ?? 0; * } * // ... * } * ``` */ declare function filterDecorator(options: { name?: string; toMemory: (filter: InstanceType) => any; }): (target: T) => void; declare namespace RegisteredFilters { /** * Register a filter class in the game. * @param target The class of the filter. Must be constructible from a single, serializable `args` object. * @param options.name Name of the filter, by default it will use the class name. If the name is already registered, it will show a warning * @param options.toMemory Reads a live instance's current parameters into a plain, serializable object. */ function add(target: T, options: { name?: string; toMemory: (filter: InstanceType) => any; }): void; /** * Get a filter class by the id. * @param filterId The id of the filter. * @returns The filter class. */ function get(filterId: string): T | undefined; /** * Get a filter instance by the id, reconstructed from previously saved `args`. * @param filterId The id of the filter. * @param args The arguments to pass to the filter's constructor, as produced by a previous `toMemory` call. * @param padding The filter's saved `padding`, if any (see {@link FilterMemory.padding}). * @returns The filter instance, or `undefined` if the filter isn't registered or construction failed. */ function getInstance(filterId: string, args: any, padding?: number): Filter | undefined; /** * Reads a live filter instance's current parameters into a serializable {@link FilterMemory}, using * the `toMemory` function it was registered with. * @param filterId The id the filter was registered under (readable on any instance as `filter.pixivnFilterId`). * @param filter The live filter instance. * @returns The memory object, or `undefined` if the filter isn't registered or conversion failed. */ function toMemory(filterId: string, filter: Filter): { filterId: string; args: any; padding?: number; } | undefined; /** * Get a list of all filter classes registered. * @returns An array of filter classes. */ function values(): { new (args: any): Filter; }[]; /** * Check if a filter is registered. * @param id The id of the filter. * @returns True if the filter is registered, false otherwise. */ function has(id: string): boolean; /** * Get a list of all filter ids registered. * @returns An array of filter ids. */ function keys(): string[]; } /** * Serializable representation of a single `Filter` attached to a canvas element's `.filters` array. * * A live `Filter` instance (PixiJS's own, like `BlurFilter`, or a custom one) generally can't be * serialized directly - it doesn't expose its constructor options after creation, and its state lives in * GPU-facing resources/uniform groups. `filterId` identifies which registration (see * {@link filterDecorator}/{@link RegisteredFilters}) knows how to convert it to and from `args`. */ interface FilterMemory { /** * The id the filter's class was registered under. Used on restore to look up the class and * reconstruct an instance from `args`. */ filterId: string; /** * The serializable arguments needed to reconstruct the filter, as produced by its registration's * `toMemory` function. */ args: any; /** * The filter's `padding` (extra pixels its area grows by on every side), when set. It's a property of * every `Filter`, not part of a specific filter's constructor `args`, so it's saved on its own - * without it a restored distortion/blur would be clipped to the element's bounds again. */ padding?: number; } /** * Animate either a `Filter`'s own properties, or a plain numeric "progress" value with no live target * (used by the mask-based transitions - wipe/iris/split - which have no filter property to write * directly, just a number and a side effect). See `GameUnifier.animateFilter`'s own doc comment for the * full parameter reference; this just forwards to it (through the same DI indirection `canvas`'s own * animate methods use - `filters` can't import `motion` directly, since `canvas` already depends on * `filters` and `motion` depends on `canvas`, so `filters -> motion` would close a cycle). * @param components The canvas element alias(es) the filter is attached to, or otherwise associated * with this animation. * @param filter The `Filter` instance to animate, or `undefined` to animate a plain value instead. * @param keyframes The keyframes to animate the filter's properties (or the plain value) with. * @param options The animation options. * @param priority The update priority of the ticker. * @param apply Called on every frame with the current interpolated value - required when `filter` is * `undefined`, ignored otherwise. * @param cleanup Called once, right before completion handling, to detach/destroy the filter or tear * down whatever `apply` was driving. * @param valueRef Plain, serializable description of what `apply`/`cleanup` drive (`{ alias, config }` of a * mask-based transition), saved with the ticker so it can be rebuilt after a save restore or a step back - * without it an `apply`-only ticker cannot be reconstructed. * @returns The id of the ticker, or `undefined` if the ticker was not added. */ declare function animate(components: string | string[], filter: Filter | undefined, keyframes: Record, options?: AnimationOptions, priority?: UPDATE_PRIORITY, apply?: (value: number) => void, cleanup?: () => void, valueRef?: { alias: string; config: unknown; }): string | undefined; /** * Every filter class Pixi'VN registers for save/restore out of the box (see * `register-builtin-filters.ts`), grouped in one place so a project can use them without importing * from `pixi.js`/`pixi-filters` directly - e.g. `new filters.BloomFilter({...})` - plus * {@link animate}. Not every filter `pixi.js`/`pixi-filters` ships is here: a few (`ColorMapFilter`, * `SimpleLightmapFilter`, `TiltShiftAxisFilter`, `ColorMatrixFilter`, `DisplacementFilter`, and * pixi.js's internal `MaskFilter`/`BlendModeFilter`/`PassthroughFilter`) are deliberately not * registered - see that file's doc comment for why. Those are still directly importable from * `pixi.js`/`pixi-filters` as usual; they just won't survive a save/restore round-trip unless a project * registers its own `toMemory` for them. */ declare const filters: { readonly AlphaFilter: typeof AlphaFilter; readonly BlurFilter: typeof BlurFilter; readonly NoiseFilter: typeof NoiseFilter; readonly AdjustmentFilter: typeof AdjustmentFilter; readonly AdvancedBloomFilter: typeof AdvancedBloomFilter; readonly AsciiFilter: typeof AsciiFilter; readonly BackdropBlurFilter: typeof BackdropBlurFilter; readonly BevelFilter: typeof BevelFilter; readonly BloomFilter: typeof BloomFilter; readonly BulgePinchFilter: typeof BulgePinchFilter; readonly ColorGradientFilter: typeof ColorGradientFilter; readonly ColorOverlayFilter: typeof ColorOverlayFilter; readonly ColorReplaceFilter: typeof ColorReplaceFilter; readonly ConvolutionFilter: typeof ConvolutionFilter; readonly CRTFilter: typeof CRTFilter; readonly CrossHatchFilter: typeof CrossHatchFilter; readonly DotFilter: typeof DotFilter; readonly DropShadowFilter: typeof DropShadowFilter; readonly EmbossFilter: typeof EmbossFilter; readonly GlitchFilter: typeof GlitchFilter; readonly GlowFilter: typeof GlowFilter; readonly GodrayFilter: typeof GodrayFilter; readonly GrayscaleFilter: typeof GrayscaleFilter; readonly HslAdjustmentFilter: typeof HslAdjustmentFilter; readonly KawaseBlurFilter: typeof KawaseBlurFilter; readonly MotionBlurFilter: typeof MotionBlurFilter; readonly MultiColorReplaceFilter: typeof MultiColorReplaceFilter; readonly OldFilmFilter: typeof OldFilmFilter; readonly OutlineFilter: typeof OutlineFilter; readonly PixelateFilter: typeof PixelateFilter; readonly RadialBlurFilter: typeof RadialBlurFilter; readonly ReflectionFilter: typeof ReflectionFilter; readonly RGBSplitFilter: typeof RGBSplitFilter; readonly ShockwaveFilter: typeof ShockwaveFilter; readonly SimplexNoiseFilter: typeof SimplexNoiseFilter; readonly TiltShiftFilter: typeof TiltShiftFilter; readonly TwistFilter: typeof TwistFilter; readonly ZoomBlurFilter: typeof ZoomBlurFilter; readonly animate: typeof animate; }; export { RegisteredFilters, filterDecorator, filters }; export type { FilterMemory };