LUADOC - Farming Simulator 22

ParticleSystemManager

Description
This class handles all particles
Parent
AbstractManager
Functions

addParticleSystem

Description
Adds a new material type
Definition
addParticleSystem(string particleType, integer materialIndex, integer materialId)
Arguments
stringparticleTypeparticleType
integermaterialIndexmaterial index
integermaterialIdinternal material id
Code
129function ParticleSystemManager:addParticleSystem(particleType, particleSystem)
130 if self.particleSystems[particleType] ~= nil then
131 ParticleUtil.deleteParticleSystem(self.particleSystems[particleType])
132 end
133
134 self.particleSystems[particleType] = particleSystem
135end

addParticleType

Description
Adds a new particle type
Definition
addParticleType(string name)
Arguments
stringnamename
Code
93function ParticleSystemManager:addParticleType(name)
94 if not ClassUtil.getIsValidIndexName(name) then
95 print("Warning: '"..tostring(name).."' is not a valid name for a particleType. Ignoring it!")
96 return nil
97 end
98
99 name = name:upper()
100
101 if self.nameToIndex[name] == nil then
102 table.insert(self.particleTypes, name)
103 self.nameToIndex[name] = #self.particleTypes
104 end
105end

getParticleSystem

Description
Returns particle system for given properties
Definition
getParticleSystem(integer fillType, string particleTypeName)
Arguments
integerfillTypefill type
stringparticleTypeNamename of particle type
Return Values
tableparticleSystem
Code
142function ParticleSystemManager:getParticleSystem(particleTypeName)
143 local particleType = self:getParticleSystemTypeByName(particleTypeName)
144 if particleType == nil then
145 return nil
146 end
147
148 return self.particleSystems[particleType]
149end

getParticleSystemTypeByName

Description
Returns a particleType by name
Definition
getParticleSystemTypeByName(string name)
Arguments
stringnamename of particle type
Return Values
stringparticleTypethe real particle name, nil if not defined
Code
111function ParticleSystemManager:getParticleSystemTypeByName(name)
112 if name ~= nil then
113 name = name:upper()
114
115 -- atm we just return the uppercase name because a particle type is only defined as a base string
116 if self.nameToIndex[name] ~= nil then
117 return name
118 end
119 end
120
121 return nil
122end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
27function ParticleSystemManager:initDataStructures()
28 self.nameToIndex = {}
29 self.particleTypes = {}
30 self.particleSystems = {}
31end

loadMapData

Description
Load data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
36function ParticleSystemManager:loadMapData()
37 ParticleSystemManager:superClass().loadMapData(self)
38
39 self:addParticleType("unloading")
40 self:addParticleType("smoke")
41 self:addParticleType("smoke_chimney")
42 self:addParticleType("chopper")
43 self:addParticleType("straw")
44 self:addParticleType("cutter_chopper")
45 self:addParticleType("soil")
46 self:addParticleType("soil_smoke")
47 self:addParticleType("soil_chunks")
48 self:addParticleType("soil_big_chunks")
49 self:addParticleType("soil_harvesting")
50 self:addParticleType("spreader")
51 self:addParticleType("spreader_smoke")
52 self:addParticleType("windrower")
53 self:addParticleType("tedder")
54 self:addParticleType("weeder")
55 self:addParticleType("crusher_wood")
56 self:addParticleType("crusher_dust")
57 self:addParticleType("prepare_fruit")
58 self:addParticleType("cleaning_soil")
59 self:addParticleType("cleaning_dust")
60 self:addParticleType("washer_water")
61 self:addParticleType("chainsaw_wood")
62 self:addParticleType("chainsaw_dust")
63 self:addParticleType("pickup")
64 self:addParticleType("pickup_falling")
65 self:addParticleType("sowing")
66 self:addParticleType("loading")
67 self:addParticleType("wheel_dust")
68 self:addParticleType("wheel_dry")
69 self:addParticleType("wheel_wet")
70 self:addParticleType("wheel_snow")
71 self:addParticleType("bees")
72 self:addParticleType("horse_step_slow")
73 self:addParticleType("horse_step_fast")
74
75 ParticleType = self.nameToIndex
76
77 return true
78end

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
19function ParticleSystemManager.new(customMt)
20 local self = AbstractManager.new(customMt or ParticleSystemManager_mt)
21
22 return self
23end

unloadMapData

Description
Unload data on mission delete
Definition
unloadMapData()
Code
82function ParticleSystemManager:unloadMapData()
83 for _, fillTypeParticleSystem in pairs(self.particleSystems) do
84 ParticleUtil.deleteParticleSystem(fillTypeParticleSystem)
85 end
86
87 ParticleSystemManager:superClass().unloadMapData(self)
88end