Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point effect sources v12 #2995

Merged
merged 25 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
56d14e7
start of BES
esheyw Dec 15, 2024
996c594
more BES work
esheyw Dec 17, 2024
2da1fe7
BES done
esheyw Dec 17, 2024
01c93b1
PIXI Enum conversion and interface spacing
esheyw Dec 17, 2024
905d808
Fix merging of PIXI.smooth and PIXI.graphics
LukeAbby Dec 18, 2024
55bc8c9
RenderedEffectSource done
esheyw Dec 21, 2024
daa6930
BaseLightSource before messing with config
esheyw Dec 21, 2024
dfe770e
remove `LightAnimationFunction` from config and update `lightAnimatio…
esheyw Dec 21, 2024
cae430c
rename `BaseLightSource.LightSourceData` to `.BaseLightSourceData`
esheyw Dec 21, 2024
9e2cae4
BaseLightSource done
esheyw Dec 21, 2024
4571f56
GlobalLightSource done
esheyw Dec 21, 2024
939b177
simplify interface names
esheyw Dec 22, 2024
495a408
Start of PointDarknessSource
esheyw Dec 22, 2024
542d57b
PointDarknessSource done
esheyw Dec 22, 2024
8ad3321
PointLightSource done
esheyw Dec 22, 2024
babad8c
Sources done?
esheyw Dec 22, 2024
0bc00b3
Merge branch 'main' into point-effect-sources-v12
esheyw Dec 22, 2024
bf1de40
canvas test fixes, and one improvement to the actual class
esheyw Dec 22, 2024
78e4e7c
more test and random error fixes
esheyw Dec 22, 2024
58e611a
Merge branch 'main' into point-effect-sources-v12
esheyw Dec 22, 2024
b56da63
update imports and lint
esheyw Dec 22, 2024
3fc57f8
last helperTypes reference got
esheyw Dec 22, 2024
526a3c7
more lint fixes
esheyw Dec 22, 2024
5027829
actual last helperType reference
esheyw Dec 22, 2024
93c5259
Merge branch 'main' into point-effect-sources-v12
LukeAbby Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions src/foundry/client-esm/canvas/sources/base-effect-source.d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { InexactPartial } from "../../../../utils/index.d.mts";
import type { NullishProps, IntentionalPartial } from "../../../../utils/index.d.mts";

/**
* TODO - Re-document after ESM refactor.
Expand All @@ -14,15 +14,16 @@ import type { InexactPartial } from "../../../../utils/index.d.mts";
* ```
* @privateRemarks The TODO is foundry's
*/
declare class BaseEffectSource<
SourceData extends BaseEffectSource.BaseEffectSourceData,
declare abstract class BaseEffectSource<
SourceData extends BaseEffectSource.SourceData,
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?: BaseEffectSource.SourceOptions | PlaceableObject);

/**
* The type of source represented by this data structure.
Expand All @@ -47,7 +48,7 @@ declare class BaseEffectSource<
* }
* ```
*/
static defaultData: BaseEffectSource.BaseEffectSourceData;
static defaultData: BaseEffectSource.SourceData;

/**
* Some other object which is responsible for this source.
Expand All @@ -56,8 +57,9 @@ declare class BaseEffectSource<

/**
* The source id linked to this effect source.
* @remarks Foundry types this as Readonly<string>, but does nothing to that effect at runtime
*/
readonly sourceId: string;
sourceId: string | undefined;

