2019-11-02 17:27:54 -05:00
|
|
|
from direct.interval.IntervalGlobal import *
|
2019-12-30 00:00:16 -06:00
|
|
|
from . import BasicEntities
|
2019-11-02 17:27:54 -05:00
|
|
|
import random
|
|
|
|
|
|
|
|
class AmbientSound(BasicEntities.NodePathEntity):
|
|
|
|
|
|
|
|
def __init__(self, level, entId):
|
|
|
|
BasicEntities.NodePathEntity.__init__(self, level, entId)
|
|
|
|
self.initSound()
|
|
|
|
|
|
|
|
def destroy(self):
|
|
|
|
self.destroySound()
|
|
|
|
BasicEntities.NodePathEntity.destroy(self)
|
|
|
|
|
|
|
|
def initSound(self):
|
|
|
|
if not self.enabled:
|
|
|
|
return
|
|
|
|
if self.soundPath == '':
|
|
|
|
return
|
2019-11-23 16:07:27 -06:00
|
|
|
self.sound = base.loader.loadSfx(self.soundPath)
|
2019-11-02 17:27:54 -05:00
|
|
|
if self.sound is None:
|
|
|
|
return
|
|
|
|
self.soundIval = SoundInterval(self.sound, node=self, volume=self.volume)
|
|
|
|
self.soundIval.loop()
|
|
|
|
self.soundIval.setT(random.random() * self.sound.length())
|
|
|
|
return
|
|
|
|
|
|
|
|
def destroySound(self):
|
|
|
|
if hasattr(self, 'soundIval'):
|
|
|
|
self.soundIval.pause()
|
|
|
|
del self.soundIval
|
|
|
|
if hasattr(self, 'sound'):
|
|
|
|
del self.sound
|
|
|
|
|
|
|
|
if __dev__:
|
|
|
|
|
|
|
|
def attribChanged(self, *args):
|
|
|
|
self.destroySound()
|
|
|
|
self.initSound()
|