Skip to content

Commit 03dd96f

Browse files
authored
Add Combat Group Number (#124)
1 parent bb10523 commit 03dd96f

29 files changed

Lines changed: 134 additions & 36 deletions

app/src/main/java/de/twonirwana/infinity/ExportArmyCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.Set;
1010

1111
public class ExportArmyCode {
12-
public static void main(String[] args) {
12+
static void main(String[] args) {
1313
Database db = DatabaseImp.createTimedUpdate();
1414

1515
String armyCode = args[0];
@@ -44,6 +44,7 @@ public static void main(String[] args) {
4444
useInch,
4545
false,
4646
false,
47+
false,
4748
Set.of(Weapon.Type.WEAPON, Weapon.Type.EQUIPMENT, Weapon.Type.SKILL, Weapon.Type.TURRET),
4849
true,
4950
false,

app/src/main/java/de/twonirwana/infinity/HtmlPrinter.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.nio.file.StandardCopyOption;
2121
import java.time.LocalDateTime;
2222
import java.util.*;
23+
import java.util.concurrent.ConcurrentSkipListSet;
2324
import java.util.concurrent.CopyOnWriteArraySet;
2425
import java.util.stream.Collectors;
2526
import java.util.stream.Stream;
@@ -122,6 +123,7 @@ public void printCardForArmyCode(List<UnitOption> unitOptions,
122123
String armyCode,
123124
boolean useInch,
124125
boolean showSavingRollInsteadOfAmmo,
126+
boolean removeDuplicates,
125127
boolean reduceColor,
126128
Set<Weapon.Type> showWeaponOfType,
127129
boolean showImage,
@@ -143,6 +145,7 @@ public void printCardForArmyCode(List<UnitOption> unitOptions,
143145
CARD_FOLDER,
144146
useInch,
145147
showSavingRollInsteadOfAmmo,
148+
removeDuplicates,
146149
reduceColor,
147150
showWeaponOfType,
148151
showImage,
@@ -266,6 +269,7 @@ public void writeToFile(UnitOption unitOption,
266269
outputFolder,
267270
useInch,
268271
showSavingRollInsteadOfAmmo,
272+
false,
269273
reduceColor,
270274
Set.of(Weapon.Type.WEAPON, Weapon.Type.EQUIPMENT, Weapon.Type.SKILL),
271275
true,
@@ -289,6 +293,7 @@ public void writeCards(List<UnitOption> unitOptions,
289293
String outputFolder,
290294
boolean useInch,
291295
boolean showSavingRollInsteadOfAmmo,
296+
boolean removeDuplicates,
292297
boolean reduceColor,
293298
Set<Weapon.Type> showWeaponOfType,
294299
boolean showImage,
@@ -335,10 +340,26 @@ public void writeCards(List<UnitOption> unitOptions,
335340
boarderColor = SECTORIAL_COLORS.get(sectorial.getParentId() - 1);
336341
}
337342

338-
339-
List<UnitPrintCard> unitPrintCards = unitOptions.stream()
340-
.flatMap(u -> UnitPrintCard.fromUnitOption(u, useInch, showWeaponOfType, showImage, allMartialArtLevels).stream())
341-
.toList();
343+
final List<UnitPrintCard> unitPrintCards;
344+
if (removeDuplicates) {
345+
Set<String> ids = new ConcurrentSkipListSet<>();
346+
unitPrintCards = unitOptions.stream()
347+
.flatMap(u -> UnitPrintCard.fromUnitOption(u, useInch, showWeaponOfType, showImage, allMartialArtLevels, null).stream())
348+
.filter(u -> {
349+
if (ids.contains(u.getCombinedProfileId())) {
350+
return false;
351+
} else {
352+
ids.add(u.getCombinedProfileId());
353+
return true;
354+
}
355+
})
356+
.toList();
357+
} else {
358+
unitPrintCards = armyList.getCombatGroups().entrySet().stream()
359+
.flatMap(e -> e.getValue().stream()
360+
.flatMap(uo -> UnitPrintCard.fromUnitOption(uo, useInch, showWeaponOfType, showImage, allMartialArtLevels, e.getKey()).stream())
361+
).toList();
362+
}
342363

343364
List<PrintHackingProgram> usedHackingPrograms = showHackingPrograms ? getUsedHackingPrograms(unitOptions, allHackingPrograms) : List.of();
344365

app/src/main/java/de/twonirwana/infinity/UnitPrintCard.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ public class UnitPrintCard {
2020
Set<Weapon.Type> showWeaponOfType;
2121
boolean showImage;
2222
MartialArtLevel martialArtLevel;
23+
Integer combatGroup;
2324

2425
public static List<UnitPrintCard> fromUnitOption(UnitOption unitOption,
2526
boolean useInch,
2627
Set<Weapon.Type> showWeaponOfType,
2728
boolean showImage,
28-
List<MartialArtLevel> allMartialArtLevels) {
29+
List<MartialArtLevel> allMartialArtLevels,
30+
Integer combatGroup) {
2931
Map<String, MartialArtLevel> martialArtLevelMap = allMartialArtLevels.stream()
3032
.collect(Collectors.toMap(MartialArtLevel::getName, Function.identity()));
3133
return unitOption.getAllTrooper().stream()
@@ -35,7 +37,7 @@ public static List<UnitPrintCard> fromUnitOption(UnitOption unitOption,
3537
useInch,
3638
showWeaponOfType,
3739
showImage,
38-
PrintUtils.getMartialArtLevel(p, martialArtLevelMap).orElse(null))))
40+
PrintUtils.getMartialArtLevel(p, martialArtLevelMap).orElse(null), combatGroup)))
3941
.toList();
4042
}
4143

app/src/main/java/de/twonirwana/infinity/util/UnitNameCheck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.Set;
99

1010
public class UnitNameCheck {
11-
public static void main(final String[] args) {
11+
static void main() {
1212

1313
/*
1414
new DatabaseImp().getAllUnitOptions().stream()
@@ -27,7 +27,7 @@ public static void main(final String[] args) {
2727

2828

2929
DatabaseImp.createTimedUpdate().getAllUnitOptions().stream()
30-
.flatMap(u -> UnitPrintCard.fromUnitOption(u, true, Set.of(Weapon.Type.WEAPON, Weapon.Type.EQUIPMENT, Weapon.Type.SKILL), true, List.of()).stream())
30+
.flatMap(u -> UnitPrintCard.fromUnitOption(u, true, Set.of(Weapon.Type.WEAPON, Weapon.Type.EQUIPMENT, Weapon.Type.SKILL), true, List.of(), null).stream())
3131
.map(c -> {
3232
String oldName = c.getProfile().getName();
3333
String newName = c.getUnitName();

app/src/main/resources/templates/ColorAndOptionalImageCard.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@
112112
gap: 2px;
113113
}
114114

115+
.unit-group-number {
116+
width: 30px;
117+
background-color: [[${secondaryColor}]];
118+
119+
display: flex;
120+
justify-content: center;
121+
align-items: center;
122+
123+
border: 4px solid lightgrey;
124+
font-size: 40px;
125+
font-weight: bold;
126+
color: [[${headerColor}]];
127+
}
128+
115129
.unit-header-icon {
116130
height: 85px;
117131
width: 85px;

app/src/main/resources/templates/ColorAndOptionalImageCard6.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@
112112
gap: 2px;
113113
}
114114

115+
.unit-group-number {
116+
width: 30px;
117+
background-color: [[${secondaryColor}]];
118+
119+
display: flex;
120+
justify-content: center;
121+
align-items: center;
122+
123+
border: 4px solid lightgrey;
124+
font-size: 40px;
125+
font-weight: bold;
126+
color: [[${headerColor}]];
127+
}
128+
115129
.unit-header-icon {
116130
height: 85px;
117131
width: 85px;

app/src/main/resources/templates/ColorAndOptionalImageCardSmall.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@
112112
gap: 2px;
113113
}
114114

115+
.unit-group-number {
116+
width: 12px;
117+
background-color: [[${secondaryColor}]];
118+
119+
display: flex;
120+
justify-content: center;
121+
align-items: center;
122+
123+
border: 1px solid lightgrey;
124+
font-size: 16px;
125+
font-weight: bold;
126+
color: [[${headerColor}]];
127+
}
128+
115129
.unit-header-icon {
116130
height: 30px;
117131
width: 30px;

app/src/main/resources/templates/OverviewList.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@
130130
gap: 2px;
131131
}
132132

133+
.unit-group-number {
134+
width: 10px;
135+
background-color: [[${secondaryColor}]];
136+
137+
display: flex;
138+
justify-content: center;
139+
align-items: center;
140+
141+
border: 2px solid lightgrey;
142+
font-size: 12px;
143+
font-weight: bold;
144+
color: [[${headerColor}]];
145+
}
146+
133147
.unit-header-icon {
134148
height: 20px;
135149
width: 20px;

app/src/main/resources/templates/fragments/UnitHeader.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ <h2 class="card-header-title">
1616
<img th:src="@{image/{fileName}(fileName=${imageName})}"
1717
alt="Unit icon" class="unit-header-icon">
1818
</th:block>
19+
<div class="unit-group-number" th:if="${unitPrintCard.getCombatGroup() != null}" th:text="${unitPrintCard.getCombatGroup()}"></div>
1920
</div>
2021
</div>
2122

app/src/test/java/de/twonirwana/infinity/HtmlPrinterTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ private static Stream<Arguments> generateTestData() {
4242
for (Set<Weapon.Type> weaponOption : WEAPON_TYPE_OPTIONS) {
4343
for (boolean showImage : new boolean[]{true, false}) {
4444
for (boolean showHackingProgram : new boolean[]{true, false}) {
45-
for (boolean reduceColor : new boolean[]{true, false}) {
46-
for (HtmlPrinter.Template template : HtmlPrinter.Template.values()) {
47-
testData.add(Arguments.of(useInch, weaponOption, showImage, showHackingProgram, showSavingRollInsteadOfAmmo, reduceColor, template));
45+
for (boolean removeDuplicate : new boolean[]{true, false}) {
46+
for (boolean reduceColor : new boolean[]{true, false}) {
47+
for (HtmlPrinter.Template template : HtmlPrinter.Template.values()) {
48+
testData.add(Arguments.of(useInch, weaponOption, showImage, showHackingProgram, showSavingRollInsteadOfAmmo, removeDuplicate, reduceColor, template));
49+
}
4850
}
4951
}
5052
}
@@ -153,7 +155,7 @@ void setup() {
153155

154156
@ParameterizedTest
155157
@MethodSource("generateTestData")
156-
void testHtml(boolean useInch, Set<Weapon.Type> weaponOption, boolean showImage, boolean showHackingProgram, boolean showSavingRollInsteadOfAmmo, boolean reduceColor, HtmlPrinter.Template template) {
158+
void testHtml(boolean useInch, Set<Weapon.Type> weaponOption, boolean showImage, boolean showHackingProgram, boolean showSavingRollInsteadOfAmmo, boolean removeDuplicate, boolean reduceColor, HtmlPrinter.Template template) {
157159
fileName = "testFile_" + System.currentTimeMillis();
158160
underTest.writeCards(List.of(unitOption),
159161
List.of(hackingProgram),
@@ -171,6 +173,7 @@ void testHtml(boolean useInch, Set<Weapon.Type> weaponOption, boolean showImage,
171173
"",
172174
useInch,
173175
showSavingRollInsteadOfAmmo,
176+
removeDuplicate,
174177
reduceColor,
175178
weaponOption,
176179
showImage,

0 commit comments

Comments
 (0)