LUADOC - Farming Simulator 22

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
63function MultiValueTween:applyValue()
64 self.setter(unpack(self.values)) -- includes target as first entry if it was set
65end

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(setterFunction, startValues, endValues, duration, customMt)
24 local self = Tween.new(setterFunction, startValues, endValues, duration, customMt or MultiValueTween_mt)
25
26 self.values = {unpack(startValues)}
27
28 return self
29end

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
34function MultiValueTween:setTarget(target)
35 local hadTarget = self.functionTarget ~= nil
36 MultiValueTween:superClass().setTarget(self, target)
37
38 if target ~= nil and not hadTarget then
39 table.insert(self.values, 1, target)
40 elseif target == nil and hadTarget then
41 table.remove(self.values, 1)
42 else
43 self.values[1] = target
44 end
45end

tweenValue

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