Fix edge-case bug in layout's group size

This commit is contained in:
Raffson 2023-04-01 17:39:42 +02:00
parent d7fda2d598
commit ce7bd9def7
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
3 changed files with 7 additions and 3 deletions

View File

@ -13,6 +13,7 @@
## Fixes ## Fixes
* **[Plugins]** Fix bug where changes to plugin options doesn't do anything. * **[Plugins]** Fix bug where changes to plugin options doesn't do anything.
* **[Campaign Management]** Fix bug in procurement when no squadrons are present. * **[Campaign Management]** Fix bug in procurement when no squadrons are present.
* **[Layouts]** Fix edge-case bug layout's group size.
# Retribution v1.1.0 # Retribution v1.1.0

View File

@ -141,7 +141,7 @@ class Campaign:
def load_ground_forces_config(self) -> TgoConfig: def load_ground_forces_config(self) -> TgoConfig:
ground_forces = self.data.get("ground_forces", {}) ground_forces = self.data.get("ground_forces", {})
if not ground_forces: if not ground_forces:
logging.warning(f"Campaign {self.name} does not define any squadrons") logging.warning(f"Campaign {self.name} does not define any ground_forces")
return TgoConfig({}) return TgoConfig({})
return TgoConfig.from_campaign_data(ground_forces) return TgoConfig.from_campaign_data(ground_forces)

View File

@ -137,11 +137,14 @@ class TgoLayoutUnitGroup:
@property @property
def group_size(self) -> int: def group_size(self) -> int:
"""The amount of units to be generated. If unit_count is defined in the layout this will be randomized accordingly. Otherwise this will be the maximum size.""" """
The amount of units to be generated. If unit_count is defined in the layout this will be
randomized accordingly. Otherwise this will be the maximum size.
"""
if self.unit_count: if self.unit_count:
if len(self.unit_count) == 1: if len(self.unit_count) == 1:
return self.unit_count[0] return self.unit_count[0]
return random.choice(range(min(self.unit_count), max(self.unit_count))) return random.choice(range(min(self.unit_count), max(self.unit_count) + 1))
return self.max_size return self.max_size
@property @property