LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

CylinderedFoldable

Description
Specialization to repeat the loading of cylindered states after the folding state was loaded, in case the animation overlaps with the moving tools
Functions

initSpecialization

Description
Definition
initSpecialization()
Code
23function CylinderedFoldable.initSpecialization()
24 local schema = Vehicle.xmlSchema
25 schema:setXMLSpecializationType("CylinderedFoldable")
26
27 schema:register(XMLValueType.BOOL, "vehicle.cylindered#loadMovingToolStatesAfterFolding", "Load moving tool states after folding state was loaded", false)
28 schema:register(XMLValueType.FLOAT, "vehicle.cylindered#loadMovingToolStatesFoldTime", "Fold time in which moving tool states should be loaded")
29
30 schema:setXMLSpecializationType()
31end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
45function CylinderedFoldable:onLoad(savegame)
46 local spec = self.spec_cylinderedFoldable
47
48 spec.loadMovingToolStatesAfterFolding = self.xmlFile:getValue("vehicle.cylindered#loadMovingToolStatesAfterFolding", false)
49 spec.loadMovingToolStatesFoldTime = self.xmlFile:getValue("vehicle.cylindered#loadMovingToolStatesFoldTime")
50end

onPostLoad

Description
Definition
onPostLoad()
Code
54function CylinderedFoldable:onPostLoad(savegame)
55 local spec = self.spec_cylinderedFoldable
56 if spec.loadMovingToolStatesAfterFolding then
57 local targetFoldTime = spec.loadMovingToolStatesFoldTime
58 if targetFoldTime == nil or self:getFoldAnimTime() == targetFoldTime then
59 Cylindered.onPostLoad(self, savegame)
60 end
61 end
62end

onReadStream

Description
Definition
onReadStream()
Code
66function CylinderedFoldable:onReadStream(streamId, connection)
67 -- update folding animation so it's finished and won't destroy the cylindered states in the first frame
68 AnimatedVehicle.updateAnimations(self, 9999999)
69
70 -- rerun the sync of cylindered since it was overwritten by foldable
71 if streamReadBool(streamId) then
72 Cylindered.onReadStream(self, streamId, connection)
73 end
74
75 -- update dependent animations initial
76 if connection:getIsServer() then
77 for i=1, #self.spec_cylindered.movingTools do
78 local tool = self.spec_cylindered.movingTools[i]
79 if tool.dirtyFlag ~= nil then
80 self:updateDependentAnimations(tool, 9999)
81 end
82 end
83 end
84end

onWriteStream

Description
Definition
onWriteStream()
Code
88function CylinderedFoldable:onWriteStream(streamId, connection)
89 local spec = self.spec_cylinderedFoldable
90
91 if streamWriteBool(streamId, spec.loadMovingToolStatesFoldTime == nil or self:getFoldAnimTime() == spec.loadMovingToolStatesFoldTime) then
92 Cylindered.onWriteStream(self, streamId, connection)
93 end
94end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
17function CylinderedFoldable.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(Cylindered, specializations) and SpecializationUtil.hasSpecialization(Foldable, specializations)
19end

registerEventListeners

Description
Definition
registerEventListeners()
Code
35function CylinderedFoldable.registerEventListeners(vehicleType)
36 SpecializationUtil.registerEventListener(vehicleType, "onLoad", CylinderedFoldable)
37 SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", CylinderedFoldable)
38 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", CylinderedFoldable)
39 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", CylinderedFoldable)
40end