Skip to content

Commit b7520ab

Browse files
committed
onRefresh working properly (considering renaming though)
1 parent 97a7de6 commit b7520ab

9 files changed

Lines changed: 34 additions & 122 deletions

File tree

v3/src/tween/builder/TweenBuilder.js

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ var TweenBuilder = function (parent, config, defaults)
6565
}
6666
}
6767

68-
var tween = new Tween(parent, data);
69-
70-
tween.totalTargets = targets.length;
68+
var tween = new Tween(parent, data, targets);
7169

7270
tween.offset = GetAdvancedValue(config, 'offset', null);
7371
tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0);
@@ -77,10 +75,10 @@ var TweenBuilder = function (parent, config, defaults)
7775
tween.useFrames = GetBoolean(config, 'useFrames', false);
7876

7977
// Set the Callbacks
80-
8178
var scope = GetValue(config, 'callbackScope', tween);
8279

83-
var tweenArray = [ tween ];
80+
// Callback parameters: 0 = a reference to the Tween itself, 1 = the target/s of the Tween, ... your own params
81+
var tweenArray = [ tween, null ];
8482

8583
var callbacks = Tween.TYPES;
8684

@@ -96,78 +94,10 @@ var TweenBuilder = function (parent, config, defaults)
9694
var callbackParams = GetValue(config, type + 'Params', []);
9795

9896
// The null is reset to be the Tween target
99-
tween.setCallback(type, callback, tweenArray.concat(null, callbackParams), callbackScope);
97+
tween.setCallback(type, callback, tweenArray.concat(callbackParams), callbackScope);
10098
}
10199
}
102100

103-
/*
104-
var onStart = GetValue(config, 'onStart', false);
105-
106-
// The Start of the Tween
107-
if (onStart)
108-
{
109-
var onStartScope = GetValue(config, 'onStartScope', scope);
110-
var onStartParams = GetValue(config, 'onStartParams', []);
111-
112-
tween.setCallback('onStart', onStart, tweenArray.concat(onStartParams), onStartScope);
113-
}
114-
115-
var onUpdate = GetValue(config, 'onUpdate', false);
116-
117-
// Every time the tween updates (regardless which TweenDatas are running)
118-
if (onUpdate)
119-
{
120-
var onUpdateScope = GetValue(config, 'onUpdateScope', scope);
121-
var onUpdateParams = GetValue(config, 'onUpdateParams', []);
122-
123-
tween.setCallback('onUpdate', onUpdate, tweenArray.concat(onUpdateParams), onUpdateScope);
124-
}
125-
126-
var onRepeat = GetValue(config, 'onRepeat', false);
127-
128-
// When a TweenData repeats
129-
if (onRepeat)
130-
{
131-
var onRepeatScope = GetValue(config, 'onRepeatScope', scope);
132-
var onRepeatParams = GetValue(config, 'onRepeatParams', []);
133-
134-
tween.setCallback('onRepeat', onRepeat, tweenArray.concat(null, onRepeatParams), onRepeatScope);
135-
}
136-
137-
var onLoop = GetValue(config, 'onLoop', false);
138-
139-
// Called when the whole Tween loops
140-
if (onLoop)
141-
{
142-
var onLoopScope = GetValue(config, 'onLoopScope', scope);
143-
var onLoopParams = GetValue(config, 'onLoopParams', []);
144-
145-
tween.setCallback('onLoop', onLoop, tweenArray.concat(onLoopParams), onLoopScope);
146-
}
147-
148-
var onYoyo = GetValue(config, 'onYoyo', false);
149-
150-
// Called when a TweenData yoyos
151-
if (onYoyo)
152-
{
153-
var onYoyoScope = GetValue(config, 'onYoyoScope', scope);
154-
var onYoyoParams = GetValue(config, 'onYoyoParams', []);
155-
156-
tween.setCallback('onYoyo', onYoyo, tweenArray.concat(null, onYoyoParams), onYoyoScope);
157-
}
158-
159-
var onComplete = GetValue(config, 'onComplete', false);
160-
161-
// Called when the Tween completes, after the completeDelay, etc.
162-
if (onComplete)
163-
{
164-
var onCompleteScope = GetValue(config, 'onCompleteScope', scope);
165-
var onCompleteParams = GetValue(config, 'onCompleteParams', []);
166-
167-
tween.setCallback('onComplete', onComplete, tweenArray.concat(onCompleteParams), onCompleteScope);
168-
}
169-
*/
170-
171101
return tween;
172102
};
173103

