From 6eb17555c048fee1e0296d75f545e178c52283a6 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Tue, 30 Aug 2016 18:39:08 +0100 Subject: [PATCH] Fixed 2 bugs relating to duplicate ItemRarity block items and spaces at the end of ItemRarity block items --- .../Services/TestItemFilterBlockTranslator.cs | 99 ++++++++++++++++++- .../Services/ItemFilterBlockTranslator.cs | 5 +- Filtration/Resources/ItemBaseTypes.txt | 93 ----------------- 3 files changed, 102 insertions(+), 95 deletions(-) diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index f34cd4a..f0a8f7f 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -835,7 +835,104 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual(20, blockItem.Color.G); Assert.AreEqual(100, blockItem.Color.B); } - + + [Test] + public void TranslateStringToItemFilterBlock_MultipleRarityItems_OnlyLastOneUsed() + { + // Arrange + var inputString = @"#8#" + Environment.NewLine + + "Hide" + Environment.NewLine + + "Rarity Magic" + Environment.NewLine + + "DropLevel >= 67" + Environment.NewLine + + "BaseType \"Sorcerer Boots\"" + Environment.NewLine + + "Rarity Rare" + Environment.NewLine + + "SetFontSize 26" + Environment.NewLine + + "SetBackgroundColor 0 20 0"; + + + _testUtility.TestBlock.Enabled = false; + _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + + // Assert + Assert.AreEqual(1, result.BlockItems.Count(b => b is RarityBlockItem)); + var blockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(ItemRarity.Rare, (ItemRarity)blockItem.FilterPredicate.PredicateOperand); + } + + + [Test] + public void TranslateStringToItemFilterBlock_SpecificTest_1() + { + // Arrange + var inputString = @"Show" + Environment.NewLine + + "DropLevel >= 67" + Environment.NewLine + + "Rarity Rare" + Environment.NewLine + + " ItemLevel >= 75 " + Environment.NewLine + + " SetBorderColor 250 40 210" + Environment.NewLine + + "BaseType \"Sorcerer Boots\" \"Titan Greaves\" \"Slink Boots\" \"Murder Boots\"" + Environment.NewLine + + "SetBackgroundColor 0 20 0 ##TOP BASE FOR LEVEL### " + Environment.NewLine + + "SetFontSize 28"; + + + _testUtility.TestBlock.Enabled = false; + _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + + // Assert + Assert.AreEqual(1, result.BlockItems.Count(b => b is ActionBlockItem)); + var actionBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(BlockAction.Show, actionBlockItem.Action); + + Assert.AreEqual(1, result.BlockItems.Count(b => b is DropLevelBlockItem)); + var droplevelBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(67, droplevelBlockItem.FilterPredicate.PredicateOperand); + Assert.AreEqual(FilterPredicateOperator.GreaterThanOrEqual, droplevelBlockItem.FilterPredicate.PredicateOperator); + + Assert.AreEqual(1, result.BlockItems.Count(b => b is RarityBlockItem)); + var rarityBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(ItemRarity.Rare, (ItemRarity)rarityBlockItem.FilterPredicate.PredicateOperand); + } + + [Test] + public void TranslateStringToItemFilterBlock_SpecificTest_2() + { + // Arrange + var inputString = @"#8#" + Environment.NewLine + + "Hide " + Environment.NewLine + + "Rarity Magic " + Environment.NewLine + + "DropLevel >= 67" + Environment.NewLine + + "BaseType \"Sorcerer Boots\"" + Environment.NewLine + + "Rarity Magic " + Environment.NewLine + + "SetFontSize 26" + Environment.NewLine + + "SetBackgroundColor 0 20 0\""; + + + _testUtility.TestBlock.Enabled = false; + _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + + // Assert + Assert.AreEqual(1, result.BlockItems.Count(b => b is ActionBlockItem)); + var actionBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(BlockAction.Hide, actionBlockItem.Action); + + Assert.AreEqual(1, result.BlockItems.Count(b => b is DropLevelBlockItem)); + var droplevelBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(67, droplevelBlockItem.FilterPredicate.PredicateOperand); + Assert.AreEqual(FilterPredicateOperator.GreaterThanOrEqual, droplevelBlockItem.FilterPredicate.PredicateOperator); + + Assert.AreEqual(1, result.BlockItems.Count(b => b is RarityBlockItem)); + var rarityBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(ItemRarity.Magic, (ItemRarity)rarityBlockItem.FilterPredicate.PredicateOperand); + } + [Test] public void TranslateItemFilterBlockToString_NothingPopulated_ReturnsCorrectString() { diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index 64fe825..2bcf2b1 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -56,7 +56,7 @@ namespace Filtration.Parser.Services } var adjustedLine = line.Replace("#", " # "); - var trimmedLine = adjustedLine.TrimStart(' '); + var trimmedLine = adjustedLine.TrimStart(' ').TrimEnd(' '); var spaceOrEndOfLinePos = trimmedLine.IndexOf(" ", StringComparison.Ordinal) > 0 ? trimmedLine.IndexOf(" ", StringComparison.Ordinal) : trimmedLine.Length; @@ -104,6 +104,8 @@ namespace Filtration.Parser.Services } case "Rarity": { + RemoveExistingBlockItemsOfType(block); + var blockItemValue = new RarityBlockItem(); var result = Regex.Match(trimmedLine, @"^\w+\s+([>(result.Groups[2].Value); } + block.BlockItems.Add(blockItemValue); break; } diff --git a/Filtration/Resources/ItemBaseTypes.txt b/Filtration/Resources/ItemBaseTypes.txt index 09a9951..9f24867 100644 --- a/Filtration/Resources/ItemBaseTypes.txt +++ b/Filtration/Resources/ItemBaseTypes.txt @@ -1,13 +1,11 @@ A Mother's Parting Gift Abandoned Cavern Map -Abandoned Cavern Map Abandoned Wealth Abyss Map Abyssal Axe Abyssal Cry Abyssal Sceptre Academy Map -Academy Map Added Chaos Damage Support Added Cold Damage Support Added Fire Damage Support @@ -47,24 +45,19 @@ Antique Rapier Apex Rapier Aquamarine Flask Arachnid Nest Map -Arachnid Nest Map Arc Arcade Map -Arcade Map Arcanist Gloves Arcanist Slippers Archon Kite Shield Arctic Armour -Arctic Armour Arctic Breath Arena Map Arena Plate Arid Lake Map -Arid Lake Map Arming Axe Armourer's Scrap Arsenal Map -Arsenal Map Ashscale Talisman Assassin Bow Assassin's Boots @@ -78,11 +71,6 @@ Auric Mace Aventail Helmet Avian Slippers Avian Twins Talisman -Avian Twins Talisman -Avian Twins Talisman -Avian Twins Talisman -Avian Twins Talisman -Avian Twins Talisman Awl Backstab Baleful Gem @@ -104,7 +92,6 @@ Battle Lamellar Battle Plate Battle Sword Bazaar Map -Bazaar Map Bear Trap Behemoth Mace Birth of the Three @@ -133,7 +120,6 @@ Bloodlust Support Blunt Arrow Quiver Boarding Axe Bog Map -Bog Map Bone Armour Bone Bow Bone Circlet @@ -141,23 +127,8 @@ Bone Offering Bone Spirit Shield Bonespire Talisman Book of Reform -Book of Reform -Book of Reform -Book of Reform Book of Regression Book of Regrets -Book of Regrets -Book of Skill -Book of Skill -Book of Skill -Book of Skill -Book of Skill -Book of Skill -Book of Skill -Book of Skill -Book of Skill -Book of Skill -Book of Skill Book of Skill Boot Blade Boot Knife @@ -190,7 +161,6 @@ Butcher Sword Cabalist Regalia Callous Mask Canyon Map -Canyon Map Cardinal Round Shield Carnal Armour Carnal Boots @@ -206,13 +176,10 @@ Cast on Melee Kill Support Cast when Damage Taken Support Cast when Stunned Support Catacomb Map -Catacomb Map Cat's Paw Caustic Arrow Cedar Tower Shield Cells Map -Cells Map -Cemetery Map Cemetery Map Ceremonial Axe Ceremonial Kite Shield @@ -257,7 +224,6 @@ Cold Penetration Support Cold Snap Cold to Fire Support Colonnade Map -Colonnade Map Colossal Hybrid Flask Colossal Life Flask Colossal Mana Flask @@ -278,7 +244,6 @@ Conjurer Gloves Conjurer's Vestment Conquest Chainmail Conservatory Map -Conservatory Map Contagion Controlled Destruction Support Conversion Trap @@ -298,12 +263,9 @@ Corrugated Buckler Corsair Sword Courtesan Sword Courtyard Map -Courtyard Map -Coves Map Coves Map Coveted Possession Crematorium Map -Crematorium Map Crescent Staff Crested Tower Shield Crimson Jewel @@ -318,7 +280,6 @@ Crusader Helmet Crusader Plate Crypt Armour Crypt Map -Crypt Map Crystal Sceptre Crystal Wand Cube Of Absorption @@ -332,7 +293,6 @@ Cyclone Dagger Axe Damage Infusion Dark Forest Map -Dark Forest Map Darkwood Sceptre Deadhand Talisman Death @@ -388,13 +348,9 @@ Driftwood Sceptre Driftwood Spiked Shield Driftwood Wand Dry Peninsula Map -Dry Peninsula Map -Dry Woods Map Dry Woods Map Dual Strike Dunes Map -Dunes Map -Dungeon Map Dungeon Map Dusk Blade Dying Anguish @@ -518,7 +474,6 @@ Gemstone Sword General's Brigandine Generosity Support Ghetto Map -Ghetto Map Giant Life Flask Giant Mana Flask Gift of the Gemling Queen @@ -555,15 +510,11 @@ Golden Mantle Golden Mask Golden Obi Golden Page -Golden Page -Golden Page -Golden Page Golden Plate Golden Wreath Goliath Gauntlets Goliath Greaves Gorge Map -Gorge Map Gouger Grace Graceful Sword @@ -573,7 +524,6 @@ Granite Flask Grappler Grave Knowledge Graveyard Map -Graveyard Map Great Crown Great Helmet Great Mallet @@ -584,7 +534,6 @@ Greater Multiple Projectiles Support Greatwolf Talisman Grinning Fetish Grotto Map -Grotto Map Ground Slam Grove Bow Gut Ripper @@ -698,7 +647,6 @@ Jeweller's Orb Jingling Spirit Shield Judgement Staff Jungle Valley Map -Jungle Valley Map Kaom's Greaves Kaom's Plate Karui Axe @@ -810,8 +758,6 @@ Mirrored Spiked Shield Molten Shell Molten Strike Monkey Paw Talisman -Monkey Paw Talisman -Monkey Paw Talisman Monkey Twins Talisman Moon Staff Moonstone Ring @@ -822,20 +768,16 @@ Mortal Ignorance Mortal Rage Mosaic Kite Shield Mountain Ledge Map -Mountain Ledge Map -Mud Geyser Map Mud Geyser Map Multiple Traps Support Multistrike Support Murder Boots Murder Mitts Museum Map -Museum Map Nailed Fist Necromancer Circlet Necromancer Silks Necropolis Map -Necropolis Map New Shock Nova NewPunishment Nightmare Bascinet @@ -867,14 +809,11 @@ Orb of Scouring Orb of Storms Orb of Transmutation Orchard Map -Orchard Map Ornate Mace Ornate Ringmail Ornate Spiked Shield Ornate Sword Overgrown Ruin Map -Overgrown Ruin Map -Overgrown Shrine Map Overgrown Shrine Map Padded Jacket Padded Vest @@ -882,7 +821,6 @@ Pagan Wand Painted Buckler Painted Tower Shield Palace Map -Palace Map Paua Amulet Paua Ring Pecoraro @@ -893,11 +831,9 @@ Petrified Club Phantasmagoria Map Phantom Mace Phase Run -Phase Run Physical Projectile Attack Damage Support Physical to Lightning Support Pier Map -Pier Map Pierce Support Pig-Faced Bascinet Piledriver @@ -908,7 +844,6 @@ Plague Mask Plank Kite Shield Plate Vest Plateau Map -Plateau Map Plated Gauntlets Plated Greaves Plated Maul @@ -928,7 +863,6 @@ Power Charge On Critical Support Power Siphon Praetor Crown Precinct Map -Precinct Map Prehistoric Claw Pride Before the Fall Primal Skull Talisman @@ -940,7 +874,6 @@ Prismatic Ring Profane Wand Projectile Weakness Promenade Map -Promenade Map Prong Dagger Prophecy Prophecy Wand @@ -982,7 +915,6 @@ Recurve Bow Reduced Mana Support Redwood Spiked Shield Reef Map -Reef Map Reflex Bow Regal Orb Regicide Mask @@ -992,7 +924,6 @@ Reinforced Tower Shield Rejuvenation Totem Remote Mine Support Residence Map -Residence Map Return Projectiles Support Ribbon Spool Righteous Fire @@ -1074,11 +1005,9 @@ Serpentine Staff Serpentscale Boots Serpentscale Gauntlets Serrated Arrow Quiver -Serrated Arrow Quiver Serrated Foil Sewer Keys Sewer Map -Sewer Map Shabby Jerkin Shackled Boots Shadow Axe @@ -1095,15 +1024,12 @@ Sharktooth Arrow Quiver Sharktooth Claw Shield Charge Shipyard Map -Shipyard Map Shock Nova Shockwave Totem Shore Map -Shore Map Short Bow Shrapnel Shot Shrine Map -Shrine Map Siege Axe Siege Ballista Siege Helmet @@ -1152,8 +1078,6 @@ Spectral Throw Spell Echo Support Spell Totem Support Spider Forest Map -Spider Forest Map -Spider Lair Map Spider Lair Map Spidersilk Robe Spiked Bundle @@ -1173,7 +1097,6 @@ Split Arrow Split Projectiles Support Splitnewt Talisman Springs Map -Springs Map Stacked Deck Stag Sceptre Static Strike @@ -1194,7 +1117,6 @@ Stone Axe Stone Hammer Storm Call Strand Map -Strand Map Strapped Boots Strapped Leather Strapped Mitts @@ -1221,11 +1143,9 @@ Teak Round Shield Tempered Foil Tempest Shield Temple Map -Temple Map Temporal Chains Tenderizer Terrace Map -Terrace Map Terror Claw Terror Maul Thaumetic Emblem @@ -1338,7 +1258,6 @@ The Wolf's Shadow The Wrath Thicket Bow Thicket Map -Thicket Map Thief's Garb Thorium Spirit Shield Thorn Rapier @@ -1365,7 +1284,6 @@ Tornado Shot Tornado Wand Torture Cage Torture Chamber Map -Torture Chamber Map Totemic Maul Touch of God Tower Key @@ -1385,8 +1303,6 @@ Tricorne Trisula Triumphant Lamellar Tropical Island Map -Tropical Island Map -Tunnel Map Tunnel Map Turn the Other Cheek Turquoise Amulet @@ -1396,12 +1312,8 @@ Twin Claw Two-Handed Sword Two-Point Arrow Quiver Two-Stone Ring -Two-Stone Ring -Two-Stone Ring Tyrant's Sekhem Underground River Map -Underground River Map -Underground Sea Map Underground Sea Map Undying Flesh Talisman Unset Ring @@ -1440,7 +1352,6 @@ Vaal Molten Shell Vaal Orb Vaal Power Siphon Vaal Pyramid Map -Vaal Pyramid Map Vaal Rain of Arrows Vaal Rapier Vaal Reave @@ -1454,7 +1365,6 @@ Vaal Storm Call Vaal Summon Skeletons Vaal Sweep Vaal Temple Map -Vaal Temple Map Variscite Blade Varnished Coat Velvet Gloves @@ -1464,7 +1374,6 @@ Vial Of Power Vigilant Strike Vile Staff Villa Map -Villa Map Village Ruin Map Vine Circlet Vinia's Token @@ -1490,7 +1399,6 @@ War Plate War Sword Warlord's Mark Waste Pool Map -Waste Pool Map Wasteland Map Waterways Map Waxed Garb @@ -1499,7 +1407,6 @@ Weapon Elemental Damage Support Wereclaw Talisman Whalebone Rapier Wharf Map -Wharf Map Whirling Blades Widowsilk Robe Wild Leather