Revert "Use the actual Country type instead of the name."

This reverts commit bd2ec12e0f.

Country is both the data (name, ID, etc) and the container for groups
added to the miz, so it can't be used across multiple mission
generations. See https://github.com/pydcs/dcs/issues/314 for potential
follow up work that would let us do this.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2864.
This commit is contained in:
Dan Albert
2023-05-15 18:06:31 -07:00
parent 03671bbfb0
commit ca96a232f0
24 changed files with 82 additions and 64 deletions

View File

@@ -7,7 +7,7 @@ from functools import cached_property
from typing import Any, Dict, Iterator, List, Optional, TYPE_CHECKING, Type
import dcs
from dcs.country import Country
from dcs.countries import country_dict
from dcs.unittype import ShipType, StaticType, UnitType as DcsUnitType
from game.armedforces.forcegroup import ForceGroup
@@ -28,7 +28,6 @@ from game.data.doctrine import (
from game.data.groups import GroupRole
from game.data.units import UnitClass
from game.dcs.aircrafttype import AircraftType
from game.dcs.countries import country_with_name
from game.dcs.groundunittype import GroundUnitType
from game.dcs.shipunittype import ShipUnitType
from game.dcs.unittype import UnitType
@@ -44,7 +43,7 @@ class Faction:
locales: Optional[List[str]]
# Country used by this faction
country: Country
country: str = field(default="")
# Nice name of the faction
name: str = field(default="")
@@ -169,15 +168,15 @@ class Faction:
@classmethod
def from_dict(cls: Type[Faction], json: Dict[str, Any]) -> Faction:
try:
country = country_with_name(json["country"])
except KeyError as ex:
raise KeyError(
f'Faction\'s country ("{json.get("country")}") is not a valid DCS '
"country ID"
) from ex
faction = Faction(locales=json.get("locales"))
faction = Faction(locales=json.get("locales"), country=country)
faction.country = json.get("country", "/")
if faction.country not in [c.name for c in country_dict.values()]:
raise AssertionError(
'Faction\'s country ("{}") is not a valid DCS country ID'.format(
faction.country
)
)
faction.name = json.get("name", "")
if not faction.name: