示例#1
0
 public void ValidateNestedTagsTest()
 {
     Assert.AreEqual(_nestedTagDescription1Corrected, DescriptionValidator.Validate(_nestedTagDescription1));
     Assert.AreEqual(_nestedTagDescription2Corrected, DescriptionValidator.Validate(_nestedTagDescription2));
     Assert.AreEqual(_nestedTagDescription3Corrected, DescriptionValidator.Validate(_nestedTagDescription3));
     Assert.AreEqual(_nestedTagDescription4Corrected, DescriptionValidator.Validate(_nestedTagDescription4));
 }
示例#2
0
 public void ValidateRealDescriptionTest()
 {
     Assert.AreEqual(_diabloBlackSoulstoneCorrected, DescriptionValidator.Validate(_diabloBlackSoulstone));
     Assert.AreEqual(_dvaMechSelfDestructCorrected, DescriptionValidator.Validate(_dvaMechSelfDestruct));
     Assert.AreEqual(_valeeraCheapShotCorrected, DescriptionValidator.Validate(_valeeraCheapShot));
     Assert.AreEqual(_crusaderPunishSame, DescriptionValidator.Validate(_crusaderPunish));
 }
示例#3
0
        public static Description From(string value)
        {
            var description = new Description(value);
            var validator   = new DescriptionValidator();
            var results     = validator.Validate(description);

            description.SetValidationResult(results);
            return(description);
        }
示例#4
0
 public void ValidateTest()
 {
     Assert.AreEqual(_noTagsDescription, DescriptionValidator.Validate(_noTagsDescription));           // no changes
     Assert.AreEqual(_normalTagsDescription1, DescriptionValidator.Validate(_normalTagsDescription1)); // no changes
     Assert.AreEqual(_normalTagsDescription2, DescriptionValidator.Validate(_normalTagsDescription2)); // no changes
     Assert.AreEqual(_noTagsDescription, DescriptionValidator.Validate(_extraTagDescription1));
     Assert.AreEqual(_noTagsDescription, DescriptionValidator.Validate(_extraTagDescription2));
     Assert.AreEqual(_noTagsDescription, DescriptionValidator.Validate(_extraTagDescription3));
     Assert.AreEqual(_noTagsDescription, DescriptionValidator.Validate(_extraTagDescription4));
     Assert.AreEqual(_noTagsDescription, DescriptionValidator.Validate(_extraTagDescription5));
     Assert.AreEqual(_noTagsDescription, DescriptionValidator.Validate(_extraTagDescription6));
     Assert.AreEqual(_newLineTagDescription1, DescriptionValidator.Validate(_newLineTagDescription1));     // no changes
     Assert.AreEqual(_newLineTagDescription2, DescriptionValidator.Validate(_newLineTagDescription2));     // no changes
     Assert.AreEqual(_selfCloseTagDescription1, DescriptionValidator.Validate(_selfCloseTagDescription1)); // no changes
     Assert.AreEqual(_selfCloseTagDescription2, DescriptionValidator.Validate(_selfCloseTagDescription2)); // no changes
     Assert.AreEqual(_selfCloseTagDescription3, DescriptionValidator.Validate(_selfCloseTagDescription3)); // no changes
     Assert.AreEqual(_selfCloseTagDescription4, DescriptionValidator.Validate(_selfCloseTagDescription4)); // no changes
     Assert.AreEqual(_normalTagsDescription2, DescriptionValidator.Validate(_duplicateTagsDescription1));
     Assert.AreEqual(_normalTagsDescription2, DescriptionValidator.Validate(_duplicateTagsDescription2));
     Assert.AreEqual(_spaceTagDescription1, DescriptionValidator.Validate(_spaceTagDescription1)); // no changes
     Assert.AreEqual(_spaceTagDescription2, DescriptionValidator.Validate(_spaceTagDescription2)); // no changes
 }
        private string ParseGameString(string tooltip, string splitter, bool nestedTooltip)
        {
            if (nestedTooltip)
            {
                tooltip = tooltip.Replace("'", "\"");
            }

            string[] parts = Regex.Split(tooltip, splitter);

            for (int i = 0; i < parts.Length; i++)
            {
                if (nestedTooltip)
                {
                    if (!parts[i].Contains("[d ref="))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!parts[i].Contains("<d ref=") && !parts[i].Contains("<d const="))
                    {
                        continue;
                    }
                }

                string pathLookup = parts[i];

                // get and remove precision
                pathLookup = GetPrecision(pathLookup, out int?precision);

                // remove the player
                pathLookup = GetPlayer(pathLookup, out _);

                // perform xml data lookup to find values
                string mathPath = ParseValues(pathLookup.AsMemory());

                if (string.IsNullOrEmpty(Regex.Replace(mathPath, @"[/*+\-()]", string.Empty)))
                {
                    return(string.Empty);
                }

                // extract the scaling and the amount
                string scalingText = GetScalingText(mathPath, out int numOfScalingTexts);

                if (!string.IsNullOrEmpty(scalingText))
                {
                    mathPath = mathPath.Replace(scalingText, string.Empty);
                }

                double number = HeroesMathEval.CalculatePathEquation(mathPath.Trim('/'));

                if (precision.HasValue)
                {
                    parts[i] = Math.Round(number, precision.Value).ToString();
                }
                else
                {
                    parts[i] = Math.Round(number, 0).ToString();
                }

                if (!string.IsNullOrEmpty(scalingText))
                {
                    // only add the scaling in certain cases
                    if (numOfScalingTexts == 1 || (numOfScalingTexts > 1 && !mathPath.Contains('/')))
                    {
                        ReadOnlySpan <char> nextPart = parts[i + 1];
                        nextPart = nextPart.TrimStart();

                        if (nextPart.StartsWith("%"))
                        {
                            parts[i]    += $"%{scalingText}";
                            parts[i + 1] = parts[i + 1].ReplaceFirst("%", string.Empty);
                        }
                        else
                        {
                            parts[i] += $"{scalingText}";
                        }
                    }
                }
            }

            if (nestedTooltip)
            {
                return(string.Join(string.Empty, parts));
            }
            else
            {
                string joinDesc = string.Join(string.Empty, parts);

                foreach (Match match in Regex.Matches(joinDesc, @"[a-z]+""[a-z]+"))
                {
                    joinDesc = joinDesc.Replace(match.Value, match.Value.Replace("\"", "'"));
                }

                return(DescriptionValidator.Validate(joinDesc));
            }
        }
