public void MappingsCanBeLoadedFromFile() { var provinceMappings = new ProvinceMappings(testFilePath); Assert.Collection(provinceMappings.Mappings, mapping1 => { Assert.Equal((ulong)3, mapping1.Key); Assert.Equal((ulong)1, mapping1.Value); }, mapping2 => { Assert.Equal((ulong)4, mapping2.Key); Assert.Equal((ulong)1, mapping2.Value); }, mapping3 => { Assert.Equal((ulong)5, mapping3.Key); Assert.Equal((ulong)4, mapping3.Value); } ); }
public void ImportVanillaProvinces(string ck3Path, Date ck3BookmarkDate) { Logger.Info("Importing Vanilla Provinces..."); // ---- Loading history/provinces var path = Path.Combine(ck3Path, "game/history/provinces"); var fileNames = SystemUtils.GetAllFilesInFolderRecursive(path); foreach (var fileName in fileNames) { if (!fileName.EndsWith(".txt")) { continue; } var provincesPath = Path.Combine(ck3Path, "game/history/provinces", fileName); LoadProvinces(provincesPath, ck3BookmarkDate); } // now load the provinces that don't have unique entries in history/provinces // they instead use history/province_mapping path = Path.Combine(ck3Path, "game/history/province_mapping"); fileNames = SystemUtils.GetAllFilesInFolderRecursive(path); foreach (var fileName in fileNames) { if (!fileName.EndsWith(".txt")) { continue; } var provinceMappingsPath = Path.Combine(ck3Path, "game/history/province_mapping", fileName); try { var newMappings = new ProvinceMappings(provinceMappingsPath); foreach (var(newProvinceId, baseProvinceId) in newMappings) { if (!ContainsKey(baseProvinceId)) { Logger.Warn($"Base province {baseProvinceId} not found for province {newProvinceId}."); continue; } if (ContainsKey(newProvinceId)) { Logger.Info($"Vanilla province duplication - {newProvinceId} already loaded! Preferring unique entry over mapping."); } else { var newProvince = new Province(newProvinceId, this[baseProvinceId]); Add(newProvince); } } } catch (Exception e) { Logger.Warn($"Invalid province filename: {provinceMappingsPath}: ({e})"); } } Logger.Info($"Loaded {Count} province definitions."); }
public void MappingsWithSameTargetProvAreOverwritten() { var mappings = new ProvinceMappings("TestFiles/CK3_province_mappings_messy2.txt"); Assert.Collection(mappings, mapping1 => { Assert.Equal((ulong)4, mapping1.Key); Assert.Equal((ulong)2, mapping1.Value); } ); }
public void MappingIsIgnoredIfRightIsSameAsLeft() { var mappings = new ProvinceMappings("TestFiles/CK3_province_mappings_messy.txt"); Assert.Collection(mappings, mapping1 => { Assert.Equal((ulong)4, mapping1.Key); Assert.Equal((ulong)1, mapping1.Value); } ); }
public void MappingsDefaultToEmpty() { var mappings = new ProvinceMappings("missingFile.txt"); Assert.Empty(mappings.Mappings); }