ApplicationConfig.java (3959B)
1 package fr.kevincorvisier.mtg.gdb; 2 3 import java.util.Date; 4 import java.util.GregorianCalendar; 5 import java.util.List; 6 import java.util.Set; 7 8 import org.apache.commons.collections4.ListUtils; 9 import org.springframework.beans.factory.annotation.Value; 10 import org.springframework.context.annotation.Bean; 11 import org.springframework.context.annotation.ComponentScan; 12 import org.springframework.context.annotation.Configuration; 13 import org.springframework.context.annotation.PropertySource; 14 import org.springframework.core.convert.ConversionService; 15 import org.springframework.core.convert.support.DefaultConversionService; 16 17 import forge.game.GameFormat; 18 import forge.game.GameFormat.FormatSubType; 19 import forge.game.GameFormat.FormatType; 20 import forge.model.FModel; 21 import fr.kevincorvisier.mtg.gdb.spring.converters.StringToCardListFileConverter; 22 import fr.kevincorvisier.mtg.gdb.spring.converters.StringToFileConverter; 23 import fr.kevincorvisier.mtg.gdb.spring.converters.StringToWinRatioContinueConditionConverter; 24 25 @Configuration 26 @PropertySource("application.properties") 27 @PropertySource("evaluation.properties") 28 @PropertySource("population.properties") 29 @ComponentScan("fr.kevincorvisier.mtg.gdb") 30 public class ApplicationConfig 31 { 32 private static final Date MIDDLE_SCHOOL_EFFECTIVE_DATE = Date.from(new GregorianCalendar(2023, 5, 1).toInstant()); 33 private static final Iterable<String> MIDDLE_SCHOOL_SETS = Set.of("4ED", "ICE", "CHR", "HML", "ALL", "MIR", "VIS", "5ED", "WTH", "POR", "TMP", "STH", "EXO", 34 "PO2", "USG", "ULG", "6ED", "UDS", "PTK", "S99", "MMQ", "NMS", "PCY", "S00", "INV", "PLS", "7ED", "APC", "ODY", "TOR", "JUD", "ONS", "LGN", "SCG", 35 "ATH", "BRB", "BTD", "DKM"); 36 private static final List<String> MIDDLE_SCHOOL_BANNED_CARDS = List.of("Amulet of Quoz", "Balance", "Brainstorm", "Bronze Tablet", "Channel", "Dark Ritual", 37 "Demonic Consultation", "Flash", "Goblin Recruiter", "Imperial Seal", "Jeweled Bird", "Mana Crypt", "Mana Vault", "Memory Jar", "Mind’s Desire", 38 "Mind Twist", "Rebirth", "Strip Mine", "Tempest Efreet", "Timmerian Fiends", "Tolarian Academy", "Vampiric Tutor", "Windfall", "Yawgmoth’s Bargain", 39 "Yawgmoth’s Will"); 40 private static final List<String> MIDDLE_SCHOOL_ADDITIONAL_CARDS = List.of("Arena", "Sewers of Estark", "Nalathni Dragon", "Giant Badger", 41 "Windseeker Centaur"); 42 43 @Bean 44 public GameFormat format(@Value("${format}") final String formatName) 45 { 46 if ("MiddleSchool".equals(formatName)) 47 return getMiddleSchool(); 48 49 else if ("PreMiddleSchool".equals(formatName)) 50 { 51 final GameFormat middleSchool = getMiddleSchool(); 52 final GameFormat premodern = FModel.getFormats().get("Premodern"); 53 54 final Iterable<String> sets = ListUtils.intersection(middleSchool.getAllowedSetCodes(), premodern.getAllowedSetCodes()); 55 final List<String> bannedCards = ListUtils.union(middleSchool.getBannedCardNames(), premodern.getBannedCardNames()); 56 final List<String> additionalCards = ListUtils.intersection(middleSchool.getAdditionalCards(), premodern.getAdditionalCards()); 57 58 return new GameFormat("PreMiddleSchool", MIDDLE_SCHOOL_EFFECTIVE_DATE, sets, bannedCards, null, false, additionalCards, null, 0, FormatType.CUSTOM, 59 FormatSubType.CUSTOM); 60 } 61 else 62 return FModel.getFormats().get(formatName); 63 } 64 65 private GameFormat getMiddleSchool() 66 { 67 return new GameFormat("MiddleSchool", MIDDLE_SCHOOL_EFFECTIVE_DATE, MIDDLE_SCHOOL_SETS, MIDDLE_SCHOOL_BANNED_CARDS, null, false, 68 MIDDLE_SCHOOL_ADDITIONAL_CARDS, null, 0, FormatType.CUSTOM, FormatSubType.CUSTOM); 69 } 70 71 @Bean 72 public ConversionService conversionService() 73 { 74 final DefaultConversionService conversionService = new DefaultConversionService(); 75 conversionService.addConverter(new StringToCardListFileConverter(conversionService)); 76 conversionService.addConverter(new StringToFileConverter()); 77 conversionService.addConverter(new StringToWinRatioContinueConditionConverter()); 78 return conversionService; 79 } 80 }