Skip to content

Commit

Permalink
Add credits
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanatosGit committed Oct 2, 2023
1 parent af9862c commit 43ce929
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
8 changes: 8 additions & 0 deletions open_samus_returns_rando/files/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@
"additionalProperties": false
},
"default": []
},
"spoiler_log": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "A dict mapping item names to a string describing their location.",
"default": {}
}
},
"required": [
Expand Down
101 changes: 101 additions & 0 deletions open_samus_returns_rando/misc_patches/credits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

import re

from mercury_engine_data_structures.formats import Txt

from open_samus_returns_rando.patcher_editor import PatcherEditor

_PROJECT_MEMBERS = {
"Project Leads": [
"Dyceron",
"Thanatos",
],
"Game Patching": [
"Henrique 'Darkszero' Gemignani",
"duncathan_salt",
"MeriKatt",
],
"Logic Database": [
"Miepee",
],
" ": [
"With contributions from many others.",
]
}

def _create_randomizer_credits(spoiler_log: dict[str, str]):
rando_credits: list[tuple[str, str]] = [
("Randomizer Credits", "CREDIT_TITLE"),
]

for group, group_members in _PROJECT_MEMBERS.items():
rando_credits.append((group, "CREDIT_SUBTITLE"))
for member in group_members:
rando_credits.append((member, "CREDIT_"))

if spoiler_log:
rando_credits.append((" ", "CREDIT_SUBTITLE"))
rando_credits.append(("Major Item Locations", "CREDIT_TITLE"))
for item, loc in spoiler_log.items():
rando_credits.append((item, "CREDIT_SUBTITLE"))
rando_credits.append((loc, "CREDIT_"))

rando_credits.append((" ", "CREDIT_SUBTITLE"))

amount_title = 0
amount_subtitle = 0
amount_credit = 0

def new_sort(prefix: str, item) -> tuple[str, str]:
nonlocal amount_title
nonlocal amount_subtitle
nonlocal amount_credit
if prefix.startswith("CREDIT_TITLE"):
amount_title = amount_title + 1
return (f"{prefix}{amount_title}", item)
elif prefix.startswith("CREDIT_SUBTITLE"):
amount_subtitle = amount_subtitle + 1
return (f"{prefix}{amount_subtitle}", item)
else:
amount_credit = amount_credit + 1
return (f"{prefix}{amount_credit}", item)

rando_credits = [
new_sort(prefix, item)
for item, prefix in rando_credits
]
return rando_credits, amount_title, amount_subtitle, amount_credit


def patch_credits(editor: PatcherEditor, spoiler_log: dict[str, str]):
english_files = [
"system/localization/mse_english.txt",
]

rando_credits, amount_title, amount_subtitle, amount_credit = _create_randomizer_credits(spoiler_log)

for file in english_files:
text = editor.get_file(file, Txt)
ordered_credits = list(text.strings.items())

# suffix needs to be sorted per "type"
for index, credit_tuple in enumerate(ordered_credits):
title = re.findall(r'CREDIT_TITLE(\d+)', credit_tuple[0])
if len(title) > 0:
new_suffix = int(title[0]) + amount_title
ordered_credits[index] = (f"CREDIT_TITLE{new_suffix}", credit_tuple[1])
continue

title = re.findall(r'CREDIT_SUBTITLE(\d+)', credit_tuple[0])
if len(title) > 0:
new_suffix = int(title[0]) + amount_subtitle
ordered_credits[index] = (f"CREDIT_SUBTITLE{new_suffix}", credit_tuple[1])
continue

title = re.findall(r'CREDIT_(\d+)', credit_tuple[0])
if len(title) > 0:
new_suffix = int(title[0]) + amount_credit
ordered_credits[index] = (f"CREDIT_{new_suffix}", credit_tuple[1])
continue

text.strings = dict(rando_credits + ordered_credits)
4 changes: 4 additions & 0 deletions open_samus_returns_rando/samus_returns_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from open_samus_returns_rando.lua_editor import LuaEditor
from open_samus_returns_rando.misc_patches import lua_util
from open_samus_returns_rando.misc_patches.credits import patch_credits
from open_samus_returns_rando.misc_patches.exefs import DSPatch
from open_samus_returns_rando.patcher_editor import PatcherEditor
from open_samus_returns_rando.pickup import patch_pickups
Expand Down Expand Up @@ -146,6 +147,9 @@ def patch_extracted(input_path: Path, output_path: Path, configuration: dict):
# Specific game patches
game_patches.apply_game_patches(editor, configuration.get("game_patches", {}))

# Patch credits
patch_credits(editor, configuration["spoiler_log"])

out_romfs = output_path.joinpath("romfs")
out_exefs = output_path.joinpath("exefs")
shutil.rmtree(out_romfs, ignore_errors=True)
Expand Down

0 comments on commit 43ce929

Please sign in to comment.