Skip to content

Commit 724f1b7

Browse files
committed
Update for 11.294
1 parent a79a675 commit 724f1b7

File tree

4 files changed

+100
-46
lines changed

4 files changed

+100
-46
lines changed

module.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"email": "dev7355608@gmail.com"
1010
}
1111
],
12-
"version": "2.0.6",
12+
"version": "2.0.7",
1313
"compatibility": {
1414
"minimum": "10",
1515
"verified": "11"
@@ -28,8 +28,8 @@
2828
},
2929
"url": "https://github.com/dev7355608/advanced-drawing-tools",
3030
"manifest": "https://raw.githubusercontent.com/dev7355608/advanced-drawing-tools/main/module.json",
31-
"download": "https://github.com/dev7355608/advanced-drawing-tools/releases/download/v2.0.6/module.zip",
32-
"changelog": "https://github.com/dev7355608/advanced-drawing-tools/releases/tag/v2.0.6",
31+
"download": "https://github.com/dev7355608/advanced-drawing-tools/releases/download/v2.0.7/module.zip",
32+
"changelog": "https://github.com/dev7355608/advanced-drawing-tools/releases/tag/v2.0.7",
3333
"bugs": "https://github.com/dev7355608/advanced-drawing-tools/issues",
3434
"readme": "https://raw.githubusercontent.com/dev7355608/advanced-drawing-tools/main/README.md",
3535
"license": "https://raw.githubusercontent.com/dev7355608/advanced-drawing-tools/main/LICENSE"

scripts/edit-mode.js

+45-25
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { MODULE_ID } from "./const.js";
22

