Skip to content

Commit

Permalink
some update
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Jun 5, 2022
1 parent 80210c2 commit 8c7cd91
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 280 deletions.
452 changes: 226 additions & 226 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
"foundryvtt-arms-reach.dialogs.resetsettings.confirm": "Reset Module Settings",
"foundryvtt-arms-reach.dialogs.resetsettings.cancel": "Cancel",

"foundryvtt-arms-reach.setting.debug.name": "Enable debugging",
"foundryvtt-arms-reach.setting.debug.label": "Prints debug messages to the console",
"foundryvtt-arms-reach.setting.debug.hint": " ",

"foundryvtt-arms-reach.settingNameRangeOverlayFeature": "[Experimental] Enable/Disable Range Overlay integration",
"foundryvtt-arms-reach.settingHintRangeOverlayFeature": "",

Expand All @@ -189,6 +193,10 @@
"foundryvtt-arms-reach.visibilities.always": "Always",
"foundryvtt-arms-reach.visibilities.hotkeys": "Only with ALT or token drag",
"foundryvtt-arms-reach.visibilities.never": "Never",
"foundryvtt-arms-reach.visibilities.overlayVisibility.always": "Always",
"foundryvtt-arms-reach.visibilities.overlayVisibility.hotkeys": "Only with ALT or token drag",
"foundryvtt-arms-reach.visibilities.overlayVisibility.never": "Never",

"foundryvtt-arms-reach.ranges": "Available weapon ranges",
"foundryvtt-arms-reach.ranges-hint": "Comma-separated list of ranges to choose from in the quick settings dialog",
"foundryvtt-arms-reach.diagonals.name": "Diagonals distance",
Expand All @@ -197,11 +205,18 @@
"foundryvtt-arms-reach.diagonals.tenFiveTen": "Ten / Five / Ten / ...",
"foundryvtt-arms-reach.diagonals.five": "Five / Five / ...",
"foundryvtt-arms-reach.diagonals.ten": "Ten / Ten / ...",

"foundryvtt-arms-reach.quick-settings.title": "Combat Range Overlay Quick Settings",
"foundryvtt-arms-reach.quick-settings.title-hint": " ",
"foundryvtt-arms-reach.quick-settings.weapon-range-header": "Weapon Range:",
"foundryvtt-arms-reach.quick-settings.weapon-range-header-hint": " ",
"foundryvtt-arms-reach.quick-settings.update-actor-checkbox": "Update actor instead of token?",
"foundryvtt-arms-reach.quick-settings.update-actor-checkbox-hint": " ",
"foundryvtt-arms-reach.quick-settings.speed-override": "Force token speed to:",
"foundryvtt-arms-reach.quick-settings.speed-override-hint": " ",
"foundryvtt-arms-reach.quick-settings.ignore-difficult-terrain": "Ignore difficult terrain?",
"foundryvtt-arms-reach.quick-settings.ignore-difficult-terrain-hint": " ",

"foundryvtt-arms-reach.controls.cant-open-no-selected-token": "Can't open quick settings without a selected token",
"foundryvtt-arms-reach.controls.cant-reset-no-token": "Can't reset token position without a selected token",
"foundryvtt-arms-reach.activated-not-visible": "The Combat Range Overlay is now activated but is not yet visible (see Settings for details)",
Expand Down
19 changes: 19 additions & 0 deletions src/module/ArmsReachModels.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Overlay } from "./apps/range_overlay/overlay";

