LUADOC - Farming Simulator 19

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)
31end

onLoad

Description
Definition
onLoad()
Code
35function FrontloaderAttacher:onLoad(savegame)
36 if self.configurations["frontloader"] ~= nil then
37 local spec = self.spec_frontloaderAttacher
38 local attacherJointsSpec = self.spec_attacherJoints
39
40 spec.attacherJoint = {}
41 local key = string.format("vehicle.frontloaderConfigurations.frontloaderConfiguration(%d)", self.configurations["frontloader"]-1)
42 if hasXMLProperty(self.xmlFile, key..".attacherJoint") and self:loadAttacherJointFromXML(spec.attacherJoint, self.xmlFile, key..".attacherJoint") then
43 table.insert(attacherJointsSpec.attacherJoints, spec.attacherJoint)
44
45 local frontAxisLimitJoint = Utils.getNoNil(getXMLBool(self.xmlFile, key..".attacherJoint#frontAxisLimitJoint"), true)
46 if frontAxisLimitJoint then
47 local frontAxisJoint = Utils.getNoNil(getXMLInt(self.xmlFile, key..".attacherJoint#frontAxisJoint"), 1)
48 if self.componentJoints[frontAxisJoint] ~= nil then
49 spec.frontAxisJoint = frontAxisJoint
50 else
51 print("Warning: Invalid front-axis joint '"..tostring(frontAxisJoint).."' in '"..self.configFileName.."'")
52 end
53 end
54
55 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.frontloaderConfigurations.frontloaderConfiguration", self.configurations["frontloader"], self.components, self)
56 else
57 -- first config is "no-frontloader"-option
58 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.frontloaderConfigurations.frontloaderConfiguration", 1, self.components, self)
59 spec.attacherJoint = nil
60 end
61 end
62end

onPreAttachImplement

Description
Definition
onPreAttachImplement()
Code
88function FrontloaderAttacher:onPreAttachImplement(attachable, inputJointDescIndex, jointDescIndex)
89 local spec = self.spec_frontloaderAttacher
90
91 if spec.frontAxisJoint ~= nil then
92 local attacherJoint = nil
93 local attacherJoints = self:getAttacherJoints()
94 if attacherJoints ~= nil then
95 attacherJoint = attacherJoints[jointDescIndex]
96 end
97 if attacherJoint ~= nil then
98 if attacherJoint.jointType == AttacherJoints.JOINTTYPE_ATTACHABLEFRONTLOADER and self.isServer then
99 -- copy rotlimit
100 spec.rotLimit = { unpack(self.componentJoints[spec.frontAxisJoint].rotLimit) }
101 for i=1, 3 do
102 self:setComponentJointRotLimit(self.componentJoints[spec.frontAxisJoint], i, 0, 0)
103 end
104 end
105 end
106 end
107end

onPreDetachImplement

Description
Definition
onPreDetachImplement()
Code
66function FrontloaderAttacher:onPreDetachImplement(implement)
67 local spec = self.spec_frontloaderAttacher
68
69 if spec.frontAxisJoint ~= nil then
70 local attacherJoint = nil
71 local attacherJointIndex = implement.jointDescIndex
72 local attacherJoints = self:getAttacherJoints()
73 if attacherJoints ~= nil then
74 attacherJoint = attacherJoints[attacherJointIndex]
75 end
76 if attacherJoint ~= nil then
77 if attacherJoint.jointType == AttacherJoints.JOINTTYPE_ATTACHABLEFRONTLOADER and self.isServer then
78 for i=1, 3 do
79 self:setComponentJointRotLimit(self.componentJoints[spec.frontAxisJoint], i, -spec.rotLimit[i], spec.rotLimit[i])
80 end
81 end
82 end
83 end
84end

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