1
1
import { MODULE_ID } from "./const.js" ;
2
2
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
+ } ) ;
6
6
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 ( ) ;
9
14
10
15
libWrapper . register ( MODULE_ID , "Drawing.prototype.activateListeners" , function ( wrapped , ...args ) {
11
16
wrapped ( ...args ) ;
@@ -20,7 +25,7 @@ Hooks.once("libWrapper.Ready", () => {
20
25
return ;
21
26
}
22
27
23
- const handle = event . data . handle = event . target ;
28
+ const handle = getInteractionData ( event ) . handle = event . target ;
24
29
25
30
if ( handle instanceof PointHandle || handle instanceof EdgeHandle ) {
26
31
handle . _hover = true ;
@@ -31,7 +36,7 @@ Hooks.once("libWrapper.Ready", () => {
31
36
} , libWrapper . OVERRIDE ) ;
32
37
33
38
libWrapper . register ( MODULE_ID , "Drawing.prototype._onHandleHoverOut" , function ( event ) {
34
- const handle = event . data . handle ;
39
+ const handle = getInteractionData ( event ) . handle ;
35
40
36
41
if ( handle instanceof PointHandle || handle instanceof EdgeHandle ) {
37
42
handle . _hover = false ;
@@ -47,10 +52,14 @@ Hooks.once("libWrapper.Ready", () => {
47
52
}
48
53
} , libWrapper . OVERRIDE ) ;
49
54
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
+
51
60
this . _original = this . document . toObject ( ) ;
52
61
53
- const { handle, destination } = event . data ;
62
+ const { handle, destination } = getInteractionData ( event ) ;
54
63
let update ;
55
64
56
65
if ( handle instanceof EdgeHandle ) {
@@ -66,17 +75,18 @@ Hooks.once("libWrapper.Ready", () => {
66
75
update = { x, y, shape : { width, height, points : Array . from ( points ) } } ;
67
76
update . shape . points . splice ( handle . index * 2 , 0 , point . x , point . y ) ;
68
77
} else if ( handle instanceof ResizeHandle ) {
69
- event . data . origin = { x : this . bounds . right , y : this . bounds . bottom } ;
78
+ return wrapped ( event ) ;
70
79
}
71
80
72
81
if ( update ) {
73
82
this . document . updateSource ( update ) ;
74
- this . refresh ( ) ;
83
+ refreshShape ( this ) ;
75
84
}
76
- } , libWrapper . OVERRIDE ) ;
85
+ } , libWrapper . MIXED ) ;
77
86
78
87
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 ;
80
90
let update ;
81
91
82
92
// Pan the canvas if the drag event approaches the edge
@@ -110,12 +120,13 @@ Hooks.once("libWrapper.Ready", () => {
110
120
111
121
try {
112
122
this . document . updateSource ( update ) ;
113
- this . refresh ( ) ;
123
+ refreshShape ( this ) ;
114
124
} catch ( err ) { }
115
125
} , libWrapper . OVERRIDE ) ;
116
126
117
127
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 ;
119
130
let update ;
120
131
121
132
if ( ! originalEvent . shiftKey ) {
@@ -154,14 +165,14 @@ Hooks.once("libWrapper.Ready", () => {
154
165
} , libWrapper . OVERRIDE ) ;
155
166
156
167
libWrapper . register ( MODULE_ID , "Drawing.prototype._onClickRight" , function ( wrapped , event ) {
157
- const handle = event . data . handle ;
168
+ const handle = getInteractionData ( event ) . handle ;
158
169
159
170
if ( ( handle instanceof PointHandle || handle instanceof EdgeHandle ) && handle . _hover ) {
160
171
const { x, y, rotation, shape : { width, height, points } } = this . document ;
161
172
let update = { x, y, shape : { width, height, points : Array . from ( points ) } } ;
162
173
163
174
if ( handle instanceof EdgeHandle ) {
164
- const origin = event . data . origin ;
175
+ const origin = getInteractionData ( event ) . origin ;
165
176
const matrix = new PIXI . Matrix ( ) ;
166
177
const point = new PIXI . Point ( origin . x , origin . y ) ;
167
178
@@ -226,14 +237,23 @@ Drawing.prototype._refreshEditMode = function () {
226
237
editHandles . points = editHandles . addChild ( new PIXI . Container ( ) ) ;
227
238
}
228
239
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
+ } ;
237
257
238
258
const points = document . shape . points ;
239
259
0 commit comments