mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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:
parent
a10e55cfd7
commit
244425381d
@ -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)
|
||||
|
||||
|
||||
@ -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 (
|
||||
|
||||
@ -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", {})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user