Bastien Sevajol 6 лет назад
Родитель
Сommit
f710d5ab01
1 измененных файлов: 25 добавлений и 0 удалений
  1. 25 0
      synergine2_cocos2d/audio.py

+ 25 - 0
synergine2_cocos2d/audio.py Просмотреть файл

@@ -0,0 +1,25 @@
1
+# coding: utf-8
2
+import typing
3
+
4
+from cocos.audio.pygame.mixer import Sound
5
+
6
+from synergine2_cocos2d.util import PathManager
7
+
8
+
9
+class AudioLibrary(object):
10
+    # name: file_name
11
+    sound_file_paths = {}  # type: typing.Dict[str, str]
12
+
13
+    def __init__(
14
+        self,
15
+        include_paths: typing.List[str],
16
+    ) -> None:
17
+        self._path_manager = PathManager(include_paths)
18
+        self._sounds = {}
19
+
20
+    def get_sound(self, name: str) -> Sound:
21
+        if name not in self._sounds:
22
+            sound_file_name = self.sound_file_paths[name]
23
+            sound_file_path = self._path_manager.path(sound_file_name)
24
+            self._sounds[name] = Sound(sound_file_path)
25
+        return self._sounds[name]