+from os.path import dirname, exists
+from platform import system
from glob import glob
+from pathlib import Path
from random import choice
from logging import info
-from panda3d.core import AudioSound
+from panda3d.core import AudioSound, Filename
class MusicMgr:
def __init__(self, volume):
- self._start_music(glob('assets/audio/music/*.ogg'))
+ files = self.curr_path + 'assets/audio/music/*.ogg'
+ self._start_music(glob(files))
base.musicManager.setVolume(.8 * volume)
base.sfxManagerList[0].setVolume(volume)
taskMgr.add(self._on_frame, 'on frame music')
+ @property
+ def is_appimage(self):
+ par_path = str(Path(__file__).parent.absolute())
+ is_appimage = par_path.startswith('/tmp/.mount_Pmachi')
+ return is_appimage and par_path.endswith('/usr/bin')
+
+ @property
+ def curr_path(self):
+ if system() == 'Windows':
+ return ''
+ if exists('main.py'):
+ return ''
+ else:
+ par_path = str(Path(__file__).parent.absolute())
+ if self.is_appimage:
+ par_path = str(Path(par_path).absolute())
+ par_path += '/'
+ return par_path
+
def _start_music(self, files):
self._music = loader.load_music(choice(files))
info('playing music ' + self._music.get_name())
def _on_frame(self, task):
if self._music.status() == AudioSound.READY:
- files = glob('assets/audio/music/*.ogg')
- files.remove('assets/audio/music/' + self._music.get_name())
+ files = glob(self.curr_path + '/assets/audio/music/*.ogg')
+ files.remove(self.curr_path + '/assets/audio/music/' + self._music.get_name())
self._start_music(files)
return task.cont