3-
Hooks.once("libWrapper.Ready", () => {
4-
libWrapper.register(MODULE_ID, "Drawing.prototype._refresh", function (wrapped, ...args) {
5-
wrapped(...args);
3+
Hooks.on("refreshDrawing", drawing => {
4+
drawing._refreshEditMode();
5+
});
66

7-
this._refreshEditMode();
8-
}, libWrapper.WRAPPER);
7+
Hooks.once("libWrapper.Ready", () => {
8+
const getInteractionData = isNewerVersion(game.version, 11)
9+
? (event) => event.interactionData
10+
: (event) => event.data;
11+
const refreshShape = isNewerVersion(game.version, 11)
12+
? (drawing) => drawing.renderFlags.set({ refreshShape: true })
13+
: (drawing) => drawing.refresh();
914

1015
libWrapper.register(MODULE_ID, "Drawing.prototype.activateListeners", function (wrapped, ...args) {
1116
wrapped(...args);
@@ -20,7 +25,7 @@ Hooks.once("libWrapper.Ready", () => {
2025
return;
2126
}
2227

23-
const handle = event.data.handle = event.target;
28+
const handle = getInteractionData(event).handle = event.target;
2429

2530
if (handle instanceof PointHandle || handle instanceof EdgeHandle) {
2631
handle._hover = true;
@@ -31,7 +36,7 @@ Hooks.once("libWrapper.Ready", () => {
3136
}, libWrapper.OVERRIDE);
3237

3338
libWrapper.register(MODULE_ID, "Drawing.prototype._onHandleHoverOut", function (event) {
34-
const handle = event.data.handle;
39+
const handle = getInteractionData(event).handle;
3540

3641
if (handle instanceof PointHandle || handle instanceof EdgeHandle) {
3742
handle._hover = false;
@@ -47,10 +52,14 @@ Hooks.once("libWrapper.Ready", () => {
4752
}
4853
}, libWrapper.OVERRIDE);
4954

50-
libWrapper.register(MODULE_ID, "Drawing.prototype._onHandleDragStart", function (event) {
55+
libWrapper.register(MODULE_ID, "Drawing.prototype._onDragLeftStart", function (wrapped, event) {
56+
if (!this._dragHandle) {
57+
return wrapped(event);
58+
}
59+
5160
this._original = this.document.toObject();
5261

53-
const { handle, destination } = event.data;
62+
const { handle, destination } = getInteractionData(event);
5463
let update;
5564

5665
if (handle instanceof EdgeHandle) {
@@ -66,17 +75,18 @@ Hooks.once("libWrapper.Ready", () => {
6675
update = { x, y, shape: { width, height, points: Array.from(points) } };
6776
update.shape.points.splice(handle.index * 2, 0, point.x, point.y);
6877
} else if (handle instanceof ResizeHandle) {
69-
event.data.origin = { x: this.bounds.right, y: this.bounds.bottom };
78+
return wrapped(event);
7079
}
7180

7281
if (update) {
7382
this.document.updateSource(update);
74-
this.refresh();
83+
refreshShape(this);
7584
}
76-
}, libWrapper.OVERRIDE);
85+
}, libWrapper.MIXED);
7786

7887
libWrapper.register(MODULE_ID, "Drawing.prototype._onHandleDragMove", function (event) {
79-
const { handle, destination, origin, originalEvent } = event.data;
88+
const { handle, destination, origin } = getInteractionData(event);
89+
const originalEvent = event.data.originalEvent;
8090
let update;
8191

8292
// Pan the canvas if the drag event approaches the edge
@@ -110,12 +120,13 @@ Hooks.once("libWrapper.Ready", () => {
110120

111121
try {
112122
this.document.updateSource(update);
113-
this.refresh();
123+
refreshShape(this);
114124
} catch (err) { }
115125
}, libWrapper.OVERRIDE);
116126

117127
libWrapper.register(MODULE_ID, "Drawing.prototype._onHandleDragDrop", function (event) {
118-
let { handle, destination, origin, originalEvent } = event.data;
128+
let { handle, destination, origin } = getInteractionData(event);
129+
const originalEvent = event.data.originalEvent;
119130
let update;
120131

121132
if (!originalEvent.shiftKey) {
@@ -154,14 +165,14 @@ Hooks.once("libWrapper.Ready", () => {
154165
}, libWrapper.OVERRIDE);
155166

156167
libWrapper.register(MODULE_ID, "Drawing.prototype._onClickRight", function (wrapped, event) {
157-
const handle = event.data.handle;
168+
const handle = getInteractionData(event).handle;
158169

159170
if ((handle instanceof PointHandle || handle instanceof EdgeHandle) && handle._hover) {
160171
const { x, y, rotation, shape: { width, height, points } } = this.document;
161172
let update = { x, y, shape: { width, height, points: Array.from(points) } };
162173

163174
if (handle instanceof EdgeHandle) {
164-
const origin = event.data.origin;
175+
const origin = getInteractionData(event).origin;
165176
const matrix = new PIXI.Matrix();
166177
const point = new PIXI.Point(origin.x, origin.y);
167178

@@ -226,14 +237,23 @@ Drawing.prototype._refreshEditMode = function () {
226237
editHandles.points = editHandles.addChild(new PIXI.Container());
227238
}
228239

229-
const activateListeners = handle => {
230-
handle.off("mouseover").off("mouseout").off("mousedown").off("mouseup")
231-
.on("mouseover", this._onHandleHoverIn.bind(this))
232-
.on("mouseout", this._onHandleHoverOut.bind(this))
233-
.on("mousedown", this._onHandleMouseDown.bind(this))
234-
.on("mouseup", this._onHandleMouseUp.bind(this));
235-
handle.interactive = true;
236-
};
240+
const activateListeners = isNewerVersion(game.version, 11)
241+
? (handle) => {
242+
handle.off("pointerover").off("pointerout").off("pointerdown").off("pointerup")
243+
.on("pointerover", this._onHandleHoverIn.bind(this))
244+
.on("pointerout", this._onHandleHoverOut.bind(this))
245+
.on("pointerdown", this._onHandleMouseDown.bind(this))
246+
.on("pointerup", this._onHandleMouseUp.bind(this));
247+
handle.eventMode = "static";
248+
}
249+
: (handle) => {
250+
handle.off("mouseover").off("mouseout").off("mousedown").off("mouseup")
251+
.on("mouseover", this._onHandleHoverIn.bind(this))
252+
.on("mouseout", this._onHandleHoverOut.bind(this))
253+
.on("mousedown", this._onHandleMouseDown.bind(this))
254+
.on("mouseup", this._onHandleMouseUp.bind(this));
255+
handle.interactive = true;
256+
};
237257

238258
const points = document.shape.points;
239259

scripts/index.js

+48-18
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,56 @@ Hooks.once("libWrapper.Ready", () => {
2424
}, libWrapper.OVERRIDE);
2525
libWrapper.ignore_conflicts(MODULE_ID, "precise-drawing-tools", "DrawingsLayer.prototype.gridPrecision");
2626

27-
libWrapper.register(MODULE_ID, "Drawing.prototype._rescaleDimensions", function (original, dx, dy) {
28-
let { points, width, height } = original.shape;
29-
width += dx;
30-
height += dy;
31-
points = points || [];
27+
if (!isNewerVersion(game.version, 11)) {
28+
libWrapper.register(MODULE_ID, "Drawing.prototype._rescaleDimensions", function (original, dx, dy) {
29+
let { points, width, height } = original.shape;
30+
width += dx;
31+
height += dy;
32+
points = points || [];
3233

33-
// Rescale polygon points
34-
if (this.isPolygon) {
35-
const scaleX = 1 + (dx / original.shape.width);
36-
const scaleY = 1 + (dy / original.shape.height);
37-
points = points.map((p, i) => p * (i % 2 ? scaleY : scaleX));
38-
}
34+
// Rescale polygon points
35+
if (this.isPolygon) {
36+
const scaleX = 1 + (dx / original.shape.width);
37+
const scaleY = 1 + (dy / original.shape.height);
38+
points = points.map((p, i) => p * (i % 2 ? scaleY : scaleX));
39+
}
3940

40-
// Normalize the shape
41-
return this.constructor.normalizeShape({
42-
x: original.x,
43-
y: original.y,
44-
shape: { width: Math.roundFast(width), height: Math.roundFast(height), points }
45-
});
46-
}, libWrapper.OVERRIDE);
41+
// Normalize the shape
42+
return this.constructor.normalizeShape({
43+
x: original.x,
44+
y: original.y,
45+
shape: { width: Math.roundFast(width), height: Math.roundFast(height), points }
46+
});
47+
}, libWrapper.OVERRIDE);
48+
} else {
49+
Drawing.prototype._rescaleDimensions = function (original, dx, dy) {
50+
let { points, width, height } = original.shape;
51+
width += dx;
52+
height += dy;
53+
points = points || [];
54+
55+
// Rescale polygon points
56+
if (this.isPolygon) {
57+
const scaleX = 1 + (dx / original.shape.width);
58+
const scaleY = 1 + (dy / original.shape.height);
59+
points = points.map((p, i) => p * (i % 2 ? scaleY : scaleX));
60+
}
61+
62+
// Constrain drawing bounds by the contained text size
63+
if (this.document.text) {
64+
const textBounds = this.text.getLocalBounds();
65+
width = Math.max(textBounds.width + 16, width);
66+
height = Math.max(textBounds.height + 8, height);
67+
}
68+
69+
// Normalize the shape
70+
return this.constructor.normalizeShape({
71+
x: original.x,
72+
y: original.y,
73+
shape: { width: Math.round(width), height: Math.round(height), points }
74+
});
75+
};
76+
}
4777
});
4878

4979
function preProcess(data) {

scripts/text.js

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { WarpedText } from "./warped-text.js";
33
import { calculateValue } from "./utils.js";
44

55
Hooks.once("libWrapper.Ready", () => {
6+
if (isNewerVersion(game.version, 11)) {
7+
return;
8+
}
9+
610
libWrapper.register(MODULE_ID, "Drawing.prototype._onDrawingTextKeydown", function (event) {
711
// Ignore events when an input is focused, or when ALT or CTRL modifiers are applied
812
if (event.altKey || event.ctrlKey || event.metaKey) return;

0 commit comments

Comments
 (0)