1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-25 14:16:11 +00:00
oot/tools/version_config.py

53 lines
1.5 KiB
Python

# Version-specific configuration for setup and assets extraction
# SPDX-FileCopyrightText: © 2024 ZeldaRET
# SPDX-License-Identifier: CC0-1.0
from __future__ import annotations
from collections import OrderedDict
import csv
import dataclasses
from pathlib import Path
from typing import Optional
import yaml
PROJECT_ROOT = Path(__file__).parent.parent
@dataclasses.dataclass
class VersionConfig:
# ROM offset to start of DMA table
dmadata_start: int
# DMA segment information, in ROM order
dmadata_segments: OrderedDict[str, SegmentInfo]
# Addresses of important variables needed for asset extraction
variables: Dict[str, int]
@dataclasses.dataclass
class SegmentInfo:
name: str
vram: int | None
def load_dmadata_segments(version: str) -> OrderedDict[str, SegmentInfo]:
segments = OrderedDict()
with open(PROJECT_ROOT / f"baseroms/{version}/segments.csv", "r") as f:
reader = csv.DictReader(f)
for row in reader:
name = row["Name"]
vram = int(row["VRAM start"], 16) if row["VRAM start"] else None
segments[name] = SegmentInfo(name, vram)
return segments
def load_version_config(version: str) -> VersionConfig:
with open(PROJECT_ROOT / f"baseroms/{version}/config.yml", "r") as f:
config = yaml.load(f, Loader=yaml.Loader)
return VersionConfig(
dmadata_start=config["dmadata_start"],
dmadata_segments=load_dmadata_segments(version),
variables=config["variables"],
)