dcs_liberation/game/settings/minutesoption.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

46 lines
1.2 KiB
Python

from dataclasses import dataclass, field
from datetime import timedelta
from typing import Any, Optional
from .optiondescription import OptionDescription, SETTING_DESCRIPTION_KEY
@dataclass(frozen=True)
class MinutesOption(OptionDescription):
min: int
max: int
def minutes_option(
text: str,
page: str,
section: str,
default: timedelta,
min: int,
max: int,
detail: Optional[str] = None,
tooltip: Optional[str] = None,
**kwargs: Any,
) -> timedelta:
return field(
metadata={
SETTING_DESCRIPTION_KEY: MinutesOption(
page,
section,
text,
detail,
tooltip,
causes_expensive_game_update=False,
# Can't preserve timedelta until we create some custom serialization for
# it. The default serialization is as a python object, which isn't
# allowed in yaml.safe_load because a malicious modification of the
# settings file would be able to execute arbitrary code.
remember_player_choice=False,
min=min,
max=max,
)
},
default=default,
**kwargs,
)