Code cleanup and improvements.

This commit is contained in:
2026-09-03 21:52:06 +02:00
parent ea323e3ab0
commit ecdea827ac
20 changed files with 312 additions and 213 deletions

View File

@@ -40,19 +40,11 @@ class GameConfig:
virtual_desktop: str
@dataclass(frozen=True)
class SafetyConfig:
allow_live_game_modification: bool
allow_prefix_modification: bool
allow_binary_patch: bool
@dataclass(frozen=True)
class AppConfig:
paths: PathsConfig
proton7: Proton7Config
game: GameConfig
safety: SafetyConfig
source: Path
def to_dict(self) -> dict[str, Any]:
@@ -81,7 +73,6 @@ def load_config(path: str | Path | None = None) -> AppConfig:
paths = _section(data, "paths")
proton7 = _section(data, "proton7")
game = _section(data, "game")
safety = _section(data, "safety")
virtual_desktop = _required_string(game, "virtual_desktop")
if re.fullmatch(r"[1-9][0-9]*x[1-9][0-9]*", virtual_desktop) is None:
raise ConfigError("game.virtual_desktop must look like 1600x900")
@@ -105,15 +96,6 @@ def load_config(path: str | Path | None = None) -> AppConfig:
args=_required_string_tuple(game, "args"),
virtual_desktop=virtual_desktop,
),
safety=SafetyConfig(
allow_live_game_modification=_required_bool(
safety, "allow_live_game_modification"
),
allow_prefix_modification=_required_bool(
safety, "allow_prefix_modification"
),
allow_binary_patch=_required_bool(safety, "allow_binary_patch"),
),
source=config_path,
)
@@ -145,13 +127,6 @@ def _required_string_tuple(section: Mapping[str, Any], key: str) -> tuple[str, .
return tuple(value)
def _required_bool(section: Mapping[str, Any], key: str) -> bool:
value = section.get(key)
if not isinstance(value, bool):
raise ConfigError(f"{key} must be true or false")
return value
def _paths_to_strings(value: Any) -> Any:
if isinstance(value, Path):
return str(value)