Improve the optional unit handling in layouts

added the fill property to the layout groups which allows to specify if a optional layout group should be filled with a faction accessible unit if it was not defined by the preset groups. This is usefull to allow more generalized templates which for example may or may not have a Search Radar without adding one to all layouts (example: Rapier and Roland Sites which use the generic SHORAD layout)

this fixes an issue which prevented optional units like logistics to be added to the forcegroup if they were not defined in the preset group yaml
This commit is contained in:
RndName
2022-03-21 20:17:17 +01:00
parent 923549ef69
commit 4ace13c857
9 changed files with 51 additions and 3 deletions

View File

@@ -96,6 +96,9 @@ class TgoLayoutGroup:
# Defines if this groupTemplate is required or not
optional: bool = False
# Should this be filled by accessible units if optional or not
fill: bool = True
def possible_types_for_faction(self, faction: Faction) -> list[Type[DcsUnitType]]:
"""Determine the possible dcs unit types for the TgoLayoutGroup and the given faction"""
unit_types = [t for t in self.unit_types if faction.has_access_to_dcs_type(t)]

View File

@@ -166,6 +166,7 @@ class LayoutLoader:
group_mapping.fallback_classes,
)
group_layout.optional = group_mapping.optional
group_layout.fill = group_mapping.fill
# Add the group at the correct index
layout.add_layout_group(group_name, group_layout, g_id)
layout_unit = LayoutUnit.from_unit(unit)

View File

@@ -19,6 +19,9 @@ class GroupLayoutMapping:
# Defines if the group is required for the template or can be skipped
optional: bool = False
# Should this be filled by accessible units if optional or not
fill: bool = True
# All static units for the group
statics: list[str] = field(default_factory=list)
@@ -40,6 +43,7 @@ class GroupLayoutMapping:
@staticmethod
def from_dict(d: dict[str, Any]) -> GroupLayoutMapping:
optional = d["optional"] if "optional" in d else False
fill = d["fill"] if "fill" in d else True
statics = d["statics"] if "statics" in d else []
unit_count = d["unit_count"] if "unit_count" in d else []
unit_types = []
@@ -59,6 +63,7 @@ class GroupLayoutMapping:
return GroupLayoutMapping(
d["name"],
optional,
fill,
statics,
unit_count,
unit_types,