Esempio n. 1
0
        public void LocCanBeModifiedByMethodForEveryLanguage()
        {
            var nameLocBlock = new LocBlock {
                english      = "$ADJ$ Revolt",
                french       = "$ADJ$ révolte",
                german       = "$ADJ$ Revolte",
                russian      = "$ADJ$ бунт",
                simp_chinese = "$ADJ$ 反叛",
                spanish      = "$ADJ$ revuelta"
            };
            var adjLocBlock = new LocBlock {
                english      = "Roman",
                french       = "Romain",
                german       = "römisch",
                russian      = "Роман",
                simp_chinese = "罗马",
                spanish      = "Romana"
            };

            nameLocBlock.ModifyForEveryLanguage(adjLocBlock, (ref string baseLoc, string modifyingLoc) => {
                baseLoc = baseLoc.Replace("$ADJ$", modifyingLoc);
            });
            Assert.Equal("Roman Revolt", nameLocBlock.english);
            Assert.Equal("Romain révolte", nameLocBlock.french);
            Assert.Equal("römisch Revolte", nameLocBlock.german);
            Assert.Equal("Роман бунт", nameLocBlock.russian);
            Assert.Equal("罗马 反叛", nameLocBlock.simp_chinese);
            Assert.Equal("Romana revuelta", nameLocBlock.spanish);
        }
Esempio n. 2
0
 // ModifyForEveryLanguage helps remove boilerplate by applying modifyingMethod to every language in the struct
 //
 // For example:
 // nameLocBlock.english = nameLocBlock.english.Replace("$ADJ$", baseAdjLocBlock.english);
 // nameLocBlock.french = nameLocBlock.french.Replace("$ADJ$", baseAdjLocBlock.french);
 // nameLocBlock.german = nameLocBlock.german.Replace("$ADJ$", baseAdjLocBlock.german);
 // nameLocBlock.russian = nameLocBlock.russian.Replace("$ADJ$", baseAdjLocBlock.russian);
 // nameLocBlock.simp_chinese = nameLocBlock.simp_chinese.Replace("$ADJ$", baseAdjLocBlock.simp_chinese);
 // nameLocBlock.spanish = nameLocBlock.spanish.Replace("$ADJ$", baseAdjLocBlock.spanish);
 //
 // Can be replaced by:
 // nameLocBlock.ModifyForEveryLanguage(baseAdjLocBlock, (ref string baseLoc, string modifyingLoc) => {
 //     baseLoc = baseLoc.Replace("$ADJ$", modifyingLoc);
 // });
 public void ModifyForEveryLanguage(LocBlock otherLocBlock, LocDelegate modifyingMethod)
 {
     modifyingMethod(ref english, otherLocBlock.english);
     modifyingMethod(ref french, otherLocBlock.french);
     modifyingMethod(ref german, otherLocBlock.german);
     modifyingMethod(ref russian, otherLocBlock.russian);
     modifyingMethod(ref simp_chinese, otherLocBlock.simp_chinese);
     modifyingMethod(ref spanish, otherLocBlock.spanish);
 }
Esempio n. 3
0
 public LocBlock(LocBlock otherLocBlock)
 {
     english      = otherLocBlock.english;
     french       = otherLocBlock.french;
     german       = otherLocBlock.german;
     russian      = otherLocBlock.russian;
     simp_chinese = otherLocBlock.simp_chinese;
     spanish      = otherLocBlock.spanish;
 }
Esempio n. 4
0
        public void LocalizationCanBeSet()
        {
            var title    = new Title();
            var locBlock = new LocBlock {
                english = "engloc",
                french  = "frloc",
                german  = "germloc",
                russian = "rusloc",
                spanish = "spaloc"
            };

            title.SetNameLoc(locBlock);
            Assert.Equal(1, title.Localizations.Count);
        }
Esempio n. 5
0
    public Dynasty(Family imperatorFamily, LocDB locDB)
    {
        Id   = $"dynn_IMPTOCK3_{imperatorFamily.Id}";
        Name = Id;

        var imperatorMembers = imperatorFamily.Members;

        if (imperatorMembers.Count > 0)
        {
            Imperator.Characters.Character?firstMember = imperatorMembers[0] as Imperator.Characters.Character;
            if (firstMember?.CK3Character is not null)
            {
                Culture = firstMember.CK3Character.Culture;                 // make head's culture the dynasty culture
            }
        }
        else
        {
            Logger.Warn($"Couldn't determine culture for dynasty {Id}, needs manual setting!");
        }

        foreach (var member in imperatorMembers.Values)
        {
            var ck3Member = (member as Imperator.Characters.Character)?.CK3Character;
            if (ck3Member is not null)
            {
                ck3Member.DynastyId = Id;
            }
        }

        var impFamilyLocKey = imperatorFamily.Key;
        var impFamilyLoc    = locDB.GetLocBlockForKey(impFamilyLocKey);

        if (impFamilyLoc is not null)
        {
            Localization = new(Name, impFamilyLoc);
        }
        else             // fallback: use unlocalized Imperator family key
        {
            var locBlock = new LocBlock("english", "french", "german", "russian", "simp_chinese", "spanish")
            {
                ["english"] = impFamilyLocKey
            };
            locBlock.FillMissingLocWithBaseLanguageLoc();
            Localization = new(Name, locBlock);
        }
    }
