@@ -97,33 +97,51 @@ public HtmlPrinter() {
9797
9898 /*todo:
9999 * T2, AP, Shock, Continous Damage from Skill to weapon table
100- * dina7 format: points and sws
101100 * Mark profiles cards that belong to the same trooper, like transformations
102101 * Mark trooper cards that belong to the same unit, like peripherals
103102 * Max Image width
104103 * Second page for units with more then 6 weapons?
105- * weapon add saving modifier, savingNum to table? -> in notes?
106104 */
107105
108106 public void printCardForArmyCode (List <UnitOption > unitOptions ,
109107 List <HackingProgram > allHackingPrograms ,
110108 List <MartialArtLevel > allMartialArtLevels ,
109+ List <BootyRoll > allBootyRolls ,
110+ List <MetaChemistryRoll > allMetaChemistryRolls ,
111111 Sectorial sectorial ,
112112 String fileName ,
113113 String armyCode ,
114114 boolean useInch ,
115+ boolean showSavingRollInstantOfAmmo ,
115116 Set <Weapon .Type > showWeaponOfType ,
116117 boolean showImage ,
117118 boolean showHackingPrograms ,
118119 Template template ) {
119- writeCards (unitOptions , allHackingPrograms , allMartialArtLevels , fileName , armyCode , sectorial , UNIT_IMAGE_FOLDER , CUSTOM_UNIT_IMAGE_FOLDER , UNIT_LOGOS_FOLDER , CARD_FOLDER , useInch , showWeaponOfType , showImage , showHackingPrograms , template );
120+ writeCards (unitOptions ,
121+ allHackingPrograms ,
122+ allMartialArtLevels ,
123+ allBootyRolls ,
124+ allMetaChemistryRolls ,
125+ fileName ,
126+ armyCode ,
127+ sectorial ,
128+ UNIT_IMAGE_FOLDER ,
129+ CUSTOM_UNIT_IMAGE_FOLDER ,
130+ UNIT_LOGOS_FOLDER ,
131+ CARD_FOLDER ,
132+ useInch ,
133+ showSavingRollInstantOfAmmo ,
134+ showWeaponOfType ,
135+ showImage ,
136+ showHackingPrograms ,
137+ template );
120138 }
121139
122140 public void printAll (Database db , boolean useInch , Template template ) {
123141 db .getAllSectorials ().stream ()
124142 .filter (s -> !s .isDiscontinued ())
125143 .flatMap (s -> db .getAllUnitsForSectorialWithoutMercs (s ).stream ())
126- .forEach (u -> writeToFile (u , db .getAllMartialArtLevels (), UNIT_IMAGE_FOLDER , CUSTOM_UNIT_IMAGE_FOLDER , UNIT_LOGOS_FOLDER , "all/" + u .getSectorial ().getSlug (), useInch , template ));
144+ .forEach (u -> writeToFile (u , db .getAllMartialArtLevels (), UNIT_IMAGE_FOLDER , CUSTOM_UNIT_IMAGE_FOLDER , UNIT_LOGOS_FOLDER , "all/" + u .getSectorial ().getSlug (), useInch , false , template ));
127145 }
128146
129147 private void copyFile (String fileName , String sourcePath , String outPath ) {
@@ -201,17 +219,19 @@ private void copyCustomUnitImages(UnitOption option, String unitImagePath, Strin
201219
202220 public void writeToFile (UnitOption unitOption ,
203221 List <MartialArtLevel > allMartialArtLevels ,
204-
205222 String unitImagePath ,
206223 String customUnitImagePath ,
207224 String logoImagePath ,
208225 String outputFolder ,
209226 boolean useInch ,
227+ boolean showSavingRollInstantOfAmmo ,
210228 Template template ) {
211229 String fileName = "%s_%s" .formatted (unitOption .getCombinedId (), unitOption .getSlug ());
212230 writeCards (List .of (unitOption ),
213231 List .of (),
214232 allMartialArtLevels ,
233+ List .of (),
234+ List .of (),
215235 fileName ,
216236 "-" ,
217237 unitOption .getSectorial (),
@@ -220,6 +240,7 @@ public void writeToFile(UnitOption unitOption,
220240 logoImagePath ,
221241 outputFolder ,
222242 useInch ,
243+ showSavingRollInstantOfAmmo ,
223244 Set .of (Weapon .Type .WEAPON , Weapon .Type .EQUIPMENT , Weapon .Type .SKILL ),
224245 true ,
225246 false ,
@@ -229,6 +250,8 @@ public void writeToFile(UnitOption unitOption,
229250 public void writeCards (List <UnitOption > unitOptions ,
230251 List <HackingProgram > allHackingPrograms ,
231252 List <MartialArtLevel > allMartialArtLevels ,
253+ List <BootyRoll > allBootyRolls ,
254+ List <MetaChemistryRoll > allMetaChemistryRolls ,
232255 String fileName ,
233256 String armyCode ,
234257 Sectorial sectorial ,
@@ -237,6 +260,7 @@ public void writeCards(List<UnitOption> unitOptions,
237260 String logoImagePath ,
238261 String outputFolder ,
239262 boolean useInch ,
263+ boolean showSavingRollInstantOfAmmo ,
240264 Set <Weapon .Type > showWeaponOfType ,
241265 boolean showImage ,
242266 boolean showHackingPrograms ,
@@ -273,7 +297,7 @@ public void writeCards(List<UnitOption> unitOptions,
273297 final List <PrintHackingProgram > programsCard1 ;
274298 final List <PrintHackingProgram > programsCard2 ;
275299
276- int maxProgramsOnFirstCard = 7 ;
300+ int maxProgramsOnFirstCard = template . numberOfHackingProgramsPerCard ;
277301 if (usedHackingPrograms .size () > maxProgramsOnFirstCard ) {
278302 programsCard1 = usedHackingPrograms .subList (0 , maxProgramsOnFirstCard );
279303 programsCard2 = usedHackingPrograms .subList (maxProgramsOnFirstCard , usedHackingPrograms .size ());
@@ -285,6 +309,9 @@ public void writeCards(List<UnitOption> unitOptions,
285309 int cardWidthInMm = template .widthInMm ;
286310 int cardHeightInMm = template .heightInMm ;
287311
312+ boolean hasBooty = hasAnySkill (unitOptions , "Booty" );
313+ boolean hasMetaChemistry = hasAnySkill (unitOptions , "MetaChemistry" );
314+
288315 Context context = new Context ();
289316 context .setVariable ("unitPrintCards" , unitPrintCards );
290317 context .setVariable ("rangeModifierClassMap" , RANGE_CLASS_MAP );
@@ -293,15 +320,17 @@ public void writeCards(List<UnitOption> unitOptions,
293320 context .setVariable ("primaryColor" , primaryColor );
294321 context .setVariable ("secondaryColor" , secondaryColor );
295322 context .setVariable ("headerColor" , headerColor );
296- context .setVariable ("showImage " , true );
323+ context .setVariable ("showSavingRollInstantOfAmmo " , showSavingRollInstantOfAmmo );
297324 context .setVariable ("printUtils" , new PrintUtils ());
298325 context .setVariable ("programs" , programsCard1 );
299326 context .setVariable ("programs2" , programsCard2 );
327+ context .setVariable ("metaChemistry" , hasMetaChemistry ? mapToPrintMetaChemistry (allMetaChemistryRolls ) : List .of ());
328+ context .setVariable ("bootyRolls" , hasBooty ? mapToPrintBootyRoll (allBootyRolls ) : List .of ());
329+ context .setVariable ("bootyWeapons" , hasBooty ? mapBootyWeapons (allBootyRolls ) : List .of ());
300330 context .setVariable ("pageSize" , "%dmm %dmm" .formatted (cardWidthInMm , cardHeightInMm ));
301331 context .setVariable ("cardWidthInMm" , "%dmm" .formatted (cardWidthInMm ));
302332 context .setVariable ("cardHeightInMm" , "%dmm" .formatted (cardHeightInMm ));
303- context .setVariable ("primaryFontSize" , template .primaryFontSize );
304- context .setVariable ("secondaryFontSize" , template .secondaryFontSize );
333+ context .setVariable ("useInch" , useInch );
305334
306335 String savePath = "%s/%s.html" .formatted (outputPath , fileName );
307336 try (FileWriter writer = new FileWriter (savePath )) {
@@ -311,6 +340,44 @@ public void writeCards(List<UnitOption> unitOptions,
311340 }
312341 }
313342
343+ private boolean hasAnySkill (List <UnitOption > unitOptions , String skillName ) {
344+ return unitOptions .stream ()
345+ .flatMap (u -> u .getAllTrooper ().stream ())
346+ .flatMap (t -> t .getProfiles ().stream ())
347+ .flatMap (s -> s .getSkills ().stream ())
348+ .anyMatch (s -> skillName .equals (s .getName ()));
349+ }
350+
351+ private List <PrintDoubleTable > mapToPrintMetaChemistry (List <MetaChemistryRoll > metaChemistryRolls ) {
352+ int halfCount = (metaChemistryRolls .size () / 2 ) - 1 ;
353+ List <PrintDoubleTable > printMetaChemistries = new ArrayList <>();
354+ for (int i = 0 ; i <= halfCount ; i ++) {
355+ MetaChemistryRoll r1 = metaChemistryRolls .get (i );
356+ MetaChemistryRoll r2 = metaChemistryRolls .get (halfCount + i + 1 );
357+ printMetaChemistries .add (new PrintDoubleTable (r1 .getRoll (), r1 .getBonus (), r2 .getRoll (), r2 .getBonus ()));
358+ }
359+ return printMetaChemistries ;
360+ }
361+
362+ private List <PrintDoubleTable > mapToPrintBootyRoll (List <BootyRoll > bootyRolls ) {
363+ int halfCount = (bootyRolls .size () / 2 ) - 1 ;
364+ List <PrintDoubleTable > doubleTables = new ArrayList <>();
365+ for (int i = 0 ; i <= halfCount ; i ++) {
366+ BootyRoll r1 = bootyRolls .get (i );
367+ BootyRoll r2 = bootyRolls .get (halfCount + i + 1 );
368+ doubleTables .add (new PrintDoubleTable (r1 .getRoll (), r1 .getBonus (), r2 .getRoll (), r2 .getBonus ()));
369+ }
370+ return doubleTables ;
371+ }
372+
373+ private List <Weapon > mapBootyWeapons (List <BootyRoll > bootyRolls ) {
374+ return bootyRolls .stream ()
375+ .flatMap (b -> b .getWeapons ().stream ())
376+ .filter (Objects ::nonNull )
377+ .distinct ()
378+ .toList ();
379+ }
380+
314381 private List <PrintHackingProgram > getUsedHackingPrograms (List <UnitOption > unitOptions , List <HackingProgram > allHackingPrograms ) {
315382 Set <Integer > hackingDeviceIds = allHackingPrograms .stream ()
316383 .flatMap (h -> Optional .ofNullable (h .getDeviceIds ()).orElse (List .of ()).stream ())
@@ -353,14 +420,13 @@ private List<PrintHackingProgram> getUsedHackingPrograms(List<UnitOption> unitOp
353420
354421 @ AllArgsConstructor
355422 public enum Template {
356- a7_image ("ColorAndOptionalImageCard " , 99 , 70 , "6pt" , "4pt" ),
357- a4_image ("ColorAndOptionalImageCard" , 297 , 210 , "18pt" , "12pt" ),
358- letter_image ("ColorAndOptionalImageCard" , 279 , 216 , "18pt" , "12pt" ),
359- card_bw ("CardBW" , 0 , 0 , "0" , "0" );
423+ a7_image ("ColorAndOptionalImageCardSmall " , 99 , 70 , 7 ),
424+ a4_image ("ColorAndOptionalImageCard" , 297 , 210 , 10 ),
425+ letter_image ("ColorAndOptionalImageCard" , 279 , 216 , 10 ),
426+ card_bw ("CardBW" , 0 , 0 , 0 );
360427 final String fileName ;
361428 final int widthInMm ;
362429 final int heightInMm ;
363- final String primaryFontSize ;
364- final String secondaryFontSize ;
430+ final int numberOfHackingProgramsPerCard ;
365431 }
366432}
0 commit comments