v3/src/tween/tween/ReservedProps.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ module.exports = [
3636
'onLoop',
3737
'onLoopParams',
3838
'onLoopScope',
39+
'onRefresh',
40+
'onRefreshParams',
41+
'onRefreshScope',
3942
'onRepeat',
4043
'onRepeatParams',
4144
'onRepeatScope',

v3/src/tween/tween/Tween.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Tween = new Class({
55

66
initialize:
77

8-
function Tween (parent, data)
8+
function Tween (parent, data, targets)
99
{
1010
this.parent = parent;
1111

@@ -18,8 +18,11 @@ var Tween = new Class({
1818
// data array doesn't change, so we can cache the length
1919
this.totalData = data.length;
2020

21+
// An array of references to the target/s this Tween is operating on
22+
this.targets = targets;
23+
2124
// Cached target total (not necessarily the same as the data total)
22-
this.totalTargets = 0;
25+
this.totalTargets = targets.length;
2326

2427
// If true then duration, delay, etc values are all frame totals
2528
this.useFrames = false;
@@ -109,17 +112,7 @@ var Tween = new Class({
109112

110113
hasTarget: function (target)
111114
{
112-
var data = this.data;
113-
114-
for (var i = 0; i < this.totalData; i++)
115-
{
116-
if (data[i].target === target)
117-
{
118-
return true;
119-
}
120-
}
121-
122-
return false;
115+
return (this.targets.indexOf(target) !== -1);
123116
},
124117

125118
calcDuration: require('./components/CalcDuration'),

v3/src/tween/tween/TweenData.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ var TweenData = function (target, key, value, ease, delay, duration, yoyo, hold,
5555
start: 0,
5656
current: 0,
5757
end: 0,
58-
startCache: 0,
5958

6059
// Time Durations
6160
t1: 0,

v3/src/tween/tween/components/NextState.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var NextState = function ()
1414

1515
if (onLoop)
1616
{
17+
onLoop.params[1] = this.targets;
18+
1719
onLoop.func.apply(onLoop.scope, onLoop.params);
1820
}
1921

@@ -38,6 +40,8 @@ var NextState = function ()
3840

3941
if (onComplete)
4042
{
43+
onComplete.params[1] = this.targets;
44+
4145
onComplete.func.apply(onComplete.scope, onComplete.params);
4246
}
4347

v3/src/tween/tween/components/Play.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ var Play = function (resetFromTimeline)
4141

4242
if (onStart)
4343
{
44+
onStart.params[1] = this.targets;
45+
4446
onStart.func.apply(onStart.scope, onStart.params);
4547
}
4648
};

v3/src/tween/tween/components/ResetTweenData.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,15 @@ var ResetTweenData = function (resetFromLoop)
1313

1414
tweenData.repeatCounter = (tweenData.repeat === -1) ? 999999999999 : tweenData.repeat;
1515

16-
/*
17-
The function below is called to get the END value of the TweenData
18-
bob.x is read to get the START/CACHE value and never read again
19-
20-
targets: bob,
21-
x: function () { return 700; },
22-
onRefresh: function (target, key, previousValue, startOfTween) { return target[key]; },
23-
ease: 'Sine.easeInOut',
24-
duration: 2000
25-
26-
*/
27-
2816
if (resetFromLoop)
2917
{
30-
var onRefresh = tween.callbacks.onRefresh;
18+
var onRefresh = this.callbacks.onRefresh;
3119

3220
if (onRefresh)
3321
{
34-
tweenData.startCache = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.startCache, true);
22+
tweenData.start = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.start, true);
3523
}
3624

37-
tweenData.start = tweenData.startCache;
38-
3925
tweenData.current = tweenData.start;
4026

4127
tweenData.end = tweenData.value(tweenData.start, tweenData.target, tweenData.key);

v3/src/tween/tween/components/SetCallback.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
var Tween = require('../Tween');
21

32
var SetCallback = function (type, callback, params, scope)
43
{
5-
if (Tween.TYPES.indexOf(type) !== -1)
6-
{
7-
this.callbacks[type] = { func: callback, scope: scope, params: params };
8-
}
4+
this.callbacks[type] = { func: callback, scope: scope, params: params };
95

106
return this;
117
};

v3/src/tween/tween/components/UpdateTweenData.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ var SetStateFromEnd = function (tween, tweenData)
3232
onYoyo.func.apply(onYoyo.scope, onYoyo.params);
3333
}
3434

35+
// Do we update the start value before returning to it?
3536
var onRefresh = tween.callbacks.onRefresh;
3637

3738
if (onRefresh)
3839
{
39-
tweenData.startCache = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.startCache, false);
40-
tweenData.start = tweenData.startCache;
40+
tweenData.start = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.start, false);
4141
}
4242

4343
return TWEEN_CONST.PLAYING_BACKWARD;
@@ -72,17 +72,16 @@ var SetStateFromEnd = function (tween, tweenData)
7272
onRepeat.func.apply(onRepeat.scope, onRepeat.params);
7373
}
7474

75-
// Do we want to refresh the start value before we return to it?
75+
// Do we update the start value before returning to it?
7676
var onRefresh = tween.callbacks.onRefresh;
7777

7878
if (onRefresh)
7979
{
80-
tweenData.startCache = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.startCache, false);
81-
tweenData.start = tweenData.startCache;
80+
tweenData.start = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.start, false);
8281
}
8382

8483
// Reset the destination value, in case it's dynamic
85-
tweenData.end = tweenData.value(tweenData.startCache, tweenData.target, tweenData.key);
84+
tweenData.end = tweenData.value(tweenData.start, tweenData.target, tweenData.key);
8685

8786
// Delay?
8887
if (tweenData.repeatDelay > 0)
@@ -139,12 +138,11 @@ var SetStateFromStart = function (tween, tweenData)
139138

140139
if (onRefresh)
141140
{
142-
tweenData.startCache = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.startCache, false);
143-
tweenData.start = tweenData.startCache;
141+
tweenData.start = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.start, true);
144142
}
145143

