LUADOC - Farming Simulator 22

FillPlane

Functions

delete

Description
Destructor
Definition
delete()
Code
38function FillPlane:delete()
39end

load

Description
Loads fill plane
Definition
load(table components, table xmlFile, string xmlNode, table i3dMappings)
Arguments
tablecomponentscomponents
tablexmlFilexml file object
stringxmlNodexml key
tablei3dMappingsi3dMappings
Return Values
booleansuccesssuccess
Code
48function FillPlane:load(components, xmlFile, xmlNode, i3dMappings)
49 local fillPlaneNode = xmlFile:getValue(xmlNode .. "#node", nil, components, i3dMappings)
50 if fillPlaneNode ~= nil then
51 self.node = fillPlaneNode
52 local x, y, z = getTranslation(self.node)
53 self.moveMinY = xmlFile:getValue(xmlNode .. "#minY", y)
54 self.moveMaxY = xmlFile:getValue(xmlNode .. "#maxY", y)
55 self.colorChange = xmlFile:getValue(xmlNode .. "#colorChange", false)
56 if self.colorChange then
57 if not getHasShaderParameter(self.node, "colorScale") then
58 Logging.warning("Fillplane '%s' has no shader parameter 'colorScale'. Disabled color change!", getName(self.node))
59 self.colorChange = false
60 end
61 end
62 if self.moveMinY > self.moveMaxY then
63 self.moveMinY, self.moveMaxY = self.moveMaxY, self.moveMinY
64 Logging.warning("Fillplane '%s' has inverted moveMinY and moveMaxY values. Switched values!", getName(self.node))
65 end
66
67 self.loaded = true
68 setTranslation(self.node, x, self.moveMinY, z)
69
70 local rotX, _, _ = getRotation(self.node)
71 self.rotMinX = xmlFile:getValue(xmlNode .. "#minRotX", rotX)
72 self.rotMaxX = xmlFile:getValue(xmlNode .. "#maxRotX", rotX)
73
74 self.changeVisibility = xmlFile:getValue(xmlNode .. "#changeVisibility", false)
75
76 return true
77 end
78
79 return false
80end

new

Description
Creates a new instance of the class
Definition
new(table customMt)
Arguments
tablecustomMtmeta table
Return Values
tableselfreturns the instance
Code
23function FillPlane.new(customMt)
24 local self = setmetatable({}, customMt or FillPlane_mt)
25
26 self.node = nil
27 self.maxCapacity = 0
28 self.moveMinY = 0
29 self.moveMaxY = 0
30 self.loaded = false
31 self.colorChange = false
32
33 return self
34end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
114function FillPlane.registerXMLPaths(schema, basePath)
115 schema:register(XMLValueType.NODE_INDEX, basePath .. "#node", "Fill plane node")
116 schema:register(XMLValueType.FLOAT, basePath .. "#minY", "Fill plane min y")
117 schema:register(XMLValueType.FLOAT, basePath .. "#maxY", "Fill plane max y")
118 schema:register(XMLValueType.ANGLE, basePath .. "#minRotX", "Fill plane min rotation x")
119 schema:register(XMLValueType.ANGLE, basePath .. "#maxRotX", "Fill plane max rotation x")
120 schema:register(XMLValueType.BOOL, basePath .. "#changeVisibility", "Hide node if state is zero")
121 schema:register(XMLValueType.BOOL, basePath .. "#colorChange", "Fill plane color change", false)
122end

setColorScale

Description
Sets fill plane color shader
Definition
setColorScale(float[] a)
Arguments
float[]afloat array for r, g, b
Code
106function FillPlane:setColorScale(colorScale)
107 if self.loaded then
108 setShaderParameter(self.node, "colorScale", colorScale[1], colorScale[2], colorScale[3], 0, false)
109 end
110end

setState

Description
Changes fill levels visuals
Definition
setState(table instance)
Arguments
tableinstancetarget to check fillLevel
Return Values
booltrueif level has changed
Code
86function FillPlane:setState(state)
87 if self.loaded then
88 local y = MathUtil.lerp(self.moveMinY, self.moveMaxY, state)
89 local x, oldY, z = getTranslation(self.node)
90 setTranslation(self.node, x, y, z)
91
92 local rotX = MathUtil.lerp(self.rotMinX, self.rotMaxX, state)
93 setRotation(self.node, rotX, 0, 0)
94
95 setVisibility(self.node, not self.changeVisibility or state > 0)
96
97 return oldY ~= y
98 end
99
100 return false
101end