-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFormationSystem.js
2126 lines (1779 loc) · 65.6 KB
/
FormationSystem.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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*:
@target MZ
@plugindesc formation system v1.3.0
@author unagi ootoro
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/FormationSystem.js
@help
It is a plugin that introduces the formation system.
【Overview】
In this plugin, some formations are stocked in advance from the menu screen,
You can select and apply one of the formations stocked during the battle.
You can change the formation at any time during the battle.
【Method of operation】
・ Setting the formation to be used during battle
By opening the "Tactics" menu from the menu screen,
Customize the formation slots available during battle.
Of the formations in the slot, the formation with the E mark is the formation currently adopted.
The formation you are currently using can be changed to another formation by pressing the Shift key.
・ Change of formation during battle
During combat, a "tactical" command is added to the party command.
When this command is selected, the formations set in the slot are selected.
You can change the formation to apply.
【How to use】
■ Creation of formation
Edit the plugin parameter "Formation Datas" to create a formation.
In formation setting, there are two ways to set the position of each actor.
・ Enter the coordinates using a mathematical formula
It is a method to specify the X coordinate and the Y coordinate. You can use mathematical formulas for the coordinates.
Also, if you use the word index in the formula, the corresponding actor will start from the beginning.
It will be replaced with a numerical value indicating the number. (It will be 0, 1, 2 ... from the beginning)
When using this method, specify 0 for the map ID of the plug-in parameter.
-Read coordinates from the map
It is a method to regard the event placed on the map as the position of each actor.
Create an event on the target map and enter the order from the beginning of the corresponding actor in the memo column.
(Example) When setting the position of the first actor
Create an event and put it in the memo field
0
Described as.
The created formations are assigned IDs in the form of (0, 1, 2, ...) in the order in which the plug-in parameters are registered.
Of these, the formation with ID0 is used as the default formation.
■ Setting additional effects for formations
Additional effects for formations are created by states.
Specify the state to apply for each position of each actor in the formation,
Set the content of the additional effect to the state.
■ Invalid formation
You can create states that negate the additional effects of formations.
In the memo field of the state
<FormationInvalid>
If there is even one actor in that state,
The additional effects of the formation are negated.
■ About the acquisition of formation
You can learn formations by using the plugin parameter "LearnFormation".
On the contrary, you can forget the formation by using "Forget Formation".
【License】
This plugin is available under the terms of the MIT license.
@param FormationDatas
@text formation data
@type struct<FormationData>[]
@default []
@desc
Set formation data.
@param NumEquipFormationSlots
@text Number of formation slots
@type number
@default 3
@desc
Specifies the number of formations that can be set.
@param EnabledBattleFormationChange
@text Enable formation change during battle
@on valid
@off invalid
@type boolean
@default true
@desc
Set to true to enable formation changes during battle.
@param UseBattleBackgroundInMenu
@text Use battle background in menu
@on valid
@off invalid
@type boolean
@default true
@desc
If set to true, the battle background will be displayed on the formation edit screen of the menu.
@param EnabledFormationMenuSwitchId
@text formation menu display switch
@type switch
@default 0
@desc
Specify the switch to switch whether to display the formation menu.
@param ChangeFormationSlotSe
@text Formation slot change SE
@type struct<SE>
@default {"FileName": "Decision5", "Volume": "90", "Pitch": "100", "Pan": "0"}
@desc
Specifies the SE to play when changing formation slots.
@param ChangeCurrentFormationSe
@text Formation change SE
@type struct<SE>
@default {"FileName": "Decision5", "Volume": "90", "Pitch": "100", "Pan": "0"}
@desc
Specifies the SE to play when the formation used is changed.
@param MenuFormationXOfs
@text Menu formation X coordinate offset
@type number
@default 0
@desc
Specifies the X coordinate offset to the start of the formation in the menu.
@param MenuFormationYOfs
@text Menu formation Y coordinate offset
@type number
@default 80
@desc
Specifies the Y coordinate offset to the formation start in the menu.
@param BattleFormationXOfs
@text Combat formation X coordinate offset
@type number
@default 360
@desc
Specifies the X coordinate offset to the starting point of the formation in battle.
@param BattleFormationYOfs
@text Combat formation Y coordinate offset
@type number
@default 100
@desc
Specifies the Y coordinate offset to the start of the formation in battle.
@param WindowSize
@text Window size
@type struct<WindowSize>
@default {"FormationListHeight":"216"}
@desc
Set the size of various windows.
@param ShiftButton
@text shift button
@type struct <ShiftButton>
@default {"ButtonSetX": "8", "ButtonSetW": "2"}
@desc
Set the shift button information.
@param Text
@text Display text
@type struct<Text>
@default {"MenuFormationText":"tactics","EquipFormationList":"Available formations","HasFormationList":"All formations","EmptySlot":"------"}
@desc
Sets the text used in the game.
@command StartFormationScene
@text Formation scene start
@desc Starts the formation scene.
@command LearnFormation
@text Formation acquisition
@desc Learn formations.
@arg FormationId
@text Formation ID
@type number
@desc Specify the formation ID to learn.
@arg VariableId
@text variable ID
@type variable
@desc Specify the variable ID that stores the formation ID to be learned.
@command ForgetFormation
@text formation forgetting
@desc Forget the formation.
@arg FormationId
@text Formation ID
@type number
@default 0
@desc Specify the formation ID to forget.
@arg VariableId
@text variable ID
@type variable
@default 0
@desc Specifies the variable ID that stores the formation ID to forget.
@command ChangeEquipFormations
@text Equipment formation change
@desc Change the formation you are equipped with.
@arg EquipSlotIndex
@text Equipment formation slot
@type number
@desc Specifies the formation slot to change. If -1 is specified, the equipment formation of the slot will be removed.
@arg HasFormationId
@text Formation ID in possession
@type number
@desc Specify the formation ID you have.
@command ChangeFormation
@text Current formation change
@desc Change the current formation.
@arg SlotIndex
@text Equipment formation slot
@type number
@desc Specifies the formation slot to change.
*/
/*~struct~FormationData:
@param Name
@text formation name
@type string
@desc
Specify the formation name.
@param IconIndex
@text icon
@type number
@desc
Specify the formation icon.
@param Description
@text Formation description
@type multiline_string
@desc
Specifies the formation description.
@param Positions
@text position
@type struct<Position>[]
@desc
Specify the position of each actor.
@param MapId
@text map ID
@type number
@desc
Specifies the map ID to read the position.
*/
/*~struct~Position:
@param X
@text X coordinates
@type string
@desc
Specifies the X coordinate of the actor.
@param Y
@text Y coordinates
@type string
@desc
Specifies the Y coordinate of the actor.
@param StateId
@text state ID
@type state
@desc
Specify the state ID to be assigned when applying the formation.
*/
/*~struct~SE:
@param FileName
@text SE filename
@type file
@dir audio / se
@default Decision5
@desc
Specify the file name of the SE to play.
@param Volume
@text SE volume
@type number
@default 90
@desc
Specify the volume of SE to be played.
@param Pitch
@text SE pitch
@type number
@default 100
@desc
Specify the pitch of the SE to play.
@param Pan
@text SE phase
@type number
@default 0
@desc
Specify the pan of the SE to play.
*/
/*~struct~WindowSize:
@param FormationListHeight
@text Formation list height
@type number
@default 216
@desc
Specifies the vertical width of the formation list window.
*/
/*~struct~ShiftButton:
@param ButtonSetX
@text button set X
@type string
@default 8
@desc
Specifies the X position of the shift button on the button set. (Unit: 48px)
@param ButtonSetW
@text button set W
@type string
@default 2
@desc
Specifies the width of the shift button on the button set. (Unit: 48px)
*/
/*~struct~Text:
@param MenuFormationText
@text Menu display text
@type string
@default tactics
@desc
Specifies the name of the formation change to add to the menu and battle.
@param EquipFormationList
@text Available formations
@type string
@default Available formations
@desc
Specifies the name of the formation that can be used.
@param HasFormationList
@text All formations
@type string
@default All formations
@desc
Specify the names of all formations.
@param EmptySlot
@text empty slot
@type string
@default ------
@desc
Specifies the text to display in the empty slot.
*/
/*:ja
@target MZ
@plugindesc 陣形システム v1.3.0
@author うなぎおおとろ
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/FormationSystem.js
@help
陣形システムを導入するプラグインです。
【概要】
このプラグインでは、メニュー画面からいくつかの陣形を事前にストックしておいて、
戦闘中にストックしておいた陣形の中から一つを選んで適用することができます。
陣形の変更は、戦闘中のどのタイミングでも行うことができます。
【操作方法】
・戦闘中に使用する陣形の設定
メニュー画面から「戦術」メニューを開くことで、
戦闘中に使用可能な陣形のスロットをカスタマイズします。
スロットにある陣形のうち、Eマークがついている陣形は、現在採用している陣形になります。
現在採用している陣形は、Shiftキーを押すことで別の陣形に変更することができます。
・戦闘中における陣形の変更
戦闘中では、パーティコマンドに「戦術」コマンドが追加されます。
このコマンドを選択すると、スロットに設定されている陣形の中から
適用する陣形を変更することができます。
【使用方法】
■陣形の作成
プラグインパラメータ「FormationDatas」を編集して、陣形を作成します。
陣形の設定では各アクターのポジションの設定には、次の二つの方法があります。
・数式で座標を入力する
X座標とY座標を指定する方法です。座標には数式を使うことができます。
また、数式内でindexというワードを使用すると、該当するアクターが先頭から
何番目かを表す数値に置き換えられます。(先頭から0, 1, 2...という値になります)
この方法を使用する場合、プラグインパラメータのマップIDには0を指定してください。
・マップから座標を読み込む
マップに配置されたイベントを各アクターのポジションと見立てる方法です。
対象のマップにイベントを作成し、メモ欄に該当するアクターの先頭からの順番を記載します。
(例)先頭のアクターのポジションを設定する場合
イベントを作成し、メモ欄に
0
と記載します。
作成した陣形は、プラグインパラメータの登録順に(0, 1, 2, ...)という形でIDが振られます。
このうち、ID0の陣形についてはデフォルトの陣形として使用されます。
陣形のポジションは戦闘に参加するアクターの数だけ用意する必要があります。
例えば4人戦闘に参加させる場合、4人分のポジションの登録が必要となります。
なお、1~3人が戦闘に参加するといった場合は3人分のポジションの登録が必要です。
■陣形の追加効果の設定
陣形の追加効果はステートによって作成します。
陣形の各アクターのポジションごとに適用するステートを指定し、
ステートに追加効果の内容を設定します。
■陣形無効
陣形の追加効果を無効化するステートを作成することができます。
ステートのメモ欄に
<FormationInvalid>
と記載すると、そのステートにかかったアクターが一人でもいる場合、
陣形の追加効果が無効化されます。
■陣形の習得について
プラグインパラメータ「LearnFormation」を使用することで、陣形を習得することができます。
逆に「ForgetFormation」を使用することで、陣形を忘れることができます。
【ライセンス】
このプラグインは、MITライセンスの条件の下で利用可能です。
@param FormationDatas
@text 陣形データ
@type struct<FormationData>[]
@default []
@desc
陣形データを設定します。
@param NumEquipFormationSlots
@text 陣形スロット数
@type number
@default 3
@desc
セットできる陣形数を指定します。
@param EnabledBattleFormationChange
@text 戦闘中の陣形変更有効化
@on 有効
@off 無効
@type boolean
@default true
@desc
trueを設定すると、戦闘中の陣形変更を有効化します。
@param UseBattleBackgroundInMenu
@text メニューで戦闘背景を使用
@on 有効
@off 無効
@type boolean
@default true
@desc
trueを設定すると、メニューの陣形編集画面で戦闘背景を表示します。
@param EnabledFormationMenuSwitchId
@text 陣形メニュー表示スイッチ
@type switch
@default 0
@desc
陣形メニュー表示有無を切り替えるスイッチを指定します。
@param ChangeFormationSlotSe
@text 陣形スロット変更SE
@type struct<SE>
@default {"FileName":"Decision5","Volume":"90","Pitch":"100","Pan":"0"}
@desc
陣形のスロットを変更したときに再生するSEを指定します。
@param ChangeCurrentFormationSe
@text 使用陣形変更SE
@type struct<SE>
@default {"FileName":"Decision5","Volume":"90","Pitch":"100","Pan":"0"}
@desc
使用する陣形を変更したときに再生するSEを指定します。
@param MenuFormationXOfs
@text メニュー陣形X座標オフセット
@type number
@default 0
@desc
メニューでの陣形の開始地点までのX座標オフセットを指定します。
@param MenuFormationYOfs
@text メニュー陣形Y座標オフセット
@type number
@default 80
@desc
メニューでの陣形の開始地点までのY座標オフセットを指定します。
@param BattleFormationXOfs
@text 戦闘陣形X座標オフセット
@type number
@default 360
@desc
戦闘での陣形の開始地点までのX座標オフセットを指定します。
@param BattleFormationYOfs
@text 戦闘陣形Y座標オフセット
@type number
@default 100
@desc
戦闘での陣形の開始地点までのY座標オフセットを指定します。
@param WindowSize
@text ウィンドウサイズ
@type struct<WindowSize>
@default {"FormationListHeight":"216"}
@desc
各種ウィンドウのサイズを設定します。
@param ShiftButton
@text シフトボタン
@type struct<ShiftButton>
@default {"ButtonSetX":"8","ButtonSetW":"2"}
@desc
シフトボタンの情報設定します。
@param Text
@text 表示テキスト
@type struct<Text>
@default {"MenuFormationText":"戦術","EquipFormationList":"使用可能な陣形","HasFormationList":"全ての陣形","EmptySlot":"------"}
@desc
ゲーム中で使用されるテキストを設定します。
@command StartFormationScene
@text 陣形シーン開始
@desc 陣形シーンを開始します。
@command LearnFormation
@text 陣形習得
@desc 陣形を習得します。
@arg FormationId
@text 陣形ID
@type number
@desc 習得する陣形IDを指定します。
@arg VariableId
@text 変数ID
@type variable
@desc 習得する陣形IDが格納された変数IDを指定します。
@command ForgetFormation
@text 陣形忘却
@desc 陣形を忘れます。
@arg FormationId
@text 陣形ID
@type number
@default 0
@desc 忘れる陣形IDを指定します。
@arg VariableId
@text 変数ID
@type variable
@default 0
@desc 忘れる陣形IDが格納された変数IDを指定します。
@command ChangeEquipFormations
@text 装備陣形変更
@desc 装備中の陣形を変更します。
@arg EquipSlotIndex
@text 装備陣形スロット
@type number
@desc 変更する陣形スロットを指定します。-1を指定した場合、スロットの装備陣形を外します。
@arg HasFormationId
@text 所持している陣形ID
@type number
@desc 所持している陣形IDを指定します。
@command ChangeFormation
@text 現在陣形変更
@desc 現在の陣形を変更します。
@arg SlotIndex
@text 装備陣形スロット
@type number
@desc 変更する陣形のスロットを指定します。
*/
/*~struct~FormationData:ja
@param Name
@text 陣形名
@type string
@desc
陣形名を指定します。
@param IconIndex
@text アイコン
@type number
@desc
陣形のアイコンを指定します。
@param Description
@text 陣形の説明
@type multiline_string
@desc
陣形の説明を指定します。
@param Positions
@text ポジション
@type struct<Position>[]
@desc
各アクターのポジションを指定します。
@param MapId
@text マップID
@type number
@desc
ポジションを読み込むマップIDを指定します。
*/
/*~struct~Position:ja
@param X
@text X座標
@type string
@desc
アクターのX座標を指定します。
@param Y
@text Y座標
@type string
@desc
アクターのY座標を指定します。
@param StateId
@text ステートID
@type state
@desc
陣形適用時に付与するステートIDを指定します。
*/
/*~struct~SE:ja
@param FileName
@text SEファイル名
@type file
@dir audio/se
@default Decision5
@desc
再生するSEのファイル名を指定します。
@param Volume
@text SE音量
@type number
@default 90
@desc
再生するSEのvolumeを指定します。
@param Pitch
@text SEピッチ
@type number
@default 100
@desc
再生するSEのpitchを指定します。
@param Pan
@text SE位相
@type number
@default 0
@desc
再生するSEのpanを指定します。
*/
/*~struct~WindowSize:ja
@param FormationListHeight
@text 陣形リスト縦幅
@type number
@default 216
@desc
陣形リストウィンドウの縦幅を指定します。
*/
/*~struct~ShiftButton:ja
@param ButtonSetX
@text ボタンセットX
@type string
@default 8
@desc
シフトボタンのボタンセット上でのX位置を指定します。(単位: 48px)
@param ButtonSetW
@text ボタンセットW
@type string
@default 2
@desc
シフトボタンのボタンセット上での横幅を指定します。(単位: 48px)
*/
/*~struct~Text:ja
@param MenuFormationText
@text メニュー表示テキスト
@type string
@default 戦術
@desc
メニューと戦闘に追加する陣形変更の名称を指定します。
@param EquipFormationList
@text 使用可能な陣形
@type string
@default 使用可能な陣形
@desc
使用可能な陣形の名称を指定します。
@param HasFormationList
@text 全ての陣形
@type string
@default 全ての陣形
@desc
全ての陣形の名称を指定します。
@param EmptySlot
@text 空スロット
@type string
@default ------
@desc
空スロットに表示するテキストを指定します。
*/
const FormationSystemPluginName = document.currentScript.src.match(/^.*\/(.+)\.js$/)[1];
let $dataFormations = null;
const FormationSystemClassAlias = (() => {
"use strict";
const MapLoaders = {};
// Common library.
class HttpResponse {
constructor(result, xhr, event) {
this._result = result;
this._xhr = xhr;
this._event = event;
}
result() {
return this._result;
}
status() {
return this._xhr.status;
}
response() {
return this._xhr.response;
}
}
class HttpRequest {
static get(path, opt = { mimeType: null }, responseCallback) {
const req = new HttpRequest(path, "GET", opt, responseCallback);
req.send();
return req;
}
static post(path, params, opt = { mimeType: null }, responseCallback) {
const req = new HttpRequest(path, "POST", opt, responseCallback);
req.send(params);
return req;
}
constructor(path, method, opt = { mimeType: null }, responseCallback) {
this._path = path;
this._method = method;
this._responseCallback = responseCallback;
this._mimeType = opt.mimeType;
}
send(params = null) {
const xhr = new XMLHttpRequest();
xhr.open(this._method, this._path);
if (this._mimeType) xhr.overrideMimeType(this._mimeType);
let json = null;
if (params) json = JSON.stringify(params);
xhr.addEventListener("load", (e) => {
this._responseCallback(new HttpResponse("load", xhr, e));
});
xhr.addEventListener("error", (e) => {
this._responseCallback(new HttpResponse("error", xhr, e));
});
xhr.send(json);
}
}
class PluginParamsParser {
static parse(params, typeData, predictEnable = true) {
return new PluginParamsParser(predictEnable).parse(params, typeData);
}
constructor(predictEnable = true) {
this._predictEnable = predictEnable;
}
parse(params, typeData, loopCount = 0) {
if (++loopCount > 255) throw new Error("endless loop error");
const result = {};
for (const name in typeData) {
if (params[name] === "" || params[name] === undefined) {
result[name] = null;
} else {
result[name] = this.convertParam(params[name], typeData[name], loopCount);
}
}
if (!this._predictEnable) return result;
if (typeof params === "object" && !(params instanceof Array)) {
for (const name in params) {
if (result[name]) continue;
const param = params[name];
const type = this.predict(param);
result[name] = this.convertParam(param, type, loopCount);
}
}
return result;
}
convertParam(param, type, loopCount) {
if (typeof type === "string") {
return this.cast(param, type);
} else if (typeof type === "object" && type instanceof Array) {
const aryParam = JSON.parse(param);
if (type[0] === "string") {
return aryParam.map(strParam => this.cast(strParam, type[0]));
} else {
return aryParam.map(strParam => this.parse(JSON.parse(strParam), type[0]), loopCount);
}
} else if (typeof type === "object") {
return this.parse(JSON.parse(param), type, loopCount);
} else {
throw new Error(`${type} is not string or object`);
}
}
cast(param, type) {
switch(type) {
case "any":
if (!this._predictEnable) throw new Error("Predict mode is disable");
return this.cast(param, this.predict(param));
case "string":
return param;
case "number":
if (param.match(/^\-?\d+\.\d+$/)) return parseFloat(param);
return parseInt(param);
case "boolean":
return param === "true";
default:
throw new Error(`Unknow type: ${type}`);
}
}
predict(param) {
if (param.match(/^\-?\d+$/) || param.match(/^\-?\d+\.\d+$/)) {
return "number";
} else if (param === "true" || param === "false") {
return "boolean";
} else {
return "string";
}
}
}
class SpriteMover {
constructor(sprite, moveSpeed) {
this._moveSpeed = moveSpeed;
this._sprite = sprite;
this._targetX = null;
this._targetY = null;
this._moving = false;
}
get moveSpeed() { return this._moveSpeed }
set moveSpeed(_moveSpeed) { this._moveSpeed = _moveSpeed; }
update() {
if (this._moving) this.updateMove();
}
updateMove() {
const sprite = this._sprite;
const oy = this._targetY - sprite.y;
const ox = this._targetX - sprite.x;
const rad = Math.atan2(oy, ox);
const disX = this._moveSpeed * Math.cos(rad);
const disY = this._moveSpeed * Math.sin(rad);
sprite.x += disX;
sprite.y += disY;
if ((disX < 0 && sprite.x + disX < this._targetX) || (disX > 0 && sprite.x + disX > this._targetX)) sprite.x = this._targetX;
if ((disY < 0 && sprite.y + disY < this._targetY) || (disY > 0 && sprite.y + disY > this._targetY)) sprite.y = this._targetY;
if (sprite.x === this._targetX && sprite.y === this._targetY) this._moving = false;
}
isMoving() {
return this._moving;
}
isBusy() {
return this.isMoving();
}
startMove(targetPoint) {
this._targetX = targetPoint.x;
this._targetY = targetPoint.y;
this._moving = true;
}
fastMove(targetPoint) {
this._sprite.x = targetPoint.x;
this._sprite.y = targetPoint.y;
this._moving = false;
}
forceEndMove() {
this._sprite.x = this._targetX;
this._sprite.y = this._targetY;
this._moving = false;
}
}
class Window_DataList extends Window_Selectable {
initialize(rect) {
super.initialize(rect);
this.refresh();
this.select(0);
this.activate();
}
maxItems() {
return this._list.length;
}
clearCommandList() {
this._list = [];
}
makeCommandList() {
}
addData(data) {
this._list.push(data);
}
currentData() {
return this.index() >= 0 ? this.dataAt(this.index()) : null;
}
dataAt(index) {
return this._list[index];
}
drawItem(index) {
const rect = this.itemLineRect(index);
const align = this.itemTextAlign();
this.resetTextColor();
this.drawText(this.dataAt(index).toString(), rect.x, rect.y, rect.width, align);