diff --git a/README.md b/README.md index b969353..a9672d8 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,12 @@ BCCE is in active development and this may break at any time; see the first para These sections in the BCEX/BCCE spoiler logs currently have no logic and I'm aware of it. That doesn't mean sections *not* listed here have support; they may not and I'm not aware of them. -- AESTHETICS - MAGITEK - DANCES - ESPERS - ITEM MAGIC - ITEM EFFECTS - COLOSSEUM -- MUSIC - SHOPS - TREASURE CHESTS - JUNCTIONS diff --git a/main.py b/main.py index a0f3b37..f31a827 100644 --- a/main.py +++ b/main.py @@ -15,14 +15,12 @@ class Parser: BCEX/BCCE spoiler logfile parser. Sections missing support: - - AESTHETICS - MAGITEK - DANCES - ESPERS - ITEM MAGIC - ITEM EFFECTS - COLOSSEUM - - MUSIC - SHOPS - TREASURE CHESTS - JUNCTIONS @@ -288,6 +286,85 @@ class Parser: # I have no idea what this is lol, dump it to a list for now return [line for line in data.split("\n") if not line.startswith("---")] + @staticmethod + def parse_MUSIC(data: str) -> dict[str, dict]: + """ + Parse the MUSIC section. + + This differs significantly between BCEX and BCCE: Numbers and data are split + with a period in BCCE and a colon in BCEX. BCEX puts arranger on the same line + as composer, split with --, BCEX lacks the Jukebox Title section entirely. + """ + music_sections = data.split("\n\n") + + replacements = {} + + for section in music_sections[1:]: + if not section.strip(): + continue + + # BCEX and BCCE divide numbers from data differently + if ":" in section[:6]: + _, info = section.split(":", 1) + else: + _, info = section.split(".", 1) + + # The name of the song being replaced preceeds a -> + old_name, info = info.split("->", 1) + old_name = old_name.strip() + + replacements[old_name] = {} + + # Info is, mostly, one item per line, so let's go by line + tok_info = info.split("\n") + + for k in ("name", "title", "composer", "arranger", "jukebox_title"): + # Not every song has all the data + if not len(tok_info): + break + + line = tok_info.pop(0).strip() + + # BCCE puts arranger on its own line. BCEX puts it on the same line as + # composed, split by "--". So we have to handle both + if "-- Arranged by " in line: + line, arranger = line.split("-- Arranged by ", 1) + replacements[old_name]["arranger"] = arranger + + # Jukebox Title is in prens with extra stuff to chomp + if "Jukebox title" in line: + line = line[16:-1] + + # These strings are fluff but should only appear in compose/arranger lines + # so it's safe to just blindly chomp them + line = line.split("Composed by ", 1)[-1].strip() + line = line.replace("Ripped and/or arranged by ", "") + + replacements[old_name][k] = line + + return replacements + + @staticmethod + def parse_AESTHETICS(data: str) -> dict[str, str]: + """ + Parse the BCCE-only AESTHETICS section. + + This is just a k=v list we split up and strip. + """ + replacements = {} + + for line in data.split("\n"): + if ":" not in line: + continue + + old, new = line.split(":") + old = old.strip() + new = new.strip() + + replacements[old] = new + + return replacements + @staticmethod def cleanup_STATS(data: dict) -> bool: """