LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

FrontloaderAttacher

Description
Specialization providing a frontloader attacher dependent on configuration
Functions

initSpecialization

Description
Definition
initSpecialization()
Code
29function FrontloaderAttacher.initSpecialization()
30 g_configurationManager:addConfigurationType("frontloader", g_i18n:getText("configuration_frontloaderAttacher"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
31
32 local schema = Vehicle.xmlSchema
33 schema:setXMLSpecializationType("FrontloaderAttacher")
34
35 local basePath = "vehicle.frontloaderConfigurations.frontloaderConfiguration(?)"
36 AttacherJoints.registerAttacherJointXMLPaths(schema, basePath .. ".attacherJoint")
37
38 schema:register(XMLValueType.BOOL, basePath .. ".attacherJoint#frontAxisLimitJoint", "Front axis joint will be limited while attached", true)
39 schema:register(XMLValueType.INT, basePath .. ".attacherJoint#frontAxisJoint", "Front axis joint index", 1)
40
41 ObjectChangeUtil.registerObjectChangeXMLPaths(schema, basePath)
42
43 schema:setXMLSpecializationType()
44end

onLoad

Description
Definition
onLoad()
Code
48function FrontloaderAttacher:onLoad(savegame)
49 if self.configurations["frontloader"] ~= nil then
50 local spec = self.spec_frontloaderAttacher
51 local attacherJointsSpec = self.spec_attacherJoints
52
53 spec.attacherJoint = {}
54 local key = string.format("vehicle.frontloaderConfigurations.frontloaderConfiguration(%d)", self.configurations["frontloader"]-1)
55 if self.xmlFile:hasProperty(key..".attacherJoint") and self:loadAttacherJointFromXML(spec.attacherJoint, self.xmlFile, key..".attacherJoint", 0) then
56 table.insert(attacherJointsSpec.attacherJoints, spec.attacherJoint)
57
58 local frontAxisLimitJoint = self.xmlFile:getValue(key..".attacherJoint#frontAxisLimitJoint", true)
59 if frontAxisLimitJoint then
60 local frontAxisJoint = self.xmlFile:getValue(key..".attacherJoint#frontAxisJoint", 1)
61 if self.componentJoints[frontAxisJoint] ~= nil then
62 spec.frontAxisJoint = frontAxisJoint
63 else
64 print("Warning: Invalid front-axis joint '"..tostring(frontAxisJoint).."' in '"..self.configFileName.."'")
65 end
66 end
67
68 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.frontloaderConfigurations.frontloaderConfiguration", self.configurations["frontloader"], self.components, self)
69 else
70 -- first config is "no-frontloader"-option
71 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.frontloaderConfigurations.frontloaderConfiguration", 1, self.components, self)
72 spec.attacherJoint = nil
73 end
74 end
75end

onPreAttachImplement

Description
Definition
onPreAttachImplement()
Code
101function FrontloaderAttacher:onPreAttachImplement(attachable, inputJointDescIndex, jointDescIndex)
102 local spec = self.spec_frontloaderAttacher
103
104 if spec.frontAxisJoint ~= nil then
105 local attacherJoint = nil
106 local attacherJoints = self:getAttacherJoints()
107 if attacherJoints ~= nil then
108 attacherJoint = attacherJoints[jointDescIndex]
109 end
110 if attacherJoint ~= nil then
111 if attacherJoint.jointType == AttacherJoints.JOINTTYPE_ATTACHABLEFRONTLOADER and self.isServer then
112 -- copy rotlimit
113 spec.rotLimit = { unpack(self.componentJoints[spec.frontAxisJoint].rotLimit) }
114 for i=1, 3 do
115 self:setComponentJointRotLimit(self.componentJoints[spec.frontAxisJoint], i, 0, 0)
116 end
117 end
118 end
119 end
120end

onPreDetachImplement

Description
Definition
onPreDetachImplement()
Code
79function FrontloaderAttacher:onPreDetachImplement(implement)
80 local spec = self.spec_frontloaderAttacher
81
82 if spec.frontAxisJoint ~= nil then
83 local attacherJoint = nil
84 local attacherJointIndex = implement.jointDescIndex
85 local attacherJoints = self:getAttacherJoints()
86 if attacherJoints ~= nil then
87 attacherJoint = attacherJoints[attacherJointIndex]
88 end
89 if attacherJoint ~= nil then
90 if attacherJoint.jointType == AttacherJoints.JOINTTYPE_ATTACHABLEFRONTLOADER and self.isServer then
91 for i=1, 3 do
92 self:setComponentJointRotLimit(self.componentJoints[spec.frontAxisJoint], i, -spec.rotLimit[i], spec.rotLimit[i])
93 end
94 end
95 end
96 end
97end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
15function FrontloaderAttacher.prerequisitesPresent(specializations)
16 return SpecializationUtil.hasSpecialization(AttacherJoints, specializations)
17end

registerEventListeners

Description
Definition
registerEventListeners()
Code
21function FrontloaderAttacher.registerEventListeners(vehicleType)
22 SpecializationUtil.registerEventListener(vehicleType, "onLoad", FrontloaderAttacher)
23 SpecializationUtil.registerEventListener(vehicleType, "onPreDetachImplement", FrontloaderAttacher)
24 SpecializationUtil.registerEventListener(vehicleType, "onPreAttachImplement", FrontloaderAttacher)
25end