コード例 #1
0
ファイル: SSFaction.cs プロジェクト: FabriceValade/PortraitSS
        public void ParseJson(List <SSMod> availableMods)
        {
            if (JsonContent == null)
            {
                return;
            }
            JToken DisplayNameToken;

            if (JsonContent.TryGetValue("displayName", out DisplayNameToken))
            {
                DisplayName = DisplayNameToken.Value <string>();
            }

            JToken LogoToken;

            if (JsonContent.TryGetValue("logo", out LogoToken))
            {
                string path          = LogoToken.Value <string>();
                SSMod  LogoSourceMod = CheckModSourceOfPath(path, availableMods);
                LogoPath = Path.Combine(LogoSourceMod.Url.CommonUrl, LogoSourceMod.Url.LinkingUrl, path);
            }


            JToken ColorToken;

            if (JsonContent.TryGetValue("color", out ColorToken))
            {
                List <int> ColorCode = ColorToken.Values <int>().ToList <int>();
                if (ColorCode.Count == 4)
                {
                    List <string> ColorArray = (from color in ColorCode
                                                select color.ToString("X2")).ToList <string>();
                    ColorRGB = "#" + ColorArray[3] + ColorArray[0] + ColorArray[1] + ColorArray[2];
                }
            }

            JToken portraitGendered;

            if (JsonContent.TryGetValue("portraits", out portraitGendered))
            {
                if (portraitGendered.Type == JTokenType.Object)
                {
                    List <string> subproperty = new List <string> {
                        Gender.MalePropertyName, Gender.FemalePropertyName
                    };
                    foreach (string sub in subproperty)
                    {
                        JToken portraitToken;
                        if ((portraitGendered as JObject).TryGetValue(sub, out portraitToken))
                        {
                            List <string> paths = portraitToken.Values <string>().ToList <string>();
                            foreach (string path in paths)
                            {
                                SSMod       PortraitSourceMod = CheckModSourceOfPath(path, availableMods);
                                URLRelative newPortraitUrl    = new URLRelative(PortraitSourceMod.Url.CommonUrl, PortraitSourceMod.Url.LinkingUrl, path);
                                Gender      newGender         = new Gender();
                                if (sub == Gender.MalePropertyName)
                                {
                                    newGender.Value = Gender.GenderValue.Male;
                                }
                                else
                                {
                                    newGender.Value = Gender.GenderValue.Female;
                                }

                                Portraits.Add(new SSPortrait(newPortraitUrl, newGender, PortraitSourceMod, this.ModSource));
                            }
                        }
                    }
                }
            }
        }