/// <summary>
        /// Updates the <paramref name="rewardPortrait"/>'s localized gamestrings to the currently selected <see cref="Localization"/>.
        /// </summary>
        /// <param name="rewardPortrait">The data to be updated.</param>
        /// <exception cref="ArgumentNullException"><paramref name="rewardPortrait"/> is <see langword="null"/>.</exception>
        public void UpdateGameStrings(RewardPortrait rewardPortrait)
        {
            if (rewardPortrait is null)
            {
                throw new ArgumentNullException(nameof(rewardPortrait));
            }

            JsonElement element = JsonGameStringDocument.RootElement;

            if (element.TryGetProperty("gamestrings", out JsonElement gameStringElement))
            {
                if (gameStringElement.TryGetProperty("rewardportrait", out JsonElement keyValue))
                {
                    if (TryGetValueFromJsonElement(keyValue, "name", rewardPortrait.Id, out JsonElement nameElement))
                    {
                        rewardPortrait.Name = nameElement.GetString();
                    }

                    if (TryGetValueFromJsonElement(keyValue, "description", rewardPortrait.Id, out JsonElement descriptionElement))
                    {
                        rewardPortrait.Description = SetTooltipDescription(descriptionElement.GetString());
                    }

                    if (TryGetValueFromJsonElement(keyValue, "descriptionunearned", rewardPortrait.Id, out JsonElement descriptionUnearnedElement))
                    {
                        rewardPortrait.DescriptionUnearned = SetTooltipDescription(descriptionUnearnedElement.GetString());
                    }
                }
            }
        }
 protected override XElement GetImageObject(RewardPortrait rewardPortrait)
 {
     return(new XElement(
                "TextureSheet",
                new XElement("Image", Path.ChangeExtension(rewardPortrait.TextureSheet.Image?.ToLowerInvariant(), StaticImageExtension)),
                rewardPortrait.TextureSheet.Columns.HasValue ? new XElement("Columns", rewardPortrait.TextureSheet.Columns.Value) : null !,
                rewardPortrait.TextureSheet.Rows.HasValue ? new XElement("Rows", rewardPortrait.TextureSheet.Rows.Value) : null !));
 }
Example #3
0
        public void UpdateGameStringsThrowArgumentNullException()
        {
            RewardPortrait rewardPortrait = new RewardPortrait
            {
                Id = "2016FallGlobalChampionshipPortrait",
            };

            Assert.ThrowsException <ArgumentNullException>(() => rewardPortrait.UpdateGameStrings(null !));
        }
        /// <summary>
        /// Updates the localized gamestrings to the selected <see cref="Localization"/>.
        /// </summary>
        /// <param name="rewardPortrait">The data to be updated.</param>
        /// <param name="gameStringDocument">Instance of a <see cref="GameStringDocument"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="gameStringDocument"/> is null.</exception>
        public static void UpdateGameStrings(this RewardPortrait rewardPortrait, GameStringDocument gameStringDocument)
        {
            if (gameStringDocument is null)
            {
                throw new ArgumentNullException(nameof(gameStringDocument));
            }

            gameStringDocument.UpdateGameStrings(rewardPortrait);
        }
