-
Notifications
You must be signed in to change notification settings - Fork 14
/
Spriter.js
4179 lines (3739 loc) · 156 KB
/
Spriter.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
//=============================================================================
// Spriter Pro Plugin
// by KanaX
// version 1.4.0
// Last Update: 2018.11.09
//=============================================================================
/*:
* @plugindesc Allows user to utilize Spriter Pro save files and sprite parts for Skeletal Animations
<Spriter> v1.3.5
* @author KanaX
*
*
* @param Show Skeleton
* @desc Display the Animation Skeleton (true or false).
* @type boolean
* @on Enabled
* @off Disabled
*
* @param Show Frames
* @desc Display the Animation Frames (true or false).
* @type boolean
* @on Enabled
* @off Disabled
*
* @param Evaluate Parameters
* @desc Use variables in plugin commands by adding "var_" in front of the variable (true or false).
* @default false
* @type boolean
* @on Enabled
* @off Disabled
*
* @param Log Animations
* @desc Print all animations in the data/animations folder.
* @default false
* @type boolean
* @on Log
* @off Do not Log
*
* @param TexturePacker Folder Character
* @desc The characters you use on folders containing TexturePacker spritesheets.
* @default $
*
* @param Limit Frame Counter
* @desc If Limit Process Check is On, determine in how many frames a Spriter Sprite will be updating.
* @default 0
*
* @param Animations Folder
* @desc Folder where animations are kept.
* @default data/animations/
*
* @param Spriter Sprites Folder
* @desc Folder where skinsets and single bitmaps are kept.
* @default img/characters/
*
* @param Actor Parts
* @desc Actors have changing equipment. This parameters allow for more dynamically changing cosmetic parts like hair, accessories, cloaks etc.
* @default "{\n\"AccA\": {\"isSkinset\": true, \"name\":\"\", \"isSpriterSprite\": false},\n\"AccB\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"FrontHair\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"RearHair1\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"RearHair2\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"BeastEars\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"Tail\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"Cloaks\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"Ears\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"FacialMark\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false},\n\"Wing\": {\"isSkinset\": true, \"name\": \"\", \"isSpriterSprite\": false}\n}"
* @type note
*
* @param Spriter Objects Common Event ID
* @desc ID of the Common Event where Spriter Objects data is stores
* @default 69
*
* @help
*
* Contact:
* [1] forums.rpgmakerweb.com: KanaX
*
* Special Thanks to ivan.popelyshev (https://github.com/pixijs/pixi-display/tree/layers)
*
* Terms of Use:
* [1] Free for use in all projects.
* [2] Please provide credits to KanaX.
* [3] Feel free to let me know about your project, or any ideas regarding the plugin.
*
* Spriter Pro Plugin Instructions:
*
* Installation:
* [1] Paste js file in js/plugins/
* [2] Create path img/characters/Spriter/ and inside Spriter, a folder named Single Bitmaps.
* [3] Create path data/animations/.
* [4] Enable the plugin from the Plugin Manager.
* [5] Have some ramen noodles, because you deserve them.
*
* Regarding Spriter:
* [1] The plugin should work as expected in most regards (please check "Future Updates/Fixes" for more information).
* [2] The first 4 animations in a Spriter project will respond to the character's 4 directions. If you want your character
* to move without Direction Fix, you have to create at least 4 animations.
* [3] While you can change the pivot of your bitmaps when you have inserted them into your project, you must not edit pivot x
* and pivot y in Edit Image's Default Pivot
* [4] Spriter might face some problems with its documentation, so if something inexplicably does not work, try redoing the animation.
* If that does not fix your problem, feel free to contact the plugin creator.
*
* Plugin Operation:
* [1] Paste Spriter Pro save file in data/animations/. The file name will be the skeleton,
* [2] Create a folder in img/character/Spriter/, named after the Skinset. The Skinset folder should have 4 folder which each taking the parts for each direction.
* Example: Folder_1: [head,torso,r_arm,_r_leg,_l_arm,l_leg], Folder_2: [head,torso,r_arm,_r_leg,_l_arm,l_leg], Folder_3: [head,torso,r_arm,_r_leg,_l_arm,l_leg], Folder_4: [head,torso,r_arm,_r_leg,_l_arm,l_leg]
* [3] Inside the Skinset folder, create the folders with the bitmaps you used for the animation.
* Note: If you want to use Texture Packer, just place the sprite sheet and json file inside the Skinset folder. Their names should be the same as the Skinset folder.
* [4] If you want certain Spriter Sprites to appear globally across the game (such as animated armor and weapons for actors) you need to create them in the SpriterObjects.json file in your data folder.
* (See more info about SpriterObjects.json in About SpriterObjects.json).
* [5] To create a Spriter Sprite for actors, go to Tools -> Database and write this on the actors' notes:
* <Spriter:{
* "_skeleton": The file name of the animation you want to choose from data/animations/,
* "_skin": The folder name of the Skinset you want to choose from img/characters/Spriter,
* "_speed": Speed of animation,
* "_cellX": Width of the area the main animation takes part in (example: the standard MV character cell width is 48),
* "_cellY": Height of the area the main animation takes part in (example: the standard MV character cell height is 48),
* "_spriterMask": Determine if the sprite will have a mask around it. If true, you need to fill the tags below,
* "_spriteMaskX": X value of mask origin. 0, 0 is the top left corner of the cell,
* "_spriteMaskY": Y value of mask origin. 0, 0 is the top left corner of the cell,
* "_spriteMaskW": Width of the mask,
* "_spriteMaskH": Height of the mask
*
* Example:
* <Spriter:{
* "_skeleton": "f",
* "_skin": "Side/f7",
* "_speed": 7,
* "_cellX": 32,
* "_cellY": 48,
* "_spriterMask": false
* }>
*
* [6] To create a Spriter Sprite for an event create a comment in the active event page:
* <Spriter, skeleton, skinset, speed, cellX, cellY, false>
* or
* <Spriter, skeleton, skinset, speed, cellX, cellY, true, maskX, maskY, maskW, maskH>
*
* Example
* <Spriter, doggo, sheperd, 10, 48, 32, true, 0, 0, 48, 32>
*
* WARNING: 01/24/2018 THERE IS A PIXI.JS BUG IN v4.5.4 THAT MAKES MASKS NOT WORK IF THE MAP HAS TILES.
*
* [7] Animations play when 1) an actor/event has walking animation on and is moving, or 2) an actor/event has stepping animation on.
*
* [8] Animations that are supposed to loop (walking animations, rolling balls, etc.) you need to toggle the Repeat Playback button in the Spriter Pro timeline.
*
* About Spriter Objects:
* Much like the MV Sprite_Character class, Spriter_Character class looks for data in the actor/event object in order to create/update a sprite. But what happens
* when we want our character to hold an animated sprite? A sprite whose animation is separate from the animation of its parent? Like a torch, or a magic aura.
* And what do we do when we want to keep these sprites for multiple maps?
* That's why we create SpriterObjects!
* In SpriterObjects we create faux game objects, with just the bare minimum data to satisfy the needs of the Spriter_Character class. You create a new object,
* you give it a name, skeleton, skin and then you can attach it to any character you want!
* These objects are created as comments in the COMMON EVENT with the ID that you assigned on the Spriter Objects Common Event ID:
*
* <objectName, skeleton, skin, speed, cellX, cellY>
*
* Example: <shiny_axe, shiny_axe, shiny_axe, 7, 48, 48>
*
* Plugin Commands:
* [1] eventSkeleton eventId data/animations/skeleton Spriter/skinsetName (Changes skeleton. Since skeleton changes, skinset needs to change as well.)
* Example: eventSkeleton 1 waving_hello male_1
*
* [2] eventSkin eventId Spriter/skinsetName (Changes Skinset. Needs to be compatible with skeleton.)
* Example: eventSkin 1 male_2
*
* Note: Adding a "$" infront of Spriter/skinsetname will load the bitmap
* from the respective TexturePacker bitmap, as long as it exists.
*
* [3] eventStop eventId true/false (Stops Animation.)
* Example: eventStop 1 true
* [4] eventRecovery eventId ("snap"/"freeze") (Snap resets animation when movement stops. Freeze pauses animation.)
* Example: eventRecovery 1 freeze
* [5] eventSkinPart eventId imageName (Spriter/skinsetName)-or-(bitmap name from Single bitmaps) fullsprite? (Changes only a single image from that skinset to another, compatible one.)
* (fullsprite is set to true or false and determines if the new bitmap will be from a full spriteset or not)
* (if it is set to true then the user will have to use the desired spriteset path)
* (if it is set to false then the user will have to use the desired bitmap path from within the Single Bitmaps folder)
* Example1: eventSkinPart 1 hat Items/helmet true (helmet needs to be a folder with the same filename/location as the one of the previous bitmap)
* Example2: eventSkinPart 1 r_hand_weapon mace false
*
* Note: Adding a "$" infront of Spriter/skinsetname will load the bitmap
* from the respective TexturePacker bitmap, as long as it exists. (mace needs to be a bitmap inside the Single Bitmaps folder)
*
* [6] eventRemoveSkinPart eventId imageName (Removes Spriter/skinsetName bitmap from imageName)
* Example: eventRemoveSkinPart 1 r_hand_weapon
*
* [7] eventChildSprite eventId imageName objectName (Assigns a sprite from data/SpriterObjects.json to imageName)
* Example: eventChildSpriter 1 r_hand_weapon glowing_mace (glowing_mace needs to be an object in SpriterObjects)
*
* [8] eventRemoveChildSprite eventId imageName objectName (Remove sprite object)
* Example: eventChildSpriter 1 r_hand_weapon glowing_mace
*
* -----------------------------------------------------------------------------
* [9] playerSkeleton data/animations/skeleton Spriter/skinsetName
* [10] playerSkin Spriter/skinsetName
* [11] playerStop true/false
* [12] playerRecovery ("snap"/"freeze")
* [13] playerSkinPart imageName Spriter/skinsetName
* [14] playerRemoveSkinPart imageName
* [15] playerChildSprite imageName objectName
* [16] playerRemoveChildSprite imageName objectName
* -----------------------------------------------------------------------------
* [17] followerSkeleton followerId data/animations/skeleton Spriter/skinsetName
* [18] followerSkin followerId Spriter/skinsetName
* [19] followerStop followerId true/false
* [20] followerRecovery followerId ("snap"/"freeze")
* [21] followerSkinPart followerId imageName Spriter/skinsetName
* [22] followerRemoveSkinPart followerId imageName
* [23] followerChildSprite followerId imageName objectName
* [24] followerRemoveChildSprite followerId imageName objectName
*
* Script Calls:
* [1] $gameMap._events[1].resetAnimation = true; (Resets animation)
* [2] $gamePlayer.resetAnimation = true;
* [3] $gamePlayer.followers()[1].resetAnimation = true;
* [4] $gameMap._events[1].hasActiveTag("tagName"); (Checks if character has an active tag for this frame)
* [5] $gameMap._events[1]._spriter.var.variableName; (Returns value for variableName for this Frame)
* [6] $gamePlayer.changeSkinPart(parameters same as plugin command);
* [7] $gamePlayer.removeSkinPart(parameters same as plugin command);
* [8] $gamePlayer.createChildSprite(parameters same as plugin command);
* [9] $gamePlayer.removeChildSprite(parameters same as plugin command);
*
* Tag Commands: (Place tags with the following labels for special effects)
* [1] se,seName,pan,pitch,volume,fade(, areaOfMaxVolume, areaOfTotalFade) (Plays SE sound. If fade is true, the sound fades away the further the player is from the source)
* Example1: se,step,0,100,60,true,3,10
* Example2: se,clock,0,80,100,false
*
* [2] SkinPart,imageName,(Spriter/skinsetName)-or-(bitmap name from Single bitmaps),fullsprite? (Works exactly like the plugin command. Useful for automatically spawning sprites with certain skinParts. Not so useful if those sprites change parts often.)
* Example1: SkinPart,hat,stink_lines,false
* Example2: SkinPart,torso,Items/tuxedo,true
*
* [3] RemoveSkinPart,imageName,(Spriter/skinsetName)-or-(bitmap name from Single bitmaps),fullsprite?
* Example: RemoveSkinPart,hat,stink_lines,false
*
* [4] ChildSprite,imageName,objectName (Works exactly like the plugin command.Useful for automatically spawning sprites with certain childSprites. Not so useful if those sprites change children often.)
* Example: ChildSprite,r_hand_tool,twinking_axe
*
* [5] RemoveChildSprite,imageName,objectName
* Example: ChildSprite,r_hand_tool,twinking_axe
*
* ----------------------------------------------------------------------------
* Revisions
* 02/22/2018: Updated for MV version 1.6
* 03/18/2018: Added Bezier Curve Tweening for Animations
* Added Instant Tweening for Animations
* Added TexturePacker Support.
* Added Paramaters to give Spriter Plugin better Performance.
* 04/30/2018: Fixed saving bug.
* Formatted the core classes for future add-ons and updates.
* Added ability to tag sprites to be replaced with equiped items.
* 07/12/2018: Fixed Bug regarding deletion of unused sprite parts.
* Added game variable control via tags.
* Added self switch control via tags.
* Added functional update limiter.
*
* ----------------------------------------------------------------------------
*
* ----------------------------------------------------------------------------
* Future Updates/Fixes
*
* [1] Fix reverse animations (this._speed < 0).
* [2] Add ability to distort texture meshes.
* [3] Make functional masks after dealing with a pixi.js bug.
*
* ----------------------------------------------------------------------------
*
*
*/
var parameters = $plugins.filter(function(p) { return p.description.contains('<Spriter>'); })[0].parameters;;
var showSkeleton = eval(parameters['Show Skeleton'] || false);
var showFrames = eval(parameters['Show Frames'] || false);
var evaluateParameters = eval(parameters['Evaluate Parameters'] || false);
var logAnimations = eval(parameters['Log Animations'] || false);
var texturePackerCharacter = parameters['TexturePacker Folder Character'] || "$";
var limitCounter = Number(parameters['Limit Frame Counter']) || 0;
var animFolder = parameters['Animations Folder'] || "data/animations/";
var spriteFolder = parameters['Spriter Sprite Folder'] || "img/characters/";
var actorParts = parameters['Actor Parts'].substring(1, parameters['Actor Parts'].length-1).replace(/\\n/g,'').replace(/\\/g,'');
var sObjectsID = Number(parameters['Spriter Objects Common Event ID']) || 69;
// var sAnimationsID = Number(parameters['Spriter img Animations Common Event ID']) || 70;
//-------------------------------------------------------------------------------------------------------------
//*************************************************************************************************************
// Initializes New Parameters for Characters
//*************************************************************************************************************
//-------------------------------------------------------------------------------------------------------------
var spriter_alias_Game_CharacterBase_initmembers = Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.prototype.initMembers = function() {
spriter_alias_Game_CharacterBase_initmembers.call(this);
this._spriter = {};
this._spriter._skeleton = null;
this._spriter._skin = null;
this._spriter._skinParts = [];
this._spriter._spriteChildren = [];
this._spriter._speed = 1;
this._spriter._repeat = false;
this._spriter._stop = false;
this._spriter._recovery = "snap";
this._spriter.tag = [];
this._spriter.var = {};
this._spriter._spriteMask = {};
this._spriter._showSkeleton = false;
this._spriter._spriteRequests = [];
this._spriter._spriteRemoveRequests = [];
this._spriter._scaleX = 1;
this._spriter._scaleY = 1;
this._spriter._animLimiter = null;
};
//-------------------------------------------------------------------------------------------------------------
// Give values to properies from meta or stored global values.
//-------------------------------------------------------------------------------------------------------------
Game_CharacterBase.prototype.setAnimationInfo = function(character, list, visible) {
var notes = {};
if (character.constructor == Game_Player) {
notes = $dataActors[$gameParty.leader()._actorId].meta;
}
else if (character.constructor == Game_Follower) {
notes = $dataActors[character.actor()._actorId].meta;
}
else if (character.constructor == Game_Event) {
// Giving the Event comment a similar format to that of Actor meta data
var comment = list.parameters[0].substring(9, list.parameters[0].length - 1);
param = comment.split(",");
notes.Spriter = '{';
notes.Spriter += '"_skeleton":' + '"' + param[0] + '"';
notes.Spriter += ', "_skin":' + '"' + param[1] + '"';
notes.Spriter += ', "_speed":' + param[2];
notes.Spriter += ', "_cellX":' + param[3];
notes.Spriter += ', "_cellY":' + param[4];
notes.Spriter += ', "_spriteMask":' + '"' + param[5] + '"';
if (param[5] == 'true') {
notes.Spriter += ', "_spriteMaskX":' + param[6];
notes.Spriter += ', "_spriteMaskY":' + param[7];
notes.Spriter += ', "_spriteMaskW":' + param[8];
notes.Spriter += ', "_spriteMaskH":' + param[9];
}
notes.Spriter += '}';
}
// Getting Character Info stored in global variable. It will replace Meta/Comment data if it exists.
var globalInfo = this.getCharacterGlobal();
if (notes.Spriter) {
notes = JSON.parse(notes.Spriter);
character._spriter._skeleton = visible ? globalInfo._skeleton || notes._skeleton : null;
character._spriter._skin = visible ? globalInfo._skin || notes._skin : null;
character._spriter._skinParts = globalInfo._skinParts || [];
character._spriter._spriteChildren = globalInfo._spriteChildren || [];
character._spriter._speed = globalInfo._speed || notes._speed;
character._spriter._cellX = notes._cellX;
character._spriter._cellY = notes._cellY;
character._spriter._stop = globalInfo._stop || false;
character._spriter._spriteMask.available = notes._spriteMask;
if (character._spriter._spriteMask.available) {
character._spriter._spriteMask.x = notes._spriteMaskX;
character._spriter._spriteMask.y = notes._spriteMaskY;
character._spriter._spriteMask.w = notes._spriteMaskW;
character._spriter._spriteMask.h = notes._spriteMaskH;
}
}
// Temp animation info for deprecated notes.
else {
if (character.actor()) {
console.log('WARNING: The Spriter Plugin note commands used for actor ' + character.actor()._actorId + ' are deprecated.')
}
character._spriter._skeleton = visible ? globalInfo._skeleton || notes._skeleton.trim() : null;
character._spriter._skin = visible ? globalInfo._skin || notes._skin.trim() : null;
character._spriter._skinParts = globalInfo._skinParts || [];
character._spriter._spriteChildren = globalInfo._spriteChildren || [];
character._spriter._speed = globalInfo._speed || notes._speed.trim();
character._spriter._cellX = notes._cellX.trim();
character._spriter._cellY = notes._cellY.trim();
character._spriter._stop = globalInfo._stop || false;
character._spriter._spriteMask.available = eval(notes._spriteMask.trim());
if (character._spriter._spriteMask.available) {
character._spriter._spriteMask.x = notes._spriteMaskX.trim();
character._spriter._spriteMask.y = notes._spriteMaskY.trim();
character._spriter._spriteMask.w = notes._spriteMaskW.trim();
character._spriter._spriteMask.h = notes._spriteMaskH.trim();
}
}
};
Game_CharacterBase.prototype.changeSkinPart = function(originName, newSkin, isSkinset) {
this._spriter.forceUpdate = true;
a = {};
a.originName = originName;
a.newSkin = newSkin;
a.isSkinset = eval(isSkinset);
if (this._spriter._skinParts.length > 0) {
for (i = 0; i < this._spriter._skinParts.length; i++) {
if (this._spriter._skinParts[i].originName == a.originName) {
this._spriter._skinParts[i] = a;
break;
}
else if (i == this._spriter._skinParts.length - 1) {
this._spriter._skinParts.push(a);
}
}
}
else {
this._spriter._skinParts.push(a);
}
this.removeChildSprite(originName);
var globalInfo = this.getCharacterGlobal();
globalInfo._skinParts = this._spriter._skinParts;
};
Game_CharacterBase.prototype.removeSkinPart = function(originName) {
this._spriter.forceUpdate = true;
a = {};
a.originName = originName;
for (i = 0; i < this._spriter._skinParts.length; i++) {
if (this._spriter._skinParts[i].originName == a.originName) {
this._spriter._skinParts.splice(i,1);
break;
}
}
var globalInfo = this.getCharacterGlobal();
globalInfo._skinParts = this._spriter._skinParts;
}
Game_CharacterBase.prototype.createChildSprite = function(parentSprite, spriteObjectName) {
this._spriter.forceUpdate = true;
var children = this._spriter._spriteChildren;
// Get object from SpriterObjects.json
for (var i = 0; i < $dataSpriterObjects.length; i++) {
if ($dataSpriterObjects[i]._name == spriteObjectName) {
var content = $dataSpriterObjects[i];
}
}
// Add new SpriterCharacter as child of this character
children.push(new Game_SpriterCharacter(content, parentSprite, children.length))
// Make request for Spriteset_Map to make a new Sprite for the Child
this._spriter._spriteRequests.push(children[children.length-1]);
this.removeSkinPart(parentSprite);
// Save new changes in global variable
var globalInfo = this.getCharacterGlobal();
globalInfo._spriteChildren = children;
};
Game_CharacterBase.prototype.removeChildSprite = function(spriteParentName) {
this._spriter.forceUpdate = true;
var children = this._spriter._spriteChildren;
for (var i = 0; i < children.length; i++) {
if (children[i]._spriteParent == spriteParentName) {
children.splice(i,1);
}
}
this._spriter._spriteRemoveRequests.push(spriteParentName);
var globalInfo = this.getCharacterGlobal();
globalInfo._spriteChildren = children;
};
Game_CharacterBase.prototype.getCharacterGlobal = function() {
if (this instanceof Game_Player) {
return $infoSpriter.player
}
else if (this instanceof Game_Follower) {
return $infoSpriter.followers["follower_" + this._memberIndex]
}
else if (this instanceof Game_Event) {
this.eventDataExists();
return $infoSpriter.maps["map_" + $gameMap._mapId]["event_" + this._eventId]
}
};
// Creates Event Data for unvisited Maps
Game_CharacterBase.prototype.eventDataExists = function () {
var map = $infoSpriter.maps["map_" + $gameMap._mapId];
if (!map.hasOwnProperty("event_" + String(this._eventId))) {
map["event_" + String(this._eventId)] = {};
}
};
//-------------------------------------------------------------------------------------------------------------
// Check Character for Active Tags
//-------------------------------------------------------------------------------------------------------------
Game_CharacterBase.prototype.hasActiveTag = function(tagName) {
for (var i = 0; i < this._spriter.tag.length; i++) {
if (this._spriter.tag[i].name == tagName) {
return true;
}
}
return false;
};
var spriter_alias_Game_CharacterBase_update = Game_CharacterBase.prototype.update;
Game_CharacterBase.prototype.update = function() {
spriter_alias_Game_CharacterBase_update.call(this);
this.checkTags();
};
Game_CharacterBase.prototype.checkTags = function() {
if (this.hasOwnProperty("_spriter")) {
for (var i = 0; i < this._spriter.tag.length; i++) {
this.checkForSpecialTag(this._spriter.tag[i]);
}
}
};
Game_CharacterBase.prototype.checkForSpecialTag = function(tag) {
console.log(tag.name)
if (tag.name.includes("se,")) {
this.playSpriterSE(tag);
}
else if (tag.name.includes("g-variable,")) {
this.changeGameVariable(tag);
}
else if (tag.name.includes("s-switch,")) {
this.changeSelfSwitch(tag);
}
else if (tag.name.includes("SkinPart,")) {
var tagArray = tag.name.split(",")
this.changeSkinPart(tagArray[1],tagArray[2],tagArray[3]);
}
else if (tag.name.includes("script<")) {
var scriptCall = tag.name.replace("script<","").replace(">","");
console.log(scriptCall)
eval(scriptCall);
}
};
Game_CharacterBase.prototype.playSpriterSE = function(tag) {
tagArray = tag.name.split(",");
params = {};
params.name = tagArray[1];
params.pan = tagArray[2];
params.pitch = tagArray[3];
params.volume = Number(tagArray[4]);
if (tagArray[5] === "true") {
maxVolumeArea = Number(tagArray[6]);
maxArea = Number(tagArray[7]);
dx = Math.abs(this.x - $gamePlayer.x);
dy = Math.abs(this.y - $gamePlayer.y);
d = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));
if (d > maxVolumeArea && (d - maxVolumeArea) <= maxArea) {
params.volume -= params.volume * (d - maxVolumeArea) / maxArea;
}
else if ((d - maxVolumeArea) > maxArea) {
params.volume = 0;
}
}
AudioManager.playSe(params);
};
Game_CharacterBase.prototype.changeGameVariable = function(tag) {
tagArray = tag.name.split(",");
var id = eval(tagArray[1]);
var value = eval(tagArray[2]);
$gameVariables.setValue(id, value);
};
Game_CharacterBase.prototype.changeSelfSwitch = function(tag) {
if (this instanceof Game_Event) {
tagArray = tag.name.split(",");
var key = tagArray[1];
var value = eval(tagArray[2]);
$gameSelfSwitches.setValue([$gameMap.mapId(), this._eventId, key], value);
}
};
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
// Refreshes additional Spriter properties
//-------------------------------------------------------------------------------------------------------------
var spriter_alias_Game_Player_refresh = Game_Player.prototype.refresh;
Game_Player.prototype.refresh = function() {
spriter_alias_Game_Player_refresh.call(this);
var playerNotes = $dataActors[$gameParty.leader()._actorId].meta;
if (playerNotes.hasOwnProperty("Spriter")) {
this.setAnimationInfo(this, null, true);
}
};
var spriter_alias_Game_Follower_refresh = Game_Follower.prototype.refresh;
Game_Follower.prototype.refresh = function() {
spriter_alias_Game_Follower_refresh.call(this);
if (this.actor()) {
var followerNotes = $dataActors[this.actor()._actorId].meta;
if (followerNotes.hasOwnProperty("Spriter")) {
this.setAnimationInfo(this, null, this.isVisible());
}
}
};
var spriter_alias_Game_Event_refresh = Game_Event.prototype.refresh;
Game_Event.prototype.refresh = function() {
this.checkForNewSpriterSprite();
spriter_alias_Game_Event_refresh.call(this);
// Change Animation if the New Page has a Spriter Comment
var pageSpriterInfo = this.hasSpriterSprite(this._pageIndex);
if (pageSpriterInfo) {
this.setAnimationInfo(this, pageSpriterInfo, true);
}
};
Game_Event.prototype.checkForNewSpriterSprite = function () {
var newPageIndex = this._erased ? -1 : this.findProperPageIndex();
// If Event doesn't have a Spriter Sprite and New Page has a Spriter Comment Request new Spriter Sprite
if (this._pageIndex !== newPageIndex && this.newPageAddsSprite(newPageIndex)) {
// Adds a request to create Spriter Character for Actor.
$infoSpriter._eventRequests.push(this._eventId);
}
}
// Check if Current Page has Spriter Comment
Game_Event.prototype.hasSpriterSprite = function (pageIndex) {
if (this.event().pages[pageIndex]) {
var commandList = this.event().pages[pageIndex].list;
for (var i = 0; i < commandList.length; i++) {
if (commandList[i].code == 108){
if (commandList[i].parameters[0].includes("Spriter")) {
return commandList[i];
break;
}
}
}
}
return false;
};
// If Event doesn't have a Spriter Sprite and New Page has a Spriter Comment
Game_Event.prototype.newPageAddsSprite = function (newPageIndex) {
var newPage = this.hasSpriterSprite(newPageIndex);
return this._spriter._skeleton == null && newPage;
};
//-------------------------------------------------------------------------------------------------------------
// When a new Actor is added, they are checked for Spriter Sprite
//-------------------------------------------------------------------------------------------------------------
var spriter_alias_Game_Party_addActor = Game_Party.prototype.addActor;
Game_Party.prototype.addActor = function(actorId) {
spriter_alias_Game_Party_addActor.call(this, actorId);
if (this._actors.contains(actorId)) {
// Adds a request to create Spriter Character for Actor.
$infoSpriter._followerRequests.push(actorId);
}
};
//-------------------------------------------------------------------------------------------------------------
//*************************************************************************************************************
// Game Actor is used for data that is needed both in Scene_Map and Scene_Battle
//*************************************************************************************************************
//-------------------------------------------------------------------------------------------------------------
var spriter_alias_Game_Actor_initMembers = Game_Actor.prototype.initMembers;
Game_Actor.prototype.initMembers = function() {
spriter_alias_Game_Actor_initMembers.call(this);
this._apparel = {};
};
var spriter_alias_Game_Actor_setup = Game_Actor.prototype.setup;
Game_Actor.prototype.setup = function(actorId) {
spriter_alias_Game_Actor_setup.call(this, actorId)
this._apparel = JSON.parse(actorParts);
};
Game_Actor.prototype.changeApparel = function(apparelType, apparelName, isSkinset, isSpriterSprite) {
var newApparel = {name: apparelName, isSkinset: (isSkinset != "undefined" ? isSkinset : true), isSpriterSprite: (isSpriterSprite != "undefined" ? isSpriterSprite : false)}
this._apparel[apparelType] = newApparel;
};
//-------------------------------------------------------------------------------------------------------------
//*************************************************************************************************************
// Creates and Updates Sprite Characters from New Spriter Class
//*************************************************************************************************************
// Word "Spriter" is searched for in meta, event comments and SpriterObjects.json
//-------------------------------------------------------------------------------------------------------------
var spriter_alias_Spriteset_Map_createCharacters = Spriteset_Map.prototype.createCharacters;
Spriteset_Map.prototype.createCharacters = function() {
spriter_alias_Spriteset_Map_createCharacters.call(this);
this.createSpriterCharacters();
};
Spriteset_Map.prototype.createSpriterCharacters = function() {
this._spriterCharacterSprites = [];
// Creating Spriter Event
$gameMap.events().forEach(function(event) {
if (this.hasSpriterSprite(event)) {
this._spriterCharacterSprites.push(new Spriter_Character(event));
}
}, this);
// Creating Spriter Player
var playerNotes = $dataActors[$gameParty.leader()._actorId].meta;
if (playerNotes.hasOwnProperty("Spriter")) {
this._spriterCharacterSprites.push(new Spriter_Character($gamePlayer));
}
// Creating Spriter Followers
$gamePlayer.followers().reverseEach(function(follower) {
if (follower.actor() && this.hasSpriterSprite(follower)) {
this._spriterCharacterSprites.push(new Spriter_Character(follower));
}
}, this);
for (var j = 0; j < this._spriterCharacterSprites.length; j++) {
this._tilemap.addChild(this._spriterCharacterSprites[j]);
}
};
var spriter_alias_Spriteset_Map_update = Spriteset_Map.prototype.update;
Spriteset_Map.prototype.update = function() {
spriter_alias_Spriteset_Map_update.call(this);
if ($infoSpriter) {
this.updateFollowers();
this.updateEvents()
}
};
// Checks for requests to add Spriter Character
Spriteset_Map.prototype.updateFollowers = function() {
var followerRequests = $infoSpriter._followerRequests;
for (var i = 0; i < followerRequests.length; i ++) {
var followerId = followerRequests[i];
var followerNotes = $dataActors[followerId].meta;
if (followerNotes.hasOwnProperty("Spriter")) {
for (var j = 0; j < $gamePlayer.followers()._data.length; j++) {
var follower = $gamePlayer.followers()._data[j];
if (follower.actor() && follower.actor()._actorId == followerId) {
this._spriterCharacterSprites.push(new Spriter_Character(follower));
var index = this._spriterCharacterSprites.length - 1;
this._tilemap.addChild(this._spriterCharacterSprites[index]);
$infoSpriter._followerRequests = [];
}
}
}
}
};
Spriteset_Map.prototype.updateEvents = function() {
var eventRequests = $infoSpriter._eventRequests;
for (var i = 0; i < eventRequests.length; i ++) {
var eventId = eventRequests[i];
var event = $gameMap._events[eventId];
this._spriterCharacterSprites.push(new Spriter_Character(event));
var index = this._spriterCharacterSprites.length - 1;
this._tilemap.addChild(this._spriterCharacterSprites[index]);
$infoSpriter._eventRequests = [];
}
};
//-------------------------------------------------------------------------------------------------------------
// Checks Character For Spriter Comment/Note
//-------------------------------------------------------------------------------------------------------------
Spriteset_Map.prototype.hasSpriterSprite = function (character) {
if (character.constructor === Game_Event) {
if (character._pageIndex !== -1) {
var commandList = character.page(character._pageIndex).list;
for (var i = 0; i < commandList.length; i++) {
if (commandList[i].code == 108){
if (commandList[i].parameters[0].substring(1,8) == "Spriter") {
return true;
}
}
}
}
}
else if (character.constructor === Game_Follower) {
var followerId = character.actor()._actorId;
var followerNotes = $dataActors[followerId].meta;
if (followerNotes.hasOwnProperty("Spriter")) {
return true;
}
}
return false;
};
//-------------------------------------------------------------------------------------------------------------
//*************************************************************************************************************
// Spriter_Base
//*************************************************************************************************************
// Superclass for Spriter_Character and Spriter_Battler.
// Deals with the core functions of the Character/Actor animation.
//-------------------------------------------------------------------------------------------------------------
function Spriter_Base() {
this.initialize.apply(this, arguments);
}
Spriter_Base.prototype = Object.create(Sprite_Base.prototype);
Spriter_Base.prototype.constructor = Spriter_Base;
//-------------------------------------------------------------------------------------------------------------
// Initializing Sprite
//-------------------------------------------------------------------------------------------------------------
Spriter_Base.prototype.initialize = function(character) {
Sprite_Base.prototype.initialize.call(this);
this.initMembers();
this.setCharacter(character);
this.getAnimation(this._skeleton);
this.initSprite();
this.displaceSprite();
};
Spriter_Base.prototype.initMembers = function() {
this.anchor.x = 0.5;
this.anchor.y = 1;
this._character = null;
this._animationId = 0;
this._animation = null;
this._pathMain = null;
this._pathTime = null;
this._animationFrame = 0;
this._key = 0;
this._sprite = null;
this._skin = null;
this._skinParts = [];
this._childrenSprites = [];
this._skeleton = null;
this._speed = 1;
this._cellX = null;
this._cellY = null;
this._spriteMaskX = null;
this._spriteMaskY = null;
this._repeat = false;
this._spriteMask = {};
this._spriteType = '';
this._animLimiter = null;
this._metaKeyArray = [];
};
Spriter_Base.prototype.setCharacter = function(character) {
//Getting Character Meta
this._character = character;
this._spriteType = this._character instanceof Game_CharacterBase ? 'character' : 'object';
this._skeleton = this._character._spriter._skeleton;
this._skin = this._character._spriter._skin;
this._skinParts = this._character._spriter._skinParts;
this._cellX = Number(this._character._spriter._cellX);
this._cellY = Number(this._character._spriter._cellY);
this._speed = Number(this._character._spriter._speed);
this._stop = this._character._spriter._stop;
this._waitCounter = this._character._spriter._animLimiter !== null ? this._character._spriter._animLimiter : limitCounter;
this._animLimiter = this._character._spriter._animLimiter !== null ? this._character._spriter._animLimiter : limitCounter;
if (this._character._spriter._spriteMask) {
this._spriteMask.available = this._character._spriter._spriteMask.available;
}
if (this._spriteMask.available) {
this._spriteMask.x = Number(this._character._spriter._spriteMask.x);
this._spriteMask.y = Number(this._character._spriter._spriteMask.y);
this._spriteMask.w = Number(this._character._spriter._spriteMask.w);
this._spriteMask.h = Number(this._character._spriter._spriteMask.h);
}
};
//-------------------------------------------------------------------------------------------------------------
// Get animation from $spriterAnimations
//-------------------------------------------------------------------------------------------------------------
Spriter_Base.prototype.getAnimation = function(name) {
var property = name + ".scml";
this._animation = $spriterAnimations[property];
};
//-------------------------------------------------------------------------------------------------------------
// Set sprite's objects, bones and layers
//-------------------------------------------------------------------------------------------------------------
Spriter_Base.prototype.initSprite = function() {
this._pathTime = this._animation.entity.animation[this._animationId].timeline;
this._sprite = new Sprite();
this._group = new PIXI.display.Group(0, true);
this._layer = new PIXI.display.Layer(this._group);
this.addChild(this._sprite);
this._sprite.addChild(this._layer);
this._layer.group.enableSort = true;
this._element = [];
this._animLength = Number(this._animation.entity.animation[this._animationId].length);
this._repeat = this._animation.entity.animation[this._animationId].looping || "true";
this._repeat = eval(this._repeat);
var j = 0 ;
// Creating All Objects and Bones in the Timeline
for (var i = 0; i < this._pathTime.length; i++) {
if (this._pathTime[i].object_type == "bone"){
this._element[i] = new Sprite();
this._element[i].parent = null;
}
else {
this._element[i] = new PIXI.Sprite();
this._element[i].parent = null;
this._element[i].removeChildren();
this._element[i].parentGroup = this._group;
}
}
// Info Sprite
this._infoDisplaySprite = new Sprite();
this.addChild(this._infoDisplaySprite);
bitmapH = this._cellY;
this._infoDisplaySprite.bitmap = new Bitmap(200, bitmapH);
this._infoDisplaySprite.bitmap.fontSize = 10;
this._infoDisplaySprite.y = - bitmapH - 35;
this._infoDisplaySprite.x = -25;
// Sprite Mask
if (this._spriteMask.available) {
var x = this._spriteMask.x;
var y = this._spriteMask.y;
var w = this._spriteMask.w;
var h = this._spriteMask.h;
var myMask = new PIXI.Graphics();
myMask.beginFill();
myMask.drawRect(-this._cellX/2 + 2 + x, -this._cellY + 2 + y, w + 2, h + 2);
myMask.endFill();
this.addChild(myMask);
this.mask = myMask;
}
};
//-------------------------------------------------------------------------------------------------------------
// Moves Sprite from 0,0 point to -width/2,-height point.
//-------------------------------------------------------------------------------------------------------------
Spriter_Base.prototype.displaceSprite = function() {
this._sprite.x = -this._cellX/2;
this._sprite.y = -this._cellY;
};
//-------------------------------------------------------------------------------------------------------------
// Updating Sprite
//-------------------------------------------------------------------------------------------------------------
Spriter_Base.prototype.update = function() {
if (this._waitCounter == this._animLimiter) {
Sprite_Base.prototype.update.call(this);
this.checkCharacterState();
this.updateSprite();
this._waitCounter = 0;
}
else {
this._waitCounter++;
}
};
Spriter_Base.prototype.checkCharacterState = function() {
if (this.characterIsErased()) {
this.parent.removeChild(this);
delete this;
}
};
Spriter_Base.prototype.characterIsErased = function() {
var character = this._character;
if (character instanceof Game_Event && character._erased) {
return true;
}
else if (character instanceof Game_Follower && !character.actor()) {
return true;
}
return false;
};
Spriter_Base.prototype.updateDisplay = function() {
if (showFrames) {
this._infoDisplaySprite.bitmap.clear();
this._infoDisplaySprite.bitmap.drawText("key: " + this._key, 0, 10, 100, 1, 'left');
this._infoDisplaySprite.bitmap.drawText("frame: " + String(Math.round(this._animationFrame)), 0, 25, 100, 1, 'left');
}
};
Spriter_Base.prototype.resetSpriterSprite = function() {
this._character._spriter.forceUpdate = true;
this._character._spriter.tag = [];
this._character._spriter.var = {};
this._animationFrame = 0;
this._key = 0;
this._waitCounter = this._animLimiter;
this.refreshSpriterSprite();
};
Spriter_Base.prototype.refreshSpriterSprite = function() {
this.removeChildren();
this.getAnimation(this._skeleton);
delete this._sprite;
delete this._layer;
delete this._group;