Skip to content

Commit

Permalink
Sources done?
Browse files Browse the repository at this point in the history
  • Loading branch information
esheyw committed Dec 22, 2024
1 parent 8ad3321 commit babad8c
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +31,7 @@ declare class PointEffectSource {
*/
get radius(): number;

_initialize(data: IntentionalPartial<PointEffectSourceMixin.SourceData>): void;
_initialize(data: IntentionalPartial<PointEffectSourceMixin.MixedSourceData>): void;

_initializeSoftEdges(): void;

Expand Down Expand Up @@ -73,7 +73,9 @@ declare function PointEffectSourceMixin<BaseClass extends BaseEffectSource.AnyCo
declare namespace PointEffectSourceMixin {
type AnyMixed = ReturnType<typeof PointEffectSourceMixin<BaseEffectSource.AnyConstructor>>;

interface SourceData extends BaseEffectSource.SourceData {
type MixedSourceData = SourceData & BaseEffectSource.SourceData;

interface SourceData {
/**
* The radius of the source
*/
Expand Down
18 changes: 14 additions & 4 deletions src/foundry/client-esm/canvas/sources/point-light-source.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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)<SourceData, SourceShape> {
/** @defaultValue `"lightSources"` */
Expand Down Expand Up @@ -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;
24 changes: 20 additions & 4 deletions src/foundry/client-esm/canvas/sources/point-movement-source.d.mts
Original file line number Diff line number Diff line change
@@ -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)<SourceData, SourceShape> {
/** @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;
32 changes: 25 additions & 7 deletions src/foundry/client-esm/canvas/sources/point-sound-source.d.mts
Original file line number Diff line number Diff line change
@@ -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)<SourceData, SourceShape> {
/** @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<this>;

override _getPolygonConfiguration(): PointSourcePolygonConfig;
Expand All @@ -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;
32 changes: 20 additions & 12 deletions src/foundry/client-esm/canvas/sources/point-vision-source.d.mts
Original file line number Diff line number Diff line change
@@ -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)<SourceData, SourceShape, RenderingLayers> {
Expand All @@ -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;

Expand All @@ -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<string, RenderedEffectSource.LayerConfig>;

/**
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -110,7 +114,7 @@ declare class PointVisionSource<
*/
visionModeOverrides: object;

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

override _createShapes(): void;

Expand All @@ -119,7 +123,7 @@ declare class PointVisionSource<
*/
protected _updateVisionMode(): void;

override _configure(changes: Partial<SourceData>): void;
override _configure(changes: IntentionalPartial<SourceData>): void;

override _configureLayer(layer: RenderedEffectSource.SourceLayer, layerId: string): void;

Expand All @@ -141,7 +145,7 @@ declare class PointVisionSource<
*/
protected _createRestrictedPolygon(): PointSourcePolygon;

override _configureShaders(): Record<keyof RenderingLayers, typeof AdaptiveLightingShader>;
override _configureShaders(): Record<keyof RenderingLayers, typeof AdaptiveVisionShader>;

override _updateColorationUniforms(): void;

Expand All @@ -160,9 +164,11 @@ declare class PointVisionSource<
}

declare namespace PointVisionSource {
type Any = PointVisionSource<VisionSourceData>;
type Any = PointVisionSource<SourceData>;

type AnyConstructor = typeof AnyPointVisionSource;

interface VisionSourceData extends RenderedEffectSource.SourceData, PointEffectSourceMixin.SourceData {
interface SourceData extends RenderedEffectSource.SourceData, PointEffectSourceMixin.SourceData {
/**
* The amount of contrast
*/
Expand Down Expand Up @@ -191,7 +197,7 @@ declare namespace PointVisionSource {
/**
* The range of light perception.
*/
lightRadius: number;
lightRadius: number | null;

/**
* Is this vision source blinded?
Expand All @@ -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;
Original file line number Diff line number Diff line change
@@ -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<boolean>();
expectTypeOf(
mySource.initialize({ x: 3, y: 5, elevation: 7 }),
).toEqualTypeOf<foundry.canvas.sources.PointMovementSource>();
expectTypeOf(mySource.initialize({ x: 3, y: 5, elevation: 7 })).toEqualTypeOf<PointMovementSource>();
expectTypeOf(mySource.shape).toEqualTypeOf<PointSourcePolygon>();
expectTypeOf(mySource.data).toEqualTypeOf<PointMovementSource.SourceData>();
Original file line number Diff line number Diff line change
@@ -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<boolean>();
expectTypeOf(
mySource.initialize({ radius: 5, walls: true, disabled: false }),
).toEqualTypeOf<foundry.canvas.sources.PointSoundSource>();
expectTypeOf(mySource.initialize({ radius: 5, walls: true, disabled: false })).toEqualTypeOf<PointSoundSource>();
expectTypeOf(mySource.shape).toEqualTypeOf<PointSourcePolygon>();
expectTypeOf(mySource.data).toEqualTypeOf<PointSoundSource.SourceData>();
Original file line number Diff line number Diff line change
@@ -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<boolean>();
expectTypeOf(mySource.drawMeshes().background.visible).toEqualTypeOf<boolean>();
expectTypeOf(mySource.drawMeshes().background?.visible).toEqualTypeOf<boolean | undefined>();
expectTypeOf(mySource.data).toEqualTypeOf<PointVisionSource.SourceData>();
expectTypeOf(mySource.shape).toEqualTypeOf<PointSourcePolygon>();
expectTypeOf(mySource._configureShaders().background).toEqualTypeOf<typeof AdaptiveVisionShader>();

0 comments on commit babad8c

Please sign in to comment.