LUADOC - Farming Simulator 22

AIParameterFillType

Parent
AIParameter
Functions

getFillTypeIndex

Description
Definition
getFillTypeIndex()
Code
143function AIParameterFillType:getFillTypeIndex()
144 return self.fillTypeIndex
145end

getString

Description
Definition
getString()
Code
149function AIParameterFillType:getString()
150 for _, data in ipairs(self.fillTypes) do
151 if data.fillTypeIndex == self.fillTypeIndex then
152 return data.title
153 end
154 end
155
156 return ""
157end

loadFromXMLFile

Description
Definition
loadFromXMLFile()
Code
38function AIParameterFillType:loadFromXMLFile(xmlFile, key)
39 local fillTypeName = xmlFile:getString(key .. "#fillType")
40 if fillTypeName ~= nil then
41 self.fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeName)
42 end
43end

new

Description
Definition
new()
Code
16function AIParameterFillType.new(customMt)
17 local self = AIParameter.new(customMt or AIParameterFillType_mt)
18
19 self.type = AIParameterType.FILLTYPE
20
21 self.fillTypes = {}
22 self.fillTypeIndex = nil
23
24 return self
25end

readStream

Description
Definition
readStream()
Code
47function AIParameterFillType:readStream(streamId, connection)
48 if streamReadBool(streamId) then
49 local fillTypeIndex = streamReadUIntN(streamId, FillTypeManager.SEND_NUM_BITS)
50 self:setFillTypeIndex(fillTypeIndex)
51 end
52end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
29function AIParameterFillType:saveToXMLFile(xmlFile, key, usedModNames)
30 if self.fillTypeIndex ~= nil then
31 local fillTypeName = g_fillTypeManager:getFillTypeNameByIndex(self.fillTypeIndex)
32 xmlFile:setString(key .. "#fillType", fillTypeName)
33 end
34end

setFillTypeByIndex

Description
Definition
setFillTypeByIndex()
Code
126function AIParameterFillType:setFillTypeByIndex(index)
127 local data = self.fillTypes[index]
128 if data ~= nil then
129 self.fillTypeIndex = data.fillTypeIndex
130 else
131 self.fillTypeIndex = nil
132 end
133end

setFillTypeIndex

Description
Definition
setFillTypeIndex()
Code
137function AIParameterFillType:setFillTypeIndex(fillTypeIndex)
138 self.fillTypeIndex = fillTypeIndex
139end

setNextItem

Description
Definition
setNextItem()
Code
92function AIParameterFillType:setNextItem()
93 local nextIndex = 0
94 for k, data in ipairs(self.fillTypes) do
95 if self.fillTypeIndex == data.fillTypeIndex then
96 nextIndex = k + 1
97 end
98 end
99
100 if nextIndex > #self.fillTypes then
101 nextIndex = 1
102 end
103
104 self:setFillTypeByIndex(nextIndex)
105end

setPreviousItem

Description
Definition
setPreviousItem()
Code
109function AIParameterFillType:setPreviousItem()
110 local previousIndex = 0
111 for k, data in ipairs(self.fillTypes) do
112 if self.fillTypeIndex == data.fillTypeIndex then
113 previousIndex = k - 1
114 end
115 end
116
117 if previousIndex < 1 then
118 previousIndex = #self.fillTypes
119 end
120
121 self:setFillTypeByIndex(previousIndex)
122end

setValidFillTypes

Description
Definition
setValidFillTypes()
Code
64function AIParameterFillType:setValidFillTypes(fillTypes)
65 self.fillTypes = {}
66 local maxFillLevel = 0
67 local maxFillLevelFillTypeIndex
68 for fillTypeIndex, fillLevel in pairs(fillTypes) do
69 if fillLevel > maxFillLevel then
70 maxFillLevelFillTypeIndex = fillTypeIndex
71 end
72 local title = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex).title
73 title = string.format("%s (%d l)", title, fillLevel)
74 table.insert(self.fillTypes, {index=#self.fillTypes + 1, fillTypeIndex=fillTypeIndex, title=title, fillLevel=fillLevel})
75 end
76
77 table.sort(self.fillTypes, function(a, b)
78 return a.title < b.title
79 end)
80
81 if self.fillTypeIndex == nil then
82 if maxFillLevelFillTypeIndex ~= nil then
83 self.fillTypeIndex = maxFillLevelFillTypeIndex
84 else
85 self:setFillTypeByIndex(1)
86 end
87 end
88end

validate

Description
Definition
validate()
Code
161function AIParameterFillType:validate()
162 if self.fillTypeIndex == nil then
163 return false, g_i18n:getText("ai_validationErrorNoFillType")
164 end
165
166 return true, nil
167end

writeStream

Description
Definition
writeStream()
Code
56function AIParameterFillType:writeStream(streamId, connection)
57 if streamWriteBool(streamId, self.fillTypeIndex ~= nil) then
58 streamWriteUIntN(streamId, self.fillTypeIndex, FillTypeManager.SEND_NUM_BITS)
59 end
60end