File size: 1,111 Bytes
3831e97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""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  # default OFF

    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