This repository has been archived by the owner on Jul 9, 2023. It is now read-only.
forked from ImaginaryVillain/community_lights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Community_Lighting.js
3681 lines (3442 loc) · 161 KB
/
Community_Lighting.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
//=============================================================================
// Community Plugins - Lighting system
// Community_Lighting.js
/*=============================================================================
Forked from Terrax Lighting
=============================================================================*/
if (typeof require !== "undefined" && typeof module != "undefined") {
var {
Game_Player,
Game_Interpreter,
Game_Event,
Game_Variables,
Game_Map,
} = require("../rpg_objects");
var {
PluginManager,
ConfigManager,
} = require("../rpg_managers");
var { Window_Selectable, Window_Options } = require("../rpg_windows");
var { Spriteset_Map, Spriteset_Battle } = require("../rpg_sprites");
var { Scene_Map } = require("../rpg_scenes");
var { Bitmap, Tilemap, ShaderTilemap } = require("../rpg_core");
}
var Community = Community || {};
Community.Lighting = Community.Lighting || {};
Community.Lighting.name = "Community_Lighting";
Community.Lighting.parameters = PluginManager.parameters(Community.Lighting.name);
Community.Lighting.version = 5.0;
var Imported = Imported || {};
Imported[Community.Lighting.name] = true;
/*:
* @plugindesc v4.6 Creates an extra layer that darkens a map and adds lightsources! Released under the MIT license!
* @author Terrax, iVillain, Aesica, Eliaquim, Alexandre, Nekohime1989
*
* @param ---General Settings---
* @default
*
* @param Options Menu Entry
* @parent ---General Settings---
* @desc Adds an option to disable this plugin's lighting effects to the options menu (leave blank to omit)
* @default Lighting Effects
*
* @param Use smoother lights
* @parent ---General Settings---
* @desc Instead of looking like spotlights, the lights get blended further. Does not work on old browsers.
* @type boolean
* @default false
*
* @param Light event required
* @parent ---General Settings---
* @desc At least one light event on the current is needed to make the plugin active (as in original TerraxLighting)
* @type boolean
* @default false
*
* @param Triangular flashlight
* @parent ---General Settings---
* @desc Alternative triangular flashlight beam
* @type boolean
* @default false
*
* @param Shift lights with events
* @parent ---General Settings---
* @desc Should a light be shifted 6 pixel up if its associated event does?
* @type boolean
* @default false
*
* @param Lights Active Radius
* @parent ---Offset and Sizes---
* @desc The number of grid spaces away from the player that lights are turned on. (0 to not use this functionality)
* Default: 0
* @default 0
*
* @param Daynight Cycle
* @parent ---General Settings---
* @desc Should the tint change over time. Must also be enabled in individual maps.
* @type boolean
* @default true
*
* @param Reset Lights
* @parent ---General Settings---
* @desc Resets the conditional lights on map change
* @type boolean
* @default false
*
* @param Kill Switch
* @parent ---General Settings---
* @desc Possible values A,B,C,D. If Selfswitch X is switched ON, the event's lightsource will be disabled.
* @type select
* @option None
* @option A
* @option B
* @option C
* @option D
* @default None
*
* @param Kill Switch Auto
* @parent ---General Settings---
* @desc If a conditional light is OFF(ON), lock the Kill Switch to ON(OFF)?
* @type boolean
* @default false
*
* @param Note Tag Key
* @parent ---General Settings---
* @desc Specify a key (<Key: Light 25 ...>) to be used with all note tags or leave blank for Terrax compatibility (Light 25 ...)
* @default cl
*
* @param ---DayNight Settings---
* @default
*
* @param Daynight Initial Speed
* @parent ---DayNight Settings---
* @desc What is the initial speed of the DayNight cycle?
* @type number
* @min 0
* @default 10
*
* @param Save DaynightHours
* @parent ---DayNight Settings---
* @desc Game variable the time of day (0-23) can be stored in. Disable: 0
* @type number
* @min 0
* @default 0
*
* @param Save DaynightMinutes
* @parent ---DayNight Settings---
* @desc Game variable the time of day (0-59) can be stored in. Disable: 0
* @type number
* @min 0
* @default 0
*
* @param Save DaynightSeconds
* @parent ---DayNight Settings---
* @desc Game variable the time of day (0-59) can be stored in. Disable: 0
* @type number
* @min 0
* @default 0
*
* @param Save Night Switch
* @parent ---DayNight Settings---
* @desc Game switch to set as ON during night and OFF during day. Disable: 0
* @type number
* @min 0
* @default 0
*
* @param No Autoshadow During Night
* @parent ---DayNight Settings---
* @desc Hide autoshadow during night?
* @type number
* @type boolean
* @default false
*
* @param Night Hours
* @parent ---DayNight Settings---
* @desc Comma-separated list of night hours. Not used/relevant if Save Night Switch set to 0.
* @default 0, 1, 2, 3, 4, 5, 6, 19, 20, 21, 22, 23
*
* @param DayNight Colors
* @parent ---DayNight Settings---
* @desc Set DayNight colors. Each color represents 1 hour of the day
* @default ["#6666ff","#6666ff","#6666ff","#6666ff","#6666ff","#6666ff","#9999ff","#ccccff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffcc88","#9999ff","#6666ff","#6666ff","#6666ff","#6666ff"]
* @type text[]
*
* @param Daynight Initial Hour
* @parent ---DayNight Settings---
* @desc What is the initial hour?
* @type number
* @min 0
* @default 0
*
* @param ---Offset and Sizes---
* @default
*
* @param Player radius
* @parent ---Offset and Sizes---
* @desc Adjust the light radius around the player
* Default: 300
* @type number
* @min 0
* @default 300
*
* @param Flashlight offset
* @parent ---Offset and Sizes---
* @desc Increase this setting to move up the flashlight for double height characters.
* Default: 0
* @type number
* @min -100
* @max 100
* @default 0
*
* @param Flashlight X offset
* @parent ---Offset and Sizes---
* @desc Use this setting for characters larger than one space.
* Default: 0
* @type number
* @min -100
* @max 100
* @default 0
*
* @param Screensize X
* @parent ---Offset and Sizes---
* @desc Increase if your using a higher screen resolution then the default
* Default : 816
* @default 816
* @type number
* @min 0
*
* @param Screensize Y
* @parent ---Offset and Sizes---
* @desc Increase if your using a higher screen resolution then the default
* Default : 624
* @default 624
* @type number
* @min 0
*
* @param Lightmask Padding
* @parent ---Offset and Sizes---
* @desc Offscreen x-padding size for the light mask
* @type number
* @min 0
* @default 32
*
* @param ---Battle Settings---
* @default
*
* @param Battle Tinting
* @parent ---Battle Settings---
* @desc Add a tint layer to the battle screen? If set to false, no light effect will occur during battles.
* @type boolean
* @default true
*
* @param Light Mask Position
* @parent ---Battle Settings---
* @desc Place the light mask above the battlers, or between the battleground and the battlers?
* @type select
* @option Above Battlers
* @value Above Background and Battler
* @option Between Background and Battlers
* @value Between
* @default Above
*
* @help
*
* --------------------------------------------------------------------------
* Important info about note tags and the note tag key plugin parameter:
*
* 1. This plugin features an optional note tag key that lets this plugin's
* note tags work alongside those of other plugins--a feature not found in the
* original Terrax Lighting plugin. If a note tag key is set in the plugin
* parameters, all of these commands must be enclosed in a note tag with that
* particular key in in order to be recognized.
*
* This note tag key applies to anything this plugin would have placed inside
* a note box, such as "DayNight" on a map or "Light/Fire/etc on an event.
*
* Examples:
*
* With the default note tag key, "CL" (not case sensitive):
* <cl: light 250 #ffffff>
* <cl: daynight>
* ...etc
*
* Without a note tag key set:
* light 250 #ffffff
* daynight
* ...etc
*
* Using a note tag key is recommended since it allows for other things
* (plugins, or even your own personal notes) to make use of the note box
* without breaking things. Omitting the key is intended primarily as legacy
* support, allowing this plugin to be used with older projects that have
* been upgraded from Terrax Lighting so you don't have to go back and
* change a bunch of event and map notes.
*
* 2. New with version 4.2+ is the option to place the lighting note tag
* anywhere in an event page's comment field instead of the note box, as
* long as the comment field is the first thing on the page. This allows
* for more advanced lighting tricks to be done on a per-page basis. Page
* Comment note tags will be prioritized over general note tags, allowing
* tags in the general note box to serve as a default that 1 or more pages
* can override.
*
* It's important to note that active lighting events are only updated
* periodically to avoid needlessly looping through events on the map
* that have nothing to do with lighting. As such, if your event's note
* box is empty and page 1 has no lighting tag set, but page 2 does, there
* will be a brief delay before the light comes on when you switch to page
* 2. You can get around this by setting a default empty light note tag
* <cl: light 0 #000> in the general note box.
*
* Finally, this feature isn't available in Terrax compatibility mode (when
* there's no note tag key set). This is to avoid conflicts when a comment
* appears at the top of a page that has nothing to do with this plugin.
*
* --------------------------------------------------------------------------
* List of Note Tags
* --------------------------------------------------------------------------
*
* Notation legend:
* [] These values are optional (the brightness parameter in light, etc)
* | Select the value from the specified list (on|off, etc)
*
* Do not include these in the actual note tags or plugin commands.
*
* --------------------------------------------------------------------------
* Events
* --------------------------------------------------------------------------
* Light radius color [enable] [day|night] [brightness] [direction] [anglerange] [x] [y] [id]
* Light radius cycle <color [pauseDuration]>... [enable] [day|night] [brightness] [direction] [anglerange] [x] [y] [id]
* Light [radius] [color] [{CycleProps}...] [enable] [day|night] [brightness] [direction] [anglerange] [x] [y] [id]
* - Light
* - radius For a circular radius this can be any number, optionally preceded by "R" or
* "r", so 100, R100, r100, etc. For an elliptical radius, must be any number
* preceded by xr or XR, and yr or YR, so "xr100 yr150", "XR100 yr150", etc.
* - cycle Allows any number of color + duration pairs to follow that will be cycled
* through before repeating from the beginning. See the examples below for usage.
* In Terrax Lighting, there was a hard limit of 4, but now there is no limit.
* To cycle any light property or for fade transitions, use the cycleProps
* format instead. [optional]
* - cycleProps Cyclic conditional lighting properties can be specified within {} brackets.
* The can be used to create transitioning light patterns See the Conditional
* Lighting section for more details. * Any non-cyclic properties are inherited
* unless overridden by the first cyclic properties [Optional]
* - color #ffffff, #ff0000, etc
* - enable Initial state: off, on (default). May optionally use 'E1|e1|E0|e0' syntax
* where 1 is on, and 0 is off. Ignored if day|night passed [optional]
* - day Causes the light to only come on during the day [optional]
* - night Causes the light to only come on during the night [optional]
* - brightness B50, B25, etc [optional]
* - direction D1: n.wall, D2: e.wall, D3: s.wall, D4: w.wall
* D5 n.+e. walls, D6 s.+e. walls, D7 s.+w. walls,
* D8 n.+w. walls, D9 n.-e. corner, D10 s.-e. corner
* D11 s.-w. corner, D12 n.-w. corner [optional]
* - anglerange Forced direction range in degrees in the format of aN:M where N is the start
* angle and M Is the end angle. Must be preceded by "A" or "a". If omitted,
* direction is used. [optional]
* - x x offset [optional] (0.5: half tile, 1 = full tile, etc)
* - y y offset [optional]
* - id 1, 2, potato, etc. An id (alphanumeric) for plugin commands [optional]
* These should not be in the format of '<a|b|d|e|l|w|x|y|A|B|D|E|L|W|X|Y>N'
* where N is a number following any supported optional parameter prefix
* otherwise it will be mistaken for one of the previous optional parameters.
* Generally, it is adviseable to avoid any single letter followed by a number.
*
* Fire ...params
* - Same as Light params above, but adds a subtle flicker
*
* Flashlight bl bw color [enable] [day|night] [sdir|angle] [x] [y] [id]
* Flashlight bl bw cycle <color [pauseDuration]>... [enable] [day|night] [sdir|angle] [x] [y] [id]
* Flashlight [bl] [bw] [{CycleProps}...] [enable] [day|night] [sdir|angle] [x] [y] [id]
* - Sets the light as a flashlight with beam length (bl) beam width (bw) color (c),
* 0|1 (onoff), and 1=up, 2=right, 3=down, 4=left for static direction (sdir)
* - bl: Beam length: Any number, optionally preceded by "L" or "l", so 8, L8, l8, etc.
* - bw: Beam width: Any number, optionally preceded by "W", or 'w', so 12, W12, w12, etc.
* - cycle Allows any number of color + duration pairs to follow that will be cycled
* through before repeating from the beginning. See the examples below for usage.
* In Terrax Lighting, there was a hard limit of 4, but now there is no limit.
* To cycle any light property or for fade transitions, use the cycleProps
* format instead. [optional]
* - cycleProps Cyclic conditional lighting properties can be specified within {} brackets.
* The can be used to create transitioning light patterns See the Conditional
* Lighting section for more details. * Any non-cyclic properties are inherited
* unless overridden by the first cyclic properties [Optional]
* - color #ffffff, #ff0000, etc
* - enable Initial state: off, on (default). May optionally use 'E1|e1|E0|e0' syntax
* where 1 is on, and 0 is off. Ignored if day|night passed [optional]
* - day Sets the event's light to only show during the day [optional]
* - night Sets the event's light to only show during night time [optional]
* - sdir Forced direction: 0:auto, 1:up, 2:right, 3:down, 4:left [optional]
* Can be preceded by "D" or "d", so D4, d4, etc. If omitted, defaults to 0
* - angle Forced direction in degrees. Must be preceded by "A" or "a". If
* omitted, sdir is used. [optional]
* - x x[offset] Work the same as regular light [optional]
* - y y[offset] [optional]
* - id 1, 2, potato, etc. An id (alphanumeric) for plugin commands [optional]
* These should not be in the format of '<a|b|d|e|l|w|x|y|A|B|D|E|L|W|X|Y>N'
* where N is a number following any supported optional parameter prefix
* otherwise it will be mistaken for one of the previous optional parameters.
* Generally, it is adviseable to avoid any single letter followed by a number.
*
* Example note tags:
*
* <cl: light 250 #ffffff>
* <cl: light r250 #ffffff>
* Creates a basic light
*
* <cl: light xr250 yr300 #ffffff>
* Creates a basic elliptical light
*
* <cl: light r250 a180:360 #ffffff>
* Creates a basic light that displays from 180 degrees to 360 degrees (north facing).
*
* <cl: light 300 cycle #ff0000 15 #ffff00 15 #00ff00 15 #00ffff 15 #0000ff 15>
* <cl: light r300 {#ff0000 p15} {#ffff00} {#00ff00} {#00ffff} {#0000ff}>
* Creates a cycling light that rotates every 15 frames. Great for parties!
*
* <cl: light r300 {#ff0000 t30 p60} {#ffff00} {#00ff00} {#00ffff}>
* Creates a cycling light that stays on for 30 frames and transitions to the next color over 60 frames.
*
* <cl: light {#ff0000 t30 p60 r250} {#ffff00 r300} {#00ff00 r250} {#00ffff r300}>
* Creates a cycling light that grows and shrink between radius sizes of 250 and 300, stays on for 30 frames,
* and transitions to the next color and size over 60 frames.
*
* <cl: fire 150 #ff8800 b15 night>
* Creates a fire that only lights up at night.
*
* <cl: Flashlight l8 w12 #ff0000 on asdf>
* Creates a flashlight beam with id asdf which can be turned on or off via
* plugin commands.
*
* <cl: Flashlight l8 w12 #ff0000 on asdf>
* Creates a flashlight beam with id asdf which can be turned on or off via
* plugin commands.
*
* <cl: Flashlight l8 w12 cycle #f00 15 #ff0 15 #0f0 15>
* <cl: Flashlight l8 w12 {#f00 p15} {#ff0} {#0f0}>
* Creates a flashlight beam that rotates every 15 frames.
*
* --------------------------------------------------------------------------
* Additive Lighting Effects
* --------------------------------------------------------------------------
* Additive lighting gives lights a volumetric appearance. To enable, put 'a' or 'A'
* in front of any color light color.
*
* Example note tags:
*
* <cl: light r300 {a#990000 t15} {a#999900} {a#009900} {a#009999} {a#000099}>
* Creates a cycling volumetric light that rotates every 15 frames.
*
* <cl: Flashlight l8 w12 a#660000 on asdf>
* Creates a red volumetric flashlight beam with id asdf which can be turned on or off
* via plugin commands.
*
* --------------------------------------------------------------------------
* Conditional Lighting
* --------------------------------------------------------------------------
* Conditional Lighting allows light properties to be changed either cyclically or
* dynamically over time via properties that consist of a prefix followed by a property
* value. This is useful for creating any number of transitional lighting effects.
* Properties will hold their given value until a change or reset (including pause and
* transition durations).
*
* The properties are supported in light tags or via the 'light cond' command. Light tags
* support any number of light properties wrapped in {} brackets See the example note tags
* above.
*
* The 'light cond' command allows for conditional lights to be dynamically changed on demand.
* See the Plugin Commands section for more details.
*
* Ranges can be used if random values are desired. Cycle tags are statically generated at map
* load. If dynamic random property values are desired, use the 'light cond' command instead in
* combination with the 'light wait' command.
* See the table below for property specific formatting.
*
* The following table shows supported properties:
* ---------------------------------------------------------------------------------------------------------------------
* | Property | Prefix | Format*† | Examples | Description |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | pause | p | p<N|N:N> | p0, p1, p20, | time period in cycles to pause after |
* | duration | | | p0:20, p1:20 | transitioning for cycling lights |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | transition | t | t<N|N:N> | t0, t1, t30 | time period to transition the |
* | duration | | | t0:30, t1:30 | specified properties over |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | color | #, #a | <#|#a><hex|hex:hex> | #, #FFEEDD, #ffeedd, | color or additive color |
* | | | | a#000000:a#ffffff | |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | enable | e | e<0|1|0:1> | e0, e1, e0:1 | turns light on or off instantly |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | angle | a, +a, -a | <a|+a|-a><N|N:N> | a, a30, +a30, -a30 | flashlight angle in degrees. '+' moves |
* | | | | +a0:30, -a0:30 | clockwise, '-' moves counterclockwise |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | brightness | b | b<N|N:N> | b, b0, b1, b5, b1:5 | brightness |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | x offset | x | x<N|N:N> | x, x2, x-2, x-2:2 | x offset |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | y offset | y | y<N|N:N> | y, y2, y-2, y-2:2 | y offset |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | radius | r | r<N|N:N> | r, r50, r150, r50:75 | light radius |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | beam length | l | l<N|N:N> | l, l8, l9, l10, l7:9 | flashlight beam length |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | beam width | w | w<N|N:N> | w, w8, w14, w7:9 | flashlight beam width |
* |-------------|-----------|-------------------------|----------------------|----------------------------------------|
* | * Omitting N or hex value will transition the given property back to its initial state |
* |-------------------------------------------------------------------------------------------------------------------|
* | † using the N:N or hex:hex format allows for a randomly generated value within the given range (inclusive) |
* ---------------------------------------------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------
* Easy hex color references
* --------------------------------------------------------------------------
* white - #FFFFFF
* blue - #0000FF
* red - #FF0000
* orange - #FFA500
* green - #008000
* cyan - #00FFFF
* yellow - #FFFF00
* purple - #800080
* pink - #FFC0CB
* black - #000000
* -------------------------------------------------------------------------------
* Migrating from Khas Ultra Lights
* -------------------------------------------------------------------------------
* Using the smooth lights options make it look extremely close.
* The default light radius that Khas appears to be around 122. Smooth lights
* need to be turned on to get similar effects.
*
* All [light_size] tags should be combined with the initial light radius tag.
*
* Eg.
* Original:
* [light cyan]
* [light size 75]
*
* Replacement:
* <cl: light 75 #00FFFF>
*
* All [region_light] tags need to be replaced with <cl: region light> tags.
* Eg.
* Original:
* [region_light 5 red]
*
* Replacement:
* <cl: RegionLight 5 #FF0000 122>
* -------------------------------------------------------------------------------
* Maps
* -------------------------------------------------------------------------------
* DayNight [speed]
* Activates day/night cycle. Put in map note or event note
* - speed Optional parameter to alter the speed at which time passes.
* 10 is the default speed, higher numbers are slower, lower
* numbers are faster, and 0 stops the flow of time entirely.
* If speed is not specified, then the current speed is used.
*
* TileLight id ON c r
* RegionLight id ON c r
* - Turns on lights for tile tag or region tag (id) using color (c) and radius (r)
* - Replace ON with OFF to turn them off
*
* RegionFire, RegionGlow
* - Same as above, but different lighting effects
*
* RegionBlock id ON color
* - Turns on light blocking for tile with region id (id) using color (color)
*
* RegionBlock id OFF
* - Turns off light blocking for tile with region id (id)
*
* defaultbrightness
* - Sets the default brightness of all the lights in the map
*
* Tint set c
* - Sets the current screen tint to the color (c)
*
* Tint daylight
* - Sets the tint based on the current hour.
* -------------------------------------------------------------------------------
* Plugin Commands (for MZ these use the new plugin interface)
* -------------------------------------------------------------------------------
* Light deactivate|activate
* - Completely disables the lighting effects of this plugin
*
* Light on id
* - Turn on light with matching id number
*
* Light off id
* - Turn off light with matching id number
*
* Light cond id [tN] [pN] [<#|#a>hex] [eN] [<a|+a|-a>N] [bN] [xN] [yN] [rN] [lN] [wN]
* - where N can either be a single number such as 0, 2, 3, etc., or a range of numbers,
* - such as 0:1, 1:9, 2:10, etc. And hex can either be a single hex color such as #000000,
* - #ffffff, a#ffffff, etc. or a range such as #000000:#ffffff, a#333333bb:a#999999bb.
* - The command transitions a conditional light to the specified properties over the given
* - time period in cycles. Supported propreties are transition duration (t),
* - pause duration (p), color (#, a#), enable (e), flashlight angle (a, +a, -a),
* - brightness (b), x offset (x), y offset (y), radius (r), flashlight beam length (l),
* - flashlight beam width (w). Must use the specified prefixes. Unsupported prefixes are
* - ignored. See the Conditional Light section for more detail on each property.
*
* Light wait id
* - wait for the conditional light to finish both transitioning and pausing before continuing
* - the event script.
*
* Light color id c
* - Change the color (c) of lightsource with id (id)
* - Work even if the associated light is currently off.
* - Will be in effect until conditional lights are resetted
* - If c is set to 'defaultcolor' (without the quotes),
* it will reset the light back to its initial color.
*
* Light switch reset
* - Reset all conditional lights.
*
* Light radius r c b
* - Change player light radius (r), color (c), and brightness (b)
*
* Light radiusgrow r c b t
* - Same as above, but apply changes over time.
* The duration is either (t) frames or 500 frames if (t) isn't specified.
*
* Setfire r s
* - Alters fire settings with radius shift (r) and red/yellow color shift (s)
*
* Flashlight on bl bw c bd
* - turn on flashlight for player with beam length (bl), beam width (hw), color (c),
* and beam density (bd)
*
* Flashlight off
* - Turn off the flashlight. yup.
*
* DayNight on|off [fade]
* - Activates or deactivates the day/night cycle. Specifying 'fade' will gradually
* transition the tint to that of the next hour.
*
* Daynight speed n
* - Changes the speed by which hours pass in game in relation to real life seconds
*
* Daynight hour h m [fade]
* - Sets the in game time to hh:mm. Specifying 'fade' will gradually transition the
* tint to that of the next hour.
*
* Daynight color h c
* - Sets the hour (h) to use color (c)
*
* Daynight add h m [fade]
* - Adds the specified hours (h) and minutes (m) to the in game clock. Specifying
* 'fade' will gradually transition the tint to that of the next hour.
*
* Daynight subtract h m [fade]
* - Subtracts the specified hours (h) and minutes (m) from the in game clock.
* Specifying 'fade' will gradually transition the tint to that of the next hour.
*
* Daynight show
* - Shows the current time of day in the upper right corner of the map screen (h:mm)
*
* Daynight showseconds
* - Shows the current time of day in the upper right corner of the map screen (h:mm:ss)
*
* Daynight hide
* - Hides the current time of day mini-window
*
* Daynight hoursinday h [fade]
* - Sets the number of hours in a day to [h] (set hour colors if doing this).
* Specifying 'fade' will gradually transition the tint to that of the next hour.
*
* Tint set c [s] [cycles]
* Tint fade c [s] [cycles]
* - Sets or fades the current screen tint to the color (c)
* - The optional argument speed (s) sets the fade speed (1 = fast, 20 = very slow).
* - If the optional argument 'cycles' is provided, then speed is treated as a cycle count.
* - Both commands operate identically.
*
* Tint reset [s] [cycles]
* Tint daylight [s] [cycles]
* - Resets or fades the tint based on the current hour.
* - The optional argument speed (s) sets the fade speed (1 = fast, 20 = very slow)
* - If the optional argument 'cycles' is provided, then speed is treated as a cycle count.
* - Both commands operate identically.
*
* Tint wait
* - wait for the tint to finish transitioning before continuing the event script.
*
* TileLight id ON c r
* RegionLight id ON c r
* - Turns on lights for tile tag or region tag (id) using color (c) and radius (r)
* - Replace ON with OFF to turn them off
*
* TileFire, TileGlow, RegionFire, RegionGlow
* - Same as above, but different lighting effects
*
* TileBlock id ON color
* - Turns on light blocking for tile with tiletag id (id) using color (color)
*
* TileBlock id OFF
* - Turns off light blocking for tile with tiletag id (id)
*
* RegionBlock id ON color
* - Turns on light blocking for tile with region id (id) using color (color)
*
* RegionBlock id OFF
* - Turns off light blocking for tile with region id (id)
*
* RegionBlock id ON color shape xoffset yoffset width height
* - id id of region
* - color color of block (usually #000000)
* - shape 1=square, 2=oval
* - xoffset x offset
* - yoffset y offset
* - width width of shape
* - height height of shape
*
* --------------------------------------------------------------------------
* Kill Switch and conditional lighting
* --------------------------------------------------------------------------
*
* If the 'Kill Switch Auto' parameter has been set to true, any event with
* a (non) active conditional light have their killswitch locked to ON(OFF).
* You can use this difference to give alternate appearances to these events.
* For example, a conditional light event can have a page where it shows a
* burning candle, and second page (active only when the kill switch is ON)
* who shows an unlit candle
*
* -------------------------------------------------------------------------------
* Plugin in battle
* -------------------------------------------------------------------------------
*
* If the plugin is active while a battle begin, the battle screen will
* be tinted like it was on the map. Too dark color will be automatically set
* to '#666666' (dark gray).
*
* If there is no map to take the tint from (ex: battle test),
* the screen will not be tinted.
*
* You can manually tint the battle screen with the following plugin commands.
* Note that these commands affect only the current battle,
* and will have no effect on the map.
*
* -------------------------------------------------------------------------------
* Plugin Commands - Battle
* -------------------------------------------------------------------------------
*
* The following tag may be used in a comment field in the first page of a
* battle event to change the battle tint prior to the first turn:
*
* TintBattle set
* - Sets the current screen tint to the color (c)
*
* The following commands may be used at any time in battle events (note, these do
* not work as tags in comment fields):
*
* TintBattle set [c] [s]
* TintBattle fade [c] [s]
* - Sets or fades the battle screen to the color (c)
* - The optional argument speed (s) sets the fade speed (1 = fast, 20 = very slow)
* - Automatically set too dark color to '#666666' (dark gray).
* - Both commands operate identically.
*
* TintBattle reset [s]
* TintBattle daylight [s]
* - Resets or fades the battle screen to its original color.
* - The optional argument speed (s) sets the fade speed (1 = fast, 20 = very slow)
* - Both commands operate identically.
*
* --------------------------------------------------------------------------
* Lights Active Radius
* --------------------------------------------------------------------------
* This allows you to decide how far away from the player lights are active,
* anything beyond this range will not light up until the player gets
* closer to it.
*
* It can be changed in the plugin parameters, or using the script call...
*
* $gameVariables.SetActiveRadius(#)
*
* ....where # is the max distance you want in tiles.
*/
const M_2PI = 2 * Math.PI; // cache 2PI - this is faster
const M_PI_180 = Math.PI / 180; // cache PI/180 - this is faster
Number.prototype.is = function(...a) { return a.includes(Number(this)); };
Number.prototype.inRange = function(min, max) { return this >= min && this <= max; };
Number.prototype.clone = function() { return Number(this); };
Boolean.prototype.clone = function() { return this == true; };
String.prototype.equalsIC = function(...a) { return a.map(s => s.toLowerCase()).includes(this.toLowerCase()); };
String.prototype.startsWithIC = function(s) { return this.toLowerCase().startsWith(s.toLowerCase()); };
Math.minmax = (minOrMax, ...a) => minOrMax ? Math.min(...a) : Math.max(...a); // min if positive
let isRMMZ = () => Utils.RPGMAKER_NAME === "MZ";
let isRMMV = () => Utils.RPGMAKER_NAME === "MV";
function orBoolean(...a) {
for (let i = 0; i < a.length; i++) {
if (typeof a[i] === "boolean") return a[i];
else if (typeof a[i] === "string") {
if (a[i].equalsIC('true')) return true;
else if (a[i].equalsIC('false')) return false;
}
}
}
function orNullish(...a) { for (let i = 0; i < a.length; i++) if (a[i] != null) return a[i]; }
function orNaN(...a) { for (let i = 0; i < a.length; i++) if (!isNaN(a[i])) return a[i]; }
let isOn = (x) => x.toLowerCase() === "on";
let isOff = (x) => x.toLowerCase() === "off";
let isActivate = (x) => x.toLowerCase() === "activate";
let isDeactivate = (x) => x.toLowerCase() === "deactivate";
// Map community light directions to polar angles (360 degrees)
const CLDirectionMap = {
0: undefined, // auto
1: 3 * Math.PI / 2, // up
2: 2 * Math.PI, // right
3: Math.PI / 2, // down
4: Math.PI // left
};
// Map RM directions to polar angles (360 degrees)
const RMDirectionMap = {
1: 3 * Math.PI / 4, // down-left
2: Math.PI / 2, // down
3: Math.PI / 4, // down-right
4: Math.PI, // left
6: 2 * Math.PI, // right
7: 5 * Math.PI / 4, // up-left
8: 3 * Math.PI / 2, // up
9: 7 * Math.PI / 4 // up-right
};
const TileType = {
Terrain: 1, terrain: 1, 1: 1,
Region: 2, region: 2, 2: 2
};
const LightType = {
Light : 1, light : 1, 1: 1,
Fire : 2, fire : 2, 2: 2,
Flashlight: 3, flashlight: 3, 3: 3,
Glow : 4, glow : 4, 4: 4
};
const TileLightType = {
tilelight: [TileType.Terrain, LightType.Light],
tilefire: [TileType.Terrain, LightType.Fire],
tileglow: [TileType.Terrain, LightType.Glow],
regionlight: [TileType.Region, LightType.Light],
regionfire: [TileType.Region, LightType.Fire],
regionglow: [TileType.Region, LightType.Glow],
};
const TileBlockType = {
tileblock: TileType.Terrain,
regionblock: TileType.Region
};
class TileLight {
constructor(tileType, lightType, id, onoff, color, radius, brightness) {
this.tileType = TileType[tileType];
this.lightType = LightType[lightType];
this.id = +id || 0;
this.enabled = isOn(onoff);
this.color = new VRGBA(color);
this.radius = +radius || 0;
this.brightness = brightness && (brightness.slice(1, brightness.length) / 100).clamp(0, 1) ||
Community.Lighting.defaultBrightness || 0;
}
}
class TileBlock {
constructor(tileType, id, onoff, color, shape, xOffset, yOffset, blockWidth, blockHeight) {
this.tileType = TileType[tileType];
this.id = +id || 0;
this.enabled = isOn(onoff);
this.color = new VRGBA(color);
this.shape = +shape || 0;
this.xOffset = +xOffset || 0;
this.yOffset = +yOffset || 0;
this.blockWidth = +blockWidth || 0;
this.blockHeight = +blockHeight || 0;
}
}
const isValidColorRegex = /^[Aa]?#[A-F\d]{8}$/i; // a|A before # for additive lighting
/**
* @param {Number} r
* @param {Number} g
* @param {Number} b
* @param {Number} a
* @returns {String}
*/
function rgba(r, g, b, a) {
return "rgba(" + r + "," + g + "," + b + "," + a + ")";
}
/** Class to handle volumetric/additive coloring with rgba colors uniformly. Additive coloring prefixes an 'a' on a
* normal hex color. E.g. a#ccddeeff, a#ccddee, a#cdef, a#cde.
*/
class VRGBA {
/**
* Creates a VRGBA object representing a VRGBA color string. Either v, r, g, b, a values can be passed directly, or a
* hex String can be passed with an optional default alternative Hex string which is used in case of parsing failure.
* @param {String|Boolean|VRGBA} vOrHex - Boolean representing the additive component, or
* String representing the hex color, or
* other VRGBA object to clone.
* @param {String|Number} rOrDefault - Number representing the red component, or
* String representing a default hex string.
* @param {null|Number} g - Number representing the green component.
* @param {null|Number} b - Number representing the blue component.
* @param {null|Number} a - Number representing the alpha component.
* @returns {VRGBA}
*/
constructor(vOrHex, rOrDefault = "#000000ff", g = undefined, b = undefined, a = 0xff) {
this.name = VRGBA.name;
if (arguments.length == 0) return; // return if no arguments (allows construction).
else if (typeof vOrHex === "boolean") // Passed v, r, g, b, a
[this.v, this.r, this.g, this.b, this.a] = // - assign
[vOrHex, +rOrDefault || 0, +g || 0, +b || 0, +a || 0xff]; // -
else if (vOrHex == null || typeof vOrHex === "string") { // passed a hex String or nullish
vOrHex = this.normalizeHex(vOrHex, rOrDefault); // - parse hex
this.v = vOrHex.startsWithIC("a#"); // - assign v
const shift = this.v ? 1 : 0; // - shift for volumetric/additive prefix
this.r = parseInt(vOrHex.slice(1 + shift, 3 + shift), 16); // - assign red
this.g = parseInt(vOrHex.slice(3 + shift, 5 + shift), 16); // - assign green
this.b = parseInt(vOrHex.slice(5 + shift, 7 + shift), 16); // - assign blue
this.a = parseInt(vOrHex.slice(7 + shift, 9 + shift), 16); // - assign alpha
} else {
throw Error(`${Community.Lighting.name} - VRGBA constructor given incorrect parameters!`);
}
}
/**
* Creates a copy of the VRGBA object.
* @returns {VRGBA}
*/
clone() {
let that = new VRGBA();
[that.v, that.r, that.g, that.b, that.a] = [this.v, this.r, this.g, this.b, this.a];
return that;
}
/**
* Creates an VRGBA object will r,g,b = 0, a = 255, and v = false.
* @returns {VRGBA}
*/
static minRGBA() {
let that = new VRGBA();
[that.v, that.r, that.g, that.b, that.a] = [false, 0, 0, 0, 255];
return that;
}
/**
* Creates an VRGBA object will r,g,b,a = 255 and v = false.
* @returns {VRGBA}
*/
static maxRGBA() {
let that = new VRGBA();
[that.v, that.r, that.g, that.b, that.a] = [false, 255, 255, 255, 255];
return that;
}
/**
* Sets the v, r, b, g, or a properties to that of the cooresponding properties in the that Object.
* @param {VRGBA} that
*/
set(that) { for (let k in that) if (this[k] != null) this[k] = that[k]; }
/**
* Adds together the r, g, and b properties and returns the result.
* @returns {Number}
*/
magnitude() { return this.r + this.g + this.b; }
/**
* Attempts to normalize the provided hex String. If invalid, it then tries to normalize the provided altHex String.
* If invalid, a default value of "#000000ff" is returned. If either provided String is valid, it will be returned
* as an 'a#rrggbbaa' formatted color hex String.
* @param {String} hex
* @param {String} alt
* @returns {String}
*/
normalizeHex(hex, altHex) {
if (typeof hex !== "string") return this.normalizeHex(altHex, "#000000ff");
let h = hex.toLowerCase().trim();
const s = hex.startsWithIC("a#") ? 1 : 0; // shift
if (h.length == 4 + s) h += "f"; // normalize #RGB format
if (h.length == 5 + s) h = h.replace(/(^a?#)|(.)/g, "$1$2$2"); // normalize #RGBA
if (h.length == 7 + s) h += "ff"; // normalize #RRGGBB format
if (!isValidColorRegex.test(h)) {
console.log(`${Community.Lighting.name} - Invalid Color: ` + hex);
return this.normalizeHex(altHex, "#000000ff");
}
return h; // return RRGGBBAA
}
/**
* Converts the VRGBA Object into an 'a#rrggbbaa' formatted color hex string where the first 'a' tells whether the
* hex is additive or not. The setWebSafe parameter is used to to strip the additive property (v) so that the
* resulting color can be used with Canvas APIs. An override Object can be provided to override the existing v, r, g,
* b, or a properties in the output.
* @param {Boolean} setWebSafe
* @param {VRGBA} override
* @returns {String}
*/
toHex(setWebSafe = false, override = undefined) {
let temp = this.clone(); // create temporary copy
for (let k in override) if (temp[k]) temp[k] = override[k]; // assign temporary setters
if (temp.r.inRange(0, 255) && temp.g.inRange(0, 255) && temp.b.inRange(0, 255) && temp.a.inRange(0, 255)) {
let rHex = (temp.r < 16 ? "0" : "") + Math.floor(temp.r).toString(16); // clamp to whole numbers
let gHex = (temp.g < 16 ? "0" : "") + Math.floor(temp.g).toString(16);
let bHex = (temp.b < 16 ? "0" : "") + Math.floor(temp.b).toString(16);
let aHex = (temp.a < 16 ? "0" : "") + Math.floor(temp.a).toString(16);
return (temp.v && !setWebSafe ? "a" : "") + "#" + rHex + gHex + bHex + aHex;
}
return null; // The hex color code doesn't exist
}
/**