Load TgoLayoutGroups in correct order

Add handling to insert the layout group at the correct index according to the order used in the layout yaml
This commit is contained in:
RndName 2022-02-23 00:06:34 +01:00
parent ac80c4adc1
commit ff12b37431
No known key found for this signature in database
GPG Key ID: 5EF516FD9537F7C0
3 changed files with 13 additions and 6 deletions

View File

@ -168,6 +168,13 @@ class TgoLayout:
# campaign initialization. For each generic layout a new Group will be created.
self.generic: bool = False
def add_layout_group(
self, name: str, group: TgoLayoutGroup, index: int = 0
) -> None:
"""Adds the layout group to the group dict at the given index"""
# If the index is greater than the actual len it will add it after the last item
self.groups[name].insert(min(len(self.groups[name]), index), group)
def usable_by_faction(self, faction: Faction) -> bool:
# Special handling for Buildings
if (

View File

@ -127,7 +127,7 @@ class LayoutLoader:
):
try:
group_name, group_mapping = mapping.group_for_name(
g_id, group_name, group_mapping = mapping.group_for_name(
dcs_group.name
)
except KeyError:
@ -166,8 +166,8 @@ class LayoutLoader:
group_mapping.fallback_classes,
)
group_layout.optional = group_mapping.optional
# Add the group at the correct position
layout.groups[group_name].append(group_layout)
# Add the group at the correct index
layout.add_layout_group(group_name, group_layout, g_id)
layout_unit = LayoutUnit.from_unit(unit)
if i == 0 and layout.name not in template_position:
template_position[layout.name] = unit.position

View File

@ -118,9 +118,9 @@ class LayoutMapping:
layout_file,
)
def group_for_name(self, name: str) -> tuple[str, GroupLayoutMapping]:
def group_for_name(self, name: str) -> tuple[int, str, GroupLayoutMapping]:
for group_name, group_mappings in self.groups.items():
for group_mapping in group_mappings:
for g_id, group_mapping in enumerate(group_mappings):
if group_mapping.name == name or name in group_mapping.statics:
return group_name, group_mapping
return g_id, group_name, group_mapping
raise KeyError