Skip to content

Commit adc8b49

Browse files
committed
Refactored so that only a single TweenData will exist per property.
1 parent 4a71309 commit adc8b49

8 files changed

Lines changed: 77 additions & 81 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'dfab8d20-3fb2-11e7-af94-f9a09f1963c8'
2+
build: 'c32eb8a0-3fe1-11e7-bff5-b320395fe4ad'
33
};
44
module.exports = CHECKSUM;

v3/src/tween/Tween.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ var Tween = function (manager, targets, tweenData)
1111
this.totalTargets = targets.length;
1212

1313
// The property data and TweenData lists
14+
15+
// An object with a property matching those being tweened by this Tween.
1416
this.data = tweenData;
1517

18+
// {
19+
// x: TweenData reference
20+
// y: TweenData reference
21+
// }
22+
//
1623
// An object with a property matching those being tweened by this Tween.
1724
// The list arrays contain TweenData instances in a linked-list format.
18-
//
1925
// {
2026
// x: {
2127
// current: TweenData reference
@@ -75,6 +81,7 @@ Tween.prototype = {
7581
calcTargetsValue: require('./components/CalcTargetsValue'),
7682
init: require('./components/Init'),
7783
loadValues: require('./components/LoadValues'),
84+
nextState: require('./components/NextState'),
7885
nextTweenData: require('./components/NextTweenData'),
7986
play: require('./components/Play'),
8087
resetTargetsValue: require('./components/ResetTargetsValue'),

v3/src/tween/TweenBuilder.js

Lines changed: 25 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var Clone = require('../utils/object/Clone');
21
var GetValue = require('../utils/object/GetValue');
32
var GetAdvancedValue = require('../utils/object/GetAdvancedValue');
43
var Tween = require('./Tween');
@@ -64,20 +63,21 @@ var GetProps = function (config)
6463
var GetValueOp = function (key, value)
6564
{
6665
var valueCallback;
66+
var t = typeof(value);
6767

68-
if (typeof value === 'number')
68+
if (t === 'number')
6969
{
7070
// props: {
7171
// x: 400,
7272
// y: 300
7373
// }
7474

75-
valueCallback = function (i)
75+
valueCallback = function ()
7676
{
7777
return value;
7878
};
7979
}
80-
else if (typeof value === 'string')
80+
else if (t === 'string')
8181
{
8282
// props: {
8383
// x: '+=400',
@@ -126,7 +126,7 @@ var GetValueOp = function (key, value)
126126
};
127127
}
128128
}
129-
else if (typeof value === 'function')
129+
else if (t === 'function')
130130
{
131131
// Technically this could return a number, string or object
132132
// props: {
@@ -158,7 +158,8 @@ var TweenBuilder = function (manager, config)
158158
var targetKeys = {};
159159
var tweenKeys = {};
160160

161-
props.forEach(function (p) {
161+
props.forEach(function (p)
162+
{
162163
targetKeys[p.key] = { start: 0, current: 0, end: 0 };
163164
tweenKeys[p.key] = { current: null, list: [] };
164165
});
@@ -190,59 +191,24 @@ var TweenBuilder = function (manager, config)
190191
for (var p = 0; p < props.length; p++)
191192
{
192193
var key = props[p].key;
193-
var values = props[p].value;
194-
195-
if (!Array.isArray(values))
196-
{
197-
values = [ values ];
198-
}
199-
200-
var prev = null;
201-
202-
// Loop through every value for the property, i.e.: x: [ 200, 300, 400 ]
203-
for (var i = 0; i < values.length; i++)
204-
{
205-
var value = values[i];
206-
207-
var tweenData = TweenData(
208-
key,
209-
GetValueOp(key, value),
210-
GetEaseFunction(GetValue(value, 'ease', ease)),
211-
GetAdvancedValue(value, 'delay', delay),
212-
GetAdvancedValue(value, 'duration', duration),
213-
GetAdvancedValue(value, 'hold', hold),
214-
GetAdvancedValue(value, 'repeat', repeat),
215-
GetAdvancedValue(value, 'repeatDelay', repeatDelay),
216-
GetAdvancedValue(value, 'startAt', startAt),
217-
GetValue(value, 'yoyo', yoyo)
218-
);
219-
220-
// Calculate total duration
221-
222-
// Duration is derived from:
223-
// TweenData.duration
224-
// TweenData.delay
225-
// TweenData.hold
226-
// x TweenData.repeat
227-
228-
// var totalDuration = 0;
229-
230-
// var playThruDuration = tweenData.duration * tweenData.repeat;
231-
232-
// totalDuration
233-
// tweenData.totalDuration =
234-
235-
tweenData.prev = prev;
236-
237-
if (prev)
238-
{
239-
prev.next = tweenData;
240-
}
241-
242-
tween.data[key].list.push(tweenData);
243-
244-
prev = tweenData;
245-
}
194+
var value = props[p].value;
195+
196+
var tweenData = TweenData(
197+
key,
198+
GetValueOp(key, value),
199+
GetEaseFunction(GetValue(value, 'ease', ease)),
200+
GetAdvancedValue(value, 'delay', delay),
201+
GetAdvancedValue(value, 'duration', duration),
202+
GetAdvancedValue(value, 'hold', hold),
203+
GetAdvancedValue(value, 'repeat', repeat),
204+
GetAdvancedValue(value, 'repeatDelay', repeatDelay),
205+
GetAdvancedValue(value, 'startAt', startAt),
206+
GetValue(value, 'yoyo', yoyo)
207+
);
208+
209+
// TODO: Calculate total duration
210+
211+
tween.data[key] = tweenData;
246212
}
247213

248214
return tween;

v3/src/tween/TweenData.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ var TweenData = function (key, value, ease, delay, duration, hold, repeat, repea
4848
state: 0,
4949

5050
startValue: null,
51-
endValue: null,
5251

53-
// For chained TweenData these point to the prev and next references
54-
prev: null,
55-
next: null
52+
endValue: null
5653
};
5754
};
5855

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var TWEEN_CONST = require('../const');
2+
3+
var NextState = function ()
4+
{
5+
if (this.loop)
6+
{
7+
// leaves the state in PENDING_RENDER
8+
// this.setCurrentTweenData(prop, prop.list[0]);
9+
10+
// this.resetTargetsValue(prop.current);
11+
12+
if (this.loopDelay > 0)
13+
{
14+
this.countdown = this.loopDelay;
15+
this.state = TWEEN_CONST.LOOP_DELAY;
16+
}
17+
}
18+
else if (this.completeDelay > 0)
19+
{
20+
this.countdown = this.completeDelay;
21+
this.state = TWEEN_CONST.COMPLETE_DELAY;
22+
}
23+
else
24+
{
25+
this.state = TWEEN_CONST.PENDING_REMOVE;
26+
}
27+
};
28+
29+
module.exports = NextState;

v3/src/tween/components/ResetTweenData.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ var ResetTweenData = function ()
44
{
55
for (var key in this.data)
66
{
7-
var prop = this.data[key];
8-
9-
var tweenData = prop.list[0];
7+
var tweenData = this.data[key];
108

119
tweenData.progress = 0;
1210
tweenData.elapsed = 0;
@@ -22,8 +20,6 @@ var ResetTweenData = function ()
2220
{
2321
tweenData.state = TWEEN_CONST.PENDING_RENDER;
2422
}
25-
26-
prop.current = tweenData;
2723
}
2824
};
2925

v3/src/tween/components/Update.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ var Update = function (timestamp, delta)
1212
{
1313
case TWEEN_CONST.ACTIVE:
1414

15+
var stillRunning = false;
16+
1517
for (var key in this.data)
1618
{
17-
var prop = this.data[key];
18-
19-
if (UpdateTweenData(this, prop.current, delta))
19+
if (UpdateTweenData(this, this.data[key], delta))
2020
{
21-
// TweenData complete - advance to the next one
22-
// TODO:
23-
// At the moment this sets the overall Tween.state, but
24-
// it should only do that when the last remaining TweenData has ended,
25-
// otherwise a shorter property tween could start this tween looping
26-
// before a longer property tween has even finished
27-
this.nextTweenData(prop);
21+
stillRunning = true;
2822
}
2923
}
3024

25+
// Anything still running? If not, we're done
26+
if (!stillRunning)
27+
{
28+
this.nextState();
29+
}
30+
3131
break;
3232

3333
case TWEEN_CONST.LOOP_DELAY:

v3/src/tween/components/UpdateTweenData.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ var UpdateTweenData = function (tween, tweenData, delta)
171171
break;
172172
}
173173

174-
return (tweenData.state === TWEEN_CONST.COMPLETE);
174+
// Return TRUE if this TweenData still playing, otherwise return FALSE
175+
return (tweenData.state !== TWEEN_CONST.COMPLETE);
175176
};
176177

177178
module.exports = UpdateTweenData;

0 commit comments

Comments
 (0)