Fix incorrect forcegroup loading

Forcegroups were not loaded correctly from preset groups during faction initialization. When a user created a new game and directly after that created another game with different factions the Forcegroups for the preset groups were still reused and therefore units which were not accessible by the faction were accidently available to the new faction.
closes #2186
This commit is contained in:
RndName 2022-05-06 19:31:40 +02:00
parent a10e55cfd7
commit 244425381d
No known key found for this signature in database
GPG Key ID: 5EF516FD9537F7C0
3 changed files with 13 additions and 7 deletions

View File

@ -12,12 +12,10 @@ if TYPE_CHECKING:
class ArmedForces:
"""TODO Description"""
# All available force groups for a specific Role
forces: list[ForceGroup]
"""Represents all ForceGroups which are available to the faction"""
def __init__(self, faction: Faction):
self.forces: list[ForceGroup] = []
with logged_duration(f"Loading armed forces for {faction.name}"):
self._load_forces(faction)

View File

@ -118,10 +118,18 @@ class ForceGroup:
return self
@classmethod
def named(cls, name: str) -> ForceGroup:
def from_preset_group(cls, name: str) -> ForceGroup:
if not cls._loaded:
cls._load_all()
return cls._by_name[name]
preset_group = cls._by_name[name]
# Return a copy of the PresetGroup as new ForceGroup
return ForceGroup(
name=str(preset_group.name),
units=list(preset_group.units),
statics=list(preset_group.statics),
tasks=list(preset_group.tasks),
layouts=list(preset_group.layouts),
)
def has_access_to_dcs_type(self, type: Type[DcsUnitType]) -> bool:
return (

View File

@ -216,7 +216,7 @@ class Faction:
]
faction.preset_groups = [
ForceGroup.named(n) for n in json.get("preset_groups", [])
ForceGroup.from_preset_group(g) for g in json.get("preset_groups", [])
]
faction.requirements = json.get("requirements", {})