LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

TreeSaplingPallet

Description
Specialization for tree pallets only to store the loaded tree type
Functions

getTreeType

Description
Returns current tree type
Definition
getTreeType()
Return Values
stringnametree type name
Code
124function TreeSaplingPallet:getTreeType()
125 return self.spec_treeSaplingPallet.treeTypeName
126end

initSpecialization

Description
Called on specialization initializing
Definition
initSpecialization()
Code
21function TreeSaplingPallet.initSpecialization()
22 g_configurationManager:addConfigurationType("treeSaplingType", g_i18n:getText("configuration_treeType"), "treeSaplingPallet", nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
23
24 local schema = Vehicle.xmlSchema
25 schema:setXMLSpecializationType("TreeSaplingPallet")
26
27 schema:register(XMLValueType.STRING, "vehicle.treeSaplingPallet#treeType", "Tree Type Name", "spruce1")
28 schema:register(XMLValueType.STRING, "vehicle.treeSaplingPallet.treeSaplingTypeConfigurations.treeSaplingTypeConfiguration(?)#treeType", "Tree Type Name", "spruce1")
29
30 schema:register(XMLValueType.NODE_INDEX, "vehicle.treeSaplingPallet.saplingNodes.saplingNode(?)#node", "Sapling link node")
31 schema:register(XMLValueType.NODE_INDEX, "vehicle.treeSaplingPallet.treeSaplingTypeConfigurations.treeSaplingTypeConfiguration(?).saplingNodes.saplingNode(?)#node", "Sapling link node")
32
33 ObjectChangeUtil.registerObjectChangeXMLPaths(schema, "vehicle.treeSaplingPallet.treeSaplingTypeConfigurations.treeSaplingTypeConfiguration(?)")
34
35 schema:setXMLSpecializationType()
36end

onDelete

Description
Called on deleting
Definition
onDelete()
Code
95function TreeSaplingPallet:onDelete()
96 local spec = self.spec_treeSaplingPallet
97 if spec.saplingNodes ~= nil then
98 for i=1, #spec.saplingNodes do
99 local entry = spec.saplingNodes[i]
100 if entry.sharedLoadRequestId ~= nil then
101 g_i3DManager:releaseSharedI3DFile(entry.sharedLoadRequestId)
102 end
103 end
104 spec.saplingNodes = {}
105 end
106end

onFillUnitFillLevelChanged

Description
Definition
onFillUnitFillLevelChanged()
Code
130function TreeSaplingPallet:onFillUnitFillLevelChanged(fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData, appliedDelta)
131 local spec = self.spec_treeSaplingPallet
132 for i=1, #spec.saplingNodes do
133 local saplingNode = spec.saplingNodes[i]
134 setVisibility(saplingNode.node, i <= MathUtil.round(self:getFillUnitFillLevel(fillUnitIndex)))
135 end
136end

onLoad

Description
Definition
onLoad()
Code
55function TreeSaplingPallet:onLoad(savegame)
56 local spec = self.spec_treeSaplingPallet
57
58 local treeSaplingTypeConfigurationId = Utils.getNoNil(self.configurations["treeSaplingType"], 1)
59 local baseKey = string.format("vehicle.treeSaplingPallet.treeSaplingTypeConfigurations.treeSaplingTypeConfiguration(%d)", treeSaplingTypeConfigurationId - 1)
60 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.treeSaplingPallet.treeSaplingTypeConfigurations.treeSaplingTypeConfiguration", treeSaplingTypeConfigurationId, self.components, self)
61
62 if not self.xmlFile:hasProperty(baseKey) then
63 baseKey = "vehicle.treeSaplingPallet"
64 end
65
66 spec.treeTypeName = self.xmlFile:getValue(baseKey .. "#treeType", "spruce1")
67 spec.treeTypeDesc = g_treePlantManager:getTreeTypeDescFromName(spec.treeTypeName)
68
69 spec.saplingNodes = {}
70 spec.treeTypeFilename = g_treePlantManager:getTreeTypeFilename(spec.treeTypeDesc, 1)
71 if spec.treeTypeFilename ~= nil then
72 local nodeKey = baseKey .. ".saplingNodes.saplingNode"
73 if not self.xmlFile:hasProperty(nodeKey) then
74 nodeKey = "vehicle.treeSaplingPallet.saplingNodes.saplingNode"
75 end
76
77 self.xmlFile:iterate(nodeKey, function(_, key)
78 local entry = {}
79 entry.node = self.xmlFile:getValue(key .. "#node", nil, self.components, self.i3dMappings)
80
81 if entry.node ~= nil then
82 setRotation(entry.node, 0, math.random(0, math.pi * 2), 0)
83 setScale(entry.node, 1, math.random(90, 110) / 100, 1)
84
85 entry.sharedLoadRequestId = self:loadSubSharedI3DFile(spec.treeTypeFilename, false, false, self.onTreeSaplingLoaded, self, {entry=entry})
86
87 table.insert(spec.saplingNodes, entry)
88 end
89 end)
90 end
91end

onTreeSaplingLoaded

Description
Called after the sapling has been loaded
Definition
onTreeSaplingLoaded()
Return Values
integeri3dNodei3d node id
tableargsarguments
Code
112function TreeSaplingPallet:onTreeSaplingLoaded(i3dNode, failedReason, args)
113 if i3dNode ~= 0 then
114 local entry = args.entry
115 link(entry.node, getChildAt(i3dNode, 0))
116 delete(i3dNode)
117 end
118end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
15function TreeSaplingPallet.prerequisitesPresent(specializations)
16 return true
17end

registerEventListeners

Description
Definition
registerEventListeners()
Code
47function TreeSaplingPallet.registerEventListeners(vehicleType)
48 SpecializationUtil.registerEventListener(vehicleType, "onLoad", TreeSaplingPallet)
49 SpecializationUtil.registerEventListener(vehicleType, "onDelete", TreeSaplingPallet)
50 SpecializationUtil.registerEventListener(vehicleType, "onFillUnitFillLevelChanged", TreeSaplingPallet)
51end

registerFunctions

Description
Definition
registerFunctions()
Code
40function TreeSaplingPallet.registerFunctions(vehicleType)
41 SpecializationUtil.registerFunction(vehicleType, "onTreeSaplingLoaded", TreeSaplingPallet.onTreeSaplingLoaded)
42 SpecializationUtil.registerFunction(vehicleType, "getTreeType", TreeSaplingPallet.getTreeType)
43end