Dan Albert 8ed843a9cf
Move and split up weather.py.
This is getting out of hand, and I'm about to make it worse.
2023-05-18 13:31:26 +02:00

34 lines
971 B
Python

from __future__ import annotations
import random
from dataclasses import dataclass, field
from typing import Optional
from dcs.cloud_presets import Clouds as PydcsClouds
from dcs.weather import Weather as PydcsWeather, CloudPreset
@dataclass(frozen=True)
class Clouds:
base: int
density: int
thickness: int
precipitation: PydcsWeather.Preceptions
preset: Optional[CloudPreset] = field(default=None)
@classmethod
def random_preset(cls, rain: bool) -> Clouds:
clouds = (p.value for p in PydcsClouds)
if rain:
presets = [p for p in clouds if "Rain" in p.name]
else:
presets = [p for p in clouds if "Rain" not in p.name]
preset = random.choice(presets)
return Clouds(
base=random.randint(preset.min_base, preset.max_base),
density=0,
thickness=0,
precipitation=PydcsWeather.Preceptions.None_,
preset=preset,
)