Пример #1
0
 internal void LanguageAdded([NotNull] CultureKey cultureKey)
 {
     if (!Cultures.Contains(cultureKey))
     {
         Cultures.Add(cultureKey);
     }
 }
Пример #2
0
        public void LoadFromArchive(string Culture, string FileText)
        {
            if (Subnamespaces == null)
            {
                throw new System.InvalidOperationException("Load manifest first.");
            }

            if (Cultures.Contains(Culture))
            {
                throw new System.ArgumentException("Culture already appended: " + Culture);
            }

            LocaleArchive archive = JsonConvert.DeserializeObject <LocaleArchive>(FileText);

            if (ArchiveVersion != archive.FormatVersion)
            {
                throw new FormatException("Invalid Archive::FormatVersion.");
            }

            if (ArchiveNamespace != archive.Namespace)
            {
                throw new FormatException("Invalid Archive::Namespace. Must be empty.");
            }

            // Move "Children" to "Subnamespace" without name
            if (archive.Children != null && archive.Children.Count > 0)
            {
                LocaleArchiveNamespace emptyNS = new LocaleArchiveNamespace();
                emptyNS.Namespace = "";
                emptyNS.Children  = archive.Children;
                archive.Subnamespaces.Insert(0, emptyNS);
            }

            foreach (var ns in archive.Subnamespaces)
            {
                InternalNamespace ins = GetNamespace(ns.Namespace);

                if (ins == null)
                {
                    throw new FormatException("Archive::Subnamespace not found: " + ns.Namespace + "!");
                }

                foreach (var child in ns.Children)
                {
                    InternalKey ikey = ins.GetKey(child.Key);

                    if (ikey == null)
                    {
                        throw new FormatException("Invalid key (" + child.Key + ") in Archive::Subnamespace::Child " + child.Source.Text + "!");
                    }

                    InternalText text = new InternalText();
                    text.Culture = Culture;
                    text.Text    = child.Translation.Text;
                    ikey.Translations.Add(text);
                }
            }

            Cultures.Add(Culture);
        }
Пример #3
0
        /// <summary>
        /// Adds the culture.
        /// </summary>
        /// <param name="newCulture">The new culture.</param>
        public static void AddCulture(Culture newCulture)
        {
            if (Cultures.Contains(newCulture))
            {
                return;
            }

            Cultures.Add(newCulture);
        }
Пример #4
0
        internal void LanguageAdded([NotNull] CultureKey cultureKey)
        {
            Contract.Requires(cultureKey != null);

            if (!Cultures.Contains(cultureKey))
            {
                Cultures.Add(cultureKey);
            }
        }
Пример #5
0
        public string SaveToArchive(string Culture)
        {
            if (Cultures == null || Cultures.Contains(Culture) == false)
            {
                throw new System.ArgumentException("Culture not found: " + Culture);
            }

            if (Subnamespaces != null && Subnamespaces.Count > 0)
            {
                LocaleArchive archive = new LocaleArchive();
                archive.FormatVersion = ArchiveVersion;
                archive.Namespace     = ArchiveNamespace;
                archive.Subnamespaces = new List <LocaleArchiveNamespace>(Subnamespaces.Count);

                foreach (var ins in Subnamespaces)
                {
                    LocaleArchiveNamespace ns = new LocaleArchiveNamespace();
                    ns.Namespace = ins.Name;
                    if (ins.Children != null && ins.Children.Count > 0)
                    {
                        ns.Children = new List <LocaleArchiveChild>(ins.Children.Count);
                        foreach (var rec in ins.Children)
                        {
                            foreach (var ikey in rec.Keys)
                            {
                                LocaleArchiveChild child = new LocaleArchiveChild();
                                child.Source           = new LocaleSource();
                                child.Source.Text      = (Culture == NativeCulture) ? rec.Source : ikey.GetTranslationForCulture(NativeCulture);
                                child.Translation      = new LocaleTranslation();
                                child.Translation.Text = ikey.GetTranslationForCulture(Culture);
                                child.Key = ikey.Key;
                                ns.Children.Add(child);
                            }
                        }
                    }

                    if (ns.Namespace == "")
                    {
                        archive.Children = ns.Children;
                    }
                    else
                    {
                        archive.Subnamespaces.Add(ns);
                    }
                }

                return(JsonConvert.SerializeObject(archive, Formatting.Indented));
            }

            return("");
        }
Пример #6
0
 public string this[string cultureName]
 {
     get
     {
         return(Cultures.Contains(cultureName) ? this[GetCulture(cultureName)] : null);
     }
     set
     {
         if (Cultures.Contains(cultureName))
         {
             this[GetCulture(cultureName)] = value;
         }
     }
 }
Пример #7
0
        public XMLThemeChangerProvider(string file, ThemeCultureInfo culture) : this(file)
        {
            //если ничего не передано
            if (culture == null)
            {
                culture = Cultures.ElementAt(0);
            }

            //если вдруг передана ссылка на културу из списка
            if (!Cultures.Contains(culture))
            {
                Init(culture.Name);
            }
            else
            {
                CurrentCulture = culture;
            }
        }
        public override void Initialize()
        {
            Cultures.Clear();

            foreach (var basicCharacterObject in TaleWorlds.Core.Game.Current.ObjectManager.GetObjectTypeList <BasicCharacterObject>())
            {
                if (basicCharacterObject is CharacterObject characterObject)
                {
                    if (characterObject.IsTemplate || characterObject.IsChildTemplate)
                    {
                        continue;
                    }
                    var culture   = characterObject.Culture;
                    var cultureId = culture?.StringId ?? "null";
                    if (!Cultures.Contains(cultureId))
                    {
                        Cultures.Add(cultureId);
                    }
                    if (!GroupsInCultures.TryGetValue(cultureId, out var groupsInCurrentCulture))
                    {
                        GroupsInCultures[cultureId] = groupsInCurrentCulture = new List <Group>();
                    }

                    var formationClass = characterObject.DefaultFormationClass;
                    var group          = groupsInCurrentCulture.Find(g => g.Info.FormationClass == formationClass) as SPGroup;
                    if (group == null)
                    {
                        var newGroup = new SPGroup(formationClass);
                        groupsInCurrentCulture.Add(newGroup);
                        groupsInCurrentCulture.Sort((lhs, rhs) => lhs.Info.FormationClass - rhs.Info.FormationClass);
                        group = newGroup;
                    }

                    var occupation = characterObject.Occupation;
                    if (!group.OccupationsInGroup.TryGetValue(occupation, out var charactersInOccupation))
                    {
                        group.OccupationsInGroup[occupation] = charactersInOccupation = new CharactersInOccupation();
                    }

                    charactersInOccupation.Characters.Add(characterObject.StringId,
                                                          new SPCharacter(characterObject, group.Info));
                }
            }
        }