@tweenjs/tween.js 17.3.0 → 17.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tmp/Easing.d.ts +60 -0
- package/.tmp/Easing.js +188 -0
- package/.tmp/Easing.js.map +1 -0
- package/.tmp/Group.d.ts +16 -0
- package/.tmp/Group.js +58 -0
- package/.tmp/Group.js.map +1 -0
- package/.tmp/Index.d.ts +102 -0
- package/.tmp/Index.js +52 -0
- package/.tmp/Index.js.map +1 -0
- package/.tmp/Interpolation.d.ts +19 -0
- package/.tmp/Interpolation.js +81 -0
- package/.tmp/Interpolation.js.map +1 -0
- package/.tmp/Now.d.ts +2 -0
- package/.tmp/Now.js +32 -0
- package/.tmp/Now.js.map +1 -0
- package/.tmp/Sequence.d.ts +7 -0
- package/.tmp/Sequence.js +14 -0
- package/.tmp/Sequence.js.map +1 -0
- package/.tmp/Tween.d.ts +78 -0
- package/.tmp/Tween.js +404 -0
- package/.tmp/Tween.js.map +1 -0
- package/.tmp/Version.d.ts +2 -0
- package/.tmp/Version.js +3 -0
- package/.tmp/Version.js.map +1 -0
- package/.tmp/mainGroup.d.ts +2 -0
- package/.tmp/mainGroup.js +3 -0
- package/.tmp/mainGroup.js.map +1 -0
- package/.tmp/tests.cjs.js +2152 -0
- package/.tmp/tests.d.ts +91 -0
- package/.tmp/tests.js +1320 -0
- package/.tmp/tests.js.map +1 -0
- package/.travis.yml +1 -1
- package/.vscode/settings.json +4 -0
- package/.vscode/tasks.json +15 -0
- package/package.json +3 -3
- package/src/Tween.js +48 -31
- package/benchmarks/additionWithStart.js +0 -9
- package/benchmarks/additionWithUpdate.js +0 -11
- package/benchmarks/additionWithoutStart.js +0 -8
- package/benchmarks/benchmarks.html +0 -55
- package/benchmarks/updateBug.html +0 -37
- package/benchmarks/updateMany.js +0 -13
- package/src/TweenThree.js +0 -24
@@ -0,0 +1,2152 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
/**
|
6
|
+
* The Ease class provides a collection of easing functions for use with tween.js.
|
7
|
+
*/
|
8
|
+
var Easing = {
|
9
|
+
Linear: {
|
10
|
+
None: function (amount) {
|
11
|
+
return amount;
|
12
|
+
},
|
13
|
+
},
|
14
|
+
Quadratic: {
|
15
|
+
In: function (amount) {
|
16
|
+
return amount * amount;
|
17
|
+
},
|
18
|
+
Out: function (amount) {
|
19
|
+
return amount * (2 - amount);
|
20
|
+
},
|
21
|
+
InOut: function (amount) {
|
22
|
+
if ((amount *= 2) < 1) {
|
23
|
+
return 0.5 * amount * amount;
|
24
|
+
}
|
25
|
+
return -0.5 * (--amount * (amount - 2) - 1);
|
26
|
+
},
|
27
|
+
},
|
28
|
+
Cubic: {
|
29
|
+
In: function (amount) {
|
30
|
+
return amount * amount * amount;
|
31
|
+
},
|
32
|
+
Out: function (amount) {
|
33
|
+
return --amount * amount * amount + 1;
|
34
|
+
},
|
35
|
+
InOut: function (amount) {
|
36
|
+
if ((amount *= 2) < 1) {
|
37
|
+
return 0.5 * amount * amount * amount;
|
38
|
+
}
|
39
|
+
return 0.5 * ((amount -= 2) * amount * amount + 2);
|
40
|
+
},
|
41
|
+
},
|
42
|
+
Quartic: {
|
43
|
+
In: function (amount) {
|
44
|
+
return amount * amount * amount * amount;
|
45
|
+
},
|
46
|
+
Out: function (amount) {
|
47
|
+
return 1 - --amount * amount * amount * amount;
|
48
|
+
},
|
49
|
+
InOut: function (amount) {
|
50
|
+
if ((amount *= 2) < 1) {
|
51
|
+
return 0.5 * amount * amount * amount * amount;
|
52
|
+
}
|
53
|
+
return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
|
54
|
+
},
|
55
|
+
},
|
56
|
+
Quintic: {
|
57
|
+
In: function (amount) {
|
58
|
+
return amount * amount * amount * amount * amount;
|
59
|
+
},
|
60
|
+
Out: function (amount) {
|
61
|
+
return --amount * amount * amount * amount * amount + 1;
|
62
|
+
},
|
63
|
+
InOut: function (amount) {
|
64
|
+
if ((amount *= 2) < 1) {
|
65
|
+
return 0.5 * amount * amount * amount * amount * amount;
|
66
|
+
}
|
67
|
+
return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
|
68
|
+
},
|
69
|
+
},
|
70
|
+
Sinusoidal: {
|
71
|
+
In: function (amount) {
|
72
|
+
return 1 - Math.cos((amount * Math.PI) / 2);
|
73
|
+
},
|
74
|
+
Out: function (amount) {
|
75
|
+
return Math.sin((amount * Math.PI) / 2);
|
76
|
+
},
|
77
|
+
InOut: function (amount) {
|
78
|
+
return 0.5 * (1 - Math.cos(Math.PI * amount));
|
79
|
+
},
|
80
|
+
},
|
81
|
+
Exponential: {
|
82
|
+
In: function (amount) {
|
83
|
+
return amount === 0 ? 0 : Math.pow(1024, amount - 1);
|
84
|
+
},
|
85
|
+
Out: function (amount) {
|
86
|
+
return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
|
87
|
+
},
|
88
|
+
InOut: function (amount) {
|
89
|
+
if (amount === 0) {
|
90
|
+
return 0;
|
91
|
+
}
|
92
|
+
if (amount === 1) {
|
93
|
+
return 1;
|
94
|
+
}
|
95
|
+
if ((amount *= 2) < 1) {
|
96
|
+
return 0.5 * Math.pow(1024, amount - 1);
|
97
|
+
}
|
98
|
+
return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
|
99
|
+
},
|
100
|
+
},
|
101
|
+
Circular: {
|
102
|
+
In: function (amount) {
|
103
|
+
return 1 - Math.sqrt(1 - amount * amount);
|
104
|
+
},
|
105
|
+
Out: function (amount) {
|
106
|
+
return Math.sqrt(1 - --amount * amount);
|
107
|
+
},
|
108
|
+
InOut: function (amount) {
|
109
|
+
if ((amount *= 2) < 1) {
|
110
|
+
return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
|
111
|
+
}
|
112
|
+
return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
|
113
|
+
},
|
114
|
+
},
|
115
|
+
Elastic: {
|
116
|
+
In: function (amount) {
|
117
|
+
if (amount === 0) {
|
118
|
+
return 0;
|
119
|
+
}
|
120
|
+
if (amount === 1) {
|
121
|
+
return 1;
|
122
|
+
}
|
123
|
+
return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
|
124
|
+
},
|
125
|
+
Out: function (amount) {
|
126
|
+
if (amount === 0) {
|
127
|
+
return 0;
|
128
|
+
}
|
129
|
+
if (amount === 1) {
|
130
|
+
return 1;
|
131
|
+
}
|
132
|
+
return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
|
133
|
+
},
|
134
|
+
InOut: function (amount) {
|
135
|
+
if (amount === 0) {
|
136
|
+
return 0;
|
137
|
+
}
|
138
|
+
if (amount === 1) {
|
139
|
+
return 1;
|
140
|
+
}
|
141
|
+
amount *= 2;
|
142
|
+
if (amount < 1) {
|
143
|
+
return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
|
144
|
+
}
|
145
|
+
return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
|
146
|
+
},
|
147
|
+
},
|
148
|
+
Back: {
|
149
|
+
In: function (amount) {
|
150
|
+
var s = 1.70158;
|
151
|
+
return amount * amount * ((s + 1) * amount - s);
|
152
|
+
},
|
153
|
+
Out: function (amount) {
|
154
|
+
var s = 1.70158;
|
155
|
+
return --amount * amount * ((s + 1) * amount + s) + 1;
|
156
|
+
},
|
157
|
+
InOut: function (amount) {
|
158
|
+
var s = 1.70158 * 1.525;
|
159
|
+
if ((amount *= 2) < 1) {
|
160
|
+
return 0.5 * (amount * amount * ((s + 1) * amount - s));
|
161
|
+
}
|
162
|
+
return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
|
163
|
+
},
|
164
|
+
},
|
165
|
+
Bounce: {
|
166
|
+
In: function (amount) {
|
167
|
+
return 1 - Easing.Bounce.Out(1 - amount);
|
168
|
+
},
|
169
|
+
Out: function (amount) {
|
170
|
+
if (amount < 1 / 2.75) {
|
171
|
+
return 7.5625 * amount * amount;
|
172
|
+
}
|
173
|
+
else if (amount < 2 / 2.75) {
|
174
|
+
return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
|
175
|
+
}
|
176
|
+
else if (amount < 2.5 / 2.75) {
|
177
|
+
return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
|
178
|
+
}
|
179
|
+
else {
|
180
|
+
return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
|
181
|
+
}
|
182
|
+
},
|
183
|
+
InOut: function (amount) {
|
184
|
+
if (amount < 0.5) {
|
185
|
+
return Easing.Bounce.In(amount * 2) * 0.5;
|
186
|
+
}
|
187
|
+
return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
|
188
|
+
},
|
189
|
+
},
|
190
|
+
};
|
191
|
+
|
192
|
+
var now;
|
193
|
+
// Include a performance.now polyfill.
|
194
|
+
// In node.js, use process.hrtime.
|
195
|
+
// eslint-disable-next-line
|
196
|
+
// @ts-ignore
|
197
|
+
if (typeof self === 'undefined' && typeof process !== 'undefined' && process.hrtime) {
|
198
|
+
now = function () {
|
199
|
+
// eslint-disable-next-line
|
200
|
+
// @ts-ignore
|
201
|
+
var time = process.hrtime();
|
202
|
+
// Convert [seconds, nanoseconds] to milliseconds.
|
203
|
+
return time[0] * 1000 + time[1] / 1000000;
|
204
|
+
};
|
205
|
+
}
|
206
|
+
// In a browser, use self.performance.now if it is available.
|
207
|
+
else if (typeof self !== 'undefined' && self.performance !== undefined && self.performance.now !== undefined) {
|
208
|
+
// This must be bound, because directly assigning this function
|
209
|
+
// leads to an invocation exception in Chrome.
|
210
|
+
now = self.performance.now.bind(self.performance);
|
211
|
+
}
|
212
|
+
// Use Date.now if it is available.
|
213
|
+
else if (Date.now !== undefined) {
|
214
|
+
now = Date.now;
|
215
|
+
}
|
216
|
+
// Otherwise, use 'new Date().getTime()'.
|
217
|
+
else {
|
218
|
+
now = function () {
|
219
|
+
return new Date().getTime();
|
220
|
+
};
|
221
|
+
}
|
222
|
+
var now$1 = now;
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Controlling groups of tweens
|
226
|
+
*
|
227
|
+
* Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
|
228
|
+
* In these cases, you may want to create your own smaller groups of tween
|
229
|
+
*/
|
230
|
+
var Group = /** @class */ (function () {
|
231
|
+
function Group() {
|
232
|
+
this._tweens = {};
|
233
|
+
this._tweensAddedDuringUpdate = {};
|
234
|
+
}
|
235
|
+
Group.prototype.getAll = function () {
|
236
|
+
var _this = this;
|
237
|
+
return Object.keys(this._tweens).map(function (tweenId) {
|
238
|
+
return _this._tweens[tweenId];
|
239
|
+
});
|
240
|
+
};
|
241
|
+
Group.prototype.removeAll = function () {
|
242
|
+
this._tweens = {};
|
243
|
+
};
|
244
|
+
Group.prototype.add = function (tween) {
|
245
|
+
this._tweens[tween.getId()] = tween;
|
246
|
+
this._tweensAddedDuringUpdate[tween.getId()] = tween;
|
247
|
+
};
|
248
|
+
Group.prototype.remove = function (tween) {
|
249
|
+
delete this._tweens[tween.getId()];
|
250
|
+
delete this._tweensAddedDuringUpdate[tween.getId()];
|
251
|
+
};
|
252
|
+
Group.prototype.update = function (time, preserve) {
|
253
|
+
if (time === void 0) { time = now$1(); }
|
254
|
+
if (preserve === void 0) { preserve = false; }
|
255
|
+
var tweenIds = Object.keys(this._tweens);
|
256
|
+
if (tweenIds.length === 0) {
|
257
|
+
return false;
|
258
|
+
}
|
259
|
+
// Tweens are updated in "batches". If you add a new tween during an
|
260
|
+
// update, then the new tween will be updated in the next batch.
|
261
|
+
// If you remove a tween during an update, it may or may not be updated.
|
262
|
+
// However, if the removed tween was added during the current batch,
|
263
|
+
// then it will not be updated.
|
264
|
+
while (tweenIds.length > 0) {
|
265
|
+
this._tweensAddedDuringUpdate = {};
|
266
|
+
for (var i = 0; i < tweenIds.length; i++) {
|
267
|
+
var tween = this._tweens[tweenIds[i]];
|
268
|
+
var autoStart = !preserve;
|
269
|
+
if (tween && tween.update(time, autoStart) === false && !preserve) {
|
270
|
+
delete this._tweens[tweenIds[i]];
|
271
|
+
}
|
272
|
+
}
|
273
|
+
tweenIds = Object.keys(this._tweensAddedDuringUpdate);
|
274
|
+
}
|
275
|
+
return true;
|
276
|
+
};
|
277
|
+
return Group;
|
278
|
+
}());
|
279
|
+
|
280
|
+
/**
|
281
|
+
*
|
282
|
+
*/
|
283
|
+
var Interpolation = {
|
284
|
+
Linear: function (v, k) {
|
285
|
+
var m = v.length - 1;
|
286
|
+
var f = m * k;
|
287
|
+
var i = Math.floor(f);
|
288
|
+
var fn = Interpolation.Utils.Linear;
|
289
|
+
if (k < 0) {
|
290
|
+
return fn(v[0], v[1], f);
|
291
|
+
}
|
292
|
+
if (k > 1) {
|
293
|
+
return fn(v[m], v[m - 1], m - f);
|
294
|
+
}
|
295
|
+
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
|
296
|
+
},
|
297
|
+
Bezier: function (v, k) {
|
298
|
+
var b = 0;
|
299
|
+
var n = v.length - 1;
|
300
|
+
var pw = Math.pow;
|
301
|
+
var bn = Interpolation.Utils.Bernstein;
|
302
|
+
for (var i = 0; i <= n; i++) {
|
303
|
+
b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
|
304
|
+
}
|
305
|
+
return b;
|
306
|
+
},
|
307
|
+
CatmullRom: function (v, k) {
|
308
|
+
var m = v.length - 1;
|
309
|
+
var f = m * k;
|
310
|
+
var i = Math.floor(f);
|
311
|
+
var fn = Interpolation.Utils.CatmullRom;
|
312
|
+
if (v[0] === v[m]) {
|
313
|
+
if (k < 0) {
|
314
|
+
i = Math.floor((f = m * (1 + k)));
|
315
|
+
}
|
316
|
+
return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
|
317
|
+
}
|
318
|
+
else {
|
319
|
+
if (k < 0) {
|
320
|
+
return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
|
321
|
+
}
|
322
|
+
if (k > 1) {
|
323
|
+
return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
|
324
|
+
}
|
325
|
+
return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
|
326
|
+
}
|
327
|
+
},
|
328
|
+
Utils: {
|
329
|
+
Linear: function (p0, p1, t) {
|
330
|
+
return (p1 - p0) * t + p0;
|
331
|
+
},
|
332
|
+
Bernstein: function (n, i) {
|
333
|
+
var fc = Interpolation.Utils.Factorial;
|
334
|
+
return fc(n) / fc(i) / fc(n - i);
|
335
|
+
},
|
336
|
+
Factorial: (function () {
|
337
|
+
var a = [1];
|
338
|
+
return function (n) {
|
339
|
+
var s = 1;
|
340
|
+
if (a[n]) {
|
341
|
+
return a[n];
|
342
|
+
}
|
343
|
+
for (var i = n; i > 1; i--) {
|
344
|
+
s *= i;
|
345
|
+
}
|
346
|
+
a[n] = s;
|
347
|
+
return s;
|
348
|
+
};
|
349
|
+
})(),
|
350
|
+
CatmullRom: function (p0, p1, p2, p3, t) {
|
351
|
+
var v0 = (p2 - p0) * 0.5;
|
352
|
+
var v1 = (p3 - p1) * 0.5;
|
353
|
+
var t2 = t * t;
|
354
|
+
var t3 = t * t2;
|
355
|
+
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
|
356
|
+
},
|
357
|
+
},
|
358
|
+
};
|
359
|
+
|
360
|
+
/**
|
361
|
+
* Utils
|
362
|
+
*/
|
363
|
+
var Sequence = /** @class */ (function () {
|
364
|
+
function Sequence() {
|
365
|
+
}
|
366
|
+
Sequence.nextId = function () {
|
367
|
+
return Sequence._nextId++;
|
368
|
+
};
|
369
|
+
Sequence._nextId = 0;
|
370
|
+
return Sequence;
|
371
|
+
}());
|
372
|
+
|
373
|
+
var mainGroup = new Group();
|
374
|
+
|
375
|
+
/**
|
376
|
+
* Tween.js - Licensed under the MIT license
|
377
|
+
* https://github.com/tweenjs/tween.js
|
378
|
+
* ----------------------------------------------
|
379
|
+
*
|
380
|
+
* See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
|
381
|
+
* Thank you all, you're awesome!
|
382
|
+
*/
|
383
|
+
var Tween = /** @class */ (function () {
|
384
|
+
function Tween(_object, _group) {
|
385
|
+
if (_group === void 0) { _group = mainGroup; }
|
386
|
+
this._object = _object;
|
387
|
+
this._group = _group;
|
388
|
+
this._isPaused = false;
|
389
|
+
this._pauseStart = 0;
|
390
|
+
this._valuesStart = {};
|
391
|
+
this._valuesEnd = {};
|
392
|
+
this._valuesStartRepeat = {};
|
393
|
+
this._duration = 1000;
|
394
|
+
this._initialRepeat = 0;
|
395
|
+
this._repeat = 0;
|
396
|
+
this._yoyo = false;
|
397
|
+
this._isPlaying = false;
|
398
|
+
this._reversed = false;
|
399
|
+
this._delayTime = 0;
|
400
|
+
this._startTime = 0;
|
401
|
+
this._easingFunction = Easing.Linear.None;
|
402
|
+
this._interpolationFunction = Interpolation.Linear;
|
403
|
+
// eslint-disable-next-line
|
404
|
+
this._chainedTweens = [];
|
405
|
+
this._onStartCallbackFired = false;
|
406
|
+
this._id = Sequence.nextId();
|
407
|
+
this._isChainStopped = false;
|
408
|
+
this._goToEnd = false;
|
409
|
+
}
|
410
|
+
Tween.prototype.getId = function () {
|
411
|
+
return this._id;
|
412
|
+
};
|
413
|
+
Tween.prototype.isPlaying = function () {
|
414
|
+
return this._isPlaying;
|
415
|
+
};
|
416
|
+
Tween.prototype.isPaused = function () {
|
417
|
+
return this._isPaused;
|
418
|
+
};
|
419
|
+
Tween.prototype.to = function (properties, duration) {
|
420
|
+
// TODO? restore this, then update the 07_dynamic_to example to set fox
|
421
|
+
// tween's to on each update. That way the behavior is opt-in (there's
|
422
|
+
// currently no opt-out).
|
423
|
+
// for (const prop in properties) this._valuesEnd[prop] = properties[prop]
|
424
|
+
this._valuesEnd = Object.create(properties);
|
425
|
+
if (duration !== undefined) {
|
426
|
+
this._duration = duration;
|
427
|
+
}
|
428
|
+
return this;
|
429
|
+
};
|
430
|
+
Tween.prototype.duration = function (d) {
|
431
|
+
if (d === void 0) { d = 1000; }
|
432
|
+
this._duration = d;
|
433
|
+
return this;
|
434
|
+
};
|
435
|
+
Tween.prototype.start = function (time) {
|
436
|
+
if (this._isPlaying) {
|
437
|
+
return this;
|
438
|
+
}
|
439
|
+
// eslint-disable-next-line
|
440
|
+
this._group && this._group.add(this);
|
441
|
+
this._repeat = this._initialRepeat;
|
442
|
+
if (this._reversed) {
|
443
|
+
// If we were reversed (f.e. using the yoyo feature) then we need to
|
444
|
+
// flip the tween direction back to forward.
|
445
|
+
this._reversed = false;
|
446
|
+
for (var property in this._valuesStartRepeat) {
|
447
|
+
this._swapEndStartRepeatValues(property);
|
448
|
+
this._valuesStart[property] = this._valuesStartRepeat[property];
|
449
|
+
}
|
450
|
+
}
|
451
|
+
this._isPlaying = true;
|
452
|
+
this._isPaused = false;
|
453
|
+
this._onStartCallbackFired = false;
|
454
|
+
this._isChainStopped = false;
|
455
|
+
this._startTime = time !== undefined ? (typeof time === 'string' ? now$1() + parseFloat(time) : time) : now$1();
|
456
|
+
this._startTime += this._delayTime;
|
457
|
+
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
|
458
|
+
return this;
|
459
|
+
};
|
460
|
+
Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat) {
|
461
|
+
for (var property in _valuesEnd) {
|
462
|
+
var startValue = _object[property];
|
463
|
+
var startValueIsArray = Array.isArray(startValue);
|
464
|
+
var propType = startValueIsArray ? 'array' : typeof startValue;
|
465
|
+
var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
|
466
|
+
// If `to()` specifies a property that doesn't exist in the source object,
|
467
|
+
// we should not set that property in the object
|
468
|
+
if (propType === 'undefined' || propType === 'function') {
|
469
|
+
continue;
|
470
|
+
}
|
471
|
+
// Check if an Array was provided as property value
|
472
|
+
if (isInterpolationList) {
|
473
|
+
var endValues = _valuesEnd[property];
|
474
|
+
if (endValues.length === 0) {
|
475
|
+
continue;
|
476
|
+
}
|
477
|
+
// handle an array of relative values
|
478
|
+
endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
|
479
|
+
// Create a local copy of the Array with the start value at the front
|
480
|
+
_valuesEnd[property] = [startValue].concat(endValues);
|
481
|
+
}
|
482
|
+
// handle the deepness of the values
|
483
|
+
if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
|
484
|
+
_valuesStart[property] = startValueIsArray ? [] : {};
|
485
|
+
// eslint-disable-next-line
|
486
|
+
for (var prop in startValue) {
|
487
|
+
// eslint-disable-next-line
|
488
|
+
// @ts-ignore FIXME?
|
489
|
+
_valuesStart[property][prop] = startValue[prop];
|
490
|
+
}
|
491
|
+
_valuesStartRepeat[property] = startValueIsArray ? [] : {}; // TODO? repeat nested values? And yoyo? And array values?
|
492
|
+
// eslint-disable-next-line
|
493
|
+
// @ts-ignore FIXME?
|
494
|
+
this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
|
495
|
+
}
|
496
|
+
else {
|
497
|
+
// Save the starting value, but only once.
|
498
|
+
if (typeof _valuesStart[property] === 'undefined') {
|
499
|
+
_valuesStart[property] = startValue;
|
500
|
+
}
|
501
|
+
if (!startValueIsArray) {
|
502
|
+
// eslint-disable-next-line
|
503
|
+
// @ts-ignore FIXME?
|
504
|
+
_valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
|
505
|
+
}
|
506
|
+
if (isInterpolationList) {
|
507
|
+
// eslint-disable-next-line
|
508
|
+
// @ts-ignore FIXME?
|
509
|
+
_valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
|
510
|
+
}
|
511
|
+
else {
|
512
|
+
_valuesStartRepeat[property] = _valuesStart[property] || 0;
|
513
|
+
}
|
514
|
+
}
|
515
|
+
}
|
516
|
+
};
|
517
|
+
Tween.prototype.stop = function () {
|
518
|
+
if (!this._isChainStopped) {
|
519
|
+
this._isChainStopped = true;
|
520
|
+
this.stopChainedTweens();
|
521
|
+
}
|
522
|
+
if (!this._isPlaying) {
|
523
|
+
return this;
|
524
|
+
}
|
525
|
+
// eslint-disable-next-line
|
526
|
+
this._group && this._group.remove(this);
|
527
|
+
this._isPlaying = false;
|
528
|
+
this._isPaused = false;
|
529
|
+
if (this._onStopCallback) {
|
530
|
+
this._onStopCallback(this._object);
|
531
|
+
}
|
532
|
+
return this;
|
533
|
+
};
|
534
|
+
Tween.prototype.end = function () {
|
535
|
+
this._goToEnd = true;
|
536
|
+
this.update(Infinity);
|
537
|
+
return this;
|
538
|
+
};
|
539
|
+
Tween.prototype.pause = function (time) {
|
540
|
+
if (time === void 0) { time = now$1(); }
|
541
|
+
if (this._isPaused || !this._isPlaying) {
|
542
|
+
return this;
|
543
|
+
}
|
544
|
+
this._isPaused = true;
|
545
|
+
this._pauseStart = time;
|
546
|
+
// eslint-disable-next-line
|
547
|
+
this._group && this._group.remove(this);
|
548
|
+
return this;
|
549
|
+
};
|
550
|
+
Tween.prototype.resume = function (time) {
|
551
|
+
if (time === void 0) { time = now$1(); }
|
552
|
+
if (!this._isPaused || !this._isPlaying) {
|
553
|
+
return this;
|
554
|
+
}
|
555
|
+
this._isPaused = false;
|
556
|
+
this._startTime += time - this._pauseStart;
|
557
|
+
this._pauseStart = 0;
|
558
|
+
// eslint-disable-next-line
|
559
|
+
this._group && this._group.add(this);
|
560
|
+
return this;
|
561
|
+
};
|
562
|
+
Tween.prototype.stopChainedTweens = function () {
|
563
|
+
for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
|
564
|
+
this._chainedTweens[i].stop();
|
565
|
+
}
|
566
|
+
return this;
|
567
|
+
};
|
568
|
+
Tween.prototype.group = function (group) {
|
569
|
+
if (group === void 0) { group = mainGroup; }
|
570
|
+
this._group = group;
|
571
|
+
return this;
|
572
|
+
};
|
573
|
+
Tween.prototype.delay = function (amount) {
|
574
|
+
if (amount === void 0) { amount = 0; }
|
575
|
+
this._delayTime = amount;
|
576
|
+
return this;
|
577
|
+
};
|
578
|
+
Tween.prototype.repeat = function (times) {
|
579
|
+
if (times === void 0) { times = 0; }
|
580
|
+
this._initialRepeat = times;
|
581
|
+
this._repeat = times;
|
582
|
+
return this;
|
583
|
+
};
|
584
|
+
Tween.prototype.repeatDelay = function (amount) {
|
585
|
+
this._repeatDelayTime = amount;
|
586
|
+
return this;
|
587
|
+
};
|
588
|
+
Tween.prototype.yoyo = function (yoyo) {
|
589
|
+
if (yoyo === void 0) { yoyo = false; }
|
590
|
+
this._yoyo = yoyo;
|
591
|
+
return this;
|
592
|
+
};
|
593
|
+
Tween.prototype.easing = function (easingFunction) {
|
594
|
+
if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
|
595
|
+
this._easingFunction = easingFunction;
|
596
|
+
return this;
|
597
|
+
};
|
598
|
+
Tween.prototype.interpolation = function (interpolationFunction) {
|
599
|
+
if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
|
600
|
+
this._interpolationFunction = interpolationFunction;
|
601
|
+
return this;
|
602
|
+
};
|
603
|
+
// eslint-disable-next-line
|
604
|
+
Tween.prototype.chain = function () {
|
605
|
+
var tweens = [];
|
606
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
607
|
+
tweens[_i] = arguments[_i];
|
608
|
+
}
|
609
|
+
this._chainedTweens = tweens;
|
610
|
+
return this;
|
611
|
+
};
|
612
|
+
Tween.prototype.onStart = function (callback) {
|
613
|
+
this._onStartCallback = callback;
|
614
|
+
return this;
|
615
|
+
};
|
616
|
+
Tween.prototype.onUpdate = function (callback) {
|
617
|
+
this._onUpdateCallback = callback;
|
618
|
+
return this;
|
619
|
+
};
|
620
|
+
Tween.prototype.onRepeat = function (callback) {
|
621
|
+
this._onRepeatCallback = callback;
|
622
|
+
return this;
|
623
|
+
};
|
624
|
+
Tween.prototype.onComplete = function (callback) {
|
625
|
+
this._onCompleteCallback = callback;
|
626
|
+
return this;
|
627
|
+
};
|
628
|
+
Tween.prototype.onStop = function (callback) {
|
629
|
+
this._onStopCallback = callback;
|
630
|
+
return this;
|
631
|
+
};
|
632
|
+
/**
|
633
|
+
* @returns true if the tween is still playing after the update, false
|
634
|
+
* otherwise (calling update on a paused tween still returns true because
|
635
|
+
* it is still playing, just paused).
|
636
|
+
*/
|
637
|
+
Tween.prototype.update = function (time, autoStart) {
|
638
|
+
if (time === void 0) { time = now$1(); }
|
639
|
+
if (autoStart === void 0) { autoStart = true; }
|
640
|
+
if (this._isPaused)
|
641
|
+
return true;
|
642
|
+
var property;
|
643
|
+
var elapsed;
|
644
|
+
var endTime = this._startTime + this._duration;
|
645
|
+
if (!this._goToEnd && !this._isPlaying) {
|
646
|
+
if (time > endTime)
|
647
|
+
return false;
|
648
|
+
if (autoStart)
|
649
|
+
this.start(time);
|
650
|
+
}
|
651
|
+
this._goToEnd = false;
|
652
|
+
if (time < this._startTime) {
|
653
|
+
return true;
|
654
|
+
}
|
655
|
+
if (this._onStartCallbackFired === false) {
|
656
|
+
if (this._onStartCallback) {
|
657
|
+
this._onStartCallback(this._object);
|
658
|
+
}
|
659
|
+
this._onStartCallbackFired = true;
|
660
|
+
}
|
661
|
+
elapsed = (time - this._startTime) / this._duration;
|
662
|
+
elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
|
663
|
+
var value = this._easingFunction(elapsed);
|
664
|
+
// properties transformations
|
665
|
+
this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
|
666
|
+
if (this._onUpdateCallback) {
|
667
|
+
this._onUpdateCallback(this._object, elapsed);
|
668
|
+
}
|
669
|
+
if (elapsed === 1) {
|
670
|
+
if (this._repeat > 0) {
|
671
|
+
if (isFinite(this._repeat)) {
|
672
|
+
this._repeat--;
|
673
|
+
}
|
674
|
+
// Reassign starting values, restart by making startTime = now
|
675
|
+
for (property in this._valuesStartRepeat) {
|
676
|
+
if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
|
677
|
+
this._valuesStartRepeat[property] =
|
678
|
+
// eslint-disable-next-line
|
679
|
+
// @ts-ignore FIXME?
|
680
|
+
this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
|
681
|
+
}
|
682
|
+
if (this._yoyo) {
|
683
|
+
this._swapEndStartRepeatValues(property);
|
684
|
+
}
|
685
|
+
this._valuesStart[property] = this._valuesStartRepeat[property];
|
686
|
+
}
|
687
|
+
if (this._yoyo) {
|
688
|
+
this._reversed = !this._reversed;
|
689
|
+
}
|
690
|
+
if (this._repeatDelayTime !== undefined) {
|
691
|
+
this._startTime = time + this._repeatDelayTime;
|
692
|
+
}
|
693
|
+
else {
|
694
|
+
this._startTime = time + this._delayTime;
|
695
|
+
}
|
696
|
+
if (this._onRepeatCallback) {
|
697
|
+
this._onRepeatCallback(this._object);
|
698
|
+
}
|
699
|
+
return true;
|
700
|
+
}
|
701
|
+
else {
|
702
|
+
if (this._onCompleteCallback) {
|
703
|
+
this._onCompleteCallback(this._object);
|
704
|
+
}
|
705
|
+
for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
|
706
|
+
// Make the chained tweens start exactly at the time they should,
|
707
|
+
// even if the `update()` method was called way past the duration of the tween
|
708
|
+
this._chainedTweens[i].start(this._startTime + this._duration);
|
709
|
+
}
|
710
|
+
this._isPlaying = false;
|
711
|
+
return false;
|
712
|
+
}
|
713
|
+
}
|
714
|
+
return true;
|
715
|
+
};
|
716
|
+
Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
|
717
|
+
for (var property in _valuesEnd) {
|
718
|
+
// Don't update properties that do not exist in the source object
|
719
|
+
if (_valuesStart[property] === undefined) {
|
720
|
+
continue;
|
721
|
+
}
|
722
|
+
var start = _valuesStart[property] || 0;
|
723
|
+
var end = _valuesEnd[property];
|
724
|
+
var startIsArray = Array.isArray(_object[property]);
|
725
|
+
var endIsArray = Array.isArray(end);
|
726
|
+
var isInterpolationList = !startIsArray && endIsArray;
|
727
|
+
if (isInterpolationList) {
|
728
|
+
_object[property] = this._interpolationFunction(end, value);
|
729
|
+
}
|
730
|
+
else if (typeof end === 'object' && end) {
|
731
|
+
// eslint-disable-next-line
|
732
|
+
// @ts-ignore FIXME?
|
733
|
+
this._updateProperties(_object[property], start, end, value);
|
734
|
+
}
|
735
|
+
else {
|
736
|
+
// Parses relative end values with start as base (e.g.: +10, -3)
|
737
|
+
end = this._handleRelativeValue(start, end);
|
738
|
+
// Protect against non numeric properties.
|
739
|
+
if (typeof end === 'number') {
|
740
|
+
// eslint-disable-next-line
|
741
|
+
// @ts-ignore FIXME?
|
742
|
+
_object[property] = start + (end - start) * value;
|
743
|
+
}
|
744
|
+
}
|
745
|
+
}
|
746
|
+
};
|
747
|
+
Tween.prototype._handleRelativeValue = function (start, end) {
|
748
|
+
if (typeof end !== 'string') {
|
749
|
+
return end;
|
750
|
+
}
|
751
|
+
if (end.charAt(0) === '+' || end.charAt(0) === '-') {
|
752
|
+
return start + parseFloat(end);
|
753
|
+
}
|
754
|
+
else {
|
755
|
+
return parseFloat(end);
|
756
|
+
}
|
757
|
+
};
|
758
|
+
Tween.prototype._swapEndStartRepeatValues = function (property) {
|
759
|
+
var tmp = this._valuesStartRepeat[property];
|
760
|
+
var endValue = this._valuesEnd[property];
|
761
|
+
if (typeof endValue === 'string') {
|
762
|
+
this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
|
763
|
+
}
|
764
|
+
else {
|
765
|
+
this._valuesStartRepeat[property] = this._valuesEnd[property];
|
766
|
+
}
|
767
|
+
this._valuesEnd[property] = tmp;
|
768
|
+
};
|
769
|
+
return Tween;
|
770
|
+
}());
|
771
|
+
|
772
|
+
var VERSION = '18.6.4';
|
773
|
+
|
774
|
+
/**
|
775
|
+
* Tween.js - Licensed under the MIT license
|
776
|
+
* https://github.com/tweenjs/tween.js
|
777
|
+
* ----------------------------------------------
|
778
|
+
*
|
779
|
+
* See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
|
780
|
+
* Thank you all, you're awesome!
|
781
|
+
*/
|
782
|
+
var nextId = Sequence.nextId;
|
783
|
+
/**
|
784
|
+
* Controlling groups of tweens
|
785
|
+
*
|
786
|
+
* Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
|
787
|
+
* In these cases, you may want to create your own smaller groups of tweens.
|
788
|
+
*/
|
789
|
+
var TWEEN = mainGroup;
|
790
|
+
// This is the best way to export things in a way that's compatible with both ES
|
791
|
+
// Modules and CommonJS, without build hacks, and so as not to break the
|
792
|
+
// existing API.
|
793
|
+
// https://github.com/rollup/rollup/issues/1961#issuecomment-423037881
|
794
|
+
var getAll = TWEEN.getAll.bind(TWEEN);
|
795
|
+
var removeAll = TWEEN.removeAll.bind(TWEEN);
|
796
|
+
var add = TWEEN.add.bind(TWEEN);
|
797
|
+
var remove = TWEEN.remove.bind(TWEEN);
|
798
|
+
var update = TWEEN.update.bind(TWEEN);
|
799
|
+
var exports$1 = {
|
800
|
+
Easing: Easing,
|
801
|
+
Group: Group,
|
802
|
+
Interpolation: Interpolation,
|
803
|
+
now: now$1,
|
804
|
+
Sequence: Sequence,
|
805
|
+
nextId: nextId,
|
806
|
+
Tween: Tween,
|
807
|
+
VERSION: VERSION,
|
808
|
+
getAll: getAll,
|
809
|
+
removeAll: removeAll,
|
810
|
+
add: add,
|
811
|
+
remove: remove,
|
812
|
+
update: update,
|
813
|
+
};
|
814
|
+
|
815
|
+
var TWEEN$1 = /*#__PURE__*/Object.freeze({
|
816
|
+
__proto__: null,
|
817
|
+
Easing: Easing,
|
818
|
+
Group: Group,
|
819
|
+
Interpolation: Interpolation,
|
820
|
+
now: now$1,
|
821
|
+
Sequence: Sequence,
|
822
|
+
nextId: nextId,
|
823
|
+
Tween: Tween,
|
824
|
+
VERSION: VERSION,
|
825
|
+
getAll: getAll,
|
826
|
+
removeAll: removeAll,
|
827
|
+
add: add,
|
828
|
+
remove: remove,
|
829
|
+
update: update,
|
830
|
+
'default': exports$1
|
831
|
+
});
|
832
|
+
|
833
|
+
var tests = {
|
834
|
+
hello: function (test) {
|
835
|
+
test.ok(TWEEN$1 !== null);
|
836
|
+
test.done();
|
837
|
+
},
|
838
|
+
// TWEEN tests
|
839
|
+
'TWEEN.getAll': function (test) {
|
840
|
+
test.ok(getAll() instanceof Array);
|
841
|
+
test.done();
|
842
|
+
},
|
843
|
+
'TWEEN object stores tweens automatically on start': function (test) {
|
844
|
+
var numTweensBefore = getAll().length, t = new Tween({});
|
845
|
+
t.start();
|
846
|
+
var numTweensAfter = getAll().length;
|
847
|
+
test.equal(numTweensBefore + 1, numTweensAfter);
|
848
|
+
test.done();
|
849
|
+
},
|
850
|
+
'TWEEN.removeAll()': function (test) {
|
851
|
+
var t = new Tween({});
|
852
|
+
removeAll();
|
853
|
+
test.equal(getAll().length, 0, 'No tweens left');
|
854
|
+
t.start();
|
855
|
+
test.equal(getAll().length, 1, 'A tween has been added');
|
856
|
+
removeAll();
|
857
|
+
test.equal(getAll().length, 0, 'No tweens left');
|
858
|
+
test.done();
|
859
|
+
},
|
860
|
+
'TWEEN.add()': function (test) {
|
861
|
+
var all = getAll(), numTweens = all.length, t = new Tween({});
|
862
|
+
add(t);
|
863
|
+
test.equal(numTweens + 1, getAll().length);
|
864
|
+
test.done();
|
865
|
+
},
|
866
|
+
'TWEEN.remove()': function (test) {
|
867
|
+
var all = getAll(), numTweens = all.length, t = new Tween({});
|
868
|
+
add(t);
|
869
|
+
test.ok(getAll().indexOf(t) != -1);
|
870
|
+
remove(t);
|
871
|
+
test.equal(numTweens, getAll().length);
|
872
|
+
test.equal(getAll().indexOf(t), -1);
|
873
|
+
test.done();
|
874
|
+
},
|
875
|
+
'TWEEN.update() returns false when done (no tweens to animate)': function (test) {
|
876
|
+
removeAll();
|
877
|
+
test.deepEqual(update(), false);
|
878
|
+
test.done();
|
879
|
+
},
|
880
|
+
'TWEEN.update() returns true when there are active tweens': function (test) {
|
881
|
+
removeAll();
|
882
|
+
var t = new Tween({});
|
883
|
+
t.start();
|
884
|
+
test.deepEqual(update(), true);
|
885
|
+
test.done();
|
886
|
+
},
|
887
|
+
'TWEEN.update() removes tweens when they are finished': function (test) {
|
888
|
+
removeAll();
|
889
|
+
var t1 = new Tween({}).to({}, 1000), t2 = new Tween({}).to({}, 2000);
|
890
|
+
test.equal(getAll().length, 0);
|
891
|
+
t1.start(0);
|
892
|
+
t2.start(0);
|
893
|
+
test.equal(getAll().length, 2);
|
894
|
+
update(0);
|
895
|
+
test.equal(getAll().length, 2);
|
896
|
+
update(999);
|
897
|
+
test.equal(getAll().length, 2);
|
898
|
+
update(1000);
|
899
|
+
test.equal(getAll().length, 1);
|
900
|
+
test.equal(getAll().indexOf(t1), -1);
|
901
|
+
test.ok(getAll().indexOf(t2) != -1);
|
902
|
+
test.done();
|
903
|
+
},
|
904
|
+
'TWEEN.update() does not remove tweens when they are finished with preserve flag': function (test) {
|
905
|
+
removeAll();
|
906
|
+
var t1 = new Tween({}).to({}, 1000), t2 = new Tween({}).to({}, 2000);
|
907
|
+
test.equal(getAll().length, 0);
|
908
|
+
t1.start(0);
|
909
|
+
t2.start(0);
|
910
|
+
test.equal(getAll().length, 2);
|
911
|
+
update(0, true);
|
912
|
+
test.equal(getAll().length, 2);
|
913
|
+
update(999, true);
|
914
|
+
test.equal(getAll().length, 2);
|
915
|
+
update(1000, true);
|
916
|
+
test.equal(getAll().length, 2);
|
917
|
+
update(1001, true);
|
918
|
+
test.equal(getAll().length, 2);
|
919
|
+
test.ok(getAll().indexOf(t1) != -1);
|
920
|
+
test.ok(getAll().indexOf(t2) != -1);
|
921
|
+
test.done();
|
922
|
+
},
|
923
|
+
'Unremoved tweens which have been updated past their finish time may go backward in time': function (test) {
|
924
|
+
removeAll();
|
925
|
+
var target1 = { a: 0 };
|
926
|
+
var target2 = { b: 0 };
|
927
|
+
var t1 = new Tween(target1).to({ a: 1 }, 1000), t2 = new Tween(target2).to({ b: 1 }, 2000);
|
928
|
+
t1.start(0);
|
929
|
+
t2.start(0);
|
930
|
+
// To be able to make a tween go backward in time, it must be
|
931
|
+
// updated with preserve set to true. Otherwise, the
|
932
|
+
// backward-in-time feature does not apply.
|
933
|
+
update(200, true);
|
934
|
+
update(2500, true);
|
935
|
+
update(500, true);
|
936
|
+
test.equal(getAll().length, 2);
|
937
|
+
test.equal(target1.a, 0.5);
|
938
|
+
test.equal(target2.b, 0.25);
|
939
|
+
test.done();
|
940
|
+
},
|
941
|
+
// TWEEN.Tween tests
|
942
|
+
constructor: function (test) {
|
943
|
+
var t = new Tween({});
|
944
|
+
test.ok(t instanceof Tween, 'Pass');
|
945
|
+
test.done();
|
946
|
+
},
|
947
|
+
'Return the same tween instance for method chaining': function (test) {
|
948
|
+
var t = new Tween({});
|
949
|
+
test.ok(t.to({}, 0) instanceof Tween);
|
950
|
+
test.equal(t.to({}, 0), t);
|
951
|
+
test.ok(t.start() instanceof Tween);
|
952
|
+
test.equal(t.start(), t);
|
953
|
+
test.ok(t.stop() instanceof Tween);
|
954
|
+
test.equal(t.stop(), t);
|
955
|
+
test.ok(t.delay() instanceof Tween);
|
956
|
+
test.equal(t.delay(), t);
|
957
|
+
test.ok(t.easing() instanceof Tween);
|
958
|
+
test.equal(t.easing(), t);
|
959
|
+
test.ok(t.interpolation() instanceof Tween);
|
960
|
+
test.equal(t.interpolation(), t);
|
961
|
+
test.ok(t.chain() instanceof Tween);
|
962
|
+
test.equal(t.chain(), t);
|
963
|
+
test.ok(t.onStart() instanceof Tween);
|
964
|
+
test.equal(t.onStart(), t);
|
965
|
+
test.ok(t.onStop() instanceof Tween);
|
966
|
+
test.equal(t.onStop(), t);
|
967
|
+
test.ok(t.onUpdate() instanceof Tween);
|
968
|
+
test.equal(t.onUpdate(), t);
|
969
|
+
test.ok(t.onComplete() instanceof Tween);
|
970
|
+
test.equal(t.onComplete(), t);
|
971
|
+
test.ok(t.duration() instanceof Tween);
|
972
|
+
test.equal(t.duration(), t);
|
973
|
+
test.ok(t.group() instanceof Tween);
|
974
|
+
test.equal(t.group(), t);
|
975
|
+
test.done();
|
976
|
+
},
|
977
|
+
'Tween existing property': function (test) {
|
978
|
+
var obj = { x: 1 }, t = new Tween(obj);
|
979
|
+
t.to({ x: 2 }, 1000);
|
980
|
+
t.start(0);
|
981
|
+
t.update(1000);
|
982
|
+
test.deepEqual(obj.x, 2);
|
983
|
+
test.done();
|
984
|
+
},
|
985
|
+
'Tween non-existing property': function (test) {
|
986
|
+
var obj = { x: 1 }, t = new Tween(obj);
|
987
|
+
t.to({ y: 0 }, 1000);
|
988
|
+
t.start(0);
|
989
|
+
t.update(1000);
|
990
|
+
test.deepEqual(obj.x, 1);
|
991
|
+
// eslint-disable-next-line
|
992
|
+
// @ts-ignore
|
993
|
+
test.equal(obj.y, undefined);
|
994
|
+
test.done();
|
995
|
+
},
|
996
|
+
'Tween non-null property': function (test) {
|
997
|
+
var obj = { x: 1 }, t = new Tween(obj);
|
998
|
+
t.to({ x: 2 }, 1000);
|
999
|
+
t.start(0);
|
1000
|
+
t.update(1000);
|
1001
|
+
test.deepEqual(obj.x, 2);
|
1002
|
+
test.ok(obj.x !== null);
|
1003
|
+
test.done();
|
1004
|
+
},
|
1005
|
+
'Tween function property': function (test) {
|
1006
|
+
var my_function = new Function();
|
1007
|
+
var obj = { x: my_function }, t = new Tween(obj);
|
1008
|
+
t.to({ x: my_function });
|
1009
|
+
t.start(0);
|
1010
|
+
t.update(1000);
|
1011
|
+
test.ok(obj.x === my_function);
|
1012
|
+
test.done();
|
1013
|
+
},
|
1014
|
+
'Tween boolean property': function (test) {
|
1015
|
+
var obj = { x: true }, t = new Tween(obj);
|
1016
|
+
t.to({ x: new Function() });
|
1017
|
+
t.start(0);
|
1018
|
+
t.update(1000);
|
1019
|
+
test.ok(typeof obj.x === 'boolean');
|
1020
|
+
test.ok(obj.x === true);
|
1021
|
+
test.done();
|
1022
|
+
},
|
1023
|
+
'Tween null property': function (test) {
|
1024
|
+
var obj = { x: null }, t = new Tween(obj);
|
1025
|
+
t.to({ x: 2 }, 1000);
|
1026
|
+
t.start(0);
|
1027
|
+
t.update(1000);
|
1028
|
+
test.deepEqual(obj.x, 2);
|
1029
|
+
test.done();
|
1030
|
+
},
|
1031
|
+
'Tween undefined property': function (test) {
|
1032
|
+
var obj = {}, t = new Tween(obj);
|
1033
|
+
t.to({ x: 2 }, 1000);
|
1034
|
+
t.start(0);
|
1035
|
+
t.update(1000);
|
1036
|
+
// eslint-disable-next-line
|
1037
|
+
// @ts-ignore
|
1038
|
+
test.equal(obj.x, undefined);
|
1039
|
+
test.done();
|
1040
|
+
},
|
1041
|
+
'Tween relative positive value': function (test) {
|
1042
|
+
var obj = { x: 0 }, t = new Tween(obj);
|
1043
|
+
t.to({ x: '+100' }, 1000);
|
1044
|
+
t.start(0);
|
1045
|
+
t.update(1000);
|
1046
|
+
test.equal(obj.x, 100);
|
1047
|
+
test.done();
|
1048
|
+
},
|
1049
|
+
'Tween relative negative value': function (test) {
|
1050
|
+
var obj = { x: 0 }, t = new Tween(obj);
|
1051
|
+
t.to({ x: '-100' }, 1000);
|
1052
|
+
t.start(0);
|
1053
|
+
t.update(1000);
|
1054
|
+
test.equal(obj.x, -100);
|
1055
|
+
test.done();
|
1056
|
+
},
|
1057
|
+
'String values without a + or - sign should not be interpreted as relative': function (test) {
|
1058
|
+
var obj = { x: 100 }, t = new Tween(obj);
|
1059
|
+
t.to({ x: '100' }, 1000);
|
1060
|
+
t.start(0);
|
1061
|
+
t.update(1000);
|
1062
|
+
test.equal(obj.x, 100);
|
1063
|
+
test.done();
|
1064
|
+
},
|
1065
|
+
'Tween relative positive value, with yoyo': function (test) {
|
1066
|
+
var obj = { x: 0 }, t = new Tween(obj);
|
1067
|
+
t.to({ x: '+100' }, 1000);
|
1068
|
+
t.repeat(1);
|
1069
|
+
t.yoyo(true);
|
1070
|
+
t.start(0);
|
1071
|
+
t.update(500);
|
1072
|
+
test.equal(obj.x, 50);
|
1073
|
+
t.update(1000);
|
1074
|
+
test.equal(obj.x, 100);
|
1075
|
+
t.update(1500);
|
1076
|
+
test.equal(obj.x, 50);
|
1077
|
+
t.update(2000);
|
1078
|
+
test.equal(obj.x, 0);
|
1079
|
+
test.done();
|
1080
|
+
},
|
1081
|
+
'Tween relative negative value, with yoyo': function (test) {
|
1082
|
+
var obj = { x: 0 }, t = new Tween(obj);
|
1083
|
+
t.to({ x: '-100' }, 1000);
|
1084
|
+
t.repeat(1);
|
1085
|
+
t.yoyo(true);
|
1086
|
+
t.start(0);
|
1087
|
+
t.update(500);
|
1088
|
+
test.equal(obj.x, -50);
|
1089
|
+
t.update(1000);
|
1090
|
+
test.equal(obj.x, -100);
|
1091
|
+
t.update(1500);
|
1092
|
+
test.equal(obj.x, -50);
|
1093
|
+
t.update(2000);
|
1094
|
+
test.equal(obj.x, -0);
|
1095
|
+
test.done();
|
1096
|
+
},
|
1097
|
+
'Tween relative positive array interpolation values': function (test) {
|
1098
|
+
var obj = { x: 0 }, t = new Tween(obj);
|
1099
|
+
t.to({ x: ['+100', '+0', '-100', '+0'] }, 2000);
|
1100
|
+
t.start(0);
|
1101
|
+
t.update(250);
|
1102
|
+
test.equal(obj.x, 50);
|
1103
|
+
t.update(500);
|
1104
|
+
test.equal(obj.x, 100);
|
1105
|
+
t.update(750);
|
1106
|
+
test.equal(obj.x, 50);
|
1107
|
+
t.update(1000);
|
1108
|
+
test.equal(obj.x, 0);
|
1109
|
+
t.update(1250);
|
1110
|
+
test.equal(obj.x, -50);
|
1111
|
+
t.update(1500);
|
1112
|
+
test.equal(obj.x, -100);
|
1113
|
+
t.update(1750);
|
1114
|
+
test.equal(obj.x, -50);
|
1115
|
+
t.update(2000);
|
1116
|
+
test.equal(obj.x, 0);
|
1117
|
+
test.done();
|
1118
|
+
},
|
1119
|
+
'String values without a + or - sign should not be interpreted as relative with array interpolation values': function (test) {
|
1120
|
+
var obj = { x: 0 }, t = new Tween(obj);
|
1121
|
+
t.to({ x: ['100', '0', '100', '0'] }, 2000);
|
1122
|
+
t.start(0);
|
1123
|
+
t.update(250);
|
1124
|
+
test.equal(obj.x, 50);
|
1125
|
+
t.update(500);
|
1126
|
+
test.equal(obj.x, 100);
|
1127
|
+
t.update(750);
|
1128
|
+
test.equal(obj.x, 50);
|
1129
|
+
t.update(1000);
|
1130
|
+
test.equal(obj.x, 0);
|
1131
|
+
t.update(1250);
|
1132
|
+
test.equal(obj.x, 50);
|
1133
|
+
t.update(1500);
|
1134
|
+
test.equal(obj.x, 100);
|
1135
|
+
t.update(1750);
|
1136
|
+
test.equal(obj.x, 50);
|
1137
|
+
t.update(2000);
|
1138
|
+
test.equal(obj.x, 0);
|
1139
|
+
test.done();
|
1140
|
+
},
|
1141
|
+
'animate values in an array': function (test) {
|
1142
|
+
var obj = [0, 0, 0], t = new Tween(obj);
|
1143
|
+
t.to([1000, '-2000', '+2000'], 1000);
|
1144
|
+
t.start(0);
|
1145
|
+
t.update(250);
|
1146
|
+
test.equal(obj[0], 250);
|
1147
|
+
test.equal(obj[1], -500);
|
1148
|
+
test.equal(obj[2], 500);
|
1149
|
+
t.update(500);
|
1150
|
+
test.equal(obj[0], 500);
|
1151
|
+
test.equal(obj[1], -1000);
|
1152
|
+
test.equal(obj[2], 1000);
|
1153
|
+
t.update(750);
|
1154
|
+
test.equal(obj[0], 750);
|
1155
|
+
test.equal(obj[1], -1500);
|
1156
|
+
test.equal(obj[2], 1500);
|
1157
|
+
t.update(1000);
|
1158
|
+
test.equal(obj[0], 1000);
|
1159
|
+
test.equal(obj[1], -2000);
|
1160
|
+
test.equal(obj[2], 2000);
|
1161
|
+
test.done();
|
1162
|
+
},
|
1163
|
+
'animate values in a nested array': function (test) {
|
1164
|
+
var obj = { a: [0, 0, 0] }, t = new Tween(obj);
|
1165
|
+
t.to({ a: [1000, '-2000', '+2000'] }, 1000);
|
1166
|
+
t.start(0);
|
1167
|
+
t.update(250);
|
1168
|
+
test.equal(obj.a[0], 250);
|
1169
|
+
test.equal(obj.a[1], -500);
|
1170
|
+
test.equal(obj.a[2], 500);
|
1171
|
+
t.update(500);
|
1172
|
+
test.equal(obj.a[0], 500);
|
1173
|
+
test.equal(obj.a[1], -1000);
|
1174
|
+
test.equal(obj.a[2], 1000);
|
1175
|
+
t.update(750);
|
1176
|
+
test.equal(obj.a[0], 750);
|
1177
|
+
test.equal(obj.a[1], -1500);
|
1178
|
+
test.equal(obj.a[2], 1500);
|
1179
|
+
t.update(1000);
|
1180
|
+
test.equal(obj.a[0], 1000);
|
1181
|
+
test.equal(obj.a[1], -2000);
|
1182
|
+
test.equal(obj.a[2], 2000);
|
1183
|
+
test.done();
|
1184
|
+
},
|
1185
|
+
'Test TWEEN.Tween.start()': function (test) {
|
1186
|
+
var obj = {}, t = new Tween(obj);
|
1187
|
+
t.to({}, 1000);
|
1188
|
+
removeAll();
|
1189
|
+
test.equal(getAll().length, 0); // TODO move to TWEEN test
|
1190
|
+
t.start(0);
|
1191
|
+
test.equal(getAll().length, 1); // TODO ditto
|
1192
|
+
test.equal(getAll()[0], t);
|
1193
|
+
test.done();
|
1194
|
+
},
|
1195
|
+
'Ensure tweens start without calling start() method.': function (test) {
|
1196
|
+
var obj = { x: 0 }, t = new Tween(obj);
|
1197
|
+
t.to({ x: 1000 }, 1000);
|
1198
|
+
var started = false;
|
1199
|
+
t.onStart(function () { return (started = true); });
|
1200
|
+
t.onComplete(function () { return (started = false); });
|
1201
|
+
t.update(0);
|
1202
|
+
test.deepEqual(started, true);
|
1203
|
+
test.deepEqual(obj.x, 0);
|
1204
|
+
t.update(500);
|
1205
|
+
test.deepEqual(started, true);
|
1206
|
+
test.deepEqual(obj.x, 500);
|
1207
|
+
t.update(1000);
|
1208
|
+
test.deepEqual(obj.x, 1000);
|
1209
|
+
test.deepEqual(started, false);
|
1210
|
+
test.done();
|
1211
|
+
},
|
1212
|
+
'Test Tween.to() tweening towards a dynamic object': function (test) {
|
1213
|
+
var rabbit = { x: 1000, y: 0 };
|
1214
|
+
var tr = new Tween(rabbit);
|
1215
|
+
tr.to({ y: 1000 }, 1000);
|
1216
|
+
tr.start(0);
|
1217
|
+
var fox = { x: 0, y: 0 };
|
1218
|
+
var tf = new Tween(fox);
|
1219
|
+
tf.to(rabbit, 1000); // fox chase rabbit!
|
1220
|
+
tf.start(0);
|
1221
|
+
tr.update(200);
|
1222
|
+
tf.update(200);
|
1223
|
+
test.equal(rabbit.x, 1000);
|
1224
|
+
test.equal(rabbit.y, 200);
|
1225
|
+
test.equal(fox.x, 200);
|
1226
|
+
test.equal(fox.y, 40);
|
1227
|
+
tr.update(500);
|
1228
|
+
tf.update(500);
|
1229
|
+
test.equal(rabbit.x, 1000);
|
1230
|
+
test.equal(rabbit.y, 500);
|
1231
|
+
test.equal(fox.x, 500);
|
1232
|
+
test.equal(fox.y, 250);
|
1233
|
+
tr.update(800);
|
1234
|
+
tf.update(800);
|
1235
|
+
test.equal(rabbit.x, 1000);
|
1236
|
+
test.equal(rabbit.y, 800);
|
1237
|
+
test.equal(fox.x, 800);
|
1238
|
+
test.equal(fox.y, 640);
|
1239
|
+
tr.update(1000);
|
1240
|
+
tf.update(1000);
|
1241
|
+
test.equal(rabbit.x, 1000);
|
1242
|
+
test.equal(rabbit.y, 1000);
|
1243
|
+
test.equal(fox.x, 1000);
|
1244
|
+
test.equal(fox.y, 1000);
|
1245
|
+
test.done();
|
1246
|
+
},
|
1247
|
+
'Test TWEEN.Tween.stop()': function (test) {
|
1248
|
+
var obj = {}, t = new Tween(obj);
|
1249
|
+
t.to({ x: 2 }, 1000);
|
1250
|
+
removeAll();
|
1251
|
+
t.start();
|
1252
|
+
t.stop();
|
1253
|
+
test.equal(getAll().length, 0);
|
1254
|
+
test.done();
|
1255
|
+
},
|
1256
|
+
'Test TWEEN.Tween.delay()': function (test) {
|
1257
|
+
var obj = { x: 1 }, t = new Tween(obj);
|
1258
|
+
t.to({ x: 2 }, 1000);
|
1259
|
+
t.delay(500);
|
1260
|
+
t.start(0);
|
1261
|
+
t.update(100);
|
1262
|
+
test.deepEqual(obj.x, 1, "Tween hasn't started yet");
|
1263
|
+
t.update(1000);
|
1264
|
+
test.ok(obj.x !== 1 && obj.x !== 2, "Tween has started but hasn't finished yet");
|
1265
|
+
t.update(1500);
|
1266
|
+
test.equal(obj.x, 2, 'Tween finishes when expected');
|
1267
|
+
test.done();
|
1268
|
+
},
|
1269
|
+
// TODO: not really sure how to test this. Advice appreciated!
|
1270
|
+
'Test TWEEN.Tween.easing()': function (test) {
|
1271
|
+
var obj = { x: 0 }, t = new Tween(obj);
|
1272
|
+
t.to({ x: 1 }, 1000);
|
1273
|
+
t.easing(Easing.Quadratic.In);
|
1274
|
+
t.start(0);
|
1275
|
+
t.update(500);
|
1276
|
+
test.equal(obj.x, Easing.Quadratic.In(0.5));
|
1277
|
+
test.done();
|
1278
|
+
},
|
1279
|
+
// TODO test interpolation()
|
1280
|
+
'Test TWEEN.Tween.chain --with one tween': function (test) {
|
1281
|
+
var t = new Tween({}), t2 = new Tween({});
|
1282
|
+
var tStarted = false, tCompleted = false, t2Started = false;
|
1283
|
+
removeAll();
|
1284
|
+
t.to({}, 1000);
|
1285
|
+
t2.to({}, 1000);
|
1286
|
+
t.chain(t2);
|
1287
|
+
t.onStart(function () {
|
1288
|
+
tStarted = true;
|
1289
|
+
});
|
1290
|
+
t.onComplete(function () {
|
1291
|
+
tCompleted = true;
|
1292
|
+
});
|
1293
|
+
t2.onStart(function () {
|
1294
|
+
test.equal(tStarted, true);
|
1295
|
+
test.equal(tCompleted, true);
|
1296
|
+
test.equal(t2Started, false);
|
1297
|
+
t2Started = true;
|
1298
|
+
});
|
1299
|
+
test.equal(tStarted, false);
|
1300
|
+
test.equal(t2Started, false);
|
1301
|
+
t.start(0);
|
1302
|
+
update(0);
|
1303
|
+
test.equal(tStarted, true);
|
1304
|
+
test.equal(t2Started, false);
|
1305
|
+
update(1000);
|
1306
|
+
test.equal(tCompleted, true);
|
1307
|
+
update(1001);
|
1308
|
+
test.equal(t2Started, true, 't2 is automatically started by t');
|
1309
|
+
test.done();
|
1310
|
+
},
|
1311
|
+
'Test TWEEN.Tween.chain --with several tweens in an array': function (test) {
|
1312
|
+
var t = new Tween({}), chainedTweens = [], numChained = 3;
|
1313
|
+
var numChainedStarted = 0;
|
1314
|
+
removeAll();
|
1315
|
+
t.to({}, 1000);
|
1316
|
+
function onChainedStart() {
|
1317
|
+
numChainedStarted++;
|
1318
|
+
}
|
1319
|
+
for (var i = 0; i < numChained; i++) {
|
1320
|
+
var chained = new Tween({});
|
1321
|
+
chained.to({}, 1000);
|
1322
|
+
chainedTweens.push(chained);
|
1323
|
+
chained.onStart(onChainedStart);
|
1324
|
+
}
|
1325
|
+
t.chain.apply(t, chainedTweens);
|
1326
|
+
test.equal(numChainedStarted, 0);
|
1327
|
+
t.start(0);
|
1328
|
+
update(0);
|
1329
|
+
update(1000);
|
1330
|
+
update(1001);
|
1331
|
+
test.equal(numChainedStarted, numChained, 'All chained tweens have been started');
|
1332
|
+
test.done();
|
1333
|
+
},
|
1334
|
+
'Test TWEEN.Tween.chain allows endless loops': function (test) {
|
1335
|
+
var obj = { x: 0 }, t1 = new Tween(obj).to({ x: 100 }, 1000), t2 = new Tween(obj).to({ x: 0 }, 1000);
|
1336
|
+
removeAll();
|
1337
|
+
t1.chain(t2);
|
1338
|
+
t2.chain(t1);
|
1339
|
+
test.equal(obj.x, 0);
|
1340
|
+
// x == 0
|
1341
|
+
t1.start(0);
|
1342
|
+
update(0);
|
1343
|
+
test.equal(obj.x, 0);
|
1344
|
+
update(500);
|
1345
|
+
test.equal(obj.x, 50);
|
1346
|
+
// there... (x == 100)
|
1347
|
+
update(1000);
|
1348
|
+
test.equal(obj.x, 100);
|
1349
|
+
update(1500);
|
1350
|
+
test.equal(obj.x, 50);
|
1351
|
+
// ... and back again (x == 0)
|
1352
|
+
update(2000);
|
1353
|
+
test.equal(obj.x, 0);
|
1354
|
+
update(2500);
|
1355
|
+
test.equal(obj.x, 50);
|
1356
|
+
update(3000);
|
1357
|
+
test.equal(obj.x, 100); // and x == 100 again
|
1358
|
+
// Repeat the same test but with the tweens added in the
|
1359
|
+
// opposite order.
|
1360
|
+
var obj2 = { x: 0 };
|
1361
|
+
var t3 = new Tween(obj2).to({ x: 200 }, 1000);
|
1362
|
+
var t4 = new Tween(obj2).to({ x: 100 }, 1000);
|
1363
|
+
t4.chain(t3);
|
1364
|
+
t3.chain(t4);
|
1365
|
+
test.equal(obj2.x, 0);
|
1366
|
+
t4.start(0);
|
1367
|
+
update(0);
|
1368
|
+
test.equal(obj2.x, 0);
|
1369
|
+
update(500);
|
1370
|
+
test.equal(obj2.x, 50);
|
1371
|
+
update(1000);
|
1372
|
+
test.equal(obj2.x, 100);
|
1373
|
+
update(1500);
|
1374
|
+
test.equal(obj2.x, 150);
|
1375
|
+
update(2000);
|
1376
|
+
test.equal(obj2.x, 0);
|
1377
|
+
update(2500);
|
1378
|
+
test.equal(obj2.x, 50);
|
1379
|
+
update(3000);
|
1380
|
+
test.equal(obj2.x, 100);
|
1381
|
+
update(3500);
|
1382
|
+
test.equal(obj2.x, 150);
|
1383
|
+
update(4000);
|
1384
|
+
test.equal(obj2.x, 0);
|
1385
|
+
update(4500);
|
1386
|
+
test.equal(obj2.x, 50);
|
1387
|
+
test.done();
|
1388
|
+
},
|
1389
|
+
'Test TWEEN.Tween.onStart': function (test) {
|
1390
|
+
var obj = {}, t = new Tween(obj);
|
1391
|
+
var counter = 0;
|
1392
|
+
t.to({ x: 2 }, 1000);
|
1393
|
+
t.onStart(function () {
|
1394
|
+
test.ok(true, 'onStart callback is called');
|
1395
|
+
counter++;
|
1396
|
+
});
|
1397
|
+
test.deepEqual(counter, 0);
|
1398
|
+
t.start(0);
|
1399
|
+
update(0);
|
1400
|
+
test.deepEqual(counter, 1);
|
1401
|
+
update(500);
|
1402
|
+
test.deepEqual(counter, 1, 'onStart callback is not called again');
|
1403
|
+
test.done();
|
1404
|
+
},
|
1405
|
+
'Test TWEEN.Tween.onStop': function (test) {
|
1406
|
+
var obj = {}, t = new Tween(obj);
|
1407
|
+
var counter = 0;
|
1408
|
+
t.to({ x: 2 }, 1000);
|
1409
|
+
t.onStop(function () {
|
1410
|
+
test.ok(true, 'onStop callback is called');
|
1411
|
+
counter++;
|
1412
|
+
});
|
1413
|
+
test.deepEqual(counter, 0);
|
1414
|
+
t.stop();
|
1415
|
+
update(0);
|
1416
|
+
test.deepEqual(counter, 0, "onStop callback not called when the tween hasn't started yet");
|
1417
|
+
t.start(0);
|
1418
|
+
update(0);
|
1419
|
+
t.stop();
|
1420
|
+
test.deepEqual(counter, 1, 'onStop callback is called if the tween has been started already and stop is invoked');
|
1421
|
+
update(500);
|
1422
|
+
t.stop();
|
1423
|
+
test.deepEqual(counter, 1, 'onStop callback is not called again once the tween is stopped');
|
1424
|
+
test.done();
|
1425
|
+
},
|
1426
|
+
'Test TWEEN.Tween.onUpdate': function (test) {
|
1427
|
+
var obj = {}, t = new Tween(obj);
|
1428
|
+
var counter = 0;
|
1429
|
+
t.to({ x: 2 }, 1000);
|
1430
|
+
t.onUpdate(function () {
|
1431
|
+
counter++;
|
1432
|
+
});
|
1433
|
+
test.deepEqual(counter, 0);
|
1434
|
+
t.start(0);
|
1435
|
+
update(0);
|
1436
|
+
test.deepEqual(counter, 1);
|
1437
|
+
update(500);
|
1438
|
+
test.deepEqual(counter, 2);
|
1439
|
+
update(600);
|
1440
|
+
test.deepEqual(counter, 3);
|
1441
|
+
update(1000);
|
1442
|
+
test.deepEqual(counter, 4);
|
1443
|
+
update(1500);
|
1444
|
+
test.deepEqual(counter, 4, 'onUpdate callback should not be called after the tween has finished');
|
1445
|
+
test.done();
|
1446
|
+
},
|
1447
|
+
'Test TWEEN.Tween.onComplete': function (test) {
|
1448
|
+
var obj = {}, t = new Tween(obj);
|
1449
|
+
var counter = 0;
|
1450
|
+
t.to({ x: 2 }, 1000);
|
1451
|
+
t.onComplete(function () {
|
1452
|
+
counter++;
|
1453
|
+
});
|
1454
|
+
test.deepEqual(counter, 0);
|
1455
|
+
t.start(0);
|
1456
|
+
update(0);
|
1457
|
+
test.deepEqual(counter, 0);
|
1458
|
+
update(500);
|
1459
|
+
test.deepEqual(counter, 0);
|
1460
|
+
update(600);
|
1461
|
+
test.deepEqual(counter, 0);
|
1462
|
+
update(1000);
|
1463
|
+
test.deepEqual(counter, 1);
|
1464
|
+
update(1500);
|
1465
|
+
test.deepEqual(counter, 1, 'onComplete callback must be called only once');
|
1466
|
+
test.done();
|
1467
|
+
},
|
1468
|
+
'TWEEN.Tween does not repeat by default': function (test) {
|
1469
|
+
removeAll();
|
1470
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100);
|
1471
|
+
t.start(0);
|
1472
|
+
update(0);
|
1473
|
+
test.equal(obj.x, 0);
|
1474
|
+
update(50);
|
1475
|
+
test.equal(obj.x, 50);
|
1476
|
+
update(100);
|
1477
|
+
test.equal(obj.x, 100);
|
1478
|
+
update(150);
|
1479
|
+
test.equal(obj.x, 100);
|
1480
|
+
test.done();
|
1481
|
+
},
|
1482
|
+
'Test single repeat happens only once': function (test) {
|
1483
|
+
removeAll();
|
1484
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100).repeat(1);
|
1485
|
+
t.start(0);
|
1486
|
+
update(0);
|
1487
|
+
test.equal(obj.x, 0);
|
1488
|
+
update(50);
|
1489
|
+
test.equal(obj.x, 50);
|
1490
|
+
update(100);
|
1491
|
+
test.equal(obj.x, 100);
|
1492
|
+
update(150);
|
1493
|
+
test.equal(obj.x, 50);
|
1494
|
+
update(200);
|
1495
|
+
test.equal(obj.x, 100);
|
1496
|
+
test.done();
|
1497
|
+
},
|
1498
|
+
'Test Infinity repeat happens forever': function (test) {
|
1499
|
+
removeAll();
|
1500
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100).repeat(Infinity);
|
1501
|
+
t.start(0);
|
1502
|
+
update(0);
|
1503
|
+
test.equal(obj.x, 0);
|
1504
|
+
update(50);
|
1505
|
+
test.equal(obj.x, 50);
|
1506
|
+
update(100);
|
1507
|
+
test.equal(obj.x, 100);
|
1508
|
+
update(150);
|
1509
|
+
test.equal(obj.x, 50);
|
1510
|
+
update(200);
|
1511
|
+
test.equal(obj.x, 100);
|
1512
|
+
update(250);
|
1513
|
+
test.equal(obj.x, 50);
|
1514
|
+
test.done();
|
1515
|
+
},
|
1516
|
+
'Test tweening relatively with repeat': function (test) {
|
1517
|
+
removeAll();
|
1518
|
+
var obj = { x: 0, y: 0 }, t = new Tween(obj).to({ x: '+100', y: '-100' }, 100).repeat(1);
|
1519
|
+
t.start(0);
|
1520
|
+
update(0);
|
1521
|
+
test.equal(obj.x, 0);
|
1522
|
+
test.equal(obj.y, 0);
|
1523
|
+
update(50);
|
1524
|
+
test.equal(obj.x, 50);
|
1525
|
+
test.equal(obj.y, -50);
|
1526
|
+
update(100);
|
1527
|
+
test.equal(obj.x, 100);
|
1528
|
+
test.equal(obj.y, -100);
|
1529
|
+
update(150);
|
1530
|
+
test.equal(obj.x, 150);
|
1531
|
+
test.equal(obj.y, -150);
|
1532
|
+
update(200);
|
1533
|
+
test.equal(obj.x, 200);
|
1534
|
+
test.equal(obj.y, -200);
|
1535
|
+
test.done();
|
1536
|
+
},
|
1537
|
+
'Test yoyo with repeat Infinity happens forever': function (test) {
|
1538
|
+
removeAll();
|
1539
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100).repeat(Infinity).yoyo(true);
|
1540
|
+
t.start(0);
|
1541
|
+
update(0);
|
1542
|
+
test.equal(obj.x, 0);
|
1543
|
+
update(25);
|
1544
|
+
test.equal(obj.x, 25);
|
1545
|
+
update(100);
|
1546
|
+
test.equal(obj.x, 100);
|
1547
|
+
update(125);
|
1548
|
+
test.equal(obj.x, 75);
|
1549
|
+
update(200);
|
1550
|
+
test.equal(obj.x, 0);
|
1551
|
+
update(225);
|
1552
|
+
test.equal(obj.x, 25);
|
1553
|
+
test.done();
|
1554
|
+
},
|
1555
|
+
'Test yoyo with repeat 1 happens once': function (test) {
|
1556
|
+
removeAll();
|
1557
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100).repeat(1).yoyo(true);
|
1558
|
+
t.start(0);
|
1559
|
+
update(0);
|
1560
|
+
test.equal(obj.x, 0);
|
1561
|
+
update(25);
|
1562
|
+
test.equal(obj.x, 25);
|
1563
|
+
update(100);
|
1564
|
+
test.equal(obj.x, 100);
|
1565
|
+
update(125);
|
1566
|
+
test.equal(obj.x, 75);
|
1567
|
+
update(200);
|
1568
|
+
test.equal(obj.x, 0);
|
1569
|
+
update(225);
|
1570
|
+
test.equal(obj.x, 0);
|
1571
|
+
test.done();
|
1572
|
+
},
|
1573
|
+
'Test yoyo works with arrays': function (test) {
|
1574
|
+
removeAll();
|
1575
|
+
var obj = { x: 0 }, t = new Tween(obj)
|
1576
|
+
.to({ x: [100, 200] }, 100)
|
1577
|
+
.repeat(1)
|
1578
|
+
.yoyo(true);
|
1579
|
+
t.start(0);
|
1580
|
+
update(50);
|
1581
|
+
test.equal(obj.x, 100);
|
1582
|
+
update(100);
|
1583
|
+
test.equal(obj.x, 200);
|
1584
|
+
update(150);
|
1585
|
+
test.equal(obj.x, 100);
|
1586
|
+
update(200);
|
1587
|
+
test.equal(obj.x, 0);
|
1588
|
+
test.done();
|
1589
|
+
},
|
1590
|
+
'Test yoyo can be stopped and restarted properly': function (test) {
|
1591
|
+
removeAll();
|
1592
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100).repeat(1).yoyo(true);
|
1593
|
+
t.start(0);
|
1594
|
+
update(0);
|
1595
|
+
test.equal(obj.x, 0);
|
1596
|
+
update(25);
|
1597
|
+
test.equal(obj.x, 25);
|
1598
|
+
update(100);
|
1599
|
+
test.equal(obj.x, 100);
|
1600
|
+
update(125);
|
1601
|
+
test.equal(obj.x, 75);
|
1602
|
+
t.stop();
|
1603
|
+
t.start(0);
|
1604
|
+
update(0);
|
1605
|
+
test.equal(obj.x, 0);
|
1606
|
+
update(25);
|
1607
|
+
test.equal(obj.x, 25);
|
1608
|
+
update(100);
|
1609
|
+
test.equal(obj.x, 100);
|
1610
|
+
update(125);
|
1611
|
+
test.equal(obj.x, 75);
|
1612
|
+
update(200);
|
1613
|
+
test.equal(obj.x, 0);
|
1614
|
+
update(225);
|
1615
|
+
test.equal(obj.x, 0);
|
1616
|
+
test.done();
|
1617
|
+
},
|
1618
|
+
'Test TWEEN.Tween.stopChainedTweens()': function (test) {
|
1619
|
+
var t = new Tween({}), t2 = new Tween({});
|
1620
|
+
var tStarted = false, tCompleted = false, t2Started = false;
|
1621
|
+
removeAll();
|
1622
|
+
t.to({}, 1000);
|
1623
|
+
t2.delay(500).to({}, 1000);
|
1624
|
+
t.chain(t2);
|
1625
|
+
t2.chain(t);
|
1626
|
+
t.onStart(function () {
|
1627
|
+
tStarted = true;
|
1628
|
+
});
|
1629
|
+
t.onComplete(function () {
|
1630
|
+
tCompleted = true;
|
1631
|
+
});
|
1632
|
+
t2.onStart(function () {
|
1633
|
+
test.equal(tStarted, true);
|
1634
|
+
test.equal(tCompleted, true);
|
1635
|
+
test.equal(t2Started, false);
|
1636
|
+
t2Started = true;
|
1637
|
+
});
|
1638
|
+
test.equal(tStarted, false);
|
1639
|
+
test.equal(t2Started, false);
|
1640
|
+
t.start(0);
|
1641
|
+
update(1001);
|
1642
|
+
t.stop();
|
1643
|
+
test.equal(tStarted, true);
|
1644
|
+
test.equal(t2Started, false);
|
1645
|
+
test.equal(getAll().length, 0);
|
1646
|
+
test.done();
|
1647
|
+
},
|
1648
|
+
'Test TWEEN.Tween.chain progressess into chained tweens': function (test) {
|
1649
|
+
var obj = { t: 1000 };
|
1650
|
+
// 1000 of nothing
|
1651
|
+
var blank = new Tween({}).to({}, 1000);
|
1652
|
+
// tween obj.t from 1000 -> 2000 (in time with update time)
|
1653
|
+
var next = new Tween(obj).to({ t: 2000 }, 1000);
|
1654
|
+
blank.chain(next).start(0);
|
1655
|
+
update(1500);
|
1656
|
+
test.equal(obj.t, 1500);
|
1657
|
+
update(2000);
|
1658
|
+
test.equal(obj.t, 2000);
|
1659
|
+
test.done();
|
1660
|
+
},
|
1661
|
+
'Test that TWEEN.Tween.end sets the final values.': function (test) {
|
1662
|
+
var object1 = { x: 0, y: -50, z: 1000 };
|
1663
|
+
var target1 = { x: 50, y: 123, z: '+234' };
|
1664
|
+
var tween1 = new Tween(object1).to(target1, 1000);
|
1665
|
+
tween1.start();
|
1666
|
+
tween1.end();
|
1667
|
+
test.equal(object1.x, 50);
|
1668
|
+
test.equal(object1.y, 123);
|
1669
|
+
test.equal(object1.z, 1234);
|
1670
|
+
var object2 = { x: 0, y: -50, z: 1000 };
|
1671
|
+
var target2 = { x: 50, y: 123, z: '+234' };
|
1672
|
+
var tween2 = new Tween(object2).to(target2, 1000);
|
1673
|
+
tween2.start(300);
|
1674
|
+
tween2.update(500);
|
1675
|
+
tween2.end();
|
1676
|
+
test.equal(object2.x, 50);
|
1677
|
+
test.equal(object2.y, 123);
|
1678
|
+
test.equal(object2.z, 1234);
|
1679
|
+
test.done();
|
1680
|
+
},
|
1681
|
+
'Test that TWEEN.Tween.end calls the onComplete callback of the tween.': function (test) {
|
1682
|
+
test.expect(1);
|
1683
|
+
var tween1 = new Tween({}).to({}, 1000).onComplete(function () {
|
1684
|
+
test.ok(true);
|
1685
|
+
});
|
1686
|
+
tween1.start();
|
1687
|
+
tween1.end();
|
1688
|
+
test.done();
|
1689
|
+
},
|
1690
|
+
'Ensure Tween.end() works after stopping a tween.': function (test) {
|
1691
|
+
var object = { x: 0, y: -50, z: 1000 };
|
1692
|
+
var target = { x: 50, y: 123, z: '+234' };
|
1693
|
+
var tween = new Tween(object).to(target, 1000);
|
1694
|
+
tween.start(300);
|
1695
|
+
tween.update(500);
|
1696
|
+
tween.stop();
|
1697
|
+
tween.end();
|
1698
|
+
test.equal(object.x, 50);
|
1699
|
+
test.equal(object.y, 123);
|
1700
|
+
test.equal(object.z, 1234);
|
1701
|
+
test.done();
|
1702
|
+
},
|
1703
|
+
'Test delay adds delay before each repeat': function (test) {
|
1704
|
+
// If repeatDelay isn't specified then delay is used since
|
1705
|
+
// that's the way it worked before repeatDelay was added.
|
1706
|
+
removeAll();
|
1707
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100).repeat(1).delay(100);
|
1708
|
+
t.start(0);
|
1709
|
+
update(100);
|
1710
|
+
test.equal(obj.x, 0);
|
1711
|
+
update(150);
|
1712
|
+
test.equal(obj.x, 50);
|
1713
|
+
update(200);
|
1714
|
+
test.equal(obj.x, 100);
|
1715
|
+
update(250);
|
1716
|
+
test.equal(obj.x, 100);
|
1717
|
+
update(300);
|
1718
|
+
test.equal(obj.x, 0);
|
1719
|
+
update(350);
|
1720
|
+
test.equal(obj.x, 50);
|
1721
|
+
update(400);
|
1722
|
+
test.equal(obj.x, 100);
|
1723
|
+
test.done();
|
1724
|
+
},
|
1725
|
+
'Test repeatDelay adds delay before each repeat': function (test) {
|
1726
|
+
removeAll();
|
1727
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100).repeat(1).repeatDelay(200);
|
1728
|
+
t.start(0);
|
1729
|
+
update(0);
|
1730
|
+
test.equal(obj.x, 0);
|
1731
|
+
update(50);
|
1732
|
+
test.equal(obj.x, 50);
|
1733
|
+
update(100);
|
1734
|
+
test.equal(obj.x, 100);
|
1735
|
+
update(200);
|
1736
|
+
test.equal(obj.x, 100);
|
1737
|
+
update(300);
|
1738
|
+
test.equal(obj.x, 0);
|
1739
|
+
update(350);
|
1740
|
+
test.equal(obj.x, 50);
|
1741
|
+
update(400);
|
1742
|
+
test.equal(obj.x, 100);
|
1743
|
+
test.done();
|
1744
|
+
},
|
1745
|
+
'Test repeatDelay and delay can be used together': function (test) {
|
1746
|
+
removeAll();
|
1747
|
+
var obj = { x: 0 }, t = new Tween(obj).to({ x: 100 }, 100).delay(100).repeat(1).repeatDelay(200);
|
1748
|
+
t.start(0);
|
1749
|
+
update(100);
|
1750
|
+
test.equal(obj.x, 0);
|
1751
|
+
update(150);
|
1752
|
+
test.equal(obj.x, 50);
|
1753
|
+
update(200);
|
1754
|
+
test.equal(obj.x, 100);
|
1755
|
+
update(300);
|
1756
|
+
test.equal(obj.x, 100);
|
1757
|
+
update(400);
|
1758
|
+
test.equal(obj.x, 0);
|
1759
|
+
update(450);
|
1760
|
+
test.equal(obj.x, 50);
|
1761
|
+
update(500);
|
1762
|
+
test.equal(obj.x, 100);
|
1763
|
+
test.done();
|
1764
|
+
},
|
1765
|
+
'Tween.js compatible with Object.defineProperty getter / setters': function (test) {
|
1766
|
+
var obj = { _x: 0, x: 0 };
|
1767
|
+
Object.defineProperty(obj, 'x', {
|
1768
|
+
get: function () {
|
1769
|
+
return this._x;
|
1770
|
+
},
|
1771
|
+
set: function (x) {
|
1772
|
+
this._x = x;
|
1773
|
+
},
|
1774
|
+
});
|
1775
|
+
test.equal(obj.x, 0);
|
1776
|
+
var t = new Tween(obj).to({ x: 100 }, 100);
|
1777
|
+
t.start(0);
|
1778
|
+
test.equal(obj.x, 0);
|
1779
|
+
update(37);
|
1780
|
+
test.equal(obj.x, 37);
|
1781
|
+
update(100);
|
1782
|
+
test.equal(obj.x, 100);
|
1783
|
+
update(115);
|
1784
|
+
test.equal(obj.x, 100);
|
1785
|
+
test.done();
|
1786
|
+
},
|
1787
|
+
'tween.isPlaying() is false before the tween starts': function (test) {
|
1788
|
+
removeAll();
|
1789
|
+
var t = new Tween({ x: 0 }).to({ x: 1 }, 100);
|
1790
|
+
test.equal(t.isPlaying(), false);
|
1791
|
+
test.done();
|
1792
|
+
},
|
1793
|
+
'tween.isPlaying() is true when a tween is started and before it ends': function (test) {
|
1794
|
+
removeAll();
|
1795
|
+
var t = new Tween({ x: 0 }).to({ x: 1 }, 100);
|
1796
|
+
t.start(0);
|
1797
|
+
test.equal(t.isPlaying(), true);
|
1798
|
+
test.done();
|
1799
|
+
},
|
1800
|
+
'tween.isPlaying() is false after a tween ends': function (test) {
|
1801
|
+
removeAll();
|
1802
|
+
var t = new Tween({ x: 0 }).to({ x: 1 }, 100);
|
1803
|
+
t.start(0);
|
1804
|
+
update(150);
|
1805
|
+
test.equal(t.isPlaying(), false);
|
1806
|
+
test.done();
|
1807
|
+
},
|
1808
|
+
'A zero-duration tween finishes at its starting time without an error.': function (test) {
|
1809
|
+
removeAll();
|
1810
|
+
var object = { x: 0 };
|
1811
|
+
var t = new Tween(object).to({ x: 1 }, 0);
|
1812
|
+
t.start(0);
|
1813
|
+
update(0);
|
1814
|
+
test.equal(t.isPlaying(), false);
|
1815
|
+
test.equal(object.x, 1);
|
1816
|
+
test.done();
|
1817
|
+
},
|
1818
|
+
// Custom TWEEN.Group tests
|
1819
|
+
'Custom group.getAll()': function (test) {
|
1820
|
+
var group = new Group();
|
1821
|
+
test.ok(group.getAll() instanceof Array);
|
1822
|
+
test.done();
|
1823
|
+
},
|
1824
|
+
'Custom group stores tweens instead of global TWEEN group': function (test) {
|
1825
|
+
var group = new Group();
|
1826
|
+
var numGlobalTweensBefore = getAll().length;
|
1827
|
+
var numGroupTweensBefore = group.getAll().length;
|
1828
|
+
var globalTween = new Tween({});
|
1829
|
+
var groupTweenA = new Tween({}, group);
|
1830
|
+
var groupTweenB = new Tween({}, group);
|
1831
|
+
globalTween.start();
|
1832
|
+
groupTweenA.start();
|
1833
|
+
groupTweenB.start();
|
1834
|
+
test.equal(getAll().length, numGlobalTweensBefore + 1);
|
1835
|
+
test.equal(group.getAll().length, numGroupTweensBefore + 2);
|
1836
|
+
test.done();
|
1837
|
+
},
|
1838
|
+
"Custom group.removeAll() doesn't conflict with global TWEEN group": function (test) {
|
1839
|
+
var group = new Group();
|
1840
|
+
removeAll();
|
1841
|
+
group.removeAll();
|
1842
|
+
test.equal(getAll().length, 0, 'No global tweens left');
|
1843
|
+
test.equal(group.getAll().length, 0, 'No group tweens left');
|
1844
|
+
var globalTween = new Tween({});
|
1845
|
+
var groupTweenA = new Tween({}, group);
|
1846
|
+
var groupTweenB = new Tween({}, group);
|
1847
|
+
globalTween.start();
|
1848
|
+
groupTweenA.start();
|
1849
|
+
groupTweenB.start();
|
1850
|
+
test.equal(getAll().length, 1, 'One global tween has been added');
|
1851
|
+
test.equal(group.getAll().length, 2, 'Two group tweens have been added');
|
1852
|
+
group.removeAll();
|
1853
|
+
test.equal(getAll().length, 1, 'One global tween left');
|
1854
|
+
test.equal(group.getAll().length, 0, 'No group tweens left');
|
1855
|
+
removeAll();
|
1856
|
+
test.equal(getAll().length, 0, 'No global tweens left');
|
1857
|
+
test.done();
|
1858
|
+
},
|
1859
|
+
"Global TWEEN.removeAll() doesn't conflict with custom group": function (test) {
|
1860
|
+
var group = new Group();
|
1861
|
+
removeAll();
|
1862
|
+
group.removeAll();
|
1863
|
+
test.equal(getAll().length, 0, 'No global tweens left');
|
1864
|
+
test.equal(group.getAll().length, 0, 'No group tweens left');
|
1865
|
+
var globalTween = new Tween({});
|
1866
|
+
var groupTweenA = new Tween({}, group);
|
1867
|
+
var groupTweenB = new Tween({}, group);
|
1868
|
+
globalTween.start();
|
1869
|
+
groupTweenA.start();
|
1870
|
+
groupTweenB.start();
|
1871
|
+
test.equal(getAll().length, 1, 'One global tween has been added');
|
1872
|
+
test.equal(group.getAll().length, 2, 'Two group tweens have been added');
|
1873
|
+
removeAll();
|
1874
|
+
test.equal(getAll().length, 0, 'No global tweens left');
|
1875
|
+
test.equal(group.getAll().length, 2, 'Two group tweens left');
|
1876
|
+
group.removeAll();
|
1877
|
+
test.equal(group.getAll().length, 0, 'No group tweens left');
|
1878
|
+
test.done();
|
1879
|
+
},
|
1880
|
+
"Custom group.add() doesn't conflict with global TWEEN group, or vice versa": function (test) {
|
1881
|
+
var group = new Group();
|
1882
|
+
var globalTween = new Tween({});
|
1883
|
+
var groupTweenA = new Tween({}, group);
|
1884
|
+
var groupTweenB = new Tween({}, group);
|
1885
|
+
var numGlobalTweens = getAll().length;
|
1886
|
+
var numGroupTweens = group.getAll().length;
|
1887
|
+
add(globalTween);
|
1888
|
+
group.add(groupTweenA);
|
1889
|
+
group.add(groupTweenB);
|
1890
|
+
test.equal(numGlobalTweens + 1, getAll().length);
|
1891
|
+
test.equal(numGroupTweens + 2, group.getAll().length);
|
1892
|
+
test.done();
|
1893
|
+
},
|
1894
|
+
"Custom group.update() doesn't conflict with global TWEEN group": function (test) {
|
1895
|
+
var group = new Group();
|
1896
|
+
var startObj = { x: 1 };
|
1897
|
+
var endObj = { x: 2 };
|
1898
|
+
var duration = 1000;
|
1899
|
+
var globalObj = { x: 1 };
|
1900
|
+
new Tween(globalObj).to(endObj, duration).start(0);
|
1901
|
+
var groupObj = { x: 1 };
|
1902
|
+
new Tween(groupObj, group).to(endObj, duration).start(0);
|
1903
|
+
group.update(duration);
|
1904
|
+
test.deepEqual(globalObj, startObj);
|
1905
|
+
test.deepEqual(groupObj, endObj);
|
1906
|
+
test.done();
|
1907
|
+
},
|
1908
|
+
"Global TWEEN.update() doesn't conflict with custom group": function (test) {
|
1909
|
+
var group = new Group();
|
1910
|
+
var startObj = { x: 1 };
|
1911
|
+
var endObj = { x: 2 };
|
1912
|
+
var duration = 1000;
|
1913
|
+
var globalObj = { x: 1 };
|
1914
|
+
new Tween(globalObj).to(endObj, duration).start(0);
|
1915
|
+
var groupObj = { x: 1 };
|
1916
|
+
new Tween(groupObj, group).to(endObj, duration).start(0);
|
1917
|
+
update(duration);
|
1918
|
+
test.deepEqual(globalObj, endObj);
|
1919
|
+
test.deepEqual(groupObj, startObj);
|
1920
|
+
test.done();
|
1921
|
+
},
|
1922
|
+
'Ensure tweens work without any group': function (test) {
|
1923
|
+
var obj = { x: 0 }, t = new Tween(obj, false);
|
1924
|
+
t.to({ x: 1000 }, 1000);
|
1925
|
+
t.start(0);
|
1926
|
+
test.equal(obj.x, 0);
|
1927
|
+
t.update(500);
|
1928
|
+
test.equal(obj.x, 500);
|
1929
|
+
t.pause(600);
|
1930
|
+
test.equal(obj.x, 500);
|
1931
|
+
t.update(750);
|
1932
|
+
test.equal(obj.x, 500);
|
1933
|
+
t.resume(800);
|
1934
|
+
test.equal(obj.x, 500);
|
1935
|
+
t.update(1000);
|
1936
|
+
test.equal(obj.x, 800);
|
1937
|
+
t.update(1001);
|
1938
|
+
test.equal(obj.x, 801);
|
1939
|
+
t.stop().end();
|
1940
|
+
test.equal(obj.x, 1000);
|
1941
|
+
test.done();
|
1942
|
+
},
|
1943
|
+
'Stopping a tween within an update callback will not cause an error.': function (test) {
|
1944
|
+
removeAll();
|
1945
|
+
var tweenA = new Tween({ x: 1, y: 2 })
|
1946
|
+
.to({ x: 3, y: 4 }, 1000)
|
1947
|
+
.onUpdate(function () {
|
1948
|
+
tweenB.stop();
|
1949
|
+
})
|
1950
|
+
.start(0);
|
1951
|
+
var tweenB = new Tween({ x: 5, y: 6 })
|
1952
|
+
.to({ x: 7, y: 8 })
|
1953
|
+
.onUpdate(function () {
|
1954
|
+
tweenA.stop();
|
1955
|
+
})
|
1956
|
+
.start(0);
|
1957
|
+
var success = true;
|
1958
|
+
try {
|
1959
|
+
update(500);
|
1960
|
+
}
|
1961
|
+
catch (exception) {
|
1962
|
+
success = false;
|
1963
|
+
}
|
1964
|
+
finally {
|
1965
|
+
test.ok(success);
|
1966
|
+
test.done();
|
1967
|
+
}
|
1968
|
+
},
|
1969
|
+
'Set the duration with .duration': function (test) {
|
1970
|
+
var obj = { x: 1 };
|
1971
|
+
var t = new Tween(obj).to({ x: 2 }).duration(1000).start(0);
|
1972
|
+
t.update(1000);
|
1973
|
+
test.deepEqual(obj.x, 2);
|
1974
|
+
test.done();
|
1975
|
+
},
|
1976
|
+
"Tween.group sets the tween's group.": function (test) {
|
1977
|
+
var group = new Group();
|
1978
|
+
var groupTweenA = new Tween({}).group(group);
|
1979
|
+
groupTweenA.start();
|
1980
|
+
test.equal(group.getAll().length, 1);
|
1981
|
+
test.done();
|
1982
|
+
},
|
1983
|
+
'Test TWEEN.Tween.pause() and TWEEN.Tween.resume()': function (test) {
|
1984
|
+
var obj = { x: 0.0 }, t = new Tween(obj);
|
1985
|
+
t.to({ x: 1.0 }, 1000);
|
1986
|
+
removeAll();
|
1987
|
+
test.equal(getAll().length, 0);
|
1988
|
+
t.start(0);
|
1989
|
+
test.equal(getAll().length, 1);
|
1990
|
+
test.equal(t.isPaused(), false);
|
1991
|
+
update(400);
|
1992
|
+
test.equal(obj.x, 0.4);
|
1993
|
+
t.pause(450);
|
1994
|
+
test.equal(t.isPaused(), true);
|
1995
|
+
test.equal(getAll().length, 0);
|
1996
|
+
test.equal(obj.x, 0.4);
|
1997
|
+
update(900);
|
1998
|
+
test.equal(obj.x, 0.4);
|
1999
|
+
update(3000);
|
2000
|
+
test.equal(obj.x, 0.4);
|
2001
|
+
t.resume(3200);
|
2002
|
+
// values do not change until an update
|
2003
|
+
test.equal(obj.x, 0.4);
|
2004
|
+
test.equal(getAll().length, 1);
|
2005
|
+
test.equal(t.isPaused(), false);
|
2006
|
+
update(3500);
|
2007
|
+
test.equal(obj.x, 0.75);
|
2008
|
+
update(5000);
|
2009
|
+
test.equal(obj.x, 1.0);
|
2010
|
+
test.done();
|
2011
|
+
},
|
2012
|
+
'Test TWEEN.Tween.pause() and TWEEN.Tween.resume(), without groups': function (test) {
|
2013
|
+
var obj = { x: 0.0 }, t = new Tween(obj, false);
|
2014
|
+
t.to({ x: 1.0 }, 1000);
|
2015
|
+
t.start(0);
|
2016
|
+
test.equal(t.isPaused(), false);
|
2017
|
+
t.update(400);
|
2018
|
+
test.equal(obj.x, 0.4);
|
2019
|
+
t.pause(450);
|
2020
|
+
test.equal(t.isPaused(), true);
|
2021
|
+
test.equal(obj.x, 0.4);
|
2022
|
+
t.update(900);
|
2023
|
+
test.equal(obj.x, 0.4);
|
2024
|
+
t.update(3000);
|
2025
|
+
test.equal(obj.x, 0.4);
|
2026
|
+
t.resume(3200);
|
2027
|
+
// values do not change until an update
|
2028
|
+
test.equal(obj.x, 0.4);
|
2029
|
+
test.equal(t.isPaused(), false);
|
2030
|
+
t.update(3500);
|
2031
|
+
test.equal(obj.x, 0.75);
|
2032
|
+
t.update(5000);
|
2033
|
+
test.equal(obj.x, 1.0);
|
2034
|
+
test.done();
|
2035
|
+
},
|
2036
|
+
'Arrays in the object passed to to() are not modified by start().': function (test) {
|
2037
|
+
var start = { x: 10, y: 20 };
|
2038
|
+
var end = { x: 100, y: 200, values: ['a', 'b'] };
|
2039
|
+
var valuesArray = end.values;
|
2040
|
+
new Tween(start).to(end).start();
|
2041
|
+
test.equal(valuesArray, end.values);
|
2042
|
+
test.equal(end.values.length, 2);
|
2043
|
+
test.equal(end.values[0], 'a');
|
2044
|
+
test.equal(end.values[1], 'b');
|
2045
|
+
test.done();
|
2046
|
+
},
|
2047
|
+
'Tween.js animate nested object': function (test) {
|
2048
|
+
var obj = { scale: { x: 0 }, alpha: 0 };
|
2049
|
+
var t = new Tween(obj).to({ scale: { x: 100 }, alpha: 100 }, 100);
|
2050
|
+
t.start(0);
|
2051
|
+
test.equal(obj.scale.x, 0);
|
2052
|
+
update(37);
|
2053
|
+
test.equal(obj.scale.x, 37);
|
2054
|
+
test.equal(obj.alpha, 37);
|
2055
|
+
update(100);
|
2056
|
+
test.equal(obj.scale.x, 100);
|
2057
|
+
test.equal(obj.alpha, 100);
|
2058
|
+
update(115);
|
2059
|
+
test.equal(obj.scale.x, 100);
|
2060
|
+
test.equal(obj.alpha, 100);
|
2061
|
+
test.done();
|
2062
|
+
},
|
2063
|
+
'Tween.js animate nested object including relative value': function (test) {
|
2064
|
+
var obj = { world: { hero: { scale: { x: 0 }, x: 100 } }, time: 0 };
|
2065
|
+
var t = new Tween(obj).to({ world: { hero: { scale: { x: 100 }, x: '+100' } }, time: 100 }, 100);
|
2066
|
+
t.start(0);
|
2067
|
+
test.equal(obj.world.hero.scale.x, 0);
|
2068
|
+
update(37);
|
2069
|
+
test.equal(obj.world.hero.scale.x, 37);
|
2070
|
+
test.equal(obj.world.hero.x, 137);
|
2071
|
+
test.equal(obj.time, 37);
|
2072
|
+
update(100);
|
2073
|
+
test.equal(obj.world.hero.scale.x, 100);
|
2074
|
+
test.equal(obj.world.hero.x, 200);
|
2075
|
+
test.equal(obj.time, 100);
|
2076
|
+
update(115);
|
2077
|
+
test.equal(obj.world.hero.scale.x, 100);
|
2078
|
+
test.equal(obj.world.hero.x, 200);
|
2079
|
+
test.equal(obj.time, 100);
|
2080
|
+
test.done();
|
2081
|
+
},
|
2082
|
+
'Test TWEEN.Tween with nested objects': function (test) {
|
2083
|
+
var obj = { x: 0.0, y: 100, some: { value: 0.0, style: { opacity: 1.0 } } }, t = new Tween(obj);
|
2084
|
+
t.to({ x: 1.0, y: 200, some: { value: 1.0, style: { opacity: 0.5 } } }, 1000);
|
2085
|
+
removeAll();
|
2086
|
+
test.equal(getAll().length, 0);
|
2087
|
+
t.start(0);
|
2088
|
+
test.equal(getAll().length, 1);
|
2089
|
+
test.equal(t.isPaused(), false);
|
2090
|
+
update(400);
|
2091
|
+
test.equal(obj.x, 0.4);
|
2092
|
+
test.equal(obj.y, 140);
|
2093
|
+
test.equal(obj.some.style.opacity, 0.8);
|
2094
|
+
test.equal(obj.some.value, 0.4);
|
2095
|
+
update(750);
|
2096
|
+
test.equal(obj.x, 0.75);
|
2097
|
+
test.equal(obj.y, 175);
|
2098
|
+
test.equal(obj.some.style.opacity, 0.625);
|
2099
|
+
test.equal(obj.some.value, 0.75);
|
2100
|
+
update(1000);
|
2101
|
+
test.equal(obj.x, 1.0);
|
2102
|
+
test.equal(obj.y, 200);
|
2103
|
+
test.equal(obj.some.style.opacity, 0.5);
|
2104
|
+
test.equal(obj.some.value, 1.0);
|
2105
|
+
test.done();
|
2106
|
+
},
|
2107
|
+
'Test TWEEN.Tween.pause() and .resume() with nested objects': function (test) {
|
2108
|
+
var obj = { x: 0.0, y: 100, some: { value: 0.0 } }, t = new Tween(obj);
|
2109
|
+
t.to({ x: 1.0, y: 200, some: { value: 1.0 } }, 1000);
|
2110
|
+
removeAll();
|
2111
|
+
test.equal(getAll().length, 0);
|
2112
|
+
t.start(0);
|
2113
|
+
test.equal(getAll().length, 1);
|
2114
|
+
test.equal(t.isPaused(), false);
|
2115
|
+
update(400);
|
2116
|
+
test.equal(obj.x, 0.4);
|
2117
|
+
test.equal(obj.y, 140);
|
2118
|
+
test.equal(obj.some.value, 0.4);
|
2119
|
+
t.pause(450);
|
2120
|
+
test.equal(t.isPaused(), true);
|
2121
|
+
test.equal(getAll().length, 0);
|
2122
|
+
test.equal(obj.x, 0.4);
|
2123
|
+
test.equal(obj.y, 140);
|
2124
|
+
test.equal(obj.some.value, 0.4);
|
2125
|
+
update(900);
|
2126
|
+
test.equal(obj.x, 0.4);
|
2127
|
+
test.equal(obj.y, 140);
|
2128
|
+
test.equal(obj.some.value, 0.4);
|
2129
|
+
update(3000);
|
2130
|
+
test.equal(obj.x, 0.4);
|
2131
|
+
test.equal(obj.y, 140);
|
2132
|
+
test.equal(obj.some.value, 0.4);
|
2133
|
+
t.resume(3200);
|
2134
|
+
// values do not change until an update
|
2135
|
+
test.equal(obj.x, 0.4);
|
2136
|
+
test.equal(obj.y, 140);
|
2137
|
+
test.equal(obj.some.value, 0.4);
|
2138
|
+
test.equal(getAll().length, 1);
|
2139
|
+
test.equal(t.isPaused(), false);
|
2140
|
+
update(3500);
|
2141
|
+
test.equal(obj.x, 0.75);
|
2142
|
+
test.equal(obj.y, 175);
|
2143
|
+
test.equal(obj.some.value, 0.75);
|
2144
|
+
update(5000);
|
2145
|
+
test.equal(obj.x, 1.0);
|
2146
|
+
test.equal(obj.y, 200);
|
2147
|
+
test.equal(obj.some.value, 1.0);
|
2148
|
+
test.done();
|
2149
|
+
},
|
2150
|
+
};
|
2151
|
+
|
2152
|
+
exports.tests = tests;
|