-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_WaveFilter.js
1023 lines (908 loc) · 34.7 KB
/
RS_WaveFilter.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
//================================================================
// RS_WaveFilter.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2016 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @target mv
* @plugindesc This plugin applies the wave effect to the all objects by using the Fragment Shader.
* @author biud436
* @url http://biud436.tistory.com
*
* @help
*
* =============================================================================
* Sprite
* =============================================================================
* The following properties applies the wave effect to Sprite.
* For Information, Refer to http://biud436.tistory.com/17
*
* - wave : The default value is false.
* - wave_amp : The default value is to 0.05
* - wave_length : The default value is to a maxHeight (deprecated)
* - wave_speed : The default value is to 0.25
* - wave_phase : The default value is to 360
*
* =============================================================================
* Picture
* =============================================================================
* This plugin command would activate the wave effect to your picture:
*
* PictureWave Start picture_id wave_speed wave_amp
* - picture_id : Specify the id of the game picture.
* - wave_speed : The available value is the number between 0 and 1.
* (The default value is to 0.25)
* - wave_amp : The available value is the number between 0 and 1.
* (The default value is to 0.05)
*
* This plugin command would deactivate the wave effect of your picture:
*
* PictureWave Stop picture_id
* - picture_id : Specify the id of the game picture.
*
* =============================================================================
* Tilemap
* =============================================================================
*
* The following plugin commands applies the wave effect to Tilemap.
* This plugin contains these six types the plugin commands.
*
* These plugin commands allow you to enable or disable the wave effect
*
* TilemapWave Enable
* TilemapWave Disable
*
* This plugin command allows you to set the speed of the wave effect.
* the x is a floating-point number between 0 and 2.
* Default value is to 2.0. But the fragment shader does not use this value.
*
* TilemapWave waveSpeed x
*
* This plugin command allows you to set the amplitude of the wave effect.
* the x is a floating-point number between 0 and 1.
* Default value is to 0.02
*
* TilemapWave waveFrequency x
*
* This plugin command allows you to set the UV speed of the wave effect.
* the x is a floating-point number between 0 and 1.
* Default value is to 0.25
*
* TilemapWave UVSpeed x
*
* =============================================================================
* Event Notetags
* =============================================================================
*
* Notetags :
*
* These note tags allow you to enable or disable the wave effect.
* <WAVE true>
* <WAVE false>
*
* This note tag allows you to set the amplitude of the wave effect.
* the x is a floating-point number between 0 and 1.
* the default value is to 0.02
*
* <WAVE_AMP x>
*
* This note tag allows you to set the speed of the wave effect.
* the x is a floating-point number between 0 and 1.
* the default value is to 0.25
*
* <WAVE_SPEED x>
*
* =============================================================================
* Battle Notetags
* =============================================================================
*
* These note tags allow you to set the wave effect.
* You have to put the note tags in the note area of the map properties.
*
* <BATTLEBACK_WAVE : x y>
*
* These values must replace by a real value such as 0.02
* - x : the x value is the same as a waveFrequency.
* - y : the y value is the same as a waveSpeed.
*
* For Example :
* <BATTLEBACK_WAVE : 0.02 0.25>
*
* When using Yanfly's Action Sequence Pack 1, you can enable its filter too.
* This function has the pointer of the Spriteset_Battle and easy to use.
*
* eval: $gameTemp.setBattleBackWaveEffect(cond, waveAmp, waveSpeed);
* - cond : Specify true or false whether the wave effect is used.
* - waveAmp : the default value is to 0.02
* - waveSpeed : the default value is to 0.25
*
* =============================================================================
* Timing
* =============================================================================
* if you want to fade-out or fade-in the properties of the wave effect applied to the picture,
* Let's call the following function.
*
* waveUtils.quadraticBezier(start, median, end, dt);
*
* dt stands for delta time, The delta time parameter is the elapsed time since the last frame.
* if you omit it, The wave filter will measure the elapsed time automatically
* and fill it (In fact, It will be filled with the current time value)
*
* To get started with implementing this, add this code just using the script command.
*
* var _s, _p, _e, _r;
* _s = new Point(0.0, 0.0);
* _p = new Point(0.07, 0.25);
* _e = new Point(0.0, 0.0);
* _r = waveUtils.quadraticBezier(_s, _p, _e);
* $gameScreen.startWave(1, _r.x, _r.y);
*
* The value of the wave speed is started with 0.0 and then increased until 0.07 and then decreased to 0.0.
* The value of the wave amplitude is also started with 0.0 and then increased until 0.25 and then decreased to 0.0.
*
* =============================================================================
* Change Log
* =============================================================================
* 2016.01.14 (v1.0.0) - First Release.
* 2016.01.16 (v1.0.1) - Added the function to remove the filter.
* 2016.01.18 (v1.1.0) - Added the plugin command.
* 2016.01.22 (v1.2.0) - Fixed the Save and Load bug
* 2016.02.16 (v1.3.0) - Fixed Bug (After the player came back to Menu, you had to set the wave effect again)
* 2016.02.26 (v1.3.1) - Fixed the default padding value of the sprite. (default value is to 512)
* 2016.03.03 (v1.3.2) - Added new Sprite Properties (wave_amp, wave_speed, wave_length, wave_phase)
* 2016.08.17 (v1.4.0) - Fixed the issue that is not working in RMMV 1.3.0 (This filter does not support for the time being in Tile-map)
* 2016.08.18 (v1.5.0) - Supports a wave filter in ShaderTilemap.
* 2016.10.20 (v1.5.1) - Fixed the issue that is not working in RMMV 1.3.2
* 2016.11.10 (v1.5.2) - Fixed the issue that is not working in Orange Overlay plugin.
* 2016.11.18 (v1.5.3) - Fixed an issue where the original tilemap is rendered when using Orange Overlay plugin.
* 2016.11.26 (v1.5.4) - Added certain code to remove the texture from memory.
* 2016.11.30 (v1.5.5) - Fixed the issue that has the black border in a filter area.
* 2017.12.10 (v1.5.6) - Added the plugin command called 'PictureWave' (it is tested on 1.6.0 beta version)
* 2018.04.12 (v1.5.7) - Fixed a cutting issue.
* 2018.04.13 (v1.5.7c) - Added the event note tags that can have the wave effect directly for an event graphic.
* 2018.04.15 (v1.5.7e) - Added a new feature that can apply the wave filter in the battle background images
* 2018.04.25 (v1.5.7f) - Fixed the note tag error in Battle Test.
* 2018.05.09 (v1.5.8) - Fixed the bug that is not working the wave filter for the battleback image.
* 2018.11.01 (v1.5.9) :
* - Fixed the issue that the wave filter is not working in the game picture.
* - Fixed the issue that the wave effect do a horizontal looping likes as Tiling Sprite.
* 2018.11.29 (v1.5.10) :
* - Fixed the bug that causes an error when calling Erase Event event command.
* 2019.02.24 (v1.5.11) :
* - Fixed an issue that is not loaded a save file that you saved before using this script.
* 2020.08.03 (v1.6.0) :
* - Performance optimization.
* 2021.10.27 (v1.6.1) :
* - added the warning message when the certain game picture is not displayed.
* =============================================================================
* Terms of Use
* =============================================================================
* Free for commercial and non-commercial use
*
*/
var Imported = Imported || {};
Imported.RS_WaveFilter = true;
var RS = RS || {};
RS.WaveConfig = RS.WaveConfig || {};
(function () {
"use strict";
const isFilterPIXI4 =
PIXI.VERSION >= "4.0.0" && Utils.RPGMAKER_VERSION >= "1.3.0";
if (!isFilterPIXI4) {
console.error("This version does not work on your project");
console.error(
"Please download the compatible version from the following link : "
);
console.error("https://github.com/biud436/MV/raw/MV/RS_WaveFilter.js");
return;
}
const isWebGL = PIXI.utils.isWebGLSupported();
const isUseCanvas = Utils.isOptionValid("canvas");
if (isUseCanvas || !isWebGL) {
console.error("This plugin does not support in your project");
return;
}
if (PIXI.VERSION >= "5.2.4") {
PIXI.filters.VoidFilter = PIXI.filters.AlphaFilter;
}
//----------------------------------------------------------------------------
// PIXI.WaveFilter
//
//
PIXI.WaveFilter = function () {
const vertexSrc = [
"attribute vec2 aVertexPosition;",
"attribute vec2 aTextureCoord;",
"uniform mat3 projectionMatrix;",
"varying vec2 vTextureCoord;",
"void main(void){",
" gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);",
" vTextureCoord = aTextureCoord;",
"}",
].join("\n");
const fragmentSrc = [
"precision mediump float;",
"varying vec2 vTextureCoord;",
"uniform float waveHeight;",
"uniform float waveFrequency;",
"uniform float waveTime;",
"uniform float wavePhase;",
"uniform float UVSpeed;",
"uniform vec4 filterArea;",
"uniform vec4 filterClamp;",
"uniform vec2 origin;",
"uniform sampler2D uSampler;",
"void main(void) {",
" float time = waveFrequency * sin( wavePhase * (waveTime - vTextureCoord.y / (waveHeight / filterArea.y)) );",
" vec2 vCoord = vec2(vTextureCoord.x + time * UVSpeed, vTextureCoord.y);",
" gl_FragColor = texture2D(uSampler, clamp(vCoord, filterClamp.xy, filterClamp.zw));",
"}",
].join("\n");
PIXI.Filter.call(this, vertexSrc, fragmentSrc);
this.padding = 0;
this.uniforms.waveHeight = 0.5;
this.uniforms.waveFrequency = 0.02;
this.uniforms.waveTime = 0.0;
this.uniforms.UVSpeed = 0.25;
this.uniforms.origin = new PIXI.Point(0, 0);
this.uniforms.wavePhase = 3.141592653589793 * 2;
this.enabled = true;
this.resolution = 1;
};
PIXI.WaveFilter.prototype = Object.create(PIXI.Filter.prototype);
PIXI.WaveFilter.prototype.constructor = PIXI.WaveFilter;
PIXI.WaveFilter.prototype.apply = function (
filterManager,
input,
output,
clear
) {
this.uniforms.waveHeight = input.sourceFrame.height / 4;
filterManager.applyFilter(this, input, output, clear);
};
Object.defineProperties(PIXI.WaveFilter.prototype, {
waveHeight: {
get: function () {
return this.uniforms.waveHeight;
},
set: function (value) {
this.uniforms.waveHeight = value;
},
},
waveSpeed: {
get: function () {
return this.uniforms.UVSpeed;
},
set: function (value) {
this.uniforms.UVSpeed = value;
},
},
waveFrequency: {
get: function () {
return this.uniforms.waveFrequency;
},
set: function (value) {
this.uniforms.waveFrequency = value;
},
},
UVSpeed: {
get: function () {
return this.uniforms.UVSpeed;
},
set: function (value) {
this.uniforms.UVSpeed = value;
},
},
waveTime: {
get: function () {
return this.uniforms.waveTime;
},
set: function (value) {
this.uniforms.waveTime = value;
},
},
wavePhase: {
get: function () {
return this.uniforms.wavePhase;
},
set: function (value) {
this.uniforms.wavePhase = (Math.PI / 180) * Number(value);
},
},
origin: {
get: function () {
return this.uniforms.origin;
},
set: function (value) {
this.uniforms.origin = value;
},
},
});
//============================================================================
// Sprite
//============================================================================
const alias_Sprite_initialize = Sprite.prototype.initialize;
Sprite.prototype.initialize = function (bitmap) {
alias_Sprite_initialize.call(this, bitmap);
this.initWithWaveFeatures();
};
Sprite.prototype.initWithWaveFeatures = function () {
this._waveTime = 0;
this._waveHeight = 0.5;
this._waveSpeed = 0.25;
this._waveFrequency = 0.02;
this._wavePhase = 360;
this._waveFilter = null;
this._wave = false;
this._isWaveDirty = false;
};
const alias_Sprite_update = Sprite.prototype.update;
Sprite.prototype.update = function () {
alias_Sprite_update.call(this);
this.waveUpdate();
};
Sprite.prototype.getWaveFrameTime = function () {
this._waveTime = (Date.now() % 10000) / 10000;
return this._waveTime;
};
Sprite.prototype.setWaveHeight = function (n) {
this._waveHeight = this.height;
};
Sprite.prototype.getWaveHeight = function () {
return this._waveHeight;
};
Sprite.prototype.waveUpdate = function () {
if (this._wave) {
this._waveFilter.waveTime = this.getWaveFrameTime();
this._waveFilter.waveHeight = this.getWaveHeight();
this._waveFilter.waveSpeed = this._waveSpeed;
this._waveFilter.waveFrequency = this._waveFrequency;
this._waveFilter.wavePhase = this._wavePhase;
this._waveFilter.origin.x = $gameMap.canvasToMapX(this.x);
this._waveFilter.origin.y = $gameMap.canvasToMapY(this.y);
}
};
Object.defineProperty(Sprite.prototype, "waveSpeed", {
get: function () {
return this._waveSpeed;
},
set: function (value) {
this._waveSpeed = value;
},
});
Object.defineProperty(Sprite.prototype, "waveFrequency", {
get: function () {
return this._waveFrequency;
},
set: function (value) {
this._waveFrequency = value;
},
});
Object.defineProperty(Sprite.prototype, "wave_amp", {
get: function () {
return this._waveFrequency;
},
set: function (value) {
this._waveFrequency = value;
},
});
Object.defineProperty(Sprite.prototype, "wave_length", {
get: function () {
return this._waveHeight;
},
set: function (value) {
this.setWaveHeight(value);
},
});
Object.defineProperty(Sprite.prototype, "wave_speed", {
get: function () {
return this._waveSpeed;
},
set: function (value) {
this._waveSpeed = value;
},
});
Object.defineProperty(Sprite.prototype, "wave_phase", {
get: function () {
return this._wavePhase;
},
set: function (value) {
this._wavePhase = value;
},
});
Object.defineProperty(Sprite.prototype, "wave", {
get: function () {
return this._wave;
},
set: function (value) {
this._wave = value;
this._isWaveDirty = true;
if (this._wave) {
if (!this._waveFilter) {
this._waveFilter = new PIXI.WaveFilter();
}
this.filterArea = new PIXI.Rectangle(
0,
0,
Graphics.boxWidth,
Graphics.boxHeight
);
this.filters = [this._waveFilter];
} else {
this.filters = [Sprite.voidFilter];
}
},
configurable: true,
});
//============================================================================
// TilingSprite
//============================================================================
const alias_TilingSprite_initialize = TilingSprite.prototype.initialize;
TilingSprite.prototype.initialize = function (bitmap) {
alias_TilingSprite_initialize.call(this, bitmap);
this.initWithWaveFeatures();
};
TilingSprite.prototype.initWithWaveFeatures = function () {
this._waveTime = 0;
this._waveHeight = 0.5;
this._waveSpeed = 0.25;
this._waveFrequency = 0.02;
this._wavePhase = 360;
this._waveFilter = null;
this._wave = false;
};
const alias_TilingSprite_update = TilingSprite.prototype.update;
TilingSprite.prototype.update = function () {
alias_TilingSprite_update.call(this);
this.waveUpdate();
};
TilingSprite.prototype.getWaveFrameTime = function () {
this._waveTime = (Date.now() % 10000) / 10000;
return this._waveTime;
};
TilingSprite.prototype.setWaveHeight = function (n) {
this._waveHeight = this.height;
};
TilingSprite.prototype.getWaveHeight = function () {
return this._waveHeight;
};
TilingSprite.prototype.waveUpdate = function () {
if (this._wave) {
this._waveFilter.waveTime = this.getWaveFrameTime();
this._waveFilter.waveHeight = this.getWaveHeight();
this._waveFilter.waveSpeed = this._waveSpeed;
this._waveFilter.waveFrequency = this._waveFrequency;
this._waveFilter.wavePhase = this._wavePhase;
}
};
Object.defineProperty(TilingSprite.prototype, "waveSpeed", {
get: function () {
return this._waveSpeed;
},
set: function (value) {
this._waveSpeed = value;
},
});
Object.defineProperty(TilingSprite.prototype, "waveFrequency", {
get: function () {
return this._waveFrequency;
},
set: function (value) {
this._waveFrequency = value;
},
});
Object.defineProperty(TilingSprite.prototype, "wave_amp", {
get: function () {
return this._waveFrequency;
},
set: function (value) {
this._waveFrequency = value;
},
});
Object.defineProperty(TilingSprite.prototype, "wave_length", {
get: function () {
return this._waveHeight;
},
set: function (value) {
this.setWaveHeight(value);
},
});
Object.defineProperty(TilingSprite.prototype, "wave_speed", {
get: function () {
return this._waveSpeed;
},
set: function (value) {
this._waveSpeed = value;
},
});
Object.defineProperty(TilingSprite.prototype, "wave_phase", {
get: function () {
return this._wavePhase;
},
set: function (value) {
this._wavePhase = value;
},
});
Object.defineProperty(TilingSprite.prototype, "wave", {
get: function () {
return this._wave;
},
set: function (value) {
this._wave = value;
if (this._wave) {
if (!this._waveFilter) {
this._waveFilter = new PIXI.WaveFilter();
}
this.filterArea = new PIXI.Rectangle(
0,
0,
Graphics.boxWidth,
Graphics.boxHeight
);
this.filters = [this._waveFilter];
} else {
this.filters = [new PIXI.filters.VoidFilter()];
}
},
configurable: true,
});
//============================================================================
// Sprite_Picture
//============================================================================
Sprite_Picture.prototype.updateWave = function () {
const picture = this.picture();
const isValidWave = picture.wave();
if (isValidWave !== this.wave) {
this.wave = isValidWave;
}
this.wave_speed = picture.waveSpeed();
this.wave_amp = picture.waveAmp();
};
const alias_Sprite_Picture_update = Sprite_Picture.prototype.update;
Sprite_Picture.prototype.update = function () {
alias_Sprite_Picture_update.call(this);
if (this.visible) {
this.updateWave();
}
};
//============================================================================
// Spriteset_Map
//============================================================================
var alias_Spriteset_Map_createLowerLayer =
Spriteset_Map.prototype.createLowerLayer;
Spriteset_Map.prototype.createLowerLayer = function () {
alias_Spriteset_Map_createLowerLayer.call(this);
this.overwriteWaveProperty();
};
Spriteset_Map.prototype.overwriteWaveProperty = function () {
if (!this._baseSprite) return false;
const self = this;
Object.defineProperty(this._baseSprite, "wave", {
get: function () {
return this._wave;
},
set: function (value) {
this._wave = value;
if (this._wave) {
if (!this._waveFilter)
this._waveFilter = new PIXI.WaveFilter();
this.filters = [this._waveFilter, self._toneFilter];
} else {
this.filters = [self._toneFilter];
}
},
});
};
const alias_Spriteset_Map_update = Spriteset_Map.prototype.update;
Spriteset_Map.prototype.update = function () {
alias_Spriteset_Map_update.call(this);
this.updateWaveFilter();
};
Spriteset_Map.prototype.updateWaveFilter = function () {
if ($gameSystem && $gameSystem.getWaveEnabled) {
this._baseSprite.wave = $gameSystem.getWaveEnabled() || false;
this._baseSprite.wave_amp = $gameSystem.getWaveFrequency() || 0.02;
this._baseSprite.wave_phase = $gameSystem.getWavePhase() || 360;
this._baseSprite.wave_speed = $gameSystem.getUVSpeed() || 0.25;
}
};
//============================================================================
// Spriteset_Battle
//============================================================================
var alias_Spriteset_Battle_createBattleback =
Spriteset_Battle.prototype.createBattleback;
Spriteset_Battle.prototype.createBattleback = function () {
alias_Spriteset_Battle_createBattleback.call(this);
this.initWithWaveEffect();
};
Spriteset_Battle.prototype.initWithWaveEffect = function () {
if (!$dataMap) return;
const note = $dataMap.note.split(/[\r\n]+/);
note.forEach((mapNote) => {
if ($dataMap.note.match(/<BATTLEBACK_WAVE[ ]:[ ]*(.*)[ ](.*)>/i)) {
this._initWaveFilter = true;
this.changeWaveEffect(true, RegExp.$1, RegExp.$2);
}
});
};
Spriteset_Battle.prototype.changeWaveEffect = function (cond, fre, spd) {
if (!this._initWaveFilter) return;
const backs = [this._back1Sprite, this._back2Sprite];
backs.forEach((back) => {
back.wave = cond;
back.waveFrequency = parseFloat(fre) || 0.02;
back.waveSpeed = parseFloat(spd) || 0.25;
}, this);
};
//============================================================================
// Game_Picture
//============================================================================
const alias_Game_Picture_initBasic = Game_Picture.prototype.initBasic;
Game_Picture.prototype.initBasic = function () {
alias_Game_Picture_initBasic.call(this);
this._wave = false;
this._waveSpeed = 0.25;
this._waveAmp = 0.02;
};
Game_Picture.prototype.wave = function () {
return this._wave;
};
Game_Picture.prototype.waveSpeed = function () {
return this._waveSpeed;
};
Game_Picture.prototype.waveAmp = function () {
return this._waveAmp;
};
Game_Picture.prototype.startWave = function (waveSpeed, waveAmp) {
this._wave = true;
this._waveSpeed = waveSpeed;
this._waveAmp = waveAmp;
};
Game_Picture.prototype.stopWave = function () {
this._wave = false;
};
//============================================================================
// Game_Screen
//============================================================================
Game_Screen.prototype.startWave = function (pictureId, waveSpeed, waveAmp) {
const picture = this.picture(pictureId);
if (!picture) {
console.info(
`Cannot find the game picture ${pictureId}. Note that you can set the picture before starting the wave effect`
);
return;
}
picture.startWave(waveSpeed, waveAmp);
};
Game_Screen.prototype.stopWave = function (pictureId) {
const picture = this.picture(pictureId);
if (picture) {
picture.stopWave();
}
};
//============================================================================
// Game_Temp
//============================================================================
/**
* In Action Sequence Pack 1, you can use this function.
* eval: $gameTemp.setBattleBackWaveEffect(cond, waveAmp, waveSpeed);
*/
Game_Temp.prototype.setBattleBackWaveEffect = function (cond, fre, spd) {
if (!$gameParty.inBattle()) return;
const container = SceneManager._scene._spriteset;
if (container) {
container.changeWaveEffect(cond, fre, spd);
}
};
//============================================================================
// Game_System
//============================================================================
const alias_Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () {
alias_Game_System_initialize.call(this);
this.initWaveProperty();
};
Game_System.prototype.initWaveProperty = function () {
this._waveProp = {
wave: false,
waveHeight: Graphics.boxHeight,
waveFrequency: 0.02,
waveTime: 0.0,
UVSpeed: 0.25,
wavePhase: 360,
};
};
Game_System.prototype.setWaveProperty = function (name, value) {
if (this._waveProp) {
this._waveProp[name] = value;
return this._waveProp[name];
}
return 0.0;
};
Game_System.prototype.getWaveEnabled = function () {
if (!this._waveProp) this.initWaveProperty();
return this._waveProp.wave;
};
Game_System.prototype.getWaveHeight = function () {
if (!this._waveProp) this.initWaveProperty();
return this._waveProp.waveHeight;
};
Game_System.prototype.getWaveFrequency = function () {
if (!this._waveProp) this.initWaveProperty();
return this._waveProp.waveFrequency;
};
Game_System.prototype.getWaveTime = function () {
if (!this._waveProp) this.initWaveProperty();
return this._waveProp.waveTime;
};
Game_System.prototype.getUVSpeed = function () {
if (!this._waveProp) this.initWaveProperty();
return this._waveProp.UVSpeed;
};
Game_System.prototype.getWavePhase = function () {
if (!this._waveProp) this.initWaveProperty();
return this._waveProp.wavePhase;
};
//============================================================================
// Game_CharacterBase
//============================================================================
const alias_Game_CharacterBase_initMembers =
Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.prototype.initMembers = function () {
alias_Game_CharacterBase_initMembers.call(this);
this._wave = false;
this._waveFrequency = 0.02;
this._waveSpeed = 0.25;
};
Game_CharacterBase.prototype.setWave = function (toggle) {
this._wave = toggle;
};
Game_CharacterBase.prototype.setWaveFrequency = function (value) {
this._waveFrequency = value;
};
Game_CharacterBase.prototype.setWaveSpeed = function (value) {
this._waveSpeed = value;
};
Game_CharacterBase.prototype.wave = function () {
return this._wave;
};
Game_CharacterBase.prototype.waveFrequency = function () {
return this._waveFrequency || 0.02;
};
Game_CharacterBase.prototype.waveSpeed = function () {
return this._waveSpeed || 0.25;
};
//============================================================================
// Sprite_Character
//============================================================================
const alias_Sprite_Character_updatePosition =
Sprite_Character.prototype.updatePosition;
Sprite_Character.prototype.updatePosition = function () {
alias_Sprite_Character_updatePosition.call(this);
if (!this._character) return;
if (!(this._character instanceof Game_Event)) return;
const isValidWave = this._character.wave();
if (this.wave !== isValidWave) this.wave = isValidWave;
if (this.wave) {
this.waveFrequency = this._character.waveFrequency();
this.waveSpeed = this._character.waveSpeed();
}
};
//============================================================================
// Game_Map
//============================================================================
const alias_Game_Event_initMembers = Game_Event.prototype.initMembers;
Game_Event.prototype.initMembers = function () {
alias_Game_Event_initMembers.call(this);
this._lastPageIndex = -2;
};
Game_Event.prototype.updateWaveEffect = function () {
if (this._pageIndex === this._lastPageIndex) return;
if (!this.page()) return false;
if (this.findProperPageIndex() < 0) return false;
if (this._trigger > 3) return false;
this.list().forEach((list) => {
const code = list.code;
const parameters = list.parameters;
if ([108, 408].includes(code)) {
if (parameters[0].match(/<(?:WAVE)[ ](.*)>/i)) {
this.setWave(Boolean(RegExp.$1 == "true"));
}
if (parameters[0].match(/<(?:WAVE_AMP)[ ](.*)>/i)) {
this.setWaveFrequency(parseFloat(RegExp.$1) || 0.02);
}
if (parameters[0].match(/<(?:WAVE_SPEED)[ ](.*)>/i)) {
this.setWaveSpeed(parseFloat(RegExp.$1) || 0.25);
}
}
});
this._lastPageIndex = this._pageIndex;
};
const alias_Game_Event_refresh = Game_Event.prototype.refresh;
Game_Event.prototype.refresh = function () {
alias_Game_Event_refresh.call(this);
this.updateWaveEffect();
};
//============================================================================
// Wave Utils
//============================================================================
window.waveUtils = {};
/**
* @example
var _s, _e, _r;
_s = new Point(0.0, 0.0);
_e = new Point(0.07, 0.25);
_r = waveUtils.mix(_s, _e);
$gameScreen.startWave(1, _r.x, _r.y);
*/
waveUtils.mix = function (vec1, vec2, t) {
let vec = new Point(0, 0);
if (!t) t = (Date.now() % 10000) / 10000;
vec.x = vec1.x + t * (vec2.x - vec1.x);
vec.y = vec1.x + t * (vec2.y - vec1.y);
return vec;
};
/**
* @example
var _s, _p, _e, _r;
_s = new Point(0.0, 0.0);
_p = new Point(0.07, 0.25);
_e = new Point(0.0, 0.0);
_r = waveUtils.quadraticBezier(_s, _p, _e);
$gameScreen.startWave(1, _r.x, _r.y);
*/
waveUtils.quadraticBezier = function (vec1, vec2, vec3, t) {
let d, e, p;
if (!t) t = (Date.now() % 10000) / 10000;
d = waveUtils.mix(vec1, vec2, t);
e = waveUtils.mix(vec2, vec3, t);
p = waveUtils.mix(d, e, t);
return p;
};
//============================================================================
// Game_Interpreter
//============================================================================
const alias_Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
alias_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === "Tilemap_Wave" || command === "TilemapWave") {
switch (args[0]) {
case "Enable":
$gameSystem.setWaveProperty("wave", true);
break;
case "Disable":
$gameSystem.setWaveProperty("wave", false);
break;
case "waveSpeed":
$gameSystem.setWaveProperty("waveSpeed", Number(args[1]));
break;
case "waveFrequency":
$gameSystem.setWaveProperty(
"waveFrequency",