mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add campaign property for campaign start time.
This field is optional. Omitting the field (or using only a date instead of a full timestamp) will use the old behavior of picking a random daylight hour to start the campaign. This doesn't include any UI in the new game wizard yet. This is only a campaign yaml option. https://github.com/dcs-liberation/dcs_liberation/issues/2400
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional, Tuple
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
import yaml
|
||||
from packaging.version import Version
|
||||
@@ -49,7 +48,8 @@ class Campaign:
|
||||
|
||||
recommended_player_faction: str
|
||||
recommended_enemy_faction: str
|
||||
recommended_start_date: Optional[datetime.date]
|
||||
recommended_start_date: datetime.date | None
|
||||
recommended_start_time: datetime.time | None
|
||||
|
||||
recommended_player_money: int
|
||||
recommended_enemy_money: int
|
||||
@@ -64,10 +64,7 @@ class Campaign:
|
||||
@classmethod
|
||||
def from_file(cls, path: Path) -> Campaign:
|
||||
with path.open() as campaign_file:
|
||||
if path.suffix.lower() == ".yaml":
|
||||
data = yaml.safe_load(campaign_file)
|
||||
else:
|
||||
data = json.load(campaign_file)
|
||||
data = yaml.safe_load(campaign_file)
|
||||
|
||||
sanitized_theater = data["theater"].replace(" ", "")
|
||||
version_field = data.get("version", "0")
|
||||
@@ -80,14 +77,15 @@ class Campaign:
|
||||
version = Version(str(version_field))
|
||||
|
||||
start_date_raw = data.get("recommended_start_date")
|
||||
|
||||
# YAML automatically parses dates, but while we still support JSON campaigns we
|
||||
# need to be able to handle parsing dates from strings ourselves as well.
|
||||
start_date: Optional[datetime.date]
|
||||
if isinstance(start_date_raw, str):
|
||||
start_date = datetime.date.fromisoformat(start_date_raw)
|
||||
# YAML automatically parses dates.
|
||||
start_date: datetime.date | None
|
||||
start_time: datetime.time | None = None
|
||||
if isinstance(start_date_raw, datetime.datetime):
|
||||
start_date = start_date_raw.date()
|
||||
start_time = start_date_raw.time()
|
||||
elif isinstance(start_date_raw, datetime.date):
|
||||
start_date = start_date_raw
|
||||
start_time = None
|
||||
elif start_date_raw is None:
|
||||
start_date = None
|
||||
else:
|
||||
@@ -104,6 +102,7 @@ class Campaign:
|
||||
data.get("recommended_player_faction", "USA 2005"),
|
||||
data.get("recommended_enemy_faction", "Russia 1990"),
|
||||
start_date,
|
||||
start_time,
|
||||
data.get("recommended_player_money", DEFAULT_BUDGET),
|
||||
data.get("recommended_enemy_money", DEFAULT_BUDGET),
|
||||
data.get("recommended_player_income_multiplier", 1.0),
|
||||
|
||||
Reference in New Issue
Block a user