/**
* The data of this source.
Expand All @@ -66,8 +68,9 @@ declare 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;
shape: SourceShape | undefined;

/**
* A collection of boolean flags which control rendering and refresh behavior for the source.
Expand Down Expand Up @@ -129,22 +132,25 @@ declare class BaseEffectSource<
* @returns The initialized source
*/
initialize(
data?: InexactPartial<SourceData>,
options?: InexactPartial<{
// The type def references a behaviors object that is not even passed into the function
data?: NullishProps<SourceData>,
/** @privateRemarks Foundry describes an `options.behaviors` key, but it is neither checked for nor used at runtime */
options?: NullishProps<{
/**
* Should source data be reset to default values before applying changes?
* @defaultValue `false`
*/
reset?: boolean;
reset: boolean;
}>,
): this;

/**
* Subclass specific data initialization steps.
* @param data - Provided data for configuration
*/
_initialize(data: Partial<SourceData>): void;
_initialize(
/** @remarks IntentionalPartial because `this.initialize` has filtered invalid keys and replaced any nullish values before calling this */
data: IntentionalPartial<SourceData>,
): void;

/**
* Create the polygon shape (or shapes) for this source using configured data.
Expand All @@ -155,8 +161,9 @@ declare 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<SourceData>): void;
protected _configure(changes: IntentionalPartial<SourceData>): void;

/**
* Refresh the state and uniforms of the source.
Expand Down Expand Up @@ -211,19 +218,25 @@ declare class BaseEffectSource<
declare namespace BaseEffectSource {
type AnyConstructor = typeof AnyBaseEffectSource;

interface BaseEffectSourceOptions {
/** @internal */
type _SourceOptions = NullishProps<{
/**
* An optional PlaceableObject which is responsible for this source
*/
object?: PlaceableObject | undefined;
object: PlaceableObject;
}>;

interface SourceOptions extends _SourceOptions {
/**
* 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 | undefined;
sourceId?: string;
}

interface BaseEffectSourceData {
interface SourceData {
/**
* The x-coordinate of the source location
*/
Expand Down
72 changes: 57 additions & 15 deletions src/foundry/client-esm/canvas/sources/base-light-source.d.mts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { InexactPartial } from "../../../../utils/index.d.mts";
import type { InexactPartial, IntentionalPartial } from "../../../../utils/index.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<
SourceData extends BaseLightSource.LightSourceData = BaseLightSource.LightSourceData,
declare abstract class BaseLightSource<
SourceData extends BaseLightSource.SourceData = BaseLightSource.SourceData,
SourceShape extends PIXI.Polygon = PIXI.Polygon,
RenderingLayers extends Record<string, RenderedEffectSource.RenderedEffectSourceLayer> = RenderedEffectSource.Layers,
RenderingLayers extends Record<string, RenderedEffectSource.SourceLayer> = RenderedEffectSource.Layers,
> extends RenderedEffectSource<SourceData, SourceShape, RenderingLayers> {
/** @defaultValue `"light"` */
static override sourceType: string;
Expand All @@ -20,18 +20,22 @@ 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.
* @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(): CONFIG.Canvas.LightSourceAnimationConfig;
protected static get ANIMATIONS(): typeof CONFIG.Canvas.lightAnimations | typeof CONFIG.Canvas.darknessAnimations;

/**
* @defaultValue
Expand All @@ -52,14 +56,14 @@ declare class BaseLightSource<
* }
* ```
*/
static override defaultData: RenderedEffectSource.RenderedEffectSourceData;
static override defaultData: BaseLightSource.SourceData;

/**
* A ratio of dim:bright as part of the source radius
*/
ratio: number;

override _initialize(data: Partial<SourceData>): void;
override _initialize(data: IntentionalPartial<SourceData>): void;

override _updateColorationUniforms(): void;

Expand All @@ -69,12 +73,18 @@ declare class BaseLightSource<

override _updateCommonUniforms(shader: AbstractBaseShader): void;

/** @remarks This property is undocumented, and only defined during `_updateCommonUniforms` */
cachededAttentuation?: number;

esheyw marked this conversation as resolved.
Show resolved Hide resolved
/** @remarks This property is undocumented, and only defined during `_updateCommonUniforms` */
computedAttentuation?: number;

/**
* An animation with flickering ratio and light intensity.
* @param dt - Delta time
* @param options - Additional options which modify the torch animation
*/
animateTorch(dt: number, options?: InexactPartial<RenderedEffectSource.AnimationOptions>): void;
animateTorch(dt: number, options?: RenderedEffectSource.AnimationFunctionOptions): void;

/**
* An animation with flickering ratio and light intensity
Expand All @@ -83,77 +93,109 @@ 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<RenderedEffectSource.AnimationOptions>): void;
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;
}

declare namespace BaseLightSource {
interface LightSourceData extends RenderedEffectSource.RenderedEffectSourceData {
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`
esheyw marked this conversation as resolved.
Show resolved Hide resolved
*/
type LightAnimationFunction = (
this: BaseLightSource,
dt: number,
options?: RenderedEffectSource.AnimationFunctionOptions,
) => void;

interface SourceData extends RenderedEffectSource.SourceData {
/**
* 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
*/
priority: number;
}
}

declare abstract class AnyBaseLightSource extends BaseLightSource {
constructor(arg0: never, ...args: never[]);
}

export default BaseLightSource;
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ export default class GlobalLightSource extends BaseLightSource {
* }
* ```
*/
static override defaultData: BaseLightSource.LightSourceData;
static override defaultData: BaseLightSource.SourceData;

/**
* 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;

Expand All @@ -44,4 +46,6 @@ export default class GlobalLightSource extends BaseLightSource {
override _initializeSoftEdges(): void;

override _updateGeometry(): void;

override _updateCommonUniforms(shader: AbstractBaseShader): void;
}
Loading
Loading