dcs_liberation/game/settings/boundedfloatoption.py
Dan Albert e2c6d6788c Persist some campaign creation options.
We should also persist mod options, but those will go in a separate file
because they aren't a part of Settings.

Plugins need some work before that can be saved here. They're not
configurable in the NGW currently, so that needs to be fixed first. It
also appears that it may not be safe to inject the settings object with
plugin options until the game is created, but that needs more
investigation (see the comment in Settings.save_player_settings).

Another obvious candidate would be the desired player mission duration,
but we need to implement custom serialization for that first.
2023-04-24 22:49:30 -07:00

45 lines
1.0 KiB
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,
default: float,
min: float,
max: float,
divisor: int,
detail: Optional[str] = None,
tooltip: Optional[str] = None,
remember_player_choice: bool = False,
**kwargs: Any,
) -> float:
return field(
metadata={
SETTING_DESCRIPTION_KEY: BoundedFloatOption(
page,
section,
text,
detail,
tooltip,
causes_expensive_game_update=False,
remember_player_choice=remember_player_choice,
min=min,
max=max,
divisor=divisor,
)
},
default=default,
**kwargs,
)