dcs_liberation/game/settings/boundedfloatoption.py
Dan Albert 7bec4c62f7 Generate settings pages automatically.
This adds metadata to settings fields that can be used to automatically
generate the settings window. For now I have replaced the Difficulty
page. Will follow up to replace the others.
2021-10-21 18:30:56 -07:00

32 lines
664 B
Python

from dataclasses import dataclass, field
from typing import Any, Optional
from .optiondescription import OptionDescription, SETTING_DESCRIPTION_KEY
@dataclass(frozen=True)
class BoundedFloatOption(OptionDescription):
min: float
max: float
divisor: int
def bounded_float_option(
text: str,
page: str,
section: str,
min: float,
max: float,
divisor: int,
detail: Optional[str] = None,
**kwargs: Any,
) -> float:
return field(
metadata={
SETTING_DESCRIPTION_KEY: BoundedFloatOption(
page, section, text, detail, min, max, divisor
)
},
**kwargs,
)