Example #1
0
        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); }
                              );
        }
Example #2
0
    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.");
    }
Example #3
0
        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);
            }
                              );
        }
Example #4
0
        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);
            }
                              );
        }
Example #5
0
        public void MappingsDefaultToEmpty()
        {
            var mappings = new ProvinceMappings("missingFile.txt");

            Assert.Empty(mappings.Mappings);
        }