Skip to content

Commit 7d02ce3

Browse files
authored
Merge pull request #7265 from IllianiBird/factionsExcludeCommands
Fix: Adjusted Active Faction Getter to Optionally Exclude 'Command' Factions
2 parents 0bbb030 + 4c12b68 commit 7d02ce3

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

MekHQ/src/mekhq/campaign/universe/Faction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ public boolean isInactive() {
403403
return is(FactionTag.INACTIVE);
404404
}
405405

406+
public boolean isActive() {
407+
return !isInactive();
408+
}
409+
406410
public boolean isChaos() {
407411
return is(FactionTag.CHAOS);
408412
}

MekHQ/src/mekhq/campaign/universe/Factions.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,38 @@ public Collection<Faction> getFactions() {
106106
}
107107

108108
/**
109-
* Returns a list of all factions active in a specific year.
110-
* @param date
111-
* @return
109+
* Returns a collection of all active factions on the specified date, excluding Command factions.
110+
*
111+
* <p>A faction is considered active if it is valid for the given date and not marked as inactive. Command
112+
* factions (those whose short name contains a dot, {@code .}) are not included in the results.</p>
113+
*
114+
* @param date the date for which to check faction activity
115+
* @return a collection of active factions (excluding Commands) for the specified date
112116
*/
113117
public Collection<Faction> getActiveFactions(LocalDate date) {
114-
return getFactions().stream().filter(f ->
115-
f.validIn(date) && !f.isInactive())
116-
.collect(Collectors.toList());
118+
return getActiveFactions(date, false);
119+
}
120+
121+
/**
122+
* Returns a collection of all active factions on the specified date.
123+
*
124+
* <p>A faction is considered active if it is valid for the given date and not marked as inactive.</p>
125+
*
126+
* <p>If {@code includeCommands} is {@code false}, factions whose short name contains a dot ({@code .}) are
127+
* excluded, as these denote Commands rather than standard factions. If {@code includeCommands} is {@code true},
128+
* these Command factions are included in the results.</p>
129+
*
130+
* @param date the date for which to check faction activity
131+
* @param includeCommands whether to include Command factions (those whose short name contains a dot)
132+
*
133+
* @return a collection of active factions for the specified date, optionally including Commands
134+
*/
135+
public Collection<Faction> getActiveFactions(LocalDate date, boolean includeCommands) {
136+
return getFactions().stream()
137+
.filter(f -> f.validIn(date))
138+
.filter(Faction::isActive)
139+
.filter(f -> (includeCommands || !f.getShortName().contains(".")))
140+
.toList();
117141
}
118142

119143
public Collection<String> getFactionList() {

0 commit comments

Comments
 (0)