Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Aug 28, 2023
1 parent 1060219 commit 2a15af8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changelog

## Version 3.1.4
- *Effects* - Added better support for the Walled Templates module
- *Effects* - Fixed effects becoming invisible when using both `offset` and `local` with just a source location and no target
- *Effects* - Fixed `.shape()`s `isMask` property not working when the shape type was set to `polygon`
- *Sounds* - Fixed "End All Sounds" button not working in the Sequencer Manager

## Version 3.1.3
- *Sequencer* - Removed stray debugger, whoops
- *Animations* - Fixed `.rotateTowards()` being off by a few degrees
Expand Down
75 changes: 63 additions & 12 deletions src/canvas-effects/canvas-effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,16 +937,19 @@ export default class CanvasEffect extends PIXI.Container {
this.getSourceData();
this.getTargetData();
}
const angle = new Ray(
{
x: this._cachedSourceData.position.x,
y: this._cachedSourceData.position.y,
},
{
x: this._cachedTargetData.position.x,
y: this._cachedTargetData.position.y,
}
).angle;

const startPos = this._cachedSourceData.position;
const endPos = this._cachedTargetData.position;

const angle = this.target
? new Ray(startPos, endPos).angle
: Ray.fromAngle(
startPos.x,
startPos.y,
this._cachedSourceData.rotation,
1
).angle;

newOffset = canvaslib.rotateAroundPoint(
0,
0,
Expand Down Expand Up @@ -1940,10 +1943,22 @@ export default class CanvasEffect extends PIXI.Container {

if (obj instanceof MeasuredTemplate || obj instanceof Drawing) {
shape = obj?.shape?.geometry?.graphicsData?.[0]?.shape ?? obj?.shape;

if (
game.modules.get("walledtemplates")?.active &&
obj.walledtemplates?.walledTemplate
) {
let wt = obj.walledtemplates.walledTemplate;
wt.options.padding = 3 * canvas.dimensions.distancePixels;
shape = wt.computeShape();
wt.options.padding = 0;
}

shapeToAdd = new PIXI.LegacyGraphics()
.beginFill()
.drawShape(shape)
.endFill();

if (obj instanceof MeasuredTemplate) {
shapeToAdd.position.set(documentObj.x, documentObj.y);
} else {
Expand All @@ -1965,15 +1980,24 @@ export default class CanvasEffect extends PIXI.Container {
}
shapeToAdd.obj = obj;

hooksManager.addHook(this.uuid, this.getHook("update", uuid), (doc) => {
const updateMethod = (doc) => {
if (doc !== documentObj) return;
const mask = maskFilter.masks.find((shape) => shape.uuid === uuid);
if (!mask) return;
if (!mask.custom) return;
mask.clear();
mask.beginFill().drawShape(shape).endFill();
if (obj instanceof MeasuredTemplate) {
mask.position.set(documentObj.x, documentObj.y);
let maskObj = documentObj.object;
if (
game.modules.get("walledtemplates")?.active &&
maskObj.walledtemplates?.walledTemplate
) {
let wt = maskObj.walledtemplates.walledTemplate;
wt.options.padding = 3 * canvas.dimensions.distancePixels;
shape = wt.computeShape();
wt.options.padding = 0;
}
} else {
const {
x,
Expand All @@ -1985,6 +2009,33 @@ export default class CanvasEffect extends PIXI.Container {
mask.position.set(x + width / 2, y + height / 2);
mask.angle = rotation;
}
mask.beginFill().drawShape(shape).endFill();
};

if (game.modules.get("walledtemplates")?.active) {
hooksManager.addHook(this.uuid, "createWall", () => {
setTimeout(() => {
updateMethod(documentObj);
}, 100);
});

hooksManager.addHook(this.uuid, "updateWall", () => {
setTimeout(() => {
updateMethod(documentObj);
}, 100);
});

hooksManager.addHook(this.uuid, "deleteWall", () => {
setTimeout(() => {
updateMethod(documentObj);
}, 100);
});
}

hooksManager.addHook(this.uuid, this.getHook("update", uuid), (doc) => {
setTimeout(() => {
updateMethod(doc);
}, 100);
});

maskFilter.masks.push(shapeToAdd);
Expand Down
1 change: 1 addition & 0 deletions src/formapplications/effects-ui/Manager.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import SequenceManager from "../../modules/sequence-manager.js";
import EffectEntry from "./components/EffectEntry.svelte";
import SoundEntry from "./components/SoundEntry.svelte";
import SequencerAudioHelper from "../../modules/sequencer-audio-helper.js";
const VisibleEffects = SequenceManager.VisibleEffects;
const RunningSounds = SequenceManager.RunningSounds;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/canvas-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import CanvasEffect from "../canvas-effects/canvas-effect.js";
import CONSTANTS from "../constants.js";

export function createShape(shape) {
const graphic = new PIXI.Graphics();
const graphic = new PIXI.LegacyGraphics();

graphic.beginFill(
shape?.fillColor ?? 0xffffff,
shape?.fillColor !== undefined ? shape?.fillAlpha ?? 1 : 0
shape?.fillAlpha ?? shape?.isMask ? 1 : 0
);

graphic.lineStyle(
shape.lineSize ?? (shape?.lineColor !== undefined ? 1 : 0),
shape.lineSize ?? (shape?.isMask ? 1 : 0),
shape?.lineColor ?? 0xffffff
);

Expand Down Expand Up @@ -63,8 +63,8 @@ export function createShape(shape) {
graphic.drawPolygon(
shape.points.map((point) => {
return new PIXI.Point(
point[0] * sizeMultiplier + graphic.offset.x,
point[1] * sizeMultiplier + graphic.offset.y
point[0] * sizeMultiplier,
point[1] * sizeMultiplier
);
})
);
Expand Down

0 comments on commit 2a15af8

Please sign in to comment.