Skip to content

Commit ee02aec

Browse files
committed
Added fill level sound feature for discharge nodes
1 parent e7a6b85 commit ee02aec

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

docs/PROCESSOR_SPLIT.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ For more details on these look at the official documentation files for Vehicle.
189189
...
190190
</effects>
191191
<dischargeStateSound template="augerBelt" pitchScale="0.7" volumeScale="1.4" fadeIn="0.2" fadeOut="1" innerRadius="1.0" outerRadius="40.0" linkNode="dischargeNodeFront" />
192+
<fillLevelSound template="rollbeltAlarm" linkNode="alarmSoundNode" />
192193
</node>
193194
</dischargeNodes>
194195
</materialProcessor>
@@ -201,7 +202,24 @@ For more details on these look at the official documentation files for Vehicle.
201202
vehicle.materialProcessor.dischargeNodes.node(%).fillUnitObjectChanges
202203
```
203204

204-
### Attributes
205+
Trigger object changes based on the fill level percentage.
206+
207+
#### Attributes
208+
| Name | Type | Required | Default | Description |
209+
|-----------|-------|----|-----------|------------------------------|
210+
| threshold | float | No | ```0.5```| Defines at which fillUnit fill level percentage the object changes |
211+
212+
### FillLevel sound
213+
214+
```
215+
vehicle.materialProcessor.dischargeNodes.node(%).fillLevelSound
216+
```
217+
218+
Play sound depending on the fill level percentage.
219+
Same as a normal vehicle sample entry, but with two additional attributes.
220+
221+
#### Attributes
205222
| Name | Type | Required | Default | Description |
206223
|-----------|-------|----|-----------|------------------------------|
207-
| threshold | float | No | ```0.5````| Defines at which fillUnit fill level percentage the object changes |
224+
| threshold | float | No | ```0.5```| Defines at which fillUnit fill level percentage the sound is triggered |
225+
| thresholdIsGreater | boolean | No | ```true``` | If true the sound is triggered above threshold, if not then below threshold |

scripts/DischargeNode.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
---@field distanceObjectChangeThreshold number
6464
---@field lineOffset number
6565
---@field playSound boolean
66+
---@field fillLevelSoundThreshold number
67+
---@field fillLevelSoundThresholdIsGreater boolean
68+
---@field fillLevelSample? table
6669
---
6770
---@field canFillOwnVehicle boolean
6871
---@field canDischargeToVehicle boolean
@@ -123,6 +126,9 @@ function DischargeNode.registerXMLPaths(schema, key)
123126
EffectManager.registerEffectXMLPaths(schema, key .. ".effects")
124127
SoundManager.registerSampleXMLPaths(schema, key, "dischargeSound")
125128
SoundManager.registerSampleXMLPaths(schema, key, "dischargeStateSound(?)")
129+
SoundManager.registerSampleXMLPaths(schema, key, 'fillLevelSound')
130+
schema:register(XMLValueType.FLOAT, key .. '.fillLevelSound#threshold', '', 0.5)
131+
schema:register(XMLValueType.BOOL, key .. '.fillLevelSound#thresholdIsGreater', '', true)
126132
schema:register(XMLValueType.BOOL, key .. ".dischargeSound#overwriteSharedSound", "Overwrite shared discharge sound with sound defined in discharge node", false)
127133
AnimationManager.registerAnimationNodesXMLPaths(schema, key .. ".animationNodes")
128134
AnimationManager.registerAnimationNodesXMLPaths(schema, key .. ".effectAnimationNodes")
@@ -172,6 +178,7 @@ function DischargeNode:delete()
172178
g_effectManager:deleteEffects(self.effects)
173179
g_soundManager:deleteSample(self.sample)
174180
g_soundManager:deleteSample(self.dischargeSample)
181+
g_soundManager:deleteSample(self.fillLevelSample)
175182
g_soundManager:deleteSamples(self.dischargeStateSamples)
176183
g_animationManager:deleteAnimations(self.animationNodes)
177184
g_animationManager:deleteAnimations(self.effectAnimationNodes)
@@ -474,6 +481,7 @@ function DischargeNode:updateTick(dt)
474481

475482
if self.isClient then
476483
self:updateDischargeSound(dt)
484+
self:updateFillLevelSound(dt)
477485
end
478486

479487
if self.fillUnitObjectChanges ~= nil then
@@ -910,6 +918,22 @@ function DischargeNode:updateDischargeInfo(x, y, z)
910918
end
911919
end
912920

921+
function DischargeNode:updateFillLevelSound(dt)
922+
if self.playSound and self.fillLevelSample == nil then
923+
return
924+
end
925+
926+
local fillLevelPct = self:getFillLevelPercentage()
927+
local playSample = (self.fillLevelSoundThresholdIsGreater and fillLevelPct > self.fillLevelSoundThreshold) or (not self.fillLevelSoundThresholdIsGreater and fillLevelPct < self.fillLevelSoundThreshold)
928+
local isPlaying = g_soundManager:getIsSamplePlaying(self.fillLevelSample)
929+
930+
if playSample and not isPlaying then
931+
g_soundManager:playSample(self.fillLevelSample)
932+
elseif not playSample and isPlaying then
933+
g_soundManager:stopSample(self.fillLevelSample)
934+
end
935+
end
936+
913937
---@param dt number
914938
function DischargeNode:updateDischargeSound(dt)
915939
local fillType = self:getDischargeFillType()

scripts/ProcessorUtils.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ function ProcessorUtils.loadDischargeEffects(dischargeNode, xmlFile, key)
9292
dischargeNode.playSound = false
9393
end
9494

95+
dischargeNode.fillLevelSoundThreshold = xmlFile:getValue(key .. '.fillLevelSound#threshold', 0.5)
96+
dischargeNode.fillLevelSoundThresholdIsGreater = xmlFile:getValue(key .. '.fillLevelSound#thresholdIsGreater', true)
97+
dischargeNode.fillLevelSample = g_soundManager:loadSampleFromXML(xmlFile, key, "fillLevelSound", dischargeNode.vehicle.baseDirectory, dischargeNode.vehicle.components, 0, AudioGroup.VEHICLE, dischargeNode.vehicle.i3dMappings, dischargeNode.vehicle)
98+
9599
dischargeNode.dischargeStateSamples = g_soundManager:loadSamplesFromXML(xmlFile, key, "dischargeStateSound", dischargeNode.vehicle.baseDirectory, dischargeNode.vehicle.components, 0, AudioGroup.VEHICLE, dischargeNode.vehicle.i3dMappings, dischargeNode.vehicle)
96100
dischargeNode.animationNodes = g_animationManager:loadAnimations(xmlFile, key .. ".animationNodes", dischargeNode.vehicle.components, dischargeNode.vehicle, dischargeNode.vehicle.i3dMappings)
97101
dischargeNode.effectAnimationNodes = g_animationManager:loadAnimations(xmlFile, key .. ".effectAnimationNodes", dischargeNode.vehicle.components, dischargeNode.vehicle, dischargeNode.vehicle.i3dMappings)

0 commit comments

Comments
 (0)