|
| 1 | +var Defaults = require('../tween/Defaults'); |
| 2 | +var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); |
| 3 | +var GetBoolean = require('./GetBoolean'); |
| 4 | +var GetEaseFunction = require('./GetEaseFunction'); |
| 5 | +var GetNewValue = require('./GetNewValue'); |
| 6 | +var GetValue = require('../../utils/object/GetValue'); |
| 7 | +var GetValueOp = require('./GetValueOp'); |
| 8 | +var Tween = require('../tween/Tween'); |
| 9 | +var TweenData = require('../tween/TweenData'); |
| 10 | + |
| 11 | +var NumberTweenBuilder = function (parent, config, defaults) |
| 12 | +{ |
| 13 | + if (defaults === undefined) |
| 14 | + { |
| 15 | + defaults = Defaults; |
| 16 | + } |
| 17 | + |
| 18 | + // var tween = this.tweens.addCounter({ |
| 19 | + // from: 100, |
| 20 | + // to: 200, |
| 21 | + // ... (normal tween properties) |
| 22 | + // }) |
| 23 | + // |
| 24 | + // Then use it in your game via: |
| 25 | + // |
| 26 | + // tween.getValue() |
| 27 | + |
| 28 | + var from = GetValue(config, 'from', 0); |
| 29 | + var to = GetValue(config, 'to', 1); |
| 30 | + |
| 31 | + var targets = [{ value: from }]; |
| 32 | + |
| 33 | + var delay = GetNewValue(config, 'delay', defaults.delay); |
| 34 | + var duration = GetNewValue(config, 'duration', defaults.duration); |
| 35 | + var easeParams = GetValue(config, 'easeParams', defaults.easeParams); |
| 36 | + var ease = GetEaseFunction(GetValue(config, 'ease', defaults.ease), easeParams); |
| 37 | + var hold = GetNewValue(config, 'hold', defaults.hold); |
| 38 | + var repeat = GetNewValue(config, 'repeat', defaults.repeat); |
| 39 | + var repeatDelay = GetNewValue(config, 'repeatDelay', defaults.repeatDelay); |
| 40 | + var yoyo = GetBoolean(config, 'yoyo', defaults.yoyo); |
| 41 | + |
| 42 | + var data = []; |
| 43 | + |
| 44 | + var ops = GetValueOp('value', to); |
| 45 | + |
| 46 | + var tweenData = TweenData( |
| 47 | + targets[0], |
| 48 | + 'value', |
| 49 | + ops.getEnd, |
| 50 | + ops.getStart, |
| 51 | + ease, |
| 52 | + delay, |
| 53 | + duration, |
| 54 | + yoyo, |
| 55 | + hold, |
| 56 | + repeat, |
| 57 | + repeatDelay, |
| 58 | + false, |
| 59 | + false |
| 60 | + ); |
| 61 | + |
| 62 | + data.push(tweenData); |
| 63 | + |
| 64 | + var tween = new Tween(parent, data, targets); |
| 65 | + |
| 66 | + tween.offset = GetAdvancedValue(config, 'offset', null); |
| 67 | + tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0); |
| 68 | + tween.loop = Math.round(GetAdvancedValue(config, 'loop', 0)); |
| 69 | + tween.loopDelay = Math.round(GetAdvancedValue(config, 'loopDelay', 0)); |
| 70 | + tween.paused = GetBoolean(config, 'paused', false); |
| 71 | + tween.useFrames = GetBoolean(config, 'useFrames', false); |
| 72 | + |
| 73 | + // Set the Callbacks |
| 74 | + var scope = GetValue(config, 'callbackScope', tween); |
| 75 | + |
| 76 | + // Callback parameters: 0 = a reference to the Tween itself, 1 = the target/s of the Tween, ... your own params |
| 77 | + var tweenArray = [ tween, null ]; |
| 78 | + |
| 79 | + var callbacks = Tween.TYPES; |
| 80 | + |
| 81 | + for (var i = 0; i < callbacks.length; i++) |
| 82 | + { |
| 83 | + var type = callbacks[i]; |
| 84 | + |
| 85 | + var callback = GetValue(config, type, false); |
| 86 | + |
| 87 | + if (callback) |
| 88 | + { |
| 89 | + var callbackScope = GetValue(config, type + 'Scope', scope); |
| 90 | + var callbackParams = GetValue(config, type + 'Params', []); |
| 91 | + |
| 92 | + // The null is reset to be the Tween target |
| 93 | + tween.setCallback(type, callback, tweenArray.concat(callbackParams), callbackScope); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + return tween; |
| 98 | +}; |
| 99 | + |
| 100 | +module.exports = NumberTweenBuilder; |
0 commit comments