| 19 | |
| 20 | @dataclass |
| 21 | class TWConfig(base.JSONSerializable): |
| 22 | framerate: int = None, |
| 23 | interpolation: bool = False, |
| 24 | hq_pen: bool = False, |
| 25 | max_clones: float | int | None = None, |
| 26 | misc_limits: bool = True, |
| 27 | fencing: bool = True |
| 28 | width: int = None |
| 29 | height: int = None |
| 30 | |
| 31 | @staticmethod |
| 32 | def from_json(data: dict) -> TWConfig: |
| 33 | # Non-runtime options |
| 34 | _framerate = data.get("framerate") |
| 35 | _interpolation = data.get("interpolation", False) |
| 36 | _hq_pen = data.get("hq", False) |
| 37 | |
| 38 | # Runtime options |
| 39 | _runtime_options = data.get("runtimeOptions", {}) |
| 40 | |
| 41 | # Luckily for us, the JSON module actually accepts the 'Infinity' literal. Otherwise, it would be a right pain |
| 42 | _max_clones = _runtime_options.get("maxClones") |
| 43 | _misc_limits = _runtime_options.get("miscLimits", True) |
| 44 | _fencing = _runtime_options.get("fencing", True) |
| 45 | |
| 46 | # Custom stage size |
| 47 | _width = data.get("width") |
| 48 | _height = data.get("height") |
| 49 | |
| 50 | return TWConfig(_framerate, _interpolation, _hq_pen, _max_clones, _misc_limits, _fencing, _width, _height) |
| 51 | |
| 52 | def to_json(self) -> dict: |
| 53 | runtime_options = {} |
| 54 | commons.noneless_update( |
| 55 | runtime_options, |
| 56 | { |
| 57 | "maxClones": self.max_clones, |
| 58 | "miscLimits": none_if_eq(self.misc_limits, True), |
| 59 | "fencing": none_if_eq(self.fencing, True) |
| 60 | }) |
| 61 | |
| 62 | data = {} |
| 63 | commons.noneless_update(data, { |
| 64 | "framerate": self.framerate, |
| 65 | "runtimeOptions": runtime_options, |
| 66 | "interpolation": none_if_eq(self.interpolation, False), |
| 67 | "hq": none_if_eq(self.hq_pen, False), |
| 68 | "width": self.width, |
| 69 | "height": self.height |
| 70 | }) |
| 71 | return data |
| 72 | |
| 73 | @property |
| 74 | def infinite_clones(self): |
| 75 | return self.max_clones == math.inf |
| 76 | |
| 77 | @staticmethod |
| 78 | def from_str(string: str): |