mirror of
https://github.com/PrimeDecomp/prime.git
synced 2025-12-09 07:07:41 +00:00
Adjust link_order_callback API
This commit is contained in:
@@ -20,6 +20,7 @@ from pathlib import Path
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Sequence,
|
||||
cast,
|
||||
Dict,
|
||||
IO,
|
||||
@@ -192,9 +193,9 @@ class ProjectConfig:
|
||||
self.scratch_preset_id: Optional[int] = (
|
||||
None # Default decomp.me preset ID for scratches
|
||||
)
|
||||
self.link_order_callback: Optional[Callable[[int, List[str]], List[str]]] = (
|
||||
None # Callback to add/remove/reorder units within a module
|
||||
)
|
||||
self.link_order_callback: Optional[
|
||||
Callable[[int, List[str]], Sequence[Union[str, BuildConfigUnit]]]
|
||||
] = None # Callback to add/remove/reorder units within a module
|
||||
|
||||
# Progress output, progress.json and report.json config
|
||||
self.progress = True # Enable report.json generation and CLI progress output
|
||||
@@ -371,16 +372,19 @@ def load_build_config(
|
||||
modules: List[BuildConfigModule] = [build_config, *build_config["modules"]]
|
||||
for module in modules:
|
||||
unit_names = list(map(lambda u: u["name"], module["units"]))
|
||||
unit_names = config.link_order_callback(module["module_id"], unit_names)
|
||||
new_units = config.link_order_callback(module["module_id"], unit_names)
|
||||
units: List[BuildConfigUnit] = []
|
||||
for unit_name in unit_names:
|
||||
# Find existing unit or create a new one
|
||||
unit = next(
|
||||
(u for u in module["units"] if u["name"] == unit_name), None
|
||||
)
|
||||
if not unit:
|
||||
unit = {"object": None, "name": unit_name, "autogenerated": False}
|
||||
units.append(unit)
|
||||
for new_unit in new_units:
|
||||
if isinstance(new_unit, str):
|
||||
units.append(
|
||||
# Find existing unit or create a new one
|
||||
next(
|
||||
(u for u in module["units"] if u["name"] == new_unit),
|
||||
{"object": None, "name": new_unit, "autogenerated": False},
|
||||
)
|
||||
)
|
||||
else:
|
||||
units.append(new_unit)
|
||||
module["units"] = units
|
||||
|
||||
return build_config
|
||||
|
||||
Reference in New Issue
Block a user