示例#6
0
 public void ValidateEmptyTagsTest()
 {
     Assert.AreEqual(_emptyTagsDescription1Corrected, DescriptionValidator.Validate(_emptyTagsDescription1));
     Assert.AreEqual(_emptyTagsDescription2Corrected, DescriptionValidator.Validate(_emptyTagsDescription2));
     Assert.AreEqual(_emptyTagsDescription3Corrected, DescriptionValidator.Validate(_emptyTagsDescription3));
 }
示例#7
0
 public void ValidateExtraSpaceInTagsTest()
 {
     Assert.AreEqual(_normalTagsDescription2, DescriptionValidator.Validate(_extraSpacesTagDescription1));
     Assert.AreEqual(_normalTagsDescription2, DescriptionValidator.Validate(_extraSpacesTagDescription2));
 }
示例#8
0
 public void ValidateCaseTagsTest()
 {
     Assert.AreEqual(_upperCaseTagDescription1Corrected, DescriptionValidator.Validate(_upperCaseTagDescription1));
 }
示例#9
0
 public void ValidateConvertedNewlineTagsTest()
 {
     Assert.AreEqual(_convertNewLineTagDescription1Corrected, DescriptionValidator.Validate(_convertNewLineTagDescription1));
     Assert.AreEqual(_convertNewLineTagDescription2Corrected, DescriptionValidator.Validate(_convertNewLineTagDescription2));
     Assert.AreEqual(_convertNewLineTagDescription3Corrected, DescriptionValidator.Validate(_convertNewLineTagDescription3));
 }
        private void SetCostData(XElement costElement, AbilityTalentBase abilityTalentBase)
        {
            if (costElement == null)
            {
                throw new ArgumentNullException(nameof(costElement));
            }
            if (abilityTalentBase == null)
            {
                throw new ArgumentNullException(nameof(abilityTalentBase));
            }

            XElement chargeElement = costElement.Element("Charge");

            if (chargeElement != null)
            {
                XElement countMaxElement   = chargeElement.Element("CountMax");
                XElement countStartElement = chargeElement.Element("CountStart");
                XElement countUseElement   = chargeElement.Element("CountUse");
                XElement hideCountElement  = chargeElement.Element("HideCount");
                XElement timeUseElement    = chargeElement.Element("TimeUse");

                // as attributes
                if (countMaxElement != null || countStartElement != null || countUseElement != null || hideCountElement != null || timeUseElement != null)
                {
                    if (countMaxElement != null)
                    {
                        abilityTalentBase.Tooltip.Charges.CountMax = int.Parse(GameData.GetValueFromAttribute(countMaxElement.Attribute("value").Value));
                    }

                    if (countStartElement != null)
                    {
                        abilityTalentBase.Tooltip.Charges.CountStart = int.Parse(GameData.GetValueFromAttribute(countStartElement.Attribute("value").Value));
                    }

                    if (countUseElement != null)
                    {
                        abilityTalentBase.Tooltip.Charges.CountUse = int.Parse(GameData.GetValueFromAttribute(countUseElement.Attribute("value").Value));
                    }

                    if (hideCountElement != null)
                    {
                        abilityTalentBase.Tooltip.Charges.IsHideCount = int.Parse(GameData.GetValueFromAttribute(hideCountElement.Attribute("value").Value)) == 1 ? true : false;
                    }

                    if (timeUseElement != null)
                    {
                        string cooldownValue = GameData.GetValueFromAttribute(timeUseElement.Attribute("value").Value);

                        string replaceText;
                        if (abilityTalentBase.Tooltip.Charges.CountMax.HasValue && abilityTalentBase.Tooltip.Charges.CountMax.Value > 1)
                        {
                            replaceText = GameData.GetGameString(DefaultData.StringChargeCooldownColon); // Charge Cooldown:<space>
                        }
                        else
                        {
                            replaceText = GameData.GetGameString(DefaultData.StringCooldownColon); // Cooldown:<space>
                        }
                        if (cooldownValue == "1")
                        {
                            abilityTalentBase.Tooltip.Cooldown.CooldownTooltip = new TooltipDescription(GameData.GetGameString(DefaultData.AbilTooltipCooldownText)
                                                                                                        .Replace(GameData.GetGameString(DefaultData.StringCooldownColon), replaceText)
                                                                                                        .Replace(DefaultData.ReplacementCharacter, cooldownValue));
                        }
                        else
                        {
                            abilityTalentBase.Tooltip.Cooldown.CooldownTooltip = new TooltipDescription(GameData.GetGameString(DefaultData.AbilTooltipCooldownPluralText)
                                                                                                        .Replace(GameData.GetGameString(DefaultData.StringCooldownColon), replaceText)
                                                                                                        .Replace(DefaultData.ReplacementCharacter, cooldownValue));
                        }
                    }
                }
                else // as elements
                {
                    XAttribute countMaxAttribute   = chargeElement.Attribute("CountMax");
                    XAttribute countStartAttribute = chargeElement.Attribute("CountStart");
                    XAttribute countUseAttribute   = chargeElement.Attribute("CountUse");
                    XAttribute hideCountAttribute  = chargeElement.Attribute("HideCount");
                    XAttribute timeUseAttribute    = chargeElement.Attribute("TimeUse");
                    if (countMaxAttribute != null)
                    {
                        abilityTalentBase.Tooltip.Charges.CountMax = int.Parse(GameData.GetValueFromAttribute(countMaxAttribute.Value));
                    }

                    if (countStartAttribute != null)
                    {
                        abilityTalentBase.Tooltip.Charges.CountStart = int.Parse(GameData.GetValueFromAttribute(countStartAttribute.Value));
                    }

                    if (countUseAttribute != null)
                    {
                        abilityTalentBase.Tooltip.Charges.CountUse = int.Parse(GameData.GetValueFromAttribute(countUseAttribute.Value));
                    }

                    if (hideCountAttribute != null)
                    {
                        abilityTalentBase.Tooltip.Charges.IsHideCount = int.Parse(GameData.GetValueFromAttribute(hideCountAttribute.Value)) == 1 ? true : false;
                    }

                    if (timeUseAttribute != null)
                    {
                        string cooldownValue = timeUseAttribute.Value;

                        string replaceText;
                        if (abilityTalentBase.Tooltip.Charges.CountMax.HasValue && abilityTalentBase.Tooltip.Charges.CountMax.Value > 1)
                        {
                            replaceText = GameData.GetGameString(DefaultData.StringChargeCooldownColon); // Charge Cooldown:<space>
                        }
                        else
                        {
                            replaceText = GameData.GetGameString(DefaultData.StringCooldownColon); // Cooldown:<space>
                        }
                        if (!string.IsNullOrEmpty(cooldownValue))
                        {
                            if (cooldownValue == "1")
                            {
                                abilityTalentBase.Tooltip.Cooldown.CooldownTooltip = new TooltipDescription(GameData.GetGameString(DefaultData.AbilTooltipCooldownText)
                                                                                                            .Replace(GameData.GetGameString(DefaultData.StringCooldownColon), replaceText)
                                                                                                            .Replace(DefaultData.ReplacementCharacter, cooldownValue));
                            }
                            else
                            {
                                abilityTalentBase.Tooltip.Cooldown.CooldownTooltip = new TooltipDescription(GameData.GetGameString(DefaultData.AbilTooltipCooldownPluralText)
                                                                                                            .Replace(GameData.GetGameString(DefaultData.StringCooldownColon), replaceText)
                                                                                                            .Replace(DefaultData.ReplacementCharacter, cooldownValue));
                            }
                        }
                    }
                }
            }

            // cooldown
            XElement cooldownElement = costElement.Element("Cooldown");

            if (cooldownElement != null)
            {
                string cooldownValue = GameData.GetValueFromAttribute(cooldownElement.Attribute("TimeUse")?.Value);
                if (!string.IsNullOrEmpty(cooldownValue))
                {
                    if (abilityTalentBase.Tooltip.Charges.HasCharges)
                    {
                        abilityTalentBase.Tooltip.Charges.RecastCooldown = double.Parse(cooldownValue);
                    }
                    else
                    {
                        double cooldown = double.Parse(cooldownValue);

                        if (cooldown == 1)
                        {
                            abilityTalentBase.Tooltip.Cooldown.CooldownTooltip = new TooltipDescription(GameData.GetGameString(DefaultData.AbilTooltipCooldownText).Replace(DefaultData.ReplacementCharacter, cooldownValue));
                        }
                        else if (cooldown >= 1)
                        {
                            abilityTalentBase.Tooltip.Cooldown.CooldownTooltip = new TooltipDescription(GameData.GetGameString(DefaultData.AbilTooltipCooldownPluralText).Replace(DefaultData.ReplacementCharacter, cooldownValue));
                        }

                        if (cooldown < 1)
                        {
                            abilityTalentBase.Tooltip.Cooldown.ToggleCooldown = cooldown;
                        }
                    }
                }
            }

            // vitals
            XElement vitalElement = costElement.Element("Vital");

            if (vitalElement != null)
            {
                string vitalIndex = GameData.GetValueFromAttribute(vitalElement.Attribute("index").Value);
                string vitalValue = GameData.GetValueFromAttribute(vitalElement.Attribute("value").Value);

                if (vitalIndex == "Energy")
                {
                    abilityTalentBase.Tooltip.Energy.EnergyValue   = double.Parse(vitalValue);
                    abilityTalentBase.Tooltip.Energy.EnergyTooltip = new TooltipDescription(DescriptionValidator.Validate(GameData.GetGameString(DefaultData.ButtonData.ButtonTooltipEnergyVitalName).Replace(DefaultData.ReplacementCharacter, vitalValue)));
                }
            }
        }
        /// <summary>
        /// Set all element data found in the button element.
        /// </summary>
        /// <param name="abilityTalentBase"></param>
        protected void SetTooltipData(XElement buttonElement, AbilityTalentBase abilityTalentBase)
        {
            if (buttonElement == null)
            {
                throw new ArgumentNullException(nameof(buttonElement));
            }
            if (abilityTalentBase == null)
            {
                throw new ArgumentNullException(nameof(abilityTalentBase));
            }

            string defaultEnergyValue = GameData.GetGameString(DefaultData.HeroEnergyTypeManaText);

            // "UI/Tooltip/Abil/<Type>
            string vitalEnergyValueTextTemp;
            string vitalLifeValueTextTemp;

            string overrideTextTemp = string.Empty;

            // look through each element to set overrides
            foreach (XElement element in buttonElement.Elements())
            {
                string elementName = element.Name.LocalName.ToUpper();

                if (elementName == "NAME")
                {
                    abilityTalentBase.Name = GameData.GetGameString(element.Attribute("value").Value);
                }
                else if (elementName == "ICON")
                {
                    abilityTalentBase.IconFileName = Path.GetFileName(PathHelper.GetFilePath(element.Attribute("value").Value));
                }
                else if (elementName == "TOOLTIP")
                {
                    string fullTooltipValue = element.Attribute("value").Value;

                    if (GameData.TryGetGameString(fullTooltipValue, out string fullDescription))
                    {
                        abilityTalentBase.Tooltip.FullTooltip = new TooltipDescription(fullDescription, Localization);
                    }
                }
                else if (elementName == "SIMPLEDISPLAYTEXT")
                {
                    string shortTooltipValue = element.Attribute("value").Value;

                    if (GameData.TryGetGameString(shortTooltipValue, out string shortDescription))
                    {
                        abilityTalentBase.Tooltip.ShortTooltip = new TooltipDescription(shortDescription, Localization);
                    }
                }
                else if (elementName == "TOOLTIPVITALNAME")
                {
                    string index = element.Attribute("index")?.Value;

                    if (index == "Energy")
                    {
                        vitalEnergyValueTextTemp = element.Attribute("value").Value;

                        if (string.IsNullOrEmpty(vitalEnergyValueTextTemp))
                        {
                            abilityTalentBase.Tooltip.Energy.EnergyTooltip = null;
                        }
                        else if (GameData.TryGetGameString(vitalEnergyValueTextTemp, out string overrideVitalName))
                        {
                            if (string.IsNullOrEmpty(abilityTalentBase.Tooltip.Energy.EnergyTooltip?.RawDescription))
                            {
                                abilityTalentBase.Tooltip.Energy.EnergyTooltip = new TooltipDescription(DescriptionValidator.Validate(overrideVitalName));
                            }
                            else if (overrideVitalName.Contains(DefaultData.ReplacementCharacter) && abilityTalentBase.Tooltip.Energy.EnergyValue.HasValue)
                            {
                                abilityTalentBase.Tooltip.Energy.EnergyTooltip = new TooltipDescription(DescriptionValidator.Validate(overrideVitalName.Replace(DefaultData.ReplacementCharacter, abilityTalentBase.Tooltip.Energy.EnergyValue.ToString())));
                            }
                            else if (overrideVitalName.Contains(DefaultData.ReplacementCharacter) && !string.IsNullOrEmpty(abilityTalentBase.Tooltip.Energy.EnergyTooltip.RawDescription) && !overrideTextTemp.StartsWith(defaultEnergyValue))
                            {
                                if (string.IsNullOrEmpty(overrideTextTemp))
                                {
                                    abilityTalentBase.Tooltip.Energy.EnergyTooltip = new TooltipDescription(string.Empty);
                                }
                                else
                                {
                                    abilityTalentBase.Tooltip.Energy.EnergyTooltip = new TooltipDescription(DescriptionValidator.Validate(overrideVitalName.Replace(DefaultData.ReplacementCharacter, overrideTextTemp)));
                                }
                            }
                        }
                    }
                    else if (index == "Life")
                    {
                        vitalLifeValueTextTemp = element.Attribute("value").Value;

                        if (string.IsNullOrEmpty(vitalLifeValueTextTemp))
                        {
                            abilityTalentBase.Tooltip.Life.LifeCostTooltip = null;
                        }
                        else if (GameData.TryGetGameString(vitalLifeValueTextTemp, out string overrideVitalName))
                        {
                            if (string.IsNullOrEmpty(abilityTalentBase.Tooltip.Life.LifeCostTooltip?.RawDescription))
                            {
                                abilityTalentBase.Tooltip.Life.LifeCostTooltip = new TooltipDescription(DescriptionValidator.Validate(overrideVitalName));
                            }
                            else if (overrideVitalName.Contains(DefaultData.ReplacementCharacter))
                            {
                                abilityTalentBase.Tooltip.Life.LifeCostTooltip = new TooltipDescription(DescriptionValidator.Validate(overrideVitalName.Replace(DefaultData.ReplacementCharacter, abilityTalentBase.Tooltip.Life.LifeValue.ToString())));
                            }
                            else
                            {
                                abilityTalentBase.Tooltip.Life.LifeCostTooltip = new TooltipDescription(DescriptionValidator.Validate(overrideVitalName.Replace(DefaultData.ReplacementCharacter, abilityTalentBase.Tooltip.Life.LifeCostTooltip.RawDescription)));
                            }
                        }
                    }
                }
                else if (elementName == "TOOLTIPVITALOVERRIDETEXT")
                {
                    if (GameData.TryGetGameString(element.Attribute("value").Value, out string text))
                    {
                        if (element.Attribute("index")?.Value == "Energy")
                        {
                            // check if overriding text starts with the energy text
                            if (!new TooltipDescription(DescriptionValidator.Validate(text)).PlainText.StartsWith(defaultEnergyValue))
                            {
                                if (GameData.TryGetGameString(DefaultData.ButtonData.ButtonTooltipEnergyVitalName, out string energyText)) // default
                                {
                                    overrideTextTemp = text;
                                    text             = DescriptionValidator.Validate(energyText.Replace(DefaultData.ReplacementCharacter, text));
                                }
                            }

                            abilityTalentBase.Tooltip.Energy.EnergyTooltip = new TooltipDescription(text);
                        }
                        else if (element.Attribute("index")?.Value == "Life")
                        {
                            abilityTalentBase.Tooltip.Life.LifeCostTooltip = new TooltipDescription(DescriptionValidator.Validate(abilityTalentBase.Tooltip.Life.LifeCostTooltip.RawDescription.Replace(DefaultData.ReplacementCharacter, text)));
                        }
                    }
                }
                else if (elementName == "TOOLTIPCOOLDOWNOVERRIDETEXT")
                {
                    string overrideValueText = element.Attribute("value").Value;
                    if (GameData.TryGetGameString(overrideValueText, out string text))
                    {
                        if (!text.StartsWith(GameData.GetGameString(DefaultData.StringCooldownColon)))
                        {
                            text = $"{GameData.GetGameString(DefaultData.StringCooldownColon)}{text}";
                        }

                        abilityTalentBase.Tooltip.Cooldown.CooldownTooltip = new TooltipDescription(DescriptionValidator.Validate(text));
                    }
                }
                else if (elementName == "TOOLTIPFLAGS")
                {
                    string index = element.Attribute("index").Value;

                    if (index == "ShowName" && element.Attribute("value").Value == "0")
                    {
                        abilityTalentBase.Name = string.Empty;
                    }
                    else if (index == "ShowHotkey")
                    {
                    }
                    else if (index == "ShowUsage" && element.Attribute("value").Value == "0")
                    {
                        abilityTalentBase.Tooltip.Life.LifeCostTooltip = null;
                        abilityTalentBase.Tooltip.Energy.EnergyTooltip = null;
                    }
                    else if (index == "ShowTime")
                    {
                    }
                    else if (index == "ShowCooldown" && element.Attribute("value").Value == "0")
                    {
                        // ignore, always show the cooldown
                    }
                    else if (index == "ShowRequirements")
                    {
                    }
                    else if (index == "ShowAutocast")
                    {
                    }
                }
            }

            // check if the life and energy string contain the replacement character
            if (abilityTalentBase.Tooltip.Life?.LifeCostTooltip != null && abilityTalentBase.Tooltip.Life.LifeCostTooltip.RawDescription.Contains(DefaultData.ReplacementCharacter))
            {
                abilityTalentBase.Tooltip.Life.LifeCostTooltip = null;
            }
            if (abilityTalentBase.Tooltip.Energy?.EnergyTooltip != null && abilityTalentBase.Tooltip.Energy.EnergyTooltip.RawDescription.Contains(DefaultData.ReplacementCharacter))
            {
                abilityTalentBase.Tooltip.Energy.EnergyTooltip = null;
            }
        }