-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathIgnisSceneTransitions.js
9815 lines (9089 loc) · 544 KB
/
IgnisSceneTransitions.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
//=============================================================================
// RPG Maker MZ - Ignis Special Scene Transitions
//=============================================================================
/*:
* @target MZ
* @plugindesc Special Scene Transitions for MZ
* @author Reisen (Mauricio Pastana)
*
* @help Ignis Ignis Special Scene Transitions -
* For support and new plugins join our discord server! https://discord.gg/wsPeqeA
* Want to support new creations? be a patreon! https://www.patreon.com/raizen884?fan_landing=true
*
*
* The TweenMax lib is under greensock license
* @TweenMaxlicense Copyright (c) 2008-2019, GreenSock. All rights reserved.
* This work is subject to the terms at http://greensock.com/standard-license or for
* Club GreenSock members, the software agreement that was issued with your membership.
*
* TweenMaxauthors: Jack Doyle, [email protected]
*
*
* For this plugin, you first need to have a displacement map image on the
* img/displacement folder of your project.
* After that it is pretty simple, configure on the plugin parameters the displacements
* and what scene they occur, it is as simple as that :)
* @param DisplacementConfig
* @type struct<Displacement>[]
* @text Displacement Configure
* @param SceneIn
* @type struct<SceneConfig>[]
* @text Scene IN Configure
* @desc Here you can configure what effects when this scene is opened. You CAN have more than 1 effect for a scene.
*
* @param SceneOut
* @type struct<SceneConfigOut>[]
* @text Scene OUT Configure
* @desc Here you can configure what effects when this scene is closed. You CAN have more than 1 effect for a scene.
* @param BattleTransition
* @type boolean
* @default true
* @desc Keep The zoom battle transition?
* @param FadeOutTransitions
* @type boolean
* @default true
* @desc Keep The fadeOut transition?
*/
/*~struct~SceneConfig:
* @param Scene Name
* @type text
* @default Scene_Map
* @desc Choose the Scene to happen the transition effect
* @param displacement
* @type number
* @default 1
* @desc Choose from one of the displacement effects you have configured
*/
/*~struct~SceneConfigOut:
* @param Scene Name
* @type text
* @default Scene_Map
* @desc Choose the Scene to happen the transition effect
* @param Next Scene
* @type text
* @default Scene_Battle
* @desc Transition will happen only if it is this the next scene, to be any scene, just erase the value.
* @param displacement
* @type number
* @default 1
* @desc Choose from one of the displacement effects you have configured
*/
/*~struct~Displacement:
* @param displacement image
* @type file
* @dir img/displacement/
* @desc Choose a displacement map image
* @param speed
* @type number
* @decimals 1
* @default 3
* @desc The higher, the faster the effect happens
* @param time
* @type number
* @decimals 0
* @default 40
* @desc The time in frames for the Scene change
* @param fade
* @type boolean
* @default true
* @desc Will there be a fadeIn/Out for this effect?
* @param expo
* @type select
* @option IN
* @option OUT
* @option INOUT
* @default 1
* @decimals 0
* @desc Type of displacement
* @param X
* @type number
* @max 100000
* @min -100000
* @decimals 0
* @default 50000
* @desc x_axis speed for displacement
* @param Y
* @type number
* @max 100000
* @min -100000
* @decimals 0
* @default 0
* @desc y_axis speed for displacement
* @param scale
* @type number
* @decimals 1
* @default 1
* @desc scale of the map image
* @param anchor
* @type number
* @decimals 1
* @default 0.5
* @desc anchor setting for the image, 0.5 - center, 0 - top-left, 1- top-down
*/
//-----------------------------------------------------------------------------
// ImageManager
//
// The scene class that handles images.
//=============================================================================
ImageManager.loadDisplacement = function (filename, hue) {
return this.loadBitmap('img/displacement/', filename, hue, true);
};
(() => {
//-----------------------------------------------------------------------------
// SceneManager
//
// The scene class of the Manager.
//=============================================================================
let _ignisEngine_SceneTransitions_SceneManager_updateScene = SceneManager.updateScene
SceneManager.updateScene = function () {
if (this._displacementCount > 0)
return;
_ignisEngine_SceneTransitions_SceneManager_updateScene.call(this, ...arguments);
};
let _ignisEngine_SceneTransitions_SceneManager_changeScene = SceneManager.changeScene
SceneManager.changeScene = function () {
if (this.isSceneChanging() && !this.isCurrentSceneBusy()) {
if (this._scene && this._nextScene) {
if (!this._scene._displacementEnd) {
this.createDisplacement();
}
if (this._scene._displacementEnd && this._displacementCount < SceneManager._scene._displacementCount) {
this._displacementCount++
return;
}
}
}
_ignisEngine_SceneTransitions_SceneManager_changeScene.call(this, ...arguments)
this._displacementCount = 0
};
SceneManager.createDisplacement = function () {
this._displacementCount = 0
this._scene.createIgnisDisplacementVariablesOut();
this._scene.createIgnisDisplacement()
}
Scene_Base.prototype.createIgnisDisplacementVariablesOut = function () {
const ignisParametersDisplacement = JSON.parse(this.ignisParameters['DisplacementConfig']);
const ignisParametersSceneOut = JSON.parse(this.ignisParameters['SceneOut']);
let ignisDisplacementChoice = [];
let tempSceneIn;
for (var n = 0; n < ignisParametersSceneOut.length; n++) {
tempSceneIn = JSON.parse(ignisParametersSceneOut[n]);
if (eval("this instanceof ".concat(tempSceneIn["Scene Name"])) &&
((tempSceneIn["Next Scene"]) == "" || eval("SceneManager._nextScene instanceof ".concat(tempSceneIn["Next Scene"])))) { ignisDisplacementChoice.push(parseInt(tempSceneIn["displacement"])) }
}
this._ignisDisplacementChoice = ignisDisplacementChoice.length > 0 ? ignisDisplacementChoice[Math.randomInt(ignisDisplacementChoice.length)] : false;
this.getIgnisDisplacementValues(this._ignisDisplacementChoice, ignisParametersDisplacement);
}
let _ignisEngine_SceneTransitions_SceneManager_initialize = Scene_Base.prototype.initialize
Scene_Base.prototype.create = function () {
_ignisEngine_SceneTransitions_SceneManager_initialize.call(this, ...arguments)
this.ignisParameters = PluginManager.parameters('IgnisSceneTransitions');
this.createIgnisDisplacementVariables();
this.createReverseIgnisDisplacement()
this._displacementCount = 0;
};
Scene_Base.prototype.createIgnisDisplacementVariables = function () {
const ignisParametersDisplacement = JSON.parse(this.ignisParameters['DisplacementConfig']);
const ignisParametersSceneIn = JSON.parse(this.ignisParameters['SceneIn']);
let ignisDisplacementChoice = [];
let tempSceneIn;
for (var n = 0; n < ignisParametersSceneIn.length; n++) {
tempSceneIn = JSON.parse(ignisParametersSceneIn[n]);
if (eval("this instanceof ".concat(tempSceneIn["Scene Name"]))) { ignisDisplacementChoice.push(parseInt(tempSceneIn["displacement"])) }
}
this._ignisDisplacementChoice = ignisDisplacementChoice.length > 0 ? ignisDisplacementChoice[Math.randomInt(ignisDisplacementChoice.length)] : false;
this.getIgnisDisplacementValues(this._ignisDisplacementChoice, ignisParametersDisplacement);
}
Scene_Base.prototype.getIgnisDisplacementValues = function (num, ignisParametersDisplacement) {
if (!num) { return };
this.ignisDiplacementeValues = JSON.parse(ignisParametersDisplacement[num - 1]);
}
let _ignisEngine_SceneTransitions_SceneManager_update = Scene_Base.prototype.update
Scene_Base.prototype.update = function () {
_ignisEngine_SceneTransitions_SceneManager_update.call(this, ...arguments)
if (this._startCountIgnisDisplacement) {
this.tl.timeScale(parseFloat(this.ignisDiplacementeValues["speed"]));
this.tl.reverse();
this._startCountIgnisDisplacement = false
}
};
Scene_Base.prototype.createReverseIgnisDisplacement = function () {
this._startCountIgnisDisplacement = false
if (!this._ignisDisplacementChoice) { return };
let d = this.ignisDiplacementeValues;
this._startCountIgnisDisplacement = true
this._displacement = new Sprite();
this._displacement.bitmap = ImageManager.loadDisplacement(d["displacement image"]);
this._displacement.texture.baseTexture.wrapMode = PIXI.WRAP_MODES.REPEAT;
this._displacement.scale.set(parseFloat(d["scale"]));
this._displacement.anchor.set(parseFloat(d["anchor"]));
this.addChild(this._displacement);
this.displacementFilter = new PIXI.filters.DisplacementFilter(this._displacement);
this.filters.push(this.displacementFilter);
this.displacementFilter.scale.x = 0;
this.displacementFilter.scale.y = 0;
this.tl = new TimelineMax({ paused: true });
this.tl.to(this.displacementFilter.scale, 8, { x: parseInt(d["X"]), y: parseInt(d["Y"]), ease: this.getIgnisEase(d["expo"]) });
if (d["fade"] == "true")
this.startFadeIn(parseInt(d["time"]))
this.tl.timeScale(2);
this.tl.play();
this._ignisDisplacementChoice = false;
}
Scene_Base.prototype.getIgnisEase = function (type) {
switch (type) {
case "IN":
Expo.easeIn;
case "OUT":
return Expo.easeOut;
case "INOUT":
return Expo.easeInOut;
}
}
let _ignisEngine_Scene_Base_fadeOutAll = Scene_Base.prototype.fadeOutAll;
Scene_Base.prototype.fadeOutAll = function () {
if (this.ignisParameters["FadeOutTransitions"] == "false") {
const time = this.slowFadeSpeed() / 60;
AudioManager.fadeOutBgm(time);
AudioManager.fadeOutBgs(time);
AudioManager.fadeOutMe(time);
return
}
_ignisEngine_Scene_Base_fadeOutAll.call(this, ...arguments);
};
Scene_Base.prototype.createIgnisDisplacement = function () {
this._displacementCount = 1;
if (!this._ignisDisplacementChoice) { return };
let d = this.ignisDiplacementeValues;
this._displacementEnd = new Sprite();
this._displacementEnd.bitmap = ImageManager.loadDisplacement(d["displacement image"]);
this._displacementEnd.texture.baseTexture.wrapMode = PIXI.WRAP_MODES.REPEAT;
this._displacementEnd.scale.set(parseFloat(d["scale"]));
this._displacementEnd.anchor.set(parseFloat(d["anchor"]));
this.addChild(this._displacementEnd);
this.displacementFilterEnd = new PIXI.filters.DisplacementFilter(this._displacementEnd);
this.filters.push(this.displacementFilterEnd);
this.displacementFilterEnd.scale.x = 0;
this.displacementFilterEnd.scale.y = 0;
this.tl2 = new TimelineMax({ paused: true });
this.tl2.to(this.displacementFilterEnd.scale, 8, { x: parseInt(d["X"]), y: parseInt(d["Y"]), ease: this.getIgnisEase(d["expo"]) });
this.tl2.timeScale(parseFloat(d["speed"]));
this.tl2.play();
if (d["fade"] == "true") {
this.startFadeOut(parseInt(d["time"]))
this._displacementCount = 1;
} else
this._displacementCount = parseInt(d["time"]);
}
let ignisEngine_SceneTransitions_Scene_Map_updateEncounterEffect = Scene_Map.prototype.updateEncounterEffect;
Scene_Map.prototype.updateEncounterEffect = function () {
if (this.ignisParameters["BattleTransition"] == "false") {
this._encounterEffectDuration = 0;
BattleManager.playBattleBgm();
} else {
ignisEngine_SceneTransitions_Scene_Map_updateEncounterEffect.call(this, ...arguments);
}
};
let ignisEngine_SceneTransitions_Scene_Battle_stop = Scene_Battle.prototype.stop;
Scene_Battle.prototype.stop = function () {
if (this.ignisParameters["FadeOutTransitions"] == "true") {
ignisEngine_SceneTransitions_Scene_Battle_stop.call(this, ...arguments);
} else {
Scene_Message.prototype.stop.call(this);
this._statusWindow.close();
this._partyCommandWindow.close();
this._actorCommandWindow.close();
}
};
})();
/*!
/* eslint-disable */
var _gsScope = (typeof (module) !== "undefined" && module.exports && typeof (global) !== "undefined") ? global : this || window; //helps ensure compatibility with AMD/RequireJS and CommonJS/Node
(_gsScope._gsQueue || (_gsScope._gsQueue = [])).push(function () {
"use strict";
_gsScope._gsDefine("TimelineMax", ["TimelineLite", "TweenLite", "easing.Ease"], function (TimelineLite, TweenLite, Ease) {
var TimelineMax = function (vars) {
TimelineLite.call(this, vars);
this._repeat = this.vars.repeat || 0;
this._repeatDelay = this.vars.repeatDelay || 0;
this._cycle = 0;
this._yoyo = !!this.vars.yoyo;
this._dirty = true;
},
_tinyNum = 0.00000001,
TweenLiteInternals = TweenLite._internals,
_lazyTweens = TweenLiteInternals.lazyTweens,
_lazyRender = TweenLiteInternals.lazyRender,
_globals = _gsScope._gsDefine.globals,
_easeNone = new Ease(null, null, 1, 0),
p = TimelineMax.prototype = new TimelineLite();
p.constructor = TimelineMax;
p.kill()._gc = false;
TimelineMax.version = "2.1.3";
p.invalidate = function () {
this._yoyo = !!this.vars.yoyo;
this._repeat = this.vars.repeat || 0;
this._repeatDelay = this.vars.repeatDelay || 0;
this._uncache(true);
return TimelineLite.prototype.invalidate.call(this);
};
p.addCallback = function (callback, position, params, scope) {
return this.add(TweenLite.delayedCall(0, callback, params, scope), position);
};
p.removeCallback = function (callback, position) {
if (callback) {
if (position == null) {
this._kill(null, callback);
} else {
var a = this.getTweensOf(callback, false),
i = a.length,
time = this._parseTimeOrLabel(position);
while (--i > -1) {
if (a[i]._startTime === time) {
a[i]._enabled(false, false);
}
}
}
}
return this;
};
p.removePause = function (position) {
return this.removeCallback(TimelineLite._internals.pauseCallback, position);
};
p.tweenTo = function (position, vars) {
vars = vars || {};
var copy = { ease: _easeNone, useFrames: this.usesFrames(), immediateRender: false, lazy: false },
Engine = (vars.repeat && _globals.TweenMax) || TweenLite,
duration, p, t;
for (p in vars) {
copy[p] = vars[p];
}
copy.time = this._parseTimeOrLabel(position);
duration = (Math.abs(Number(copy.time) - this._time) / this._timeScale) || 0.001;
t = new Engine(this, duration, copy);
copy.onStart = function () {
t.target.paused(true);
if (t.vars.time !== t.target.time() && duration === t.duration() && !t.isFromTo) { //don't make the duration zero - if it's supposed to be zero, don't worry because it's already initting the tween and will complete immediately, effectively making the duration zero anyway. If we make duration zero, the tween won't run at all.
t.duration(Math.abs(t.vars.time - t.target.time()) / t.target._timeScale).render(t.time(), true, true); //render() right away to ensure that things look right, especially in the case of .tweenTo(0).
}
if (vars.onStart) { //in case the user had an onStart in the vars - we don't want to overwrite it.
vars.onStart.apply(vars.onStartScope || vars.callbackScope || t, vars.onStartParams || []); //don't use t._callback("onStart") or it'll point to the copy.onStart and we'll get a recursion error.
}
};
return t;
};
p.tweenFromTo = function (fromPosition, toPosition, vars) {
vars = vars || {};
fromPosition = this._parseTimeOrLabel(fromPosition);
vars.startAt = { onComplete: this.seek, onCompleteParams: [fromPosition], callbackScope: this };
vars.immediateRender = (vars.immediateRender !== false);
var t = this.tweenTo(toPosition, vars);
t.isFromTo = 1; //to ensure we don't mess with the duration in the onStart (we've got the start and end values here, so lock it in)
return t.duration((Math.abs(t.vars.time - fromPosition) / this._timeScale) || 0.001);
};
p.render = function (time, suppressEvents, force) {
if (this._gc) {
this._enabled(true, false);
}
var self = this,
prevTime = self._time,
totalDur = (!self._dirty) ? self._totalDuration : self.totalDuration(),
dur = self._duration,
prevTotalTime = self._totalTime,
prevStart = self._startTime,
prevTimeScale = self._timeScale,
prevRawPrevTime = self._rawPrevTime,
prevPaused = self._paused,
prevCycle = self._cycle,
tween, isComplete, next, callback, internalForce, cycleDuration, pauseTween, curTime, pauseTime;
if (prevTime !== self._time) { //if totalDuration() finds a child with a negative startTime and smoothChildTiming is true, things get shifted around internally so we need to adjust the time accordingly. For example, if a tween starts at -30 we must shift EVERYTHING forward 30 seconds and move this timeline's startTime backward by 30 seconds so that things align with the playhead (no jump).
time += self._time - prevTime;
}
if (time >= totalDur - _tinyNum && time >= 0) { //to work around occasional floating point math artifacts.
if (!self._locked) {
self._totalTime = totalDur;
self._cycle = self._repeat;
}
if (!self._reversed) if (!self._hasPausedChild()) {
isComplete = true;
callback = "onComplete";
internalForce = !!self._timeline.autoRemoveChildren; //otherwise, if the animation is unpaused/activated after it's already finished, it doesn't get removed from the parent timeline.
if (self._duration === 0) if ((time <= 0 && time >= -_tinyNum) || prevRawPrevTime < 0 || prevRawPrevTime === _tinyNum) if (prevRawPrevTime !== time && self._first) {
internalForce = true;
if (prevRawPrevTime > _tinyNum) {
callback = "onReverseComplete";
}
}
}
self._rawPrevTime = (self._duration || !suppressEvents || time || self._rawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration timeline or tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
if (self._yoyo && (self._cycle & 1)) {
self._time = time = 0;
} else {
self._time = dur;
time = dur + 0.0001; //to avoid occasional floating point rounding errors - sometimes child tweens/timelines were not being fully completed (their progress might be 0.999999999999998 instead of 1 because when _time - tween._startTime is performed, floating point errors would return a value that was SLIGHTLY off). Try (999999999999.7 - 999999999999) * 1 = 0.699951171875 instead of 0.7. We cannot do less then 0.0001 because the same issue can occur when the duration is extremely large like 999999999999 in which case adding 0.00000001, for example, causes it to act like nothing was added.
}
} else if (time < _tinyNum) { //to work around occasional floating point math artifacts, round super small values to 0.
if (!self._locked) {
self._totalTime = self._cycle = 0;
}
self._time = 0;
if (time > -_tinyNum) {
time = 0;
}
if (prevTime !== 0 || (dur === 0 && prevRawPrevTime !== _tinyNum && (prevRawPrevTime > 0 || (time < 0 && prevRawPrevTime >= 0)) && !self._locked)) { //edge case for checking time < 0 && prevRawPrevTime >= 0: a zero-duration fromTo() tween inside a zero-duration timeline (yeah, very rare)
callback = "onReverseComplete";
isComplete = self._reversed;
}
if (time < 0) {
self._active = false;
if (self._timeline.autoRemoveChildren && self._reversed) {
internalForce = isComplete = true;
callback = "onReverseComplete";
} else if (prevRawPrevTime >= 0 && self._first) { //when going back beyond the start, force a render so that zero-duration tweens that sit at the very beginning render their start values properly. Otherwise, if the parent timeline's playhead lands exactly at this timeline's startTime, and then moves backwards, the zero-duration tweens at the beginning would still be at their end state.
internalForce = true;
}
self._rawPrevTime = time;
} else {
self._rawPrevTime = (dur || !suppressEvents || time || self._rawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration timeline or tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
if (time === 0 && isComplete) { //if there's a zero-duration tween at the very beginning of a timeline and the playhead lands EXACTLY at time 0, that tween will correctly render its end values, but we need to keep the timeline alive for one more render so that the beginning values render properly as the parent's playhead keeps moving beyond the begining. Imagine obj.x starts at 0 and then we do tl.set(obj, {x:100}).to(obj, 1, {x:200}) and then later we tl.reverse()...the goal is to have obj.x revert to 0. If the playhead happens to land on exactly 0, without this chunk of code, it'd complete the timeline and remove it from the rendering queue (not good).
tween = self._first;
while (tween && tween._startTime === 0) {
if (!tween._duration) {
isComplete = false;
}
tween = tween._next;
}
}
time = 0; //to avoid occasional floating point rounding errors (could cause problems especially with zero-duration tweens at the very beginning of the timeline)
if (!self._initted) {
internalForce = true;
}
}
} else {
if (dur === 0 && prevRawPrevTime < 0) { //without this, zero-duration repeating timelines (like with a simple callback nested at the very beginning and a repeatDelay) wouldn't render the first time through.
internalForce = true;
}
self._time = self._rawPrevTime = time;
if (!self._locked) {
self._totalTime = time;
if (self._repeat !== 0) {
cycleDuration = dur + self._repeatDelay;
self._cycle = (self._totalTime / cycleDuration) >> 0; //originally _totalTime % cycleDuration but floating point errors caused problems, so I normalized it. (4 % 0.8 should be 0 but it gets reported as 0.79999999!)
if (self._cycle) if (self._cycle === self._totalTime / cycleDuration && prevTotalTime <= time) {
self._cycle--; //otherwise when rendered exactly at the end time, it will act as though it is repeating (at the beginning)
}
self._time = self._totalTime - (self._cycle * cycleDuration);
if (self._yoyo) if (self._cycle & 1) {
self._time = dur - self._time;
}
if (self._time > dur) {
self._time = dur;
time = dur + 0.0001; //to avoid occasional floating point rounding error
} else if (self._time < 0) {
self._time = time = 0;
} else {
time = self._time;
}
}
}
}
if (self._hasPause && !self._forcingPlayhead && !suppressEvents) {
time = self._time;
if (time > prevTime || (self._repeat && prevCycle !== self._cycle)) {
tween = self._first;
while (tween && tween._startTime <= time && !pauseTween) {
if (!tween._duration) if (tween.data === "isPause" && !tween.ratio && !(tween._startTime === 0 && self._rawPrevTime === 0)) {
pauseTween = tween;
}
tween = tween._next;
}
} else {
tween = self._last;
while (tween && tween._startTime >= time && !pauseTween) {
if (!tween._duration) if (tween.data === "isPause" && tween._rawPrevTime > 0) {
pauseTween = tween;
}
tween = tween._prev;
}
}
if (pauseTween) {
pauseTime = self._startTime + (self._reversed ? self._duration - pauseTween._startTime : pauseTween._startTime) / self._timeScale;
if (pauseTween._startTime < dur) {
self._time = self._rawPrevTime = time = pauseTween._startTime;
self._totalTime = time + (self._cycle * (self._totalDuration + self._repeatDelay));
}
}
}
if (self._cycle !== prevCycle) if (!self._locked) {
/*
make sure children at the end/beginning of the timeline are rendered properly. If, for example,
a 3-second long timeline rendered at 2.9 seconds previously, and now renders at 3.2 seconds (which
would get translated to 2.8 seconds if the timeline yoyos or 0.2 seconds if it just repeats), there
could be a callback or a short tween that's at 2.95 or 3 seconds in which wouldn't render. So
we need to push the timeline to the end (and/or beginning depending on its yoyo value). Also we must
ensure that zero-duration tweens at the very beginning or end of the TimelineMax work.
*/
var backwards = (self._yoyo && (prevCycle & 1) !== 0),
wrap = (backwards === (self._yoyo && (self._cycle & 1) !== 0)),
recTotalTime = self._totalTime,
recCycle = self._cycle,
recRawPrevTime = self._rawPrevTime,
recTime = self._time;
self._totalTime = prevCycle * dur;
if (self._cycle < prevCycle) {
backwards = !backwards;
} else {
self._totalTime += dur;
}
self._time = prevTime; //temporarily revert _time so that render() renders the children in the correct order. Without this, tweens won't rewind correctly. We could arhictect things in a "cleaner" way by splitting out the rendering queue into a separate method but for performance reasons, we kept it all inside this method.
self._rawPrevTime = (dur === 0) ? prevRawPrevTime - 0.0001 : prevRawPrevTime;
self._cycle = prevCycle;
self._locked = true; //prevents changes to totalTime and skips repeat/yoyo behavior when we recursively call render()
prevTime = (backwards) ? 0 : dur;
self.render(prevTime, suppressEvents, (dur === 0));
if (!suppressEvents) if (!self._gc) {
if (self.vars.onRepeat) {
self._cycle = recCycle; //in case the onRepeat alters the playhead or invalidates(), we shouldn't stay locked or use the previous cycle.
self._locked = false;
self._callback("onRepeat");
}
}
if (prevTime !== self._time) { //in case there's a callback like onComplete in a nested tween/timeline that changes the playhead position, like via seek(), we should just abort.
return;
}
if (wrap) {
self._cycle = prevCycle; //if there's an onRepeat, we reverted this above, so make sure it's set properly again. We also unlocked in that scenario, so reset that too.
self._locked = true;
prevTime = (backwards) ? dur + 0.0001 : -0.0001;
self.render(prevTime, true, false);
}
self._locked = false;
if (self._paused && !prevPaused) { //if the render() triggered callback that paused this timeline, we should abort (very rare, but possible)
return;
}
self._time = recTime;
self._totalTime = recTotalTime;
self._cycle = recCycle;
self._rawPrevTime = recRawPrevTime;
}
if ((self._time === prevTime || !self._first) && !force && !internalForce && !pauseTween) {
if (prevTotalTime !== self._totalTime) if (self._onUpdate) if (!suppressEvents) { //so that onUpdate fires even during the repeatDelay - as long as the totalTime changed, we should trigger onUpdate.
self._callback("onUpdate");
}
return;
} else if (!self._initted) {
self._initted = true;
}
if (!self._active) if (!self._paused && self._totalTime !== prevTotalTime && time > 0) {
self._active = true; //so that if the user renders the timeline (as opposed to the parent timeline rendering it), it is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the timeline already finished but the user manually re-renders it as halfway done, for example.
}
if (prevTotalTime === 0) if (self.vars.onStart) if (self._totalTime !== 0 || !self._totalDuration) if (!suppressEvents) {
self._callback("onStart");
}
curTime = self._time;
if (curTime >= prevTime) {
tween = self._first;
while (tween) {
next = tween._next; //record it here because the value could change after rendering...
if (curTime !== self._time || (self._paused && !prevPaused)) { //in case a tween pauses or seeks the timeline when rendering, like inside of an onUpdate/onComplete
break;
} else if (tween._active || (tween._startTime <= self._time && !tween._paused && !tween._gc)) {
if (pauseTween === tween) {
self.pause();
self._pauseTime = pauseTime; //so that when we resume(), it's starting from exactly the right spot (the pause() method uses the rawTime for the parent, but that may be a bit too far ahead)
}
if (!tween._reversed) {
tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force);
} else {
tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force);
}
}
tween = next;
}
} else {
tween = self._last;
while (tween) {
next = tween._prev; //record it here because the value could change after rendering...
if (curTime !== self._time || (self._paused && !prevPaused)) { //in case a tween pauses or seeks the timeline when rendering, like inside of an onUpdate/onComplete
break;
} else if (tween._active || (tween._startTime <= prevTime && !tween._paused && !tween._gc)) {
if (pauseTween === tween) {
pauseTween = tween._prev; //the linked list is organized by _startTime, thus it's possible that a tween could start BEFORE the pause and end after it, in which case it would be positioned before the pause tween in the linked list, but we should render it before we pause() the timeline and cease rendering. This is only a concern when going in reverse.
while (pauseTween && pauseTween.endTime() > self._time) {
pauseTween.render((pauseTween._reversed ? pauseTween.totalDuration() - ((time - pauseTween._startTime) * pauseTween._timeScale) : (time - pauseTween._startTime) * pauseTween._timeScale), suppressEvents, force);
pauseTween = pauseTween._prev;
}
pauseTween = null;
self.pause();
self._pauseTime = pauseTime; //so that when we resume(), it's starting from exactly the right spot (the pause() method uses the rawTime for the parent, but that may be a bit too far ahead)
}
if (!tween._reversed) {
tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force);
} else {
tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force);
}
}
tween = next;
}
}
if (self._onUpdate) if (!suppressEvents) {
if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when a timeline finishes, users expect things to have rendered fully. Imagine an onUpdate on a timeline that reports/checks tweened values.
_lazyRender();
}
self._callback("onUpdate");
}
if (callback) if (!self._locked) if (!self._gc) if (prevStart === self._startTime || prevTimeScale !== self._timeScale) if (self._time === 0 || totalDur >= self.totalDuration()) { //if one of the tweens that was rendered altered this timeline's startTime (like if an onComplete reversed the timeline), it probably isn't complete. If it is, don't worry, because whatever call altered the startTime would complete if it was necessary at the new time. The only exception is the timeScale property. Also check _gc because there's a chance that kill() could be called in an onUpdate
if (isComplete) {
if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when a timeline finishes, users expect things to have rendered fully. Imagine an onComplete on a timeline that reports/checks tweened values.
_lazyRender();
}
if (self._timeline.autoRemoveChildren) {
self._enabled(false, false);
}
self._active = false;
}
if (!suppressEvents && self.vars[callback]) {
self._callback(callback);
}
}
};
p.getActive = function (nested, tweens, timelines) {
var a = [],
all = this.getChildren(nested || (nested == null), tweens || (nested == null), !!timelines),
cnt = 0,
l = all.length,
i, tween;
for (i = 0; i < l; i++) {
tween = all[i];
if (tween.isActive()) {
a[cnt++] = tween;
}
}
return a;
};
p.getLabelAfter = function (time) {
if (!time) if (time !== 0) { //faster than isNan()
time = this._time;
}
var labels = this.getLabelsArray(),
l = labels.length,
i;
for (i = 0; i < l; i++) {
if (labels[i].time > time) {
return labels[i].name;
}
}
return null;
};
p.getLabelBefore = function (time) {
if (time == null) {
time = this._time;
}
var labels = this.getLabelsArray(),
i = labels.length;
while (--i > -1) {
if (labels[i].time < time) {
return labels[i].name;
}
}
return null;
};
p.getLabelsArray = function () {
var a = [],
cnt = 0,
p;
for (p in this._labels) {
a[cnt++] = { time: this._labels[p], name: p };
}
a.sort(function (a, b) {
return a.time - b.time;
});
return a;
};
p.invalidate = function () {
this._locked = false; //unlock and set cycle in case invalidate() is called from inside an onRepeat
return TimelineLite.prototype.invalidate.call(this);
};
//---- GETTERS / SETTERS -------------------------------------------------------------------------------------------------------
p.progress = function (value, suppressEvents) {
return (!arguments.length) ? (this._time / this.duration()) || 0 : this.totalTime(this.duration() * ((this._yoyo && (this._cycle & 1) !== 0) ? 1 - value : value) + (this._cycle * (this._duration + this._repeatDelay)), suppressEvents);
};
p.totalProgress = function (value, suppressEvents) {
return (!arguments.length) ? (this._totalTime / this.totalDuration()) || 0 : this.totalTime(this.totalDuration() * value, suppressEvents);
};
p.totalDuration = function (value) {
if (!arguments.length) {
if (this._dirty) {
TimelineLite.prototype.totalDuration.call(this); //just forces refresh
//Instead of Infinity, we use 999999999999 so that we can accommodate reverses.
this._totalDuration = (this._repeat === -1) ? 999999999999 : this._duration * (this._repeat + 1) + (this._repeatDelay * this._repeat);
}
return this._totalDuration;
}
return (this._repeat === -1 || !value) ? this : this.timeScale(this.totalDuration() / value);
};
p.time = function (value, suppressEvents) {
if (!arguments.length) {
return this._time;
}
if (this._dirty) {
this.totalDuration();
}
var duration = this._duration,
cycle = this._cycle,
cycleDur = cycle * (duration + this._repeatDelay);
if (value > duration) {
value = duration;
}
return this.totalTime((this._yoyo && (cycle & 1)) ? duration - value + cycleDur : this._repeat ? value + cycleDur : value, suppressEvents);
};
p.repeat = function (value) {
if (!arguments.length) {
return this._repeat;
}
this._repeat = value;
return this._uncache(true);
};
p.repeatDelay = function (value) {
if (!arguments.length) {
return this._repeatDelay;
}
this._repeatDelay = value;
return this._uncache(true);
};
p.yoyo = function (value) {
if (!arguments.length) {
return this._yoyo;
}
this._yoyo = value;
return this;
};
p.currentLabel = function (value) {
if (!arguments.length) {
return this.getLabelBefore(this._time + _tinyNum);
}
return this.seek(value, true);
};
return TimelineMax;
}, true);
/*
* ----------------------------------------------------------------
* TimelineLite
* ----------------------------------------------------------------
*/
_gsScope._gsDefine("TimelineLite", ["core.Animation", "core.SimpleTimeline", "TweenLite"], function (Animation, SimpleTimeline, TweenLite) {
var TimelineLite = function (vars) {
SimpleTimeline.call(this, vars);
var self = this,
v = self.vars,
val, p;
self._labels = {};
self.autoRemoveChildren = !!v.autoRemoveChildren;
self.smoothChildTiming = !!v.smoothChildTiming;
self._sortChildren = true;
self._onUpdate = v.onUpdate;
for (p in v) {
val = v[p];
if (_isArray(val)) if (val.join("").indexOf("{self}") !== -1) {
v[p] = self._swapSelfInParams(val);
}
}
if (_isArray(v.tweens)) {
self.add(v.tweens, 0, v.align, v.stagger);
}
},
_tinyNum = 0.00000001,
TweenLiteInternals = TweenLite._internals,
_internals = TimelineLite._internals = {},
_isSelector = TweenLiteInternals.isSelector,
_isArray = TweenLiteInternals.isArray,
_lazyTweens = TweenLiteInternals.lazyTweens,
_lazyRender = TweenLiteInternals.lazyRender,
_globals = _gsScope._gsDefine.globals,
_copy = function (vars) {
var copy = {}, p;
for (p in vars) {
copy[p] = vars[p];
}
return copy;
},
_applyCycle = function (vars, targets, i) {
var alt = vars.cycle,
p, val;
for (p in alt) {
val = alt[p];
vars[p] = (typeof (val) === "function") ? val(i, targets[i], targets) : val[i % val.length];
}
delete vars.cycle;
},
_pauseCallback = _internals.pauseCallback = function () { },
_slice = function (a) { //don't use [].slice because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
var b = [],
l = a.length,
i;
for (i = 0; i !== l; b.push(a[i++]));
return b;
},
_defaultImmediateRender = function (tl, toVars, fromVars, defaultFalse) { //default to immediateRender:true unless otherwise set in toVars, fromVars or if defaultFalse is passed in as true
var ir = "immediateRender";
if (!(ir in toVars)) {
toVars[ir] = !((fromVars && fromVars[ir] === false) || defaultFalse);
}
return toVars;
},
//for distributing values across an array. Can accept a number, a function or (most commonly) a function which can contain the following properties: {base, amount, from, ease, grid, axis, length, each}. Returns a function that expects the following parameters: index, target, array. Recognizes the following
_distribute = function (v) {
if (typeof (v) === "function") {
return v;
}
var vars = (typeof (v) === "object") ? v : { each: v }, //n:1 is just to indicate v was a number; we leverage that later to set v according to the length we get. If a number is passed in, we treat it like the old stagger value where 0.1, for example, would mean that things would be distributed with 0.1 between each element in the array rather than a total "amount" that's chunked out among them all.
ease = vars.ease,
from = vars.from || 0,
base = vars.base || 0,
cache = {},
isFromKeyword = isNaN(from),
axis = vars.axis,
ratio = { center: 0.5, end: 1 }[from] || 0;
return function (i, target, a) {
var l = (a || vars).length,
distances = cache[l],
originX, originY, x, y, d, j, max, min, wrap;
if (!distances) {
wrap = (vars.grid === "auto") ? 0 : (vars.grid || [Infinity])[0];
if (!wrap) {
max = -Infinity;
while (max < (max = a[wrap++].getBoundingClientRect().left) && wrap < l) { }
wrap--;
}
distances = cache[l] = [];
originX = isFromKeyword ? (Math.min(wrap, l) * ratio) - 0.5 : from % wrap;
originY = isFromKeyword ? l * ratio / wrap - 0.5 : (from / wrap) | 0;
max = 0;
min = Infinity;
for (j = 0; j < l; j++) {
x = (j % wrap) - originX;
y = originY - ((j / wrap) | 0);
distances[j] = d = !axis ? Math.sqrt(x * x + y * y) : Math.abs((axis === "y") ? y : x);
if (d > max) {
max = d;
}
if (d < min) {
min = d;
}
}
distances.max = max - min;
distances.min = min;
distances.v = l = vars.amount || (vars.each * (wrap > l ? l - 1 : !axis ? Math.max(wrap, l / wrap) : axis === "y" ? l / wrap : wrap)) || 0;
distances.b = (l < 0) ? base - l : base;
}
l = (distances[i] - distances.min) / distances.max;
return distances.b + (ease ? ease.getRatio(l) : l) * distances.v;
};
},
p = TimelineLite.prototype = new SimpleTimeline();
TimelineLite.version = "2.1.3";
TimelineLite.distribute = _distribute;
p.constructor = TimelineLite;
p.kill()._gc = p._forcingPlayhead = p._hasPause = false;
/* might use later...
//translates a local time inside an animation to the corresponding time on the root/global timeline, factoring in all nesting and timeScales.
function localToGlobal(time, animation) {
while (animation) {
time = (time / animation._timeScale) + animation._startTime;
animation = animation.timeline;
}
return time;
}
//translates the supplied time on the root/global timeline into the corresponding local time inside a particular animation, factoring in all nesting and timeScales
function globalToLocal(time, animation) {
var scale = 1;
time -= localToGlobal(0, animation);
while (animation) {
scale *= animation._timeScale;
animation = animation.timeline;
}
return time * scale;
}
*/
p.to = function (target, duration, vars, position) {
var Engine = (vars.repeat && _globals.TweenMax) || TweenLite;
return duration ? this.add(new Engine(target, duration, vars), position) : this.set(target, vars, position);
};
p.from = function (target, duration, vars, position) {
return this.add(((vars.repeat && _globals.TweenMax) || TweenLite).from(target, duration, _defaultImmediateRender(this, vars)), position);
};
p.fromTo = function (target, duration, fromVars, toVars, position) {
var Engine = (toVars.repeat && _globals.TweenMax) || TweenLite;
toVars = _defaultImmediateRender(this, toVars, fromVars);
return duration ? this.add(Engine.fromTo(target, duration, fromVars, toVars), position) : this.set(target, toVars, position);
};
p.staggerTo = function (targets, duration, vars, stagger, position, onCompleteAll, onCompleteAllParams, onCompleteAllScope) {