Skip to content

Commit

Permalink
PointLightSource done
Browse files Browse the repository at this point in the history
  • Loading branch information
esheyw committed Dec 22, 2024
1 parent 542d57b commit 8ad3321
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
20 changes: 11 additions & 9 deletions src/foundry/client-esm/canvas/sources/point-light-source.d.mts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -13,11 +14,17 @@ export default class PointLightSource<
/** @defaultValue `"lightSources"` */
static override effectsCollection: string;

override _initialize(data: Partial<SourceData>): 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<SourceData>): void;

override _createShapes(): void;

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

override _getPolygonConfiguration(): PointSourcePolygonConfig;

Expand All @@ -26,18 +33,13 @@ 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?
* This check should not consider the relative positions of either object, only their state.
* @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;
}
4 changes: 4 additions & 0 deletions src/foundry/client/pixi/layers/effects/visibility.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ declare global {

interface CanvasVisibilityTest {
point: PIXI.Point;
elevation: number;
los: Map<foundry.canvas.sources.PointVisionSource.Any, boolean>;
}

interface CanvasVisibilityTestConfig {
/** The target object */
object: PlaceableObject | null;

/** An array of visibility tests */
tests: CanvasVisibilityTest[];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expectTypeOf } from "vitest";
const mySource = new foundry.canvas.sources.PointLightSource();

expectTypeOf(mySource.active).toEqualTypeOf<boolean>();
expectTypeOf(mySource.drawMeshes().background.visible).toEqualTypeOf<boolean>();
expectTypeOf(mySource.drawMeshes().background?.visible).toEqualTypeOf<boolean | undefined>();
expectTypeOf(mySource.animateTorch(5)).toEqualTypeOf<void>();
expectTypeOf(mySource.add()).toEqualTypeOf<void>();
expectTypeOf(mySource.shape).toEqualTypeOf<PointSourcePolygon>();

0 comments on commit 8ad3321

Please sign in to comment.