mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
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.
46 lines
1.2 KiB
Python
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,
|
|
)
|