oldschool-toontown/toontown/battle/BattleSounds.py

47 lines
1.7 KiB
Python
Raw Permalink Normal View History

2022-01-19 18:50:20 -06:00
from panda3d.core import *
2019-11-02 17:27:54 -05:00
from direct.directnotify import DirectNotifyGlobal
class BattleSounds:
notify = DirectNotifyGlobal.directNotify.newCategory('BattleSounds')
def __init__(self):
self.mgr = AudioManager.createAudioManager()
self.isValid = 0
if self.mgr != None and self.mgr.isValid():
self.isValid = 1
2022-01-19 18:50:20 -06:00
limit = ConfigVariableInt('battle-sound-cache-size', 15).value
2019-11-02 17:27:54 -05:00
self.mgr.setCacheLimit(limit)
base.addSfxManager(self.mgr)
self.setupSearchPath()
return
def setupSearchPath(self):
self.sfxSearchPath = DSearchPath()
2021-07-06 14:34:43 -05:00
if __debug__:
# In the dev environment, it will always be here:
self.sfxSearchPath.appendDirectory(Filename('resources/phase_3/audio/sfx'))
self.sfxSearchPath.appendDirectory(Filename('resources/phase_3.5/audio/sfx'))
self.sfxSearchPath.appendDirectory(Filename('resources/phase_4/audio/sfx'))
self.sfxSearchPath.appendDirectory(Filename('resources/phase_5/audio/sfx'))
2019-11-02 17:27:54 -05:00
def clear(self):
if self.isValid:
self.mgr.clearCache()
def getSound(self, name):
if self.isValid:
filename = Filename(name)
found = vfs.resolveFilename(filename, self.sfxSearchPath)
if not found:
self.setupSearchPath()
found = vfs.resolveFilename(filename, self.sfxSearchPath)
if not found:
self.notify.warning('%s not found on:' % name)
print(self.sfxSearchPath)
2019-11-02 17:27:54 -05:00
else:
return self.mgr.getSound(filename.getFullpath())
return self.mgr.getNullSound()
globalBattleSoundCache = BattleSounds()