-
Notifications
You must be signed in to change notification settings - Fork 126
/
PictureCallCommon.js
690 lines (634 loc) · 26.3 KB
/
PictureCallCommon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
//=============================================================================
// PictureCallCommon.js
// ----------------------------------------------------------------------------
// (C)2015 Triacontane
// This plugin is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
// ----------------------------------------------------------------------------
// Version
// 1.6.1 2024/06/04 ボタンピクチャを極めて小さい拡大率(負の値への移動も含む)で表示しようとするとエラーになる場合がある問題を修正
// 1.6.0 2023/11/16 プラグインコマンドを「ピクチャの操作拡張プラグイン」が提供する一括指定機能に対応させました。
// 1.5.1 2023/06/12 ピクチャイベント解除時に指定した番号以外の番号のピクチャイベントも一緒に解除される可能性がある問題を修正
// 1.5.0 2023/04/22 ピクチャイベントを発生させる際、透過部分に反応するかどうかを設定できる機能を追加
// 1.4.0 2022/10/22 DTextPicture.jsと組み合わせたとき、フレームウィンドウをクリックイベントの範囲に含めるよう変更
// 1.3.1 2022/05/19 ヘルプ微修正
// 1.3.0 2022/04/14 ピクチャクリック時に変数を操作する機能および任意スクリプトを実行する機能を追加
// 1.2.2 2021/11/07 異なるピクチャのトリガーを同一フレームで同時に満たした場合、すべてのタッチ処理が実行されるよう修正
// 1.2.1 2021/10/08 トリガー種別がマウスが重なった場合のとき無効スイッチ中に条件を満たしていると、無効スイッチがOFFになった瞬間にイベントが発生してしまう問題を修正
// 1.2.0 2021/05/20 APNGピクチャプラグインと組み合わせたときにAPNGピクチャをボタン化できるよう修正(ただし透過色は考慮されない)
// 1.1.2 2021/04/08 トリガー「マウスをピクチャ内で移動した場合」がマウスを押していないと反応しない問題を修正
// 1.1.1 2020/12/21 スクリプト$gameScreen.showPictureを使って未キャッシュのピクチャを表示しようとすると画像が表示されなくなる問題を修正
// セーブデータロード時にエラーになる問題を修正
// 1.1.0 2020/12/20 イベントごとに無効スイッチを指定できる機能を追加
// 1.0.0 2020/12/17 MZ版として新規作成
// ----------------------------------------------------------------------------
// [Blog] : https://triacontane.blogspot.jp/
// [Twitter]: https://twitter.com/triacontane/
// [GitHub] : https://github.com/triacontane/
//=============================================================================
/*:
* @plugindesc ピクチャのボタン化プラグイン
* @target MZ
* @url https://github.com/triacontane/RPGMakerMV/tree/mz_master/PictureCallCommon.js
* @base PluginCommonBase
* @author トリアコンタン
*
* @param PictureIdVariable
* @text ピクチャ番号の変数
* @desc 最後にイベントが発生したピクチャ番号を格納する変数IDです。
* @default 0
* @type variable
*
* @param InvalidSwitchId
* @text 無効スイッチ
* @desc 指定した番号のスイッチがONになっている場合、すべてのピクチャイベントが無効になります。
* @default 0
* @type switch
*
* @param FlickDistance
* @text フリック有効距離
* @desc フリック判定が有効になる距離(ピクセル数)です。
* @default 60
* @type number
*
* @param FlickTimeVariable
* @text フリック時間の変数
* @desc フリック判定が有効になるまでに掛かったフレーム数を格納する変数IDです。この値が小さいほど速いフリックです。
* @default 0
* @type variable
*
* @param FlickDegreeVariable
* @text フリック角度の変数
* @desc フリック判定が有効になったときのフリック方向を度数法で格納する変数IDです。
* @default 0
* @type variable
*
* @command ADD_PICTURE_EVENT
* @text ピクチャイベント登録
* @desc ピクチャ操作で発生するイベントを登録します。
*
* @arg pictureId
* @text ピクチャ番号
* @desc 操作対象のピクチャ番号です。
* @default 1
* @type number
*
* @arg commonEventId
* @text コモンイベント番号
* @desc イベント発生時に呼び出すコモンイベントです。
* @default 0
* @type common_event
*
* @arg switchId
* @text スイッチ番号
* @desc イベント発生時にONになるスイッチです。
* @default 0
* @type switch
*
* @arg variableId
* @text 変数番号
* @desc イベント発生時に値が加減される変数です。
* @default 0
* @type variable
*
* @arg operationType
* @parent variableId
* @text 操作種別
* @desc イベント発生時に指定した変数の操作種別です。
* @default 0
* @type select
* @option 代入
* @value 0
* @option 加算
* @value 1
* @option 減算
* @value 2
* @option 乗算
* @value 3
* @option 除算
* @value 4
* @option 剰余
* @value 5
*
* @arg operand
* @parent variableId
* @text オペランド
* @desc イベント発生時に指定した変数の操作値です。
* @default 0
* @type number
* @min -99999999
*
* @arg script
* @text スクリプト
* @desc イベント発生時に実行されるスクリプトです。
* @type multiline_string
*
* @arg buttonBind
* @text ボタンバインド
* @desc イベント発生時に押したことになるボタンです。
* @default
* @type combo
* @option ok
* @option shift
* @option control
* @option escape
* @option left
* @option up
* @option right
* @option down
* @option pageup
* @option pagedown
*
* @arg triggerType
* @text トリガー種別
* @desc トリガーとなるマウス、タッチ操作の種別です。
* @default 1
* @type select
* @option 1:クリックした場合
* @value 1
* @option 2:右クリックした場合
* @value 2
* @option 3:長押しした場合
* @value 3
* @option 4:マウスをピクチャに重ねた場合
* @value 4
* @option 5:マウスをピクチャから放した場合
* @value 5
* @option 6:クリックを解放(リリース)した場合
* @value 6
* @option 7:クリックした場合(かつ長押しの際の繰り返しを考慮)
* @value 7
* @option 8:クリックしている間ずっと
* @value 8
* @option 9:ホイールクリックした場合(PCの場合のみ有効)
* @value 9
* @option 10:ダブルクリックした場合
* @value 10
* @option 11:マウスをピクチャ内で移動した場合
* @value 11
* @option 12:マウスを押しつつピクチャ内で移動した場合
* @value 12
* @option 13:フリック(マウス押下状態で指定距離以上動かす)した場合
* @value 13
*
* @arg invalidSwitchId
* @text 無効スイッチ
* @desc 指定した番号のスイッチがONになっている場合、ピクチャイベントが無効になります。
* @default 0
* @type switch
*
* @command SET_PICTURE_PREFERENCE
* @text ピクチャ設定
* @desc ピクチャイベントの設定を変更します。
*
* @arg pictureId
* @text ピクチャ番号
* @desc 変更対象のピクチャ番号です。
* @default 1
* @type number
*
* @arg includeOpacityZero
* @text 透過部分も含む
* @desc ピクチャの透明部分にも反応するかどうかです。
* @default false
* @type boolean
*
* @command REMOVE_PICTURE_EVENT
* @text ピクチャイベント解除
* @desc 登録したピクチャイベントを解除します。
*
* @arg pictureId
* @text ピクチャ番号
* @desc 操作対象のピクチャ番号です。
* @default 1
* @type number
*
* @help PictureCallCommon.js
*
* ピクチャに対する様々なマウス操作に反応してコモンイベント実行や
* スイッチ制御ができます。(これをピクチャイベントと呼びます)
* 一度登録したピクチャイベントはピクチャを消去しても有効です。
* 解除は専用のプラグインコマンドから可能です。
*
* 各マウス操作について、ピクチャの透明部分には反応しません。
*
* ピクチャイベントはマップ画面でも戦闘画面でも
* 他のイベントや状況の制限を受けずに速やかに並列実行されます。
* また、ピクチャイベントが発生した瞬間のフレームでは他のクリック処理は
* 無効となりタッチによるマップ移動やメッセージ送り等は行われません。
*
* 利用規約:
* 作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
* についても制限はありません。
* このプラグインはもうあなたのものです。
*/
(function() {
'use strict';
const script = document.currentScript;
const param = PluginManagerEx.createParameter(script);
PluginManagerEx.registerCommand(script, 'ADD_PICTURE_EVENT', args => {
if ($gameScreen.iteratePictures) {
$gameScreen.iteratePictures($gameScreen.addPictureEvent, [args.pictureId, args.triggerType, args]);
} else {
$gameScreen.addPictureEvent(args.pictureId, args.triggerType, args);
}
});
PluginManagerEx.registerCommand(script, 'REMOVE_PICTURE_EVENT', args => {
if ($gameScreen.iteratePictures) {
$gameScreen.iteratePictures($gameScreen.removePictureEvent, [args.pictureId]);
} else {
$gameScreen.removePictureEvent(args.pictureId);
}
});
PluginManagerEx.registerCommand(script, 'SET_PICTURE_PREFERENCE', args => {
if ($gameScreen.iteratePictures) {
$gameScreen.iteratePictures($gameScreen.setPicturePreference, [args.pictureId, args]);
} else {
$gameScreen.setPicturePreference(args.pictureId, args);
}
});
//=============================================================================
// Game_System
// ロード時にピクチャ関連メンバを初期化します。
//=============================================================================
const _Game_System_onAfterLoad = Game_System.prototype.onAfterLoad;
Game_System.prototype.onAfterLoad = function() {
_Game_System_onAfterLoad.apply(this, arguments);
$gameScreen.initPictureEventMap();
};
//=============================================================================
// Game_Screen
// ピクチャに対応するコモンイベント呼び出し用のID配列を追加定義します。
//=============================================================================
const _Game_Screen_initialize = Game_Screen.prototype.initialize;
Game_Screen.prototype.initialize = function() {
_Game_Screen_initialize.apply(this, arguments);
this.initPictureEventMap();
};
Game_Screen.prototype.initPictureEventMap = function() {
if (!this._pictureEventMap) {
this._pictureEventMap = new Game_PictureEventMap();
}
};
Game_Screen.prototype.addPictureEvent = function(pictureId, trigger, param) {
const realPictureId = this.realPictureId(pictureId);
this._pictureEventMap.append(realPictureId, trigger, param);
};
Game_Screen.prototype.removePictureEvent = function(pictureId, trigger = null) {
const realPictureId = this.realPictureId(pictureId);
if (trigger === null) {
this._pictureEventMap.removeById(realPictureId);
} else {
this._pictureEventMap.remove(realPictureId, trigger);
}
};
Game_Screen.prototype.findPictureEvent = function(pictureId, trigger) {
const realPictureId = this.realPictureId(pictureId);
return this._pictureEventMap.find(realPictureId, trigger);
};
Game_Screen.prototype.setPicturePreference = function(pictureId, param) {
const realPictureId = this.realPictureId(pictureId);
this._pictureEventMap.setPreference(realPictureId, param);
};
Game_Screen.prototype.getPicturePreference = function(pictureId) {
const realPictureId = this.realPictureId(pictureId);
return this._pictureEventMap.getPreference(realPictureId);
}
Game_Screen.prototype.disConvertPositionX = function(x) {
const unshiftX = x - this.zoomX() * (1 - this.zoomScale());
return Math.round(unshiftX / this.zoomScale());
};
Game_Screen.prototype.disConvertPositionY = function(y) {
const unshiftY = y - this.zoomY() * (1 - this.zoomScale());
return Math.round(unshiftY / this.zoomScale());
};
Game_Troop.prototype.setupDynamicCommon = Game_Map.prototype.setupDynamicCommon;
Game_Troop.prototype.setupDynamicInterpreter = Game_Map.prototype.setupDynamicInterpreter;
const _Game_Troop_setup = Game_Troop.prototype.setup;
Game_Troop.prototype.setup = function(troopId) {
_Game_Troop_setup.apply(this, arguments);
if (!this._dynamicEvents) {
this._dynamicEvents = [];
}
};
Game_Troop.prototype.updateDynamicEvents = function() {
this._dynamicEvents.forEach(interpreter => interpreter.update());
};
if (!Scene_Battle.prototype.hasOwnProperty('updateDynamicEvents')) {
const _Scene_Battle_updateBattleProcess = Scene_Battle.prototype.updateBattleProcess;
Scene_Battle.prototype.updateBattleProcess = function() {
_Scene_Battle_updateBattleProcess.apply(this, arguments);
this.updateDynamicEvents();
};
Scene_Battle.prototype.updateDynamicEvents = function() {
$gameTroop.updateDynamicEvents();
};
}
/**
* Game_PictureEventMap
* ピクチャイベントの登録状態を管理するマップです。
*/
class Game_PictureEventMap {
constructor() {
this._map = {}
this._preference = {};
}
append(pictureId, trigger, option) {
this._map[this.generateKey(pictureId, trigger)] = option;
}
find(pictureId, trigger) {
return this._map[this.generateKey(pictureId, trigger)];
}
remove(pictureId, trigger) {
delete this._map[this.generateKey(pictureId, trigger)];
}
removeById(pictureId) {
const regExp = new RegExp(`^${pictureId}\:`);
Object.keys(this._map).forEach(key => {
if (key.match(regExp)) {
delete this._map[key];
}
});
}
generateKey(pictureId, trigger) {
return `${pictureId}:${trigger}`;
}
setPreference(pictureId, option) {
this._preference[pictureId] = option;
}
getPreference(pictureId) {
return this._preference[pictureId];
}
}
window.Game_PictureEventMap = Game_PictureEventMap;
//=============================================================================
// Sprite_Picture
// ピクチャのタッチ状態からのコモンイベント呼び出し予約を追加定義します。
//=============================================================================
const _Sprite_Picture_initialize = Sprite_Picture.prototype.initialize;
Sprite_Picture.prototype.initialize = function(pictureId) {
_Sprite_Picture_initialize.call(this, pictureId);
this._touch = new PictureTouch(this, pictureId);
};
const _Sprite_update = Sprite_Picture.prototype.update;
Sprite_Picture.prototype.update = function() {
_Sprite_update.apply(this, arguments);
if (this.picture() && this._touch && !$gameSwitches.value(param.InvalidSwitchId)) {
this._touch.update();
}
};
const _Spriteset_Base_update = Spriteset_Base.prototype.update;
Spriteset_Base.prototype.update = function() {
_Spriteset_Base_update.apply(this, arguments);
TouchInput.suppressIfNeed();
};
/**
* PictureTouch
* ピクチャのタッチ状態を管理します。
*/
class PictureTouch {
constructor(picture, id) {
this._picture = picture;
this._pictureId = id;
this._handlers = [];
this._handlers[1] = () => this.isTouchEvent(TouchInput.isTriggered);
this._handlers[2] = () => this.isTouchEvent(TouchInput.isCancelled);
this._handlers[3] = () => this.isTouchEvent(TouchInput.isLongPressed);
this._handlers[4] = () => this._onMouse;
this._handlers[5] = () => this._outMouse;
this._handlers[6] = () => this.isTouchEvent(TouchInput.isReleased);
this._handlers[7] = () => this.isTouchEvent(TouchInput.isRepeated);
this._handlers[8] = () => this.isTouchEvent(TouchInput.isPressed);
this._handlers[9] = () => this.isTouchEvent(TouchInput.isWheelTriggered);
this._handlers[10] = () => this.isTouchEvent(TouchInput.isDoubleTriggered);
this._handlers[11] = () => this.isTouchEvent(TouchInput.isHovered);
this._handlers[12] = () => this.isTouchEvent(TouchInput.isMoved);
this._handlers[13] = () => this._flick;
this._onMouse = false;
this._outMouse = false;
this._wasOnMouse = false;
this._flick = false;
this._interpreter = new Game_Interpreter();
}
update() {
this.updateFlick();
this.updatePictureTouch();
this.updateMouseMove();
}
updatePictureTouch() {
if (SceneManager.isNextScene(Scene_Battle)) {
return;
}
this._handlers.forEach((handler, trigger) => {
if (this.isValidTrigger(handler, trigger)) {
const eventData = this.findPictureEvent(this._pictureId, trigger);
this.fireTouchEvent(eventData, trigger);
}
});
}
updateMouseMove() {
if (this.isOnPicturePos()) {
if (!this._wasOnMouse) {
this._outMouse = false;
this._onMouse = true;
this._wasOnMouse = true;
}
} else if (this._wasOnMouse) {
this._outMouse = true;
this._wasOnMouse = false;
this._onMouse = false;
}
}
updateFlick() {
this._flick = false;
const data = TouchInput.createFlickData();
if (!data) {
return;
}
if (data.distance >= param.FlickDistance && this.isOnPicturePos(data.start.x, data.start.y)) {
this._flick = true;
if (param.FlickTimeVariable) {
$gameVariables.setValue(param.FlickTimeVariable, data.time);
}
if (param.FlickDegreeVariable) {
$gameVariables.setValue(param.FlickDegreeVariable, data.degree);
}
}
}
isValidTrigger(handler, trigger) {
const eventData = this.findPictureEvent(this._pictureId, trigger);
return eventData && !$gameSwitches.value(eventData.invalidSwitchId) &&
handler && handler.call(this);
}
findPictureEvent(pictureId, trigger) {
return $gameScreen.findPictureEvent(pictureId, trigger);
}
fireTouchEvent(eventData, trigger) {
TouchInput.requestSuppress();
if (trigger === 3) {
TouchInput._pressedTime = -60;
}
if (trigger === 4) {
this._onMouse = false;
}
if (trigger === 5) {
this._outMouse = false;
}
this.applyTouchEvent(eventData);
}
applyTouchEvent(eventData) {
if (eventData.switchId) {
$gameSwitches.setValue(eventData.switchId, true);
}
if (eventData.variableId) {
this._interpreter.operateVariable(eventData.variableId, eventData.operationType, eventData.operand);
}
if (eventData.script) {
try {
eval(eventData.script);
} catch (e) {
console.error('Error Script:' + eventData.script);
PluginManagerEx.throwError(e.message, script);
}
}
if (eventData.buttonBind) {
Input.bindKeyState(eventData.buttonBind);
}
if (eventData.commonEventId) {
if ($gameParty.inBattle()) {
$gameTroop.setupDynamicCommon(eventData.commonEventId);
} else {
$gameMap.setupDynamicCommon(eventData.commonEventId);
}
}
if (param.PictureIdVariable > 0) {
$gameVariables.setValue(param.PictureIdVariable, this._pictureId);
}
}
isOnPicturePos(x = TouchInput.x, y = TouchInput.y) {
const pic = this._picture;
if (!pic.bitmap || !pic.bitmap.isReady() || pic.scale.x === 0 || pic.scale.y === 0) {
return false;
}
if (this.isTouchPosInFrameWindow(x, y)) {
return true;
}
if (pic.scale.x < 0.01 || pic.scale.y < 0.01) {
return false;
}
const dx = this.getTouchScreenX(x) - pic.x;
const dy = this.getTouchScreenY(y) - pic.y;
const sin = Math.sin(-pic.rotation);
const cos = Math.cos(-pic.rotation);
const bx = Math.floor(dx * cos + dy * -sin) / pic.scale.x + pic.anchor.x * pic.width;
const by = Math.floor(dx * sin + dy * cos) / pic.scale.y + pic.anchor.y * pic.height;
const preference = $gameScreen.getPicturePreference(this._pictureId);
if (pic._apngSprite || preference?.includeOpacityZero) {
return bx >= 0 && by >= 0 && bx <= pic.bitmap.width && by <= pic.bitmap.height;
}
return pic.bitmap.getAlphaPixel(bx, by) !== 0;
}
// for DTextPicture.js
isTouchPosInFrameWindow(x, y) {
if (!this._picture._frameWindow) {
return false;
}
const frame = this._picture._frameWindow;
const sx = this.getTouchScreenX(x);
const sy = this.getTouchScreenY(y);
return frame.x <= sx && frame.x + frame.width >= sx &&
frame.y <= sy && frame.y + frame.height >= sy;
}
isTouchEvent(triggerFunc) {
return triggerFunc.call(TouchInput) && this.isOnPicturePos();
}
getTouchScreenX(x) {
return $gameScreen.disConvertPositionX(x);
}
getTouchScreenY(y) {
return $gameScreen.disConvertPositionY(y);
}
}
//=============================================================================
// Input
// ピクチャクリックをキー入力に紐付けます。
//=============================================================================
Input._bindKeyStateFrames = new Map();
Input.bindKeyState = function(name) {
this._currentState[name] = true;
this._bindKeyStateFrames.set(name, 5);
};
const _Input_update = Input.update;
Input.update = function() {
_Input_update.apply(this, arguments);
this._updateBindKeyState();
};
Input._updateBindKeyState = function() {
this._bindKeyStateFrames.forEach(function(frame, keyName) {
frame--;
if (frame === 0 || !this._currentState[keyName]) {
this._currentState[keyName] = false;
this._bindKeyStateFrames.delete(keyName);
} else {
this._bindKeyStateFrames.set(keyName, frame);
}
}, this);
};
//=============================================================================
// TouchInput
// ホイールクリック、ダブルクリック等を実装
//=============================================================================
const _TouchInput__createNewState = TouchInput._createNewState;
TouchInput._createNewState = function() {
const state = _TouchInput__createNewState.apply(this, arguments);
state.wheelTriggered = false;
state.doubleTriggered = false;
return state;
};
TouchInput.requestSuppress = function() {
this._requestSuppress = true;
};
TouchInput.suppressIfNeed = function() {
if (this._requestSuppress) {
this._currentState = this._createNewState();
this._requestSuppress = false;
}
};
TouchInput.isWheelTriggered = function() {
return this._currentState.wheelTriggered;
};
TouchInput.isDoubleTriggered = function() {
return this._currentState.doubleTriggered;
};
TouchInput.createFlickData = function() {
if (!this.isPressed()) {
return null;
}
const data = {}
const dx = this._x - this._triggerX;
const dy = this._y - this._triggerY;
data.distance = Math.round(Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)));
data.time = this._pressedTime;
data.degree = Math.round((Math.atan2(dy, -dx) + Math.PI) * 180 / Math.PI);
data.start = new Point(this._triggerX, this._triggerY);
data.end = new Point(this._x, this._y);
return data;
};
const _TouchInput_onMiddleButtonDown = TouchInput._onMiddleButtonDown;
TouchInput._onMiddleButtonDown = function(event) {
_TouchInput_onMiddleButtonDown.apply(this, arguments);
const x = Graphics.pageToCanvasX(event.pageX);
const y = Graphics.pageToCanvasY(event.pageY);
if (Graphics.isInsideCanvas(x, y)) {
this._newState.wheelTriggered = true;
}
};
const _TouchInput_onTrigger = TouchInput._onTrigger;
TouchInput._onTrigger = function(x, y) {
const prevDate = this._date;
_TouchInput_onTrigger.apply(this, arguments);
if (this._date - prevDate < 300) {
this._newState.doubleTriggered = true;
}
};
})();