forked from mirror/Archipelago
Some checks failed
Analyze modified files / flake8 (push) Failing after 2m28s
Build / build-win (push) Has been cancelled
Build / build-ubuntu2204 (push) Has been cancelled
ctest / Test C++ ubuntu-latest (push) Has been cancelled
ctest / Test C++ windows-latest (push) Has been cancelled
Analyze modified files / mypy (push) Has been cancelled
Build and Publish Docker Images / Push Docker image to Docker Hub (push) Successful in 5m4s
Native Code Static Analysis / scan-build (push) Failing after 5m2s
type check / pyright (push) Successful in 1m7s
unittests / Test Python 3.11.2 ubuntu-latest (push) Failing after 16m23s
unittests / Test Python 3.12 ubuntu-latest (push) Failing after 28m19s
unittests / Test Python 3.13 ubuntu-latest (push) Failing after 14m49s
unittests / Test hosting with 3.13 on ubuntu-latest (push) Successful in 5m0s
unittests / Test Python 3.13 macos-latest (push) Has been cancelled
unittests / Test Python 3.11 windows-latest (push) Has been cancelled
unittests / Test Python 3.13 windows-latest (push) Has been cancelled
75 lines
3.3 KiB
Python
75 lines
3.3 KiB
Python
# from https://github.com/icebound777/PMR-SeedGenerator/blob/main/rando_modules/random_audio.py
|
|
"""
|
|
This module modifies the music in the ROM by pairing different song ids and
|
|
song variation ids to different songs and variations.
|
|
DBKey: A700(u8 song)(u8 variation)
|
|
DBValue: (s16 song)(s16 variation)
|
|
I.e. to map song 4, variation 1 to song F, variation 2 we'd have
|
|
A7000401 : 000F0002
|
|
"""
|
|
from copy import deepcopy
|
|
|
|
from ..data.enum_types import SongType
|
|
from ..data.song_data import SongData, song_data_array
|
|
from ..options import ShuffleMusic
|
|
|
|
|
|
def get_randomized_audio(randomize_bgm, randomize_jingles, random) -> list:
|
|
dbkey_base = 0xA7000000
|
|
db_data = []
|
|
|
|
def get_song_default_tuple(songdata: SongData) -> tuple:
|
|
return (
|
|
dbkey_base | (songdata.song_id << 8) | songdata.variation_id,
|
|
0xFFFFFFFF
|
|
)
|
|
|
|
if randomize_bgm != ShuffleMusic.option_Off:
|
|
bgms = [x for x in song_data_array if x.loops]
|
|
categorized_lists = {}
|
|
|
|
if randomize_bgm == ShuffleMusic.option_Shuffle_By_Mood:
|
|
for songdata in bgms:
|
|
if songdata.mood not in categorized_lists:
|
|
categorized_lists[songdata.mood] = []
|
|
categorized_lists[songdata.mood].append(songdata)
|
|
elif randomize_bgm == ShuffleMusic.option_Shuffle_By_Type:
|
|
for songdata in bgms:
|
|
if songdata.type not in categorized_lists:
|
|
categorized_lists[songdata.type] = []
|
|
categorized_lists[songdata.type].append(songdata)
|
|
elif randomize_bgm == ShuffleMusic.option_Full_Shuffle:
|
|
categorized_lists["all"] = bgms
|
|
for song_category in categorized_lists:
|
|
work_array = deepcopy(categorized_lists[song_category])
|
|
for songdata in categorized_lists[song_category]:
|
|
dbkey = dbkey_base | (songdata.song_id << 8) | songdata.variation_id
|
|
random_choice = random.randint(0, len(work_array) - 1)
|
|
new_song = work_array.pop(random_choice)
|
|
dbvalue = (new_song.song_id << 16) | new_song.variation_id
|
|
db_data.append((dbkey, dbvalue))
|
|
# print(f"before {songdata.song_name}/{songdata.variation_name}, after {new_song.song_name}/{new_song.variation_name}")
|
|
# print(f"{hex(dbkey)}/{hex(dbvalue)}")
|
|
else:
|
|
for songdata in song_data_array:
|
|
if songdata.loops:
|
|
db_data.append(get_song_default_tuple(songdata))
|
|
|
|
if randomize_jingles:
|
|
jingles = [x for x in song_data_array if x.type == SongType.JINGLE]
|
|
work_array = deepcopy(jingles)
|
|
for jingle in jingles:
|
|
dbkey = dbkey_base | (jingle.song_id << 8) | jingle.variation_id
|
|
random_choice = random.randint(0, len(work_array) - 1)
|
|
new_song = work_array.pop(random_choice)
|
|
dbvalue = (new_song.song_id << 16) | new_song.variation_id
|
|
db_data.append((dbkey, dbvalue))
|
|
# print(f"before {jingle.song_name}/{jingle.variation_name}, after {new_song.song_name}/{new_song.variation_name}")
|
|
# print(f"{hex(dbkey)}/{hex(dbvalue)}")
|
|
|
|
else:
|
|
for songdata in [x for x in song_data_array if x.type == SongType.JINGLE]:
|
|
db_data.append(get_song_default_tuple(songdata))
|
|
|
|
return db_data
|