LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

GuiSoundPlayer

Description
This class loads known GUI sound samples as non-spatial samples to be played in the GUI (menu and HUD).
Functions

loadSounds

Description
Load GUI sound samples from definitions.
Definition
loadSounds()
Code
55function GuiSoundPlayer:loadSounds(sampleDefinitionXmlPath)
56 local samples = {}
57
58 local xmlFile = loadXMLFile("GuiSampleDefinitions", sampleDefinitionXmlPath)
59 if xmlFile ~= nil and xmlFile ~= 0 then
60 for _, key in pairs(GuiSoundPlayer.SOUND_SAMPLES) do
61 if key ~= GuiSoundPlayer.SOUND_SAMPLES.NONE then
62 local sample = self.soundManager:loadSample2DFromXML(xmlFile, GuiSoundPlayer.SOUND_SAMPLE_DEFINITIONS_XML_ROOT, key, "", 1, AudioGroup.GUI)
63 if sample ~= nil then
64 samples[key] = sample
65 else
66 print("Warning: Could not load GUI sound sample [" .. tostring(key) .. "]")
67 end
68 end
69 end
70
71 delete(xmlFile)
72 end
73
74 return samples
75end

new

Description
Create a new GuiSoundPlayer instance.
Definition
new(table soundManager)
Arguments
tablesoundManagerSoundManager reference
Code
44function GuiSoundPlayer:new(soundManager)
45 local self = setmetatable({}, GuiSoundPlayer_mt)
46
47 self.soundManager = soundManager
48 self.soundSamples = self:loadSounds(GuiSoundPlayer.SOUND_SAMPLE_DEFINITIONS_PATH) -- name -> sample
49
50 return self
51end

playSample

Description
Play a GUI sound sample identified by name. The sample must have been loaded when the GUI was created.
Definition
playSample(string sampleName)
Arguments
stringsampleNameName of the sample to play, use one of the identifiers in GuiSoundPlayer.SOUND_SAMPLES.
Code
81function GuiSoundPlayer:playSample(sampleName)
82 if sampleName ~= GuiSoundPlayer.SOUND_SAMPLES.NONE then
83 local sample = self.soundSamples[sampleName]
84 if sample ~= nil then
85 local canPlay = not self.soundManager:getIsSamplePlaying(sample)
86 if canPlay then
87 self.soundManager:playSample(sample)
88 end
89 else
90 print("Warning: Tried playing GUI sample [" .. tostring(sampleName) .. "] which has not been loaded.")
91 end
92 end
93end