LUADOC - Farming Simulator 19

SoundManager

Description
This class handles all sounds
Parent
AbstractManager
Functions

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
29function SoundManager:initDataStructures()
30 self.samples = {}
31 self.orderedSamples = {}
32 self.activeSamples = {}
33 self.activeSamplesSet = {}
34 self.currentSampleIndex = 1
35 self.oldRandomizationIndex = 1
36 self.isIndoor = false
37 self.isInsideBuilding = false
38
39 self.soundTemplates = {}
40 self.soundTemplateXMLFile = nil
41 self:loadSoundTemplates(SoundManager.DEFAULT_SOUND_TEMPLATES)
42
43 self.modifierTypeNameToIndex = {}
44 self.modifierTypeIndexToDesc = {}
45 SoundModifierType = self.modifierTypeNameToIndex
46
47 self.indoorStateChangedListeners = {}
48end

loadSoundTemplates

Description
Loads sound templates from xml file
Definition
loadSoundTemplates()
Return Values
booleantrueif loading was successful else false
Code
74function SoundManager:loadSoundTemplates(xmlFilename)
75 local xmlFile = loadXMLFile("TempTemplates", xmlFilename)
76 if xmlFile ~= nil then
77 local i = 0
78 while true do
79 local key = string.format("soundTemplates.template(%d)", i)
80 if not hasXMLProperty(xmlFile, key) then
81 break
82 end
83
84 local name = getXMLString(xmlFile, key.."#name")
85 if name ~= nil then
86 if self.soundTemplates[name] == nil then
87 self.soundTemplates[name] = key
88 else
89 print(string.format("Warning: Sound template '%s' already exists!", name))
90 end
91 end
92
93 i = i + 1
94 end
95
96 self.soundTemplateXMLFile = xmlFile
97 return true
98 end
99
100 return false
101end

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
21function SoundManager:new(customMt)
22 local self = AbstractManager:new(customMt or SoundManager_mt)
23
24 return self
25end

registerModifierType

Description
Loads sound templates from xml file
Definition
registerModifierType()
Return Values
booleantrueif loading was successful else false
Code
53function SoundManager:registerModifierType(typeName, func, minFunc, maxFunc)
54 typeName = typeName:upper()
55
56 if SoundModifierType[typeName] == nil then
57 local desc = {}
58 desc.name = typeName
59 desc.index = #self.modifierTypeIndexToDesc + 1
60 desc.func = func
61 desc.minFunc = minFunc
62 desc.maxFunc = maxFunc
63
64 SoundModifierType[typeName] = desc.index
65 table.insert(self.modifierTypeIndexToDesc, desc)
66 end
67
68 return SoundModifierType[typeName]
69end