load BGM from config paths after loading folders to give config precedence
This commit is contained in:
parent
285181d23b
commit
6693ca4514
|
@ -152,27 +152,22 @@ class Audio(Animation):
|
||||||
def play_sfx(self, name, loops=None, maxtime=None, fade_ms=None, position=None, x=None):
|
def play_sfx(self, name, loops=None, maxtime=None, fade_ms=None, position=None, x=None):
|
||||||
return self.sfx[name].play(loops, maxtime, fade_ms, position, x)
|
return self.sfx[name].play(loops, maxtime, fade_ms, position, x)
|
||||||
|
|
||||||
#
|
|
||||||
# Loading BGM procedure
|
|
||||||
#
|
|
||||||
# - load config file name/path definitions
|
|
||||||
# - check project specific bgm paths, load any that don't conflict
|
|
||||||
# - other paths can replace loaded paths through the audio panel and get
|
|
||||||
# written to config file
|
|
||||||
#
|
|
||||||
def load_bgm(self):
|
def load_bgm(self):
|
||||||
for name, bgm_definition in self.get_configuration("bgm").items():
|
"""
|
||||||
bgm_definition_members = bgm_definition.split(self.CONFIG_SEPARATOR)
|
Loading BGM procedure:
|
||||||
path, volume = bgm_definition_members[0], 1.0
|
|
||||||
for ii, member in enumerate(bgm_definition_members[1:]):
|
- Check project specific BGM paths and load files found in those paths.
|
||||||
if ii == 0:
|
- Load config file name/path definitions, overwriting existing. This means the config file
|
||||||
volume = float(member)
|
definitions have precedence over the automatic loading of files placed in folders.
|
||||||
self.set_bgm(path, name, volume=volume)
|
|
||||||
|
Further editing of BGM while the game is running can be done through the AudioPanel object.
|
||||||
|
"""
|
||||||
|
# First load BGM files found in the BGM path set in the configuration
|
||||||
for root in self.get_configuration("audio", "bgm-project-path"):
|
for root in self.get_configuration("audio", "bgm-project-path"):
|
||||||
# look for path in resource folders
|
# look for path in resource folders
|
||||||
root = self.get_resource(root)
|
root = self.get_resource(root)
|
||||||
if os.path.exists(root):
|
if os.path.exists(root):
|
||||||
print("checking {} for music".format(root))
|
print("checking {} for background music".format(root))
|
||||||
if os.path.isfile(root):
|
if os.path.isfile(root):
|
||||||
self.set_bgm(root)
|
self.set_bgm(root)
|
||||||
else:
|
else:
|
||||||
|
@ -183,10 +178,20 @@ class Audio(Animation):
|
||||||
if prefix:
|
if prefix:
|
||||||
prefix = re.sub("/", "_", prefix) + "_"
|
prefix = re.sub("/", "_", prefix) + "_"
|
||||||
self.set_bgm(os.path.join(node, leaf), prefix=prefix)
|
self.set_bgm(os.path.join(node, leaf), prefix=prefix)
|
||||||
|
# Next load BGM paths defined in the configuration. If any of these have the same name as
|
||||||
|
# BGM loaded by the previous code block, they will be overwritten to give the config file
|
||||||
|
# precedence over automatic BGM detection.
|
||||||
|
print("checking configuration for background music".format(root))
|
||||||
|
for name, bgm_definition in self.get_configuration("bgm").items():
|
||||||
|
bgm_definition_members = bgm_definition.split(self.CONFIG_SEPARATOR)
|
||||||
|
path, volume = bgm_definition_members[0], 1.0
|
||||||
|
for ii, member in enumerate(bgm_definition_members[1:]):
|
||||||
|
if ii == 0:
|
||||||
|
volume = float(member)
|
||||||
|
self.set_bgm(path, name, volume=volume)
|
||||||
|
|
||||||
def set_bgm(self, path, name=None, prefix="", volume=1.0):
|
def set_bgm(self, path, name=None, prefix="", volume=1.0):
|
||||||
path = self.get_resource(path)
|
path = self.get_resource(path)
|
||||||
print("setting {} music to {}".format(name, path))
|
|
||||||
try:
|
try:
|
||||||
pygame.mixer.music.load(path)
|
pygame.mixer.music.load(path)
|
||||||
except:
|
except:
|
||||||
|
@ -194,6 +199,7 @@ class Audio(Animation):
|
||||||
return False
|
return False
|
||||||
if name is None:
|
if name is None:
|
||||||
name = os.path.basename(path).split(".")[0]
|
name = os.path.basename(path).split(".")[0]
|
||||||
|
print("setting {} background music to {}".format(name, path))
|
||||||
self.bgm[prefix + name] = BGM(self, path, volume)
|
self.bgm[prefix + name] = BGM(self, path, volume)
|
||||||
if self.current_bgm is None:
|
if self.current_bgm is None:
|
||||||
self.current_bgm = self.bgm[prefix + name]
|
self.current_bgm = self.bgm[prefix + name]
|
||||||
|
|
Loading…
Reference in New Issue