Browse Source

added AmbientSound

Darren Ranalli 22 years ago
parent
commit
84e1b2ee2e

+ 30 - 0
direct/src/level/AmbientSound.py

@@ -0,0 +1,30 @@
+from IntervalGlobal import *
+import BasicEntities
+
+class AmbientSound(BasicEntities.NodePathEntity):
+    def __init__(self, level, entId):
+        BasicEntities.NodePathEntity.__init__(self, level, entId)
+
+    def destroy(self):
+        BasicEntities.NodePathEntity.destroy(self)
+
+    def initSound(self):
+        if self.soundPath == '':
+            return
+        self.sound = base.loadSfx(self.soundPath)
+        if self.sound is None:
+            return
+        self.soundIval = SoundInterval(self.sound, node=self)
+        self.soundIval.loop()
+
+    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()

+ 2 - 0
direct/src/level/EntityCreator.py

@@ -13,6 +13,7 @@ import ModelEntity
 import PathEntity
 import VisibilityExtender
 import PropSpinner
+import AmbientSound
 
 # some useful constructor functions
 # ctor functions must take (level, entId)
@@ -32,6 +33,7 @@ class EntityCreator(EntityCreatorBase.EntityCreatorBase):
         EntityCreatorBase.EntityCreatorBase.__init__(self, level)
         self.level = level
         self.privRegisterTypes({
+            'ambientSound': AmbientSound.AmbientSound,
             'cutScene': CutScene.CutScene,
             'editMgr': EditMgr.EditMgr,
             'entityGroup': nothing,

+ 1 - 0
direct/src/level/EntityCreatorAI.py

@@ -44,6 +44,7 @@ class EntityCreatorAI(EntityCreatorBase.EntityCreatorBase):
         cLE = createLocalEntity
 
         self.privRegisterTypes({
+            'ambientSound': nothing,
             'cutScene': nothing,
             'editMgr': Functor(cLE, EditMgrAI.EditMgrAI),
             'entityGroup': nothing,

+ 6 - 0
direct/src/level/EntityTypes.py

@@ -119,6 +119,12 @@ class VisibilityExtender(Entity):
         ('newZones', [], 'visZoneList'),
         )
 
+class AmbientSound(Entity):
+    type = 'ambientSound'
+    attribs = (
+        ('soundPath', '', 'bamfilename'),
+        )
+
 class PropSpinner(Entity):
     type = 'propSpinner'