export class DoorData {
/// door data of the source door (WARNING: this data may change in the future)
sourceData: DoorSourceData;
Expand Down Expand Up @@ -70,3 +72,20 @@ export class ArmsreachData {
centerY: number;
placeableObjectData: any;
}

export class combatRangeOverlay {
instance:Overlay;
showNumericMovementCost: boolean;
showPathLines: boolean;
roundNumericMovementCost: boolean;
};

export class overlaysData {
distanceTexts:PIXI.Text[];
tokenOverlays:PIXI.Graphics[];
distanceOverlay:PIXI.Graphics|undefined;
pathOverlay:PIXI.Graphics|undefined;
turnOrderTexts:any[];
potentialTargetOverlay:PIXI.Graphics|undefined;
wallsOverlay:PIXI.Graphics|undefined;
}
4 changes: 3 additions & 1 deletion src/module/DoorsReach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ export const DoorsReach = {
// DEPRECATED AND REMOVED
// maxDistance = <number>game.settings.get(CONSTANTS.MODULE_NAME, 'doorInteractionDistance');
// if (maxDistance <= 0) {
maxDistance = <number>game.settings.get(CONSTANTS.MODULE_NAME, 'doorInteractionMeasurement');
if(<number>game.settings.get(CONSTANTS.MODULE_NAME, 'doorInteractionMeasurement') > 0){
maxDistance = <number>game.settings.get(CONSTANTS.MODULE_NAME, 'doorInteractionMeasurement');
}
// }
}

Expand Down
4 changes: 3 additions & 1 deletion src/module/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { WallsReach } from './WallsReach';
import { globalInteractionDistanceUniversal } from './ArmsReachHelper';
import { error, warn } from './lib/lib';
import CONSTANTS from './constants';
import type { Overlay } from './apps/range_overlay/overlay';
import type { combatRangeOverlay } from './ArmsReachModels';

const API = {

combatRangeOverlay:<any>{},
combatRangeOverlay:<combatRangeOverlay>{},

async isReachableArr(...inAttributes: any[]) {
if (!Array.isArray(inAttributes)) {
Expand Down
5 changes: 3 additions & 2 deletions src/module/apps/range_overlay/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {keyboard} from "./keyboard.js";
import {TokenInfo} from "./tokenInfo.js";
import { debug, i18n, warn } from "../../lib/lib.js";
import CONSTANTS from "../../constants.js";
import API from "../../api.js";

export const TOGGLE_BUTTON = "combatRangeOverlayButton";

Expand Down Expand Up @@ -70,12 +71,12 @@ export async function _toggleButtonClick(toggled, controls) {
warn(i18n(`${CONSTANTS.MODULE_NAME}.controls.cant-reset-no-token`), true);
} else {
TokenInfo.current.updateMeasureFrom();
globalThis.combatRangeOverlay.instance.fullRefresh();
API.combatRangeOverlay.instance.fullRefresh();
}
} else {
isActive = toggled;
if (toggled) {
globalThis.combatRangeOverlay.instance.justActivated = true;
API.combatRangeOverlay.instance.justActivated = true;
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/module/apps/range_overlay/gridTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export class GridTile {
gy:number;
distance:number;
visited = false;
upstreams:any[];
_upstreamCache:any;
upstreams:GridTile[];
_upstreamCache:Map<string,GridTile>;

constructor(gx, gy) {
this.gx = gx;
this.gy = gy;
this.distance = CONSTANTS.MAX_DIST;
this.visited = false;
// this.upstreams = undefined;
// this._upstreamCache = undefined;
this.upstreams = [];
this._upstreamCache = new Map<string,GridTile>();
}

get centerPt() {
Expand All @@ -42,9 +42,9 @@ export class GridTile {
}
}

get allUpstreams() {
get allUpstreams():Map<string,GridTile> {
if (this._upstreamCache === undefined) {
this._upstreamCache = new Map();
this._upstreamCache = new Map<string,GridTile>();
if (this.upstreams !== undefined) {
for (const upstream of this.upstreams) {
this._upstreamCache.set(upstream.key, upstream);
Expand Down
50 changes: 25 additions & 25 deletions src/module/apps/range_overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import CONSTANTS from "../../constants.js";
import { debug, info, log, warn } from "../../lib/lib.js";
import type EmbeddedCollection from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/abstract/embedded-collection.mjs.js";
import type { CombatData } from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/data/module.mjs.js";
import API from "../../api.js";
import { overlaysData } from "../../ArmsReachModels.js";

const actionsToShow = 2;

Expand Down Expand Up @@ -92,13 +94,14 @@ function diagonalDistance(rawDist) {

export class Overlay {

overlays:any = {};
overlays:overlaysData;
hookIDs:any = {};
newTarget = false;
justActivated = false;
instan

constructor() {
this.overlays = new Overlay();
this.overlays = new overlaysData();
this.hookIDs = {};
this.newTarget = false;
this.justActivated = false;
Expand Down Expand Up @@ -174,17 +177,14 @@ export class Overlay {
if (diagonalDistance(newDistance) > maxTiles) {
// Do nothing
}
//@ts-ignore
else if (Math.abs(neighbor.distance - newDistance) < FUDGE) {
neighbor.allUpstreams.add(current);
else if (Math.abs(neighbor.distance - newDistance) < CONSTANTS.FUDGE) {
neighbor.allUpstreams.set(current.key,current);
}
//@ts-ignore
else if (newDistance < neighbor.distance) {
// TODO not sure if we need this
// neighbor.allUpstreams = new Set<GridTile>();
neighbor.allUpstreams.clear();
neighbor.allUpstreams.add(current);
//@ts-ignore
neighbor.allUpstreams.set(current.key,current);
neighbor.distance = newDistance;
toVisit.add(neighbor);
}
Expand Down Expand Up @@ -503,7 +503,7 @@ export class Overlay {

const tilesMovedPerAction = TokenInfo.current.speed / CONSTANTS.FEET_PER_TILE;
this.overlays.distanceTexts = [];
this.overlays.pathOverlay.lineStyle(pathLineWidth, pathLineColor);
this.overlays.pathOverlay?.lineStyle(pathLineWidth, pathLineColor);

for (const tile of movementCostMap.values()) {
let drawTile = false;
Expand All @@ -518,24 +518,24 @@ export class Overlay {
}
}
if (drawTile) {
if (globalThis.combatRangeOverlay.showNumericMovementCost) {
if (API.combatRangeOverlay.showNumericMovementCost) {
const style = Object.assign({}, movementCostStyle);
style.fontSize = style.fontSize * (<number>canvasGridSize() / BASE_GRID_SIZE);

const label = globalThis.combatRangeOverlay.roundNumericMovementCost ? diagonalDistance(tile.distance) : tile.distance;
const label = API.combatRangeOverlay.roundNumericMovementCost ? diagonalDistance(tile.distance) : tile.distance;
const text = new PIXI.Text(label, style);
text.position.x = tile.gx;
text.position.y = tile.gy;
this.overlays.distanceTexts.push(text);
}

if (globalThis.combatRangeOverlay.showPathLines) {
if (API.combatRangeOverlay.showPathLines) {
const tileCenter = tile.centerPt;
if (tile.upstreams !== undefined) {
for (const upstream of tile.upstreams) {
const upstreamCenter = upstream.centerPt;
this.overlays.pathOverlay.moveTo(tileCenter.x, tileCenter.y);
this.overlays.pathOverlay.lineTo(upstreamCenter.x, upstreamCenter.y);
this.overlays.pathOverlay?.moveTo(tileCenter.x, tileCenter.y);
this.overlays.pathOverlay?.lineTo(upstreamCenter.x, upstreamCenter.y);
}
}
}
Expand All @@ -545,38 +545,38 @@ export class Overlay {
const color = colorByActions[colorIndex];
const cornerPt = tile.pt;
if (idealTileMap.has(tile.key)) {
this.overlays.distanceOverlay.lineStyle(highlightLineWidth, highlightLineColor);
this.overlays.distanceOverlay?.lineStyle(highlightLineWidth, highlightLineColor);
} else {
this.overlays.distanceOverlay.lineStyle(0, 0);
this.overlays.distanceOverlay?.lineStyle(0, 0);
}
this.overlays.distanceOverlay.beginFill(color, game.settings.get(CONSTANTS.MODULE_NAME,'movement-alpha'));
this.overlays.distanceOverlay.drawRect(cornerPt.x, cornerPt.y, canvasGridSize(), canvasGridSize());
this.overlays.distanceOverlay.endFill();
this.overlays.distanceOverlay?.beginFill(color, <number>game.settings.get(CONSTANTS.MODULE_NAME,'movement-alpha'));
this.overlays.distanceOverlay?.drawRect(cornerPt.x, cornerPt.y, <number>canvasGridSize(), <number>canvasGridSize());
this.overlays.distanceOverlay?.endFill();
}
}

canvas.drawings?.addChild(this.overlays.distanceOverlay);
canvas.drawings?.addChild(this.overlays.pathOverlay);
canvas.drawings?.addChild(<PIXI.Graphics>this.overlays.distanceOverlay);
canvas.drawings?.addChild(<PIXI.Graphics>this.overlays.pathOverlay);

for (const text of this.overlays.distanceTexts) {
canvas.drawings?.addChild(text);
}
}

drawWalls() {
this.overlays.wallsOverlay.lineStyle(wallLineWidth, wallLineColor);
this.overlays.wallsOverlay?.lineStyle(wallLineWidth, wallLineColor);
for (const quadtree of <Quadtree<Wall>[]>canvas.walls?.quadtree?.nodes) {
for (const obj of quadtree.objects) {
const wall = obj.t;
if (wall.data.door || !wall.data.move) {
continue;
}
const c = wall.data.c;
this.overlays.wallsOverlay.moveTo(c[0], c[1]);
this.overlays.wallsOverlay.lineTo(c[2], c[3]);
this.overlays.wallsOverlay?.moveTo(c[0], c[1]);
this.overlays.wallsOverlay?.lineTo(c[2], c[3]);
}
}
canvas.drawings?.addChild(this.overlays.wallsOverlay);
canvas.drawings?.addChild(<PIXI.Graphics>this.overlays.wallsOverlay);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/module/apps/range_overlay/tokenInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import API from "../../api";
import CONSTANTS from "../../constants";
import { debug, i18n, warn } from "../../lib/lib";
import { canvasTokensGet, getCurrentToken } from "./utility";
Expand Down Expand Up @@ -175,14 +176,14 @@ function updateLocation(token, updateData) {
Hooks.on("createCombatant", (combatant, options, someId) => {
const token = canvasTokensGet(combatant.token.id);
updateMeasureFrom(token, undefined);
globalThis.combatRangeOverlay.instance.fullRefresh();
API.combatRangeOverlay.instance.fullRefresh();
});

// noinspection JSUnusedLocalSymbols
Hooks.on("deleteCombatant", (combatant, options, someId) => {
const token = canvasTokensGet(combatant.token.id);
updateMeasureFrom(token, undefined);
globalThis.combatRangeOverlay.instance.fullRefresh();
API.combatRangeOverlay.instance.fullRefresh();
});


Expand All @@ -192,7 +193,7 @@ Hooks.on("updateCombat", (combat, turnInfo, diff, someId) => {
const token = canvasTokensGet(combat.previous.tokenId);
updateMeasureFrom(token, undefined);
}
globalThis.combatRangeOverlay.instance.fullRefresh();
API.combatRangeOverlay.instance.fullRefresh();
});

// noinspection JSUnusedLocalSymbols
Expand All @@ -203,7 +204,7 @@ Hooks.on("updateToken", (tokenDocument, updateData, options, someId) => {
if (!realToken.inCombat) {
updateMeasureFrom(realToken, updateData);
}
globalThis.combatRangeOverlay.instance.fullRefresh();
API.combatRangeOverlay.instance.fullRefresh();
});

Hooks.on("controlToken", (token, boolFlag) => {
Expand Down
2 changes: 1 addition & 1 deletion src/module/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function cleanUpString(stringToCleanUp: string) {
}
}

export function isStringEquals(stringToCheck1: string, stringToCheck2: string, startsWith = true): boolean {
export function isStringEquals(stringToCheck1: string, stringToCheck2: string, startsWith = false): boolean {
if (stringToCheck1 && stringToCheck2) {
const s1 = cleanUpString(stringToCheck1) ?? '';
const s2 = cleanUpString(stringToCheck2) ?? '';
Expand Down
Loading

0 comments on commit 8c7cd91

Please sign in to comment.