Skip to content

Commit

Permalink
0.5.29
Browse files Browse the repository at this point in the history
  • Loading branch information
gambit07 committed Aug 25, 2024
1 parent a79f086 commit d51921e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ jobs:
id: set-release-notes-github
run: |
echo "- Bugfixes:" >> release_notes.txt
echo " - Torch: Fix torch icon not oriented properly and a few animation issues" >> release_notes.txt
echo " - Hooded Lantern: Fix lantern icon not oriented properly and a few animation issues" >> release_notes.txt
echo " - Bullseye Lantern: Fix lantern icon not oriented properly and a few animation issues" >> release_notes.txt
echo " - Opportunity Attack: Fix region wrapping causing Token Enter and Token Exit events to not fire correctly, subsequently causing Opportunity Attack dialogs to fire erroneously (and causing other region related issues Im sure)" >> release_notes.txt
echo "release-notes-github<<EOF" >> $GITHUB_ENV
cat release_notes.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
Expand Down
47 changes: 10 additions & 37 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Hooks.once('init', async function() {

libWrapper.register('gambits-premades', 'Token.prototype.testInsideRegion', function (wrapped, ...args) {
const [region, position] = args;

if (!this || !this.document) {
return wrapped(...args);
}
Expand All @@ -52,54 +52,28 @@ Hooks.once('init', async function() {
{ x: this.document.x + (width * size) - reduction, y: this.document.y + (height * size / 2), elevation: this.document.elevation },
{ x: this.document.x + (width * size / 2), y: this.document.y + (height * size / 2), elevation: this.document.elevation }
];

points.forEach(point => {
pointsToTest.push(point);
});

const testResults = pointsToTest.map(point => {
const result = region.testPoint(point, position?.elevation ?? this.document.elevation);
return result;
});

const isInside = testResults.some(x => x);

if (isInside) {
const snappingMode = 0x3;
const snappedPosition = canvas.grid.getSnappedPoint({ x: this.document.x, y: this.document.y }, { mode: snappingMode });

const adjustedPoints = pointsToTest.map(point => {
return {
x: snappedPosition.x,
y: snappedPosition.y,
elevation: point.elevation
};
});

const finalResults = adjustedPoints.map(point => {
return region.testPoint(point, position?.elevation ?? this.document.elevation);
});

const finalInside = finalResults.some(x => x);

if (finalInside) {
this.document.x = snappedPosition.x;
this.document.y = snappedPosition.y;
}

return finalInside;
}
const isInside = testResults.some(x => x);

return wrapped(...args);
return isInside || wrapped(...args);
}, 'MIXED');

libWrapper.register('gambits-premades', 'Token.prototype.segmentizeRegionMovement', function (wrapped, ...args) {
const [region, waypoints, options] = args;

if (!this || !this.document) {
return wrapped(...args);
}

const { teleport = false } = options || {};
const samples = [];
const size = canvas.dimensions.size;
Expand All @@ -121,11 +95,10 @@ Hooks.once('init', async function() {
points.forEach(point => {
samples.push(point);
});

const segments = region.segmentizeMovement(waypoints, samples, { teleport });
if(segments) return segments;

return wrapped(...args);
return segments || wrapped(...args);
}, 'MIXED');
});

Expand Down

0 comments on commit d51921e

Please sign in to comment.