Skip to content

Commit

Permalink
Remove system drag measurement implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed Dec 2, 2024
1 parent 5d7d02d commit 22de35a
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 378 deletions.
4 changes: 1 addition & 3 deletions src/module/canvas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { TemplateLayerPF2e } from "./layer/template.ts";
import { TokenLayerPF2e } from "./layer/token.ts";
import { MeasuredTemplatePF2e } from "./measured-template.ts";
import { RegionPF2e } from "./region.ts";
import { RulerPF2e } from "./ruler.ts";
import { TokenPF2e } from "./token/object.ts";

export type CanvasPF2e = Canvas<
Expand All @@ -22,7 +21,7 @@ export type CanvasPF2e = Canvas<
TokenPF2e<TokenDocumentPF2e<ScenePF2e>>,
EffectsCanvasGroupPF2e,
RegionPF2e<RegionDocumentPF2e<ScenePF2e>>,
RulerPF2e
Ruler<TokenPF2e>
>;

export * from "./helpers.ts";
Expand All @@ -32,7 +31,6 @@ export {
LightingLayerPF2e,
MeasuredTemplatePF2e,
RegionPF2e,
RulerPF2e,
TemplateLayerPF2e,
TokenLayerPF2e,
TokenPF2e,
Expand Down
294 changes: 0 additions & 294 deletions src/module/canvas/ruler.ts

This file was deleted.

49 changes: 1 addition & 48 deletions src/module/canvas/token/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { UserPF2e } from "@module/user/document.ts";
import type { TokenDocumentPF2e } from "@scene";
import * as R from "remeda";
import type { CanvasPF2e, TokenLayerPF2e } from "../index.ts";
import { RulerPF2e, measureDistanceCuboid, squareAtPoint } from "../index.ts";
import { measureDistanceCuboid, squareAtPoint } from "../index.ts";
import { AuraRenderers } from "./aura/index.ts";
import { FlankingHighlightRenderer } from "./flanking-highlight/renderer.ts";

Expand Down Expand Up @@ -68,11 +68,6 @@ class TokenPF2e<TDocument extends TokenDocumentPF2e = TokenDocumentPF2e> extends
return offsets.sort((a, b) => a.j - b.j).sort((a, b) => a.i - b.i);
}

get #isDragMeasuring(): boolean {
const ruler = canvas.controls.ruler;
return !!ruler.isDragMeasuring && ruler.token === this;
}

/** Increase center-to-center point tolerance to be more compliant with 2e rules */
override get isVisible(): boolean {
// Clear the detection filter
Expand Down Expand Up @@ -579,48 +574,6 @@ class TokenPF2e<TDocument extends TokenDocumentPF2e = TokenDocumentPF2e> extends
return super._onRelease(options);
}

/** Initiate token drag measurement unless using the ruler tool. */
protected override _onDragLeftStart(event: TokenPointerEvent<this>): void {
event.interactionData.clones ??= [];
const hasModuleConflict = RulerPF2e.hasModuleConflict;
if (game.activeTool !== "ruler" || hasModuleConflict) {
if (!hasModuleConflict) canvas.controls.ruler.startDragMeasurement(event);
return super._onDragLeftStart(event);
}
}

protected override _onDragLeftMove(event: TokenPointerEvent<this>): void {
if (this.#isDragMeasuring) {
canvas.controls.ruler.onDragMeasureMove(event);
}
return super._onDragLeftMove(event);
}

protected override async _onDragLeftDrop(event: TokenPointerEvent<this>): Promise<void | TDocument[]> {
if (this.#isDragMeasuring) {
// Pass along exact destination coordinates if this token is tiny
const destination =
this.isTiny && event.interactionData.clones?.length
? R.pick(event.interactionData.clones[0], ["x", "y"])
: null;
canvas.controls.ruler.finishDragMeasurement(event, destination);
this.layer.clearPreviewContainer();
} else {
super._onDragLeftDrop(event);
}
}

protected override _onDragLeftCancel(event: TokenPointerEvent<this>): void {
if (this.#isDragMeasuring) {
canvas.controls.ruler.onDragLeftCancel(event);
if (!this.#isDragMeasuring) {
super._onDragLeftCancel(event);
}
} else {
super._onDragLeftCancel(event);
}
}

/** Handle system-specific status effects (upstream handles invisible and blinded) */
override _onApplyStatusEffect(statusId: string, active: boolean): void {
super._onApplyStatusEffect(statusId, active);
Expand Down
Loading

0 comments on commit 22de35a

Please sign in to comment.