Esempio n. 6
0
        public void LocBlockCanBeCopyConstructed()
        {
            var origLocBlock = new LocBlock {
                english      = "a",
                french       = "b",
                german       = "c",
                russian      = "d",
                simp_chinese = "e",
                spanish      = "f"
            };
            var copyLocBlock = new LocBlock(origLocBlock);

            Assert.Equal("a", copyLocBlock.english);
            Assert.Equal("b", copyLocBlock.french);
            Assert.Equal("c", copyLocBlock.german);
            Assert.Equal("d", copyLocBlock.russian);
            Assert.Equal("e", copyLocBlock.simp_chinese);
            Assert.Equal("f", copyLocBlock.spanish);
        }
 public void InitializeTest()
 {
     using (var client = TestHelper.ClientGet())
     {
         var locBlockRequest = new LocBlockRequest
         {
             Address = new AddressRequest
             {
                 StreetAddress  = "Kipdorp 30",
                 PostalCode     = "2000",
                 City           = "Antwerpen",
                 CountryId      = 1020, // Belgium
                 LocationTypeId = 1,
                 Name           = MyAddressName
             }
         };
         _myLocBlock = client.LocBlockSave(TestHelper.ApiKey, TestHelper.SiteKey, locBlockRequest).Values.First();
     }
 }
Esempio n. 8
0
        public void InitializeFromGovernorship(
            Imperator.Countries.Country country,
            Imperator.Jobs.Governorship governorship,
            Dictionary <ulong, Imperator.Characters.Character> imperatorCharacters,
            LocalizationMapper localizationMapper,
            LandedTitles landedTitles,
            ProvinceMapper provinceMapper,
            CoaMapper coaMapper,
            TagTitleMapper tagTitleMapper,
            DefiniteFormMapper definiteFormMapper,
            Mappers.Region.ImperatorRegionMapper imperatorRegionMapper
            )
        {
            IsImportedOrUpdatedFromImperator = true;

            // ------------------ determine CK3 title

            if (country.CK3Title is null)
            {
                throw new ArgumentException($"{country.Tag} governorship of {governorship.RegionName} could not be mapped to CK3 title: liege doesn't exist!");
            }

            HasDefiniteForm = definiteFormMapper.IsDefiniteForm(governorship.RegionName);

            string?title = null;

            title        = tagTitleMapper.GetTitleForGovernorship(governorship.RegionName, country.Tag, country.CK3Title.Name);
            DeJureLiege  = country.CK3Title;
            DeFactoLiege = country.CK3Title;
            if (title is null)
            {
                throw new ArgumentException($"{country.Tag} governorship of {governorship.RegionName} could not be mapped to CK3 title!");
            }

            Name = title;

            SetRank();

            PlayerCountry = false;

            var impGovernor         = imperatorCharacters[governorship.CharacterID];
            var normalizedStartDate = governorship.StartDate.Year > 0 ? governorship.StartDate : new Date(1, 1, 1);

            // ------------------ determine holder
            history.InternalHistory.AddSimpleFieldValue("holder", $"imperator{impGovernor.ID}", normalizedStartDate);

            // ------------------ determine government
            var ck3LiegeGov = country.CK3Title.GetGovernment(governorship.StartDate);

            if (ck3LiegeGov is not null)
            {
                history.InternalHistory.AddSimpleFieldValue("government", ck3LiegeGov, normalizedStartDate);
            }

            // ------------------ determine color
            var color1Opt = country.Color1;

            if (color1Opt is not null)
            {
                Color1 = color1Opt;
            }
            var color2Opt = country.Color2;

            if (color2Opt is not null)
            {
                Color2 = color2Opt;
            }

            // determine successions laws
            // https://github.com/ParadoxGameConverters/ImperatorToCK3/issues/90#issuecomment-817178552
            SuccessionLaws = new() { "high_partition_succession_law" };

            // ------------------ determine CoA
            CoA = null;             // using game-randomized CoA

            // ------------------ determine capital
            var governorProvince = impGovernor.ProvinceID;

            if (imperatorRegionMapper.ProvinceIsInRegion(governorProvince, governorship.RegionName))
            {
                foreach (var ck3Prov in provinceMapper.GetCK3ProvinceNumbers(governorProvince))
                {
                    var foundCounty = landedTitles.GetCountyForProvince(ck3Prov);
                    if (foundCounty is not null)
                    {
                        CapitalCounty = new(foundCounty.Name, foundCounty);
                        break;
                    }
                }
            }

            // ------------------ Country Name Locs
            var      nameSet                  = false;
            LocBlock?regionLocBlock           = localizationMapper.GetLocBlockForKey(governorship.RegionName);
            var      countryAdjectiveLocBlock = country.CK3Title.Localizations[country.CK3Title.Name + "_adj"];

            if (regionLocBlock is not null && countryAdjectiveLocBlock is not null)
            {
                var nameLocBlock = new LocBlock(regionLocBlock);
                nameLocBlock.ModifyForEveryLanguage(countryAdjectiveLocBlock,
                                                    (ref string orig, string adj) => orig = $"{adj} {orig}"
                                                    );
                Localizations.Add(Name, nameLocBlock);
                nameSet = true;
            }
            if (!nameSet && regionLocBlock is not null)
            {
                var nameLocBlock = new LocBlock(regionLocBlock);
                Localizations.Add(Name, nameLocBlock);
                nameSet = true;
            }
            if (!nameSet)
            {
                Logger.Warn($"{Name} needs help with localization!");
            }

            // --------------- Adjective Locs
            var adjSet = false;

            if (countryAdjectiveLocBlock is not null)
            {
                var adjLocBlock = new LocBlock(countryAdjectiveLocBlock);
                Localizations.Add(Name + "_adj", adjLocBlock);
                adjSet = true;
            }
            if (!adjSet)
            {
                Logger.Warn($"{Name} needs help with adjective localization!");
            }
        }
