@@ -5,29 +5,36 @@ Hooks.on("refreshDrawing", drawing => {
5
5
} ) ;
6
6
7
7
Hooks . once ( "libWrapper.Ready" , ( ) => {
8
- const getInteractionData = isNewerVersion ( game . version , 11 )
8
+ const getInteractionData = foundry . utils . isNewerVersion ( game . version , 11 )
9
9
? ( event ) => event . interactionData
10
10
: ( event ) => event . data ;
11
- const getOriginalData = isNewerVersion ( game . version , 11 )
11
+ const getOriginalData = foundry . utils . isNewerVersion ( game . version , 11 )
12
12
? ( drawing , event ) => event . interactionData . originalData
13
13
: ( drawing , event ) => drawing . _original ;
14
- const setOriginalData = isNewerVersion ( game . version , 11 )
14
+ const setOriginalData = foundry . utils . isNewerVersion ( game . version , 11 )
15
15
? ( drawing , event ) => event . interactionData . originalData = drawing . document . toObject ( )
16
16
: ( drawing , event ) => drawing . _original = drawing . document . toObject ( ) ;
17
- const setRestoreOriginalData = isNewerVersion ( game . version , 11 )
17
+ const setRestoreOriginalData = foundry . utils . isNewerVersion ( game . version , 11 )
18
18
? ( drawing , event , value ) => event . interactionData . restoreOriginalData = value
19
19
: ( drawing , event , value ) => { } ;
20
- const refreshShape = isNewerVersion ( game . version , 11 )
21
- ? ( drawing ) => drawing . renderFlags . set ( { refreshShape : true } )
22
- : ( drawing ) => drawing . refresh ( ) ;
23
-
24
- libWrapper . register ( MODULE_ID , "Drawing.prototype.activateListeners" , function ( wrapped , ...args ) {
25
- wrapped ( ...args ) ;
26
-
27
- const pointerup = isNewerVersion ( game . version , 11 ) ? "pointerup" : "mouseup" ;
28
-
29
- this . frame . handle . off ( pointerup ) . on ( pointerup , this . _onHandleMouseUp . bind ( this ) ) ;
30
- } , libWrapper . WRAPPER ) ;
20
+ const refreshSize = foundry . utils . isNewerVersion ( game . version , 12 )
21
+ ? ( drawing ) => drawing . renderFlags . set ( { refreshSize : true } )
22
+ : foundry . utils . isNewerVersion ( game . version , 11 )
23
+ ? ( drawing ) => drawing . renderFlags . set ( { refreshShape : true } )
24
+ : ( drawing ) => drawing . refresh ( ) ;
25
+ const isDraggingHandle = foundry . utils . isNewerVersion ( game . version , 12 )
26
+ ? ( drawing , event ) => event . interactionData . dragHandle
27
+ : ( drawing , event ) => drawing . _dragHandle ;
28
+
29
+ if ( ! foundry . utils . isNewerVersion ( game . version , 12 ) ) {
30
+ libWrapper . register ( MODULE_ID , "Drawing.prototype.activateListeners" , function ( wrapped , ...args ) {
31
+ wrapped ( ...args ) ;
32
+
33
+ const pointerup = foundry . utils . isNewerVersion ( game . version , 11 ) ? "pointerup" : "mouseup" ;
34
+
35
+ this . frame . handle . off ( pointerup ) . on ( pointerup , this . _onHandleMouseUp . bind ( this ) ) ;
36
+ } , libWrapper . WRAPPER ) ;
37
+ }
31
38
32
39
libWrapper . register ( MODULE_ID , "Drawing.prototype._onHandleHoverIn" , function ( event ) {
33
40
if ( this . _dragHandle ) {
@@ -60,27 +67,29 @@ Hooks.once("libWrapper.Ready", () => {
60
67
}
61
68
} , libWrapper . OVERRIDE ) ;
62
69
63
- libWrapper . register ( MODULE_ID , "Drawing.prototype._onHandleMouseDown" , function ( event ) {
64
- const handle = event . target ;
65
-
66
- if ( handle instanceof PointHandle || handle instanceof EdgeHandle ) {
67
- if ( ! this . document . locked ) {
68
- this . _dragHandle = true ;
69
- handle . _hover = true ;
70
- handle . refresh ( ) ;
71
- this . _editHandle = handle ;
70
+ if ( ! foundry . utils . isNewerVersion ( game . version , 12 ) ) {
71
+ libWrapper . register ( MODULE_ID , "Drawing.prototype._onHandleMouseDown" , function ( event ) {
72
+ const handle = event . target ;
73
+
74
+ if ( handle instanceof PointHandle || handle instanceof EdgeHandle ) {
75
+ if ( ! this . document . locked ) {
76
+ this . _dragHandle = true ;
77
+ handle . _hover = true ;
78
+ handle . refresh ( ) ;
79
+ this . _editHandle = handle ;
80
+ } else {
81
+ this . _editHandle = null ;
82
+ }
72
83
} else {
73
- this . _editHandle = null ;
84
+ if ( ! this . document . locked ) {
85
+ this . _dragHandle = true ;
86
+ }
74
87
}
75
- } else {
76
- if ( ! this . document . locked ) {
77
- this . _dragHandle = true ;
78
- }
79
- }
80
- } , libWrapper . OVERRIDE ) ;
88
+ } , libWrapper . OVERRIDE ) ;
89
+ }
81
90
82
91
libWrapper . register ( MODULE_ID , "Drawing.prototype._onDragLeftStart" , function ( wrapped , event ) {
83
- if ( ! this . _dragHandle ) {
92
+ if ( ! isDraggingHandle ( this , event ) ) {
84
93
return wrapped ( event ) ;
85
94
}
86
95
@@ -112,7 +121,7 @@ Hooks.once("libWrapper.Ready", () => {
112
121
113
122
if ( update ) {
114
123
this . document . updateSource ( update ) ;
115
- refreshShape ( this ) ;
124
+ refreshSize ( this ) ;
116
125
}
117
126
} , libWrapper . MIXED ) ;
118
127
@@ -126,6 +135,12 @@ Hooks.once("libWrapper.Ready", () => {
126
135
const originalEvent = event . data . originalEvent ;
127
136
let update ;
128
137
138
+ if ( ! originalEvent . shiftKey ) {
139
+ if ( foundry . utils . isNewerVersion ( game . version , 12 ) ) {
140
+ destination = this . layer . getSnappedPoint ( destination ) ;
141
+ }
142
+ }
143
+
129
144
// Pan the canvas if the drag event approaches the edge
130
145
canvas . _onDragCanvasPan ( originalEvent ) ;
131
146
@@ -157,7 +172,7 @@ Hooks.once("libWrapper.Ready", () => {
157
172
158
173
try {
159
174
this . document . updateSource ( update ) ;
160
- refreshShape ( this ) ;
175
+ refreshSize ( this ) ;
161
176
} catch ( err ) { }
162
177
} , libWrapper . OVERRIDE ) ;
163
178
@@ -174,7 +189,11 @@ Hooks.once("libWrapper.Ready", () => {
174
189
setRestoreOriginalData ( this , event , false ) ;
175
190
176
191
if ( ! originalEvent . shiftKey ) {
177
- destination = canvas . grid . getSnappedPosition ( destination . x , destination . y , this . layer . gridPrecision ) ;
192
+ if ( foundry . utils . isNewerVersion ( game . version , 12 ) ) {
193
+ destination = this . layer . getSnappedPoint ( destination ) ;
194
+ } else {
195
+ destination = canvas . grid . getSnappedPosition ( destination . x , destination . y , this . layer . gridPrecision ) ;
196
+ }
178
197
}
179
198
180
199
if ( handle instanceof PointHandle || handle instanceof EdgeHandle ) {
@@ -213,6 +232,22 @@ Hooks.once("libWrapper.Ready", () => {
213
232
return this . document . update ( update , { diff : false } ) ;
214
233
} , libWrapper . OVERRIDE ) ;
215
234
235
+ if ( foundry . utils . isNewerVersion ( game . version , 12 ) ) {
236
+ libWrapper . register ( MODULE_ID , "Drawing.prototype._onClickLeft" , function ( wrapped , event ) {
237
+ this . _editHandle = null ;
238
+
239
+ if ( this . _editHandles ?. points . children . includes ( event . target )
240
+ || this . _editHandles ?. edges . children . includes ( event . target ) ) {
241
+ event . interactionData . dragHandle = true ;
242
+ event . stopPropagation ( ) ;
243
+ this . _editHandle = event . target ;
244
+ return ;
245
+ }
246
+
247
+ return wrapped ( event ) ;
248
+ } , libWrapper . MIXED ) ;
249
+ }
250
+
216
251
libWrapper . register ( MODULE_ID , "Drawing.prototype._onClickRight" , function ( wrapped , event ) {
217
252
let handle = getInteractionData ( event ) . handle ;
218
253
@@ -221,6 +256,7 @@ Hooks.once("libWrapper.Ready", () => {
221
256
}
222
257
223
258
if ( ( handle instanceof PointHandle || handle instanceof EdgeHandle ) && handle . _hover ) {
259
+ event . stopPropagation ( ) ;
224
260
this . _dragHandle = false ;
225
261
handle . _hover = false ;
226
262
handle . refresh ( ) ;
@@ -252,12 +288,14 @@ Hooks.once("libWrapper.Ready", () => {
252
288
return wrapped ( event ) ;
253
289
} , libWrapper . MIXED ) ;
254
290
255
- Drawing . prototype . _onHandleMouseUp = function ( event ) {
256
- if ( ! getOriginalData ( this , event ) ) {
257
- this . _dragHandle = false ;
258
- this . _editHandle = null ;
259
- }
260
- } ;
291
+ if ( ! foundry . utils . isNewerVersion ( game . version , 12 ) ) {
292
+ Drawing . prototype . _onHandleMouseUp = function ( event ) {
293
+ if ( ! getOriginalData ( this , event ) ) {
294
+ this . _dragHandle = false ;
295
+ this . _editHandle = null ;
296
+ }
297
+ } ;
298
+ }
261
299
} ) ;
262
300
263
301
Drawing . prototype . _editMode = false ;
@@ -287,7 +325,7 @@ Drawing.prototype._editHandles = null;
287
325
Drawing . prototype . _refreshEditMode = function ( ) {
288
326
const document = this . document ;
289
327
290
- if ( this . _editMode && this . layer . active && ! document . _source . locked && document . shape . type === CONST . DRAWING_TYPES . POLYGON ) {
328
+ if ( this . _editMode && this . layer . active && ! document . _source . locked && document . shape . type === "p" ) {
291
329
let editHandles = this . _editHandles ;
292
330
293
331
if ( ! editHandles || editHandles . destroyed ) {
@@ -296,23 +334,30 @@ Drawing.prototype._refreshEditMode = function () {
296
334
editHandles . points = editHandles . addChild ( new PIXI . Container ( ) ) ;
297
335
}
298
336
299
- const activateListeners = isNewerVersion ( game . version , 11 )
337
+ const activateListeners = foundry . utils . isNewerVersion ( game . version , 12 )
300
338
? ( handle ) => {
301
- handle . off ( "pointerover" ) . off ( "pointerout" ) . off ( "pointerdown" ) . off ( "pointerup" )
339
+ handle . off ( "pointerover" ) . off ( "pointerout" )
302
340
. on ( "pointerover" , this . _onHandleHoverIn . bind ( this ) )
303
- . on ( "pointerout" , this . _onHandleHoverOut . bind ( this ) )
304
- . on ( "pointerdown" , this . _onHandleMouseDown . bind ( this ) )
305
- . on ( "pointerup" , this . _onHandleMouseUp . bind ( this ) ) ;
341
+ . on ( "pointerout" , this . _onHandleHoverOut . bind ( this ) ) ;
306
342
handle . eventMode = "static" ;
307
343
}
308
- : ( handle ) => {
309
- handle . off ( "mouseover" ) . off ( "mouseout" ) . off ( "mousedown" ) . off ( "mouseup" )
310
- . on ( "mouseover" , this . _onHandleHoverIn . bind ( this ) )
311
- . on ( "mouseout" , this . _onHandleHoverOut . bind ( this ) )
312
- . on ( "mousedown" , this . _onHandleMouseDown . bind ( this ) )
313
- . on ( "mouseup" , this . _onHandleMouseUp . bind ( this ) ) ;
314
- handle . interactive = true ;
315
- } ;
344
+ : foundry . utils . isNewerVersion ( game . version , 11 )
345
+ ? ( handle ) => {
346
+ handle . off ( "pointerover" ) . off ( "pointerout" ) . off ( "pointerdown" ) . off ( "pointerup" )
347
+ . on ( "pointerover" , this . _onHandleHoverIn . bind ( this ) )
348
+ . on ( "pointerout" , this . _onHandleHoverOut . bind ( this ) )
349
+ . on ( "pointerdown" , this . _onHandleMouseDown . bind ( this ) )
350
+ . on ( "pointerup" , this . _onHandleMouseUp . bind ( this ) ) ;
351
+ handle . eventMode = "static" ;
352
+ }
353
+ : ( handle ) => {
354
+ handle . off ( "mouseover" ) . off ( "mouseout" ) . off ( "mousedown" ) . off ( "mouseup" )
355
+ . on ( "mouseover" , this . _onHandleHoverIn . bind ( this ) )
356
+ . on ( "mouseout" , this . _onHandleHoverOut . bind ( this ) )
357
+ . on ( "mousedown" , this . _onHandleMouseDown . bind ( this ) )
358
+ . on ( "mouseup" , this . _onHandleMouseUp . bind ( this ) ) ;
359
+ handle . interactive = true ;
360
+ } ;
316
361
317
362
const points = document . shape . points ;
318
363
0 commit comments