public void GetCoaForFlagNameReturnsNullOnNonMatch() { var coaMapper = new CoaMapper("TestFiles/CoatsOfArms.txt"); Assert.Null(coaMapper.GetCoaForFlagName("e_IMPTOCK3_WRONG")); }
public void InitializeFromTag( Country country, CountryCollection imperatorCountries, LocDB locDB, ProvinceMapper provinceMapper, CoaMapper coaMapper, GovernmentMapper governmentMapper, SuccessionLawMapper successionLawMapper, DefiniteFormMapper definiteFormMapper, ReligionMapper religionMapper, CultureMapper cultureMapper, NicknameMapper nicknameMapper, CharacterCollection characters, Date conversionDate ) { IsImportedOrUpdatedFromImperator = true; ImperatorCountry = country; ImperatorCountry.CK3Title = this; LocBlock?validatedName = GetValidatedName(country, imperatorCountries, locDB); HasDefiniteForm.Value = definiteFormMapper.IsDefiniteForm(ImperatorCountry.Name); RulerUsesTitleName.Value = false; PlayerCountry = ImperatorCountry.PlayerCountry; ClearHolderSpecificHistory(); FillHolderAndGovernmentHistory(); // ------------------ determine color var color1Opt = ImperatorCountry.Color1; if (color1Opt is not null) { Color1 = color1Opt; } var color2Opt = ImperatorCountry.Color2; if (color2Opt is not null) { Color2 = color2Opt; } // determine successions laws history.InternalHistory.AddFieldValue("succession_laws", successionLawMapper.GetCK3LawsForImperatorLaws(ImperatorCountry.GetLaws()), conversionDate, "succession_laws" ); // determine CoA CoA = coaMapper.GetCoaForFlagName(ImperatorCountry.Flag); // determine other attributes var srcCapital = ImperatorCountry.Capital; if (srcCapital is not null) { var provMappingsForImperatorCapital = provinceMapper.GetCK3ProvinceNumbers((ulong)srcCapital); if (provMappingsForImperatorCapital.Count > 0) { var foundCounty = parentCollection.GetCountyForProvince(provMappingsForImperatorCapital[0]); if (foundCounty is not null) { CapitalCounty = foundCounty; } } } // determine country name localization var nameSet = false; if (validatedName is not null) { var nameLocBlock = Localizations.AddLocBlock(Id); nameLocBlock.CopyFrom(validatedName); nameSet = true; } if (!nameSet) { var impTagLoc = locDB.GetLocBlockForKey(ImperatorCountry.Tag); if (impTagLoc is not null) { var nameLocBlock = Localizations.AddLocBlock(Id); nameLocBlock.CopyFrom(impTagLoc); nameSet = true; } } if (!nameSet) { // use unlocalized name if not empty var name = ImperatorCountry.Name; if (!string.IsNullOrEmpty(name)) { Logger.Warn($"Using unlocalized Imperator name {name} as name for {Id}!"); var nameLocBlock = Localizations.AddLocBlock(Id); nameLocBlock["english"] = name; nameLocBlock.FillMissingLocWithBaseLanguageLoc(); nameSet = true; } } // giving up if (!nameSet) { Logger.Warn($"{Id} needs help with localization! {ImperatorCountry.Name}?"); } // determine adjective localization TrySetAdjectiveLoc(locDB, imperatorCountries); void FillHolderAndGovernmentHistory() { // ------------------ determine previous and current holders // there was no 0 AD, but year 0 works in game and serves well for adding BC characters to holder history var firstPossibleDate = new Date(0, 1, 1); foreach (var impRulerTerm in ImperatorCountry.RulerTerms) { var rulerTerm = new RulerTerm( impRulerTerm, characters, governmentMapper, locDB, religionMapper, cultureMapper, nicknameMapper, provinceMapper ); var characterId = rulerTerm.CharacterId; var gov = rulerTerm.Government; var startDate = new Date(rulerTerm.StartDate); if (startDate < firstPossibleDate) { startDate = new Date(firstPossibleDate); // TODO: remove this workaround if CK3 supports negative dates firstPossibleDate.ChangeByDays(1); } history.InternalHistory.AddFieldValue("holder", characterId, startDate, "holder"); if (gov is not null) { history.InternalHistory.AddFieldValue("government", gov, startDate, "government"); } } if (ImperatorCountry.Government is not null) { var lastCK3TermGov = history.GetGovernment(conversionDate); var ck3CountryGov = governmentMapper.GetCK3GovernmentForImperatorGovernment(ImperatorCountry.Government); if (lastCK3TermGov != ck3CountryGov && ck3CountryGov is not null) { history.InternalHistory.AddFieldValue("government", ck3CountryGov, conversionDate, "government"); } } } }
public void GetCoaForFlagNameReturnsCoaOnMatch() { var coaMapper = new CoaMapper("TestFiles/CoatsOfArms.txt"); // ReSharper disable once StringLiteralTypo const string coa1 = @"{ pattern=""pattern_solid.tga"" color1=ck2_green color2=bone_white color3=pitch_black colored_emblem={ color1=bone_white color2=ck2_blue texture=""ce_lamassu_01.dds"" mask ={ 1 2 3 } instance={ position={ 0.500000 0.500000 } scale={ 0.750000 0.750000 } depth=0.010000 rotation=0 } } colored_emblem={ color1=bone_white color2=ck2_blue texture=""ce_border_simple_02.tga"" mask ={ 1 2 3 } instance={ position={ 0.500000 0.500000 } scale={ 1.000000 1.000000 } depth=0.010000 rotation=90 } instance={ position={ 0.500000 0.500000 } scale={ 1.000000 1.000000 } depth=0.010000 rotation=270 } } }"; const string coa2 = "{\n" + "\tpattern =\"pattern_solid.tga\"\n" + "\tcolor1 =\"dark_green\"\n" + "\tcolor2 =\"offwhite\"\n" + "\tcolored_emblem ={\n" + "\t\ttexture =\"ce_pegasus_01.dds\"\n" + "\t\tcolor1 =\"bone_white\"\n" + "\t\tcolor2 =\"offwhite\"\n" + "\t\tinstance ={\n" + "\t\t\tscale ={-0.9 0.9 }\"\n" + "\t\t}\n" + "\t}\n" + "\tcolored_emblem ={\n" + "\t\ttexture =\"ce_border_simple_02.tga\"\n" + "\t\tcolor1 =\"bone_white\"\n" + "\t\tcolor2 =\"dark_green\"\n" + "\t\tinstance ={\n" + "\t\t\trotation =0\n" + "\t\t\tscale ={-1.0 1.0 }\n" + "\t\t}\n" + "\t\tinstance ={\n" + "\t\t\trotation =180\n" + "\t\t\tscale ={-1.0 1.0 }\n" + "\t\t}\n" + "\t}\n" + "}"; const string coa3 = @"{ pattern =""pattern_solid.tga"" color1=""offwhite"" color2 =""phrygia_red"" colored_emblem ={ texture =""ce_knot_01.dds"" color1 =""phrygia_red"" instance ={ scale ={0.75 0.75 } } } }"; Assert.Equal(coa1.Split('\n').Length, coaMapper.GetCoaForFlagName("e_IMPTOCK3_ADI").Split('\n').Length); Assert.Equal(coa2.Split('\n').Length, coaMapper.GetCoaForFlagName("e_IMPTOCK3_AMK").Split('\n').Length); Assert.Equal(coa3.Split('\n').Length, coaMapper.GetCoaForFlagName("e_IMPTOCK3_ANG").Split('\n').Length); }
public void InitializeFromTag( Imperator.Countries.Country country, Dictionary <ulong, Imperator.Countries.Country> imperatorCountries, LocalizationMapper localizationMapper, LandedTitles landedTitles, ProvinceMapper provinceMapper, CoaMapper coaMapper, TagTitleMapper tagTitleMapper, GovernmentMapper governmentMapper, SuccessionLawMapper successionLawMapper, DefiniteFormMapper definiteFormMapper ) { IsImportedOrUpdatedFromImperator = true; ImperatorCountry = country; // ------------------ determine CK3 title LocBlock?validatedName; // hard code for Antigonid Kingdom, Seleucid Empire and Maurya (which use customizable localization for name and adjective) if (ImperatorCountry.Name == "PRY_DYN") { validatedName = localizationMapper.GetLocBlockForKey("get_pry_name_fallback"); } else if (ImperatorCountry.Name == "SEL_DYN") { validatedName = localizationMapper.GetLocBlockForKey("get_sel_name_fallback"); } else if (ImperatorCountry.Name == "MRY_DYN") { validatedName = localizationMapper.GetLocBlockForKey("get_mry_name_fallback"); } // normal case else { validatedName = ImperatorCountry.CountryName.GetNameLocBlock(localizationMapper, imperatorCountries); } HasDefiniteForm = definiteFormMapper.IsDefiniteForm(ImperatorCountry.Name); string?title; if (validatedName is not null) { title = tagTitleMapper.GetTitleForTag(ImperatorCountry.Tag, ImperatorCountry.GetCountryRank(), validatedName.english); } else { title = tagTitleMapper.GetTitleForTag(ImperatorCountry.Tag, ImperatorCountry.GetCountryRank()); } if (title is null) { throw new ArgumentException("Country " + ImperatorCountry.Tag + " could not be mapped!"); } Name = title; SetRank(); PlayerCountry = ImperatorCountry.PlayerCountry; // ------------------ determine previous and current holders history.InternalHistory.SimpleFields.Remove("holder"); history.InternalHistory.SimpleFields.Remove("government"); // there was no 0 AD, but year 0 works in game and serves well for adding BC characters to holder history var firstPossibleDate = new Date(0, 1, 1); foreach (var impRulerTerm in ImperatorCountry.RulerTerms) { var rulerTerm = new RulerTerm(impRulerTerm, governmentMapper); var characterId = rulerTerm.CharacterId; var gov = rulerTerm.Government; var startDate = new Date(rulerTerm.StartDate); if (startDate < firstPossibleDate) { startDate = new Date(firstPossibleDate); // TODO: remove this workaround if CK3 supports negative dates firstPossibleDate.ChangeByDays(1); } history.InternalHistory.AddSimpleFieldValue("holder", characterId, startDate); if (gov is not null) { history.InternalHistory.AddSimpleFieldValue("government", gov, startDate); } } // ------------------ determine color var color1Opt = ImperatorCountry.Color1; if (color1Opt is not null) { Color1 = color1Opt; } var color2Opt = ImperatorCountry.Color2; if (color2Opt is not null) { Color2 = color2Opt; } // determine successions laws SuccessionLaws = successionLawMapper.GetCK3LawsForImperatorLaws(ImperatorCountry.GetLaws()); // ------------------ determine CoA CoA = coaMapper.GetCoaForFlagName(ImperatorCountry.Flag); // ------------------ determine other attributes var srcCapital = ImperatorCountry.Capital; if (srcCapital is not null) { var provMappingsForImperatorCapital = provinceMapper.GetCK3ProvinceNumbers((ulong)srcCapital); if (provMappingsForImperatorCapital.Count > 0) { var foundCounty = landedTitles.GetCountyForProvince(provMappingsForImperatorCapital[0]); if (foundCounty is not null) { CapitalCounty = new(foundCounty.Name, foundCounty); } } } // ------------------ Country Name Locs var nameSet = false; if (validatedName is not null) { Localizations.Add(Name, validatedName); nameSet = true; } if (!nameSet) { var impTagLoc = localizationMapper.GetLocBlockForKey(ImperatorCountry.Tag); if (impTagLoc is not null) { Localizations.Add(Name, impTagLoc); nameSet = true; } } // giving up if (!nameSet) { Logger.Warn($"{Name} needs help with localization! {ImperatorCountry.Name}?"); } // --------------- Adjective Locs TrySetAdjectiveLoc(localizationMapper, imperatorCountries); }