Esempio n. 9
0
        public static void OutputBookmark(World world, Configuration config)
        {
            var path = Path.Combine("output", config.OutputModName, "common/bookmarks/00_bookmarks.txt");

            using var stream = File.OpenWrite(path);
            using var output = new StreamWriter(stream, Encoding.UTF8);

            var provincePositions = world.MapData.ProvincePositions;

            output.WriteLine("bm_converted = {");

            output.WriteLine("\tdefault = yes");
            output.WriteLine($"\tstart_date = {config.CK3BookmarkDate}");
            output.WriteLine("\tis_playable = yes");
            output.WriteLine("\trecommended = yes");

            var playerTitles  = new List <Title>(world.LandedTitles.Where(title => title.PlayerCountry));
            var localizations = new Dictionary <string, LocBlock>();

            foreach (var title in playerTitles)
            {
                var holderId = title.GetHolderId(config.CK3BookmarkDate);
                if (holderId == "0")
                {
                    Logger.Warn($"Cannot add player title {title.Id} to bookmark screen: holder is 0!");
                    continue;
                }

                var holder = world.Characters[holderId];

                // Add character localization for bookmark screen.
                localizations.Add($"bm_converted_{holder.Id}", holder.Localizations[holder.Name]);
                var descLocBlock = new LocBlock("english", "french", "german", "russian", "simp_chinese", "spanish");
                localizations.Add($"bm_converted_{holder.Id}_desc", descLocBlock);

                output.WriteLine("\tcharacter = {");

                output.WriteLine($"\t\tname = bm_converted_{holder.Id}");
                output.WriteLine($"\t\tdynasty = {holder.DynastyId}");
                output.WriteLine("\t\tdynasty_splendor_level = 1");
                output.WriteLine($"\t\ttype = {holder.AgeSex}");
                output.WriteLine($"\t\thistory_id = {holder.Id}");
                output.WriteLine($"\t\tbirth = {holder.BirthDate}");
                output.WriteLine($"\t\ttitle = {title.Id}");
                var gov = title.GetGovernment(config.CK3BookmarkDate);
                if (gov is not null)
                {
                    output.WriteLine($"\t\tgovernment = {gov}");
                }

                output.WriteLine($"\t\tculture = {holder.Culture}");
                output.WriteLine($"\t\treligion = {holder.Religion}");
                output.WriteLine("\t\tdifficulty = \"BOOKMARK_CHARACTER_DIFFICULTY_EASY\"");
                WritePosition(output, title, config, provincePositions);
                output.WriteLine("\t\tanimation = personality_rational");

                output.WriteLine("\t}");

                string templatePath = holder.AgeSex switch {
                    "female" => "blankMod/templates/common/bookmark_portraits/female.txt",
                    "girl" => "blankMod/templates/common/bookmark_portraits/girl.txt",
                    "boy" => "blankMod/templates/common/bookmark_portraits/boy.txt",
                    _ => "blankMod/templates/common/bookmark_portraits/male.txt",
                };
                string templateText = File.ReadAllText(templatePath);
                templateText = templateText.Replace("REPLACE_ME_NAME", $"bm_converted_{holder.Id}");
                templateText = templateText.Replace("REPLACE_ME_AGE", holder.Age.ToString());
                var outPortraitPath = Path.Combine("output", config.OutputModName, $"common/bookmark_portraits/bm_converted_{holder.Id}.txt");
                File.WriteAllText(outPortraitPath, templateText);
            }

            output.WriteLine("}");

            DrawBookmarkMap(config, playerTitles, world);
            OutputBookmarkLoc(config, localizations);
        }