cf6c0c9bb3207d6d51eadcb49e2a52ee7456eefa
1 from os
.path
import dirname
, exists
, basename
2 from platform
import system
4 from pathlib
import Path
5 from random
import choice
6 from logging
import info
7 from panda3d
.core
import AudioSound
, Filename
12 def __init__(self
, volume
):
13 files
= self
.curr_path
+ 'assets/audio/music/*.ogg'
14 self
._start
_music
(glob(files
))
15 base
.musicManager
.setVolume(.8 * volume
)
16 base
.sfxManagerList
[0].setVolume(volume
)
17 taskMgr
.add(self
._on
_frame
, 'on frame music')
20 def is_appimage(self
):
21 par_path
= str(Path(__file__
).parent
.absolute())
22 is_appimage
= par_path
.startswith('/tmp/.mount_Pmachi')
23 return is_appimage
and par_path
.endswith('/usr/bin')
27 if system() == 'Windows':
32 par_path
= str(Path(__file__
).parent
.absolute())
34 par_path
= str(Path(par_path
).absolute())
38 def _start_music(self
, files
):
39 self
._music
= loader
.load_music(choice(files
))
40 info('playing music ' + self
._music
.get_name())
43 def set_volume(self
, volume
):
44 base
.musicManager
.setVolume(.8 * volume
)
45 base
.sfxManagerList
[0].setVolume(volume
)
47 def _on_frame(self
, task
):
48 if self
._music
.status() == AudioSound
.READY
:
49 oggs
= Filename(self
.curr_path
+ 'assets/audio/music/*.ogg').to_os_specific()
51 rm_music
= Filename(self
.curr_path
+ 'assets/audio/music/' + basename(self
._music
.get_name())).to_os_specific()
52 # basename is needed in windows
53 files
.remove(rm_music
)
54 self
._start
_music
(files
)