| """Player settings: pace, text scale, reduce_motion, telemetry.""" |
| from __future__ import annotations |
|
|
| from dataclasses import dataclass, asdict |
| from game.sim.day_cycle import Pace |
|
|
| @dataclass |
| class Settings: |
| pace: Pace = Pace.NORMAL |
| text_scale: float = 1.0 |
| reduce_motion: bool = False |
| show_atmosphere_hint: bool = False |
| telemetry_enabled: bool = False |
|
|
| def clamp_text_scale(self) -> None: |
| self.text_scale = max(0.8, min(1.6, float(self.text_scale))) |
|
|
| def to_dict(self) -> dict: |
| self.clamp_text_scale() |
| d = asdict(self) |
| d["pace"] = self.pace.value |
| return d |
|
|
| @classmethod |
| def from_dict(cls, data: dict) -> "Settings": |
| s = cls( |
| pace=Pace(data.get("pace", "Normal")), |
| text_scale=float(data.get("text_scale", 1.0)), |
| reduce_motion=bool(data.get("reduce_motion", False)), |
| show_atmosphere_hint=bool(data.get("show_atmosphere_hint", False)), |
| telemetry_enabled=bool(data.get("telemetry_enabled", False)), |
| ) |
| s.clamp_text_scale() |
| return s |
|
|