LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

MultiValueTween

Description
Tween class which handles multiple values at the same time. Start and end values must be passed in as arrays. The setter function must be able to handle as many arguments as there were entries in the start and end values arrays: setter called as function(unpack(values)).
Parent
Tween
Functions

applyValue

Description
Apply a value via the setter function.
Definition
applyValue()
Code
67function MultiValueTween:applyValue()
68 self.setter(unpack(self.values)) -- includes target as first entry if it was set
69end

new

Description
Create a new Tween.
Definition
new(table subClass, function setterFunction, table startValues, table endValues, float duration)
Arguments
tablesubClassSubclass metatable for inheritance
functionsetterFunctionValues setter function. Signature: callback(v1, ..., vn) or callback(target, v1, ..., vn).
tablestartValuesOriginal values
tableendValuesTarget values
floatdurationDuration of tween in milliseconds
Code
23function MultiValueTween.new(subClass, setterFunction, startValues, endValues, duration)
24 if not subClass or subClass == MultiValueTween then
25 subClass = MultiValueTween_mt
26 end
27
28 local self = MultiValueTween:superClass().new(subClass, setterFunction, startValues, endValues, duration)
29
30 self.values = {unpack(startValues)}
31
32 return self
33end

setTarget

Description
Set a callback target for this tween. If a target has been set, the setter function must support receiving the target as its first argument.
Definition
setTarget()
Code
38function MultiValueTween:setTarget(target)
39 local hadTarget = self.functionTarget ~= nil
40 MultiValueTween:superClass().setTarget(self, target)
41
42 if target ~= nil and not hadTarget then
43 table.insert(self.values, 1, target)
44 elseif target == nil and hadTarget then
45 table.remove(self.values, 1)
46 else
47 self.values[1] = target
48 end
49end

tweenValue

Description
Get the current tween value.
Definition
tweenValue()
Code
53function MultiValueTween:tweenValue(t)
54 local targetOffset = self.functionTarget ~= nil and 1 or 0
55
56 for i = 1, #self.startValue do
57 local startValue = self.startValue[i]
58 local endValue = self.endValue[i]
59 self.values[i + targetOffset] = MathUtil.lerp(startValue, endValue, self.curveFunc(t))
60 end
61
62 return self.values
63end