Example #5
0
    public void UpdateGameStringRewardPortraitTest()
    {
        using RewardPortraitDataDocument dataDocument = _heroesDataDirectory.RewardPortraitData(new HeroesDataVersion(2, 47, 3, 76124), true, Localization.KOKR);
        RewardPortrait data = dataDocument.GetRewardPortraitById("1YearAnniversaryPortrait");

        Assert.AreEqual("1주년 기념 초상화", data.Name);

        _heroesDataDirectory.UpdateGameString(data, new HeroesDataVersion(2, 48, 4, 77407), Localization.ENUS);
        Assert.AreEqual("rewardportraitName", data.Name);
    }
    /// <summary>
    /// Updates the gamestrings of <paramref name="rewardPortrait"/>.
    /// </summary>
    /// <param name="rewardPortrait">The data who's gamestrings will be updated.</param>
    /// <param name="version">The version directory to load the gamestrings from.</param>
    /// <param name="localization">The <see cref="Localization"/> of the gamestrings.</param>
    /// <exception cref="ArgumentNullException"><paramref name="rewardPortrait"/> is null.</exception>
    /// <exception cref="ArgumentNullException"><paramref name="version"/> is null.</exception>
    public void UpdateGameString(RewardPortrait rewardPortrait, HeroesDataVersion version, Localization localization)
    {
        ArgumentNullException.ThrowIfNull(rewardPortrait, nameof(rewardPortrait));
        ArgumentNullException.ThrowIfNull(version, nameof(version));

        (_, string gameStringPath) = GetDataAndGameStringPaths(version, true, localization, _rewardPortraitFileTemplateName, false, true);

        using GameStringDocument gameStringDocument = GameStringDocument.Parse(gameStringPath);

        rewardPortrait.UpdateGameStrings(gameStringDocument);
    }
        protected override JProperty MainElement(RewardPortrait rewardPortrait)
        {
            if (FileOutputOptions.IsLocalizedText)
            {
                AddLocalizedGameString(rewardPortrait);
            }

            JObject portraitObject = new JObject();

            if (!string.IsNullOrEmpty(rewardPortrait.Name) && !FileOutputOptions.IsLocalizedText)
            {
                portraitObject.Add("name", rewardPortrait.Name);
            }

            portraitObject.Add("hyperlinkId", rewardPortrait.HyperlinkId);
            portraitObject.Add("rarity", rewardPortrait.Rarity.ToString());

            if (!string.IsNullOrEmpty(rewardPortrait.CollectionCategory))
            {
                portraitObject.Add("category", rewardPortrait.CollectionCategory);
            }

            if (!string.IsNullOrEmpty(rewardPortrait.Description?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                portraitObject.Add("description", GetTooltip(rewardPortrait.Description, FileOutputOptions.DescriptionType));
            }

            if (!string.IsNullOrEmpty(rewardPortrait.DescriptionUnearned?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                portraitObject.Add("descriptionUnearned", GetTooltip(rewardPortrait.DescriptionUnearned, FileOutputOptions.DescriptionType));
            }

            if (!string.IsNullOrEmpty(rewardPortrait.HeroId))
            {
                portraitObject.Add(new JProperty("heroId", rewardPortrait.HeroId));
            }

            if (!string.IsNullOrEmpty(rewardPortrait.PortraitPackId))
            {
                portraitObject.Add(new JProperty("portraitPackId", rewardPortrait.PortraitPackId));
            }

            portraitObject.Add(new JProperty("iconSlot", rewardPortrait.IconSlot));

            JProperty?image = GetImageObject(rewardPortrait);

            if (image != null)
            {
                portraitObject.Add(image);
            }

            return(new JProperty(rewardPortrait.Id, portraitObject));
        }
Example #8
0
        public void UpdateGameStringsTest()
        {
            using GameStringDocument gameStringDocument = GameStringDocument.Parse(LoadEnusLocalizedStringData());

            RewardPortrait rewardPortrait = new RewardPortrait
            {
                Id = "1YearAnniversaryPortrait",
            };

            rewardPortrait.UpdateGameStrings(gameStringDocument);

            Assert.AreEqual("1 Year Anniversary Portrait", rewardPortrait.Name);
        }
Example #9
0
        private void Parse()
        {
            RewardPortraitParser rewardPortraitParser = new RewardPortraitParser(XmlDataService);

            WhitemaneCarbotsPortrait      = rewardPortraitParser.Parse("WhitemaneCarbotsPortrait");
            WhitemaneSpooky18ToonPortrait = rewardPortraitParser.Parse("WhitemaneSpooky18ToonPortrait");
            WhitemaneBasePortrait         = rewardPortraitParser.Parse("WhitemaneBasePortrait");
            WhitemaneMasteryPortrait      = rewardPortraitParser.Parse("WhitemaneMasteryPortrait");
            StitchesPortraitSummer        = rewardPortraitParser.Parse("StitchesPortraitSummer");
            TespaMembership2015Portrait   = rewardPortraitParser.Parse("2015TespaMembershipPortrait");
            Season4TL2018GrandMaster      = rewardPortraitParser.Parse("2018Season4TLGrandMaster");
            HeroesAvatar256x256Qhira      = rewardPortraitParser.Parse("HeroesAvatar256x256Qhira");
        }
        protected void AddLocalizedGameString(RewardPortrait rewardPortrait)
        {
            GameStringWriter.AddRewardPortraitName(rewardPortrait.Id, rewardPortrait.Name);

            if (rewardPortrait.Description != null)
            {
                GameStringWriter.AddRewardPortraitDescription(rewardPortrait.Id, GetTooltip(rewardPortrait.Description, FileOutputOptions.DescriptionType));
            }

            if (rewardPortrait.DescriptionUnearned != null)
            {
                GameStringWriter.AddRewardPortraitDescriptionUnearned(rewardPortrait.Id, GetTooltip(rewardPortrait.DescriptionUnearned, FileOutputOptions.DescriptionType));
            }
        }
 private static void BasicAbathurCarbotsPortraitAsserts(RewardPortrait rewardPortrait)
 {
     Assert.AreEqual("AbathurCarbotsPortrait", rewardPortrait.Id);
     Assert.AreEqual("Carbot Abathur Portrait", rewardPortrait.Name);
     Assert.AreEqual("CarbotAbathurPortrait", rewardPortrait.HyperlinkId);
     Assert.AreEqual(Rarity.Common, rewardPortrait.Rarity);
     Assert.AreEqual("HeroStormPortrait", rewardPortrait.CollectionCategory);
     Assert.AreEqual("You have unlocked this portrait in your Collection", rewardPortrait.Description?.RawDescription);
     Assert.AreEqual("Forge using Shards, purchase with Gems, or receive in a Loot Chest to unlock.", rewardPortrait.DescriptionUnearned?.RawDescription);
     Assert.AreEqual("Abathur", rewardPortrait.HeroId);
     Assert.AreEqual("AbathurCarbotsPortrait", rewardPortrait.PortraitPackId);
     Assert.AreEqual(18, rewardPortrait.IconSlot);
     Assert.AreEqual("ui_heroes_portraits_sheet25.png", rewardPortrait.TextureSheet.Image);
     Assert.AreEqual(6, rewardPortrait.TextureSheet.Columns);
     Assert.AreEqual(6, rewardPortrait.TextureSheet.Rows);
 }
        protected override JProperty GetImageObject(RewardPortrait rewardPortrait)
        {
            JObject textureSheetObject = new JObject(new JObject(
                                                         new JProperty("image", Path.ChangeExtension(rewardPortrait.TextureSheet.Image?.ToLowerInvariant(), StaticImageExtension))));

            if (rewardPortrait.TextureSheet.Columns.HasValue)
            {
                textureSheetObject.Add(new JProperty("columns", rewardPortrait.TextureSheet.Columns.Value));
            }
            if (rewardPortrait.TextureSheet.Rows.HasValue)
            {
                textureSheetObject.Add(new JProperty("rows", rewardPortrait.TextureSheet.Rows.Value));
            }

            return(new JProperty("textureSheet", textureSheetObject));
        }
 private static void Basic1YearAnniversaryPortraitAsserts(RewardPortrait rewardPortrait)
 {
     Assert.AreEqual("1YearAnniversaryPortrait", rewardPortrait.Id);
     Assert.AreEqual("1 Year Anniversary Portrait", rewardPortrait.Name);
     Assert.AreEqual("1YearAnniversaryPortrait", rewardPortrait.HyperlinkId);
     Assert.AreEqual(Rarity.Common, rewardPortrait.Rarity);
     Assert.AreEqual("PortraitAchievements1", rewardPortrait.CollectionCategory);
     Assert.AreEqual("Thank you for joining us during the celebration of Heroes of the Storm's first anniversary. To many more years to come! Oh, and don't forget to grab a slice of cake!", rewardPortrait.Description?.RawDescription);
     Assert.IsNull(rewardPortrait.DescriptionUnearned);
     Assert.IsNull(rewardPortrait.HeroId);
     Assert.IsNull(rewardPortrait.PortraitPackId);
     Assert.AreEqual(23, rewardPortrait.IconSlot);
     Assert.AreEqual("ui_heroes_portraits_sheet5.png", rewardPortrait.TextureSheet.Image);
     Assert.AreEqual(6, rewardPortrait.TextureSheet.Columns);
     Assert.AreEqual(6, rewardPortrait.TextureSheet.Rows);
     Assert.AreEqual("storm_portrait_2015tespamembershipportrait.png", rewardPortrait.ImageFileName);
 }
        protected override XElement MainElement(RewardPortrait rewardPortrait)
        {
            if (FileOutputOptions.IsLocalizedText)
            {
                AddLocalizedGameString(rewardPortrait);
            }

            return(new XElement(
                       XmlConvert.EncodeName(rewardPortrait.Id),
                       string.IsNullOrEmpty(rewardPortrait.Name) || FileOutputOptions.IsLocalizedText ? null ! : new XAttribute("name", rewardPortrait.Name),
                       string.IsNullOrEmpty(rewardPortrait.HyperlinkId) ? null ! : new XAttribute("hyperlinkId", rewardPortrait.HyperlinkId),
                       new XAttribute("rarity", rewardPortrait.Rarity),
                       string.IsNullOrEmpty(rewardPortrait.HeroId) ? null ! : new XAttribute("heroId", rewardPortrait.HeroId),
                       new XAttribute("iconSlot", rewardPortrait.IconSlot),
                       string.IsNullOrEmpty(rewardPortrait.PortraitPackId) ? null ! : new XAttribute("PortraitPackId", rewardPortrait.PortraitPackId),
                       string.IsNullOrEmpty(rewardPortrait.CollectionCategory) ? null ! : new XAttribute("category", rewardPortrait.CollectionCategory),
                       string.IsNullOrEmpty(rewardPortrait.Description?.RawDescription) || FileOutputOptions.IsLocalizedText ? null ! : new XElement("Description", GetTooltip(rewardPortrait.Description, FileOutputOptions.DescriptionType)),
                       string.IsNullOrEmpty(rewardPortrait.DescriptionUnearned?.RawDescription) || FileOutputOptions.IsLocalizedText ? null ! : new XElement("DescriptionUnearned", GetTooltip(rewardPortrait.DescriptionUnearned, FileOutputOptions.DescriptionType)),
                       GetImageObject(rewardPortrait)));
        }
 protected abstract T GetImageObject(RewardPortrait rewardPortrait);
    /// <summary>
    /// Updates the localized gamestrings to the selected <see cref="Localization"/>.
    /// </summary>
    /// <param name="rewardPortrait">The data to be updated.</param>
    /// <param name="gameStringDocument">Instance of a <see cref="GameStringDocument"/>.</param>
    /// <exception cref="ArgumentNullException"><paramref name="gameStringDocument"/> is null.</exception>
    public static void UpdateGameStrings(this RewardPortrait rewardPortrait, GameStringDocument gameStringDocument)
    {
        ArgumentNullException.ThrowIfNull(gameStringDocument, nameof(gameStringDocument));

        gameStringDocument.UpdateGameStrings(rewardPortrait);
    }
        private RewardPortrait GetRewardPortraitData(string rewardPortraitId, JsonElement rewardPortraitElement)
        {
            RewardPortrait rewardPortrait = new RewardPortrait()
            {
                Id = rewardPortraitId,
            };

            if (rewardPortraitElement.TryGetProperty("name", out JsonElement name))
            {
                rewardPortrait.Name = name.GetString();
            }

            if (rewardPortraitElement.TryGetProperty("hyperlinkId", out JsonElement hyperlinkId))
            {
                rewardPortrait.HyperlinkId = hyperlinkId.GetString();
            }

            if (rewardPortraitElement.TryGetProperty("rarity", out JsonElement rarityElement) && Enum.TryParse(rarityElement.GetString(), out Rarity rarity))
            {
                rewardPortrait.Rarity = rarity;
            }

            if (rewardPortraitElement.TryGetProperty("category", out JsonElement eventElement))
            {
                rewardPortrait.CollectionCategory = eventElement.GetString();
            }

            if (rewardPortraitElement.TryGetProperty("description", out JsonElement description))
            {
                rewardPortrait.Description = SetTooltipDescription(description.GetString(), Localization);
            }

            if (rewardPortraitElement.TryGetProperty("descriptionUnearned", out JsonElement descriptionUnearned))
            {
                rewardPortrait.DescriptionUnearned = SetTooltipDescription(descriptionUnearned.GetString(), Localization);
            }

            if (rewardPortraitElement.TryGetProperty("heroId", out JsonElement heroIdElement))
            {
                rewardPortrait.HeroId = heroIdElement.GetString();
            }

            if (rewardPortraitElement.TryGetProperty("portraitPackId", out JsonElement portraitPack))
            {
                rewardPortrait.PortraitPackId = portraitPack.GetString();
            }

            if (rewardPortraitElement.TryGetProperty("iconSlot", out JsonElement iconSlot))
            {
                rewardPortrait.IconSlot = iconSlot.GetInt32();
            }

            if (rewardPortraitElement.TryGetProperty("textureSheet", out JsonElement textureSheetElement))
            {
                if (textureSheetElement.TryGetProperty("image", out JsonElement image))
                {
                    rewardPortrait.TextureSheet.Image = image.GetString();
                }

                if (textureSheetElement.TryGetProperty("columns", out JsonElement columns))
                {
                    rewardPortrait.TextureSheet.Columns = columns.GetInt32();
                }

                if (textureSheetElement.TryGetProperty("rows", out JsonElement rows))
                {
                    rewardPortrait.TextureSheet.Rows = rows.GetInt32();
                }
            }

            if (rewardPortraitElement.TryGetProperty("image", out JsonElement imageElement))
            {
                rewardPortrait.ImageFileName = imageElement.GetString();
            }

            GameStringDocument?.UpdateGameStrings(rewardPortrait);

            return(rewardPortrait);
        }