146144
// Reset the destination value, in case it's dynamic
147-
tweenData.end = tweenData.value(tweenData.startCache, tweenData.target, tweenData.key);
145+
tweenData.end = tweenData.value(tweenData.start, tweenData.target, tweenData.key);
148146

149147
// Delay?
150148
if (tweenData.repeatDelay > 0)
@@ -209,6 +207,8 @@ var UpdateTweenData = function (tween, tweenData, delta)
209207

210208
if (onUpdate)
211209
{
210+
onUpdate.params[1] = tweenData.target;
211+
212212
onUpdate.func.apply(onUpdate.scope, onUpdate.params);
213213
}
214214

@@ -255,6 +255,7 @@ var UpdateTweenData = function (tween, tweenData, delta)
255255
if (tweenData.elapsed <= 0)
256256
{
257257
tweenData.elapsed = Math.abs(tweenData.elapsed);
258+
258259
tweenData.state = TWEEN_CONST.PLAYING_FORWARD;
259260
}
260261

@@ -273,17 +274,15 @@ var UpdateTweenData = function (tween, tweenData, delta)
273274

274275
case TWEEN_CONST.PENDING_RENDER:
275276

276-
tweenData.startCache = tweenData.target[tweenData.key];
277+
tweenData.start = tweenData.target[tweenData.key];
277278

278279
var onRefresh = tween.callbacks.onRefresh;
279280

280281
if (onRefresh)
281282
{
282-
tweenData.startCache = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.startCache, true);
283+
tweenData.start = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.start, true);
283284
}
284285

285-
tweenData.start = tweenData.startCache;
286-
287286
tweenData.current = tweenData.start;
288287

289288
tweenData.end = tweenData.value(tweenData.start, tweenData.target, tweenData.key);

0 commit comments

Comments
 (0)