Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed superior prefix causing the parser to fail #163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Sidekick.Apis.Poe/IItemMetadataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Sidekick.Apis.Poe
{
public interface IItemMetadataParser : IInitializableService
{
string GetLineWithoutSuperiorAffix(string line);

ItemMetadata? Parse(string? name, string? type);

ItemMetadata? Parse(ParsingItem parsingItem);
Expand Down
6 changes: 6 additions & 0 deletions src/Sidekick.Apis.Poe/Parser/ItemParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public ItemParser(
throw new NotSupportedException("Item not found.");
}

// Strip the Superior affix from the name
parsingItem.Blocks.First().Lines.ForEach(x =>
{
x.Text = itemMetadataProvider.GetLineWithoutSuperiorAffix(x.Text);
});

parsingItem.Metadata = metadata;
ItemMetadata? invariant = null;
if (invariantMetadataProvider.IdDictionary.TryGetValue(metadata.Id, out var invariantMetadata))
Expand Down
6 changes: 6 additions & 0 deletions src/Sidekick.Apis.Poe/Parser/MetadataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ public MetadataParser(

private Regex Affixes { get; set; } = null!;

private Regex SuperiorAffix { get; set; } = null!;

/// <inheritdoc/>
public InitializationPriority Priority => InitializationPriority.Medium;

private string GetLineWithoutAffixes(string line) => Affixes.Replace(line, string.Empty).Trim(' ', ',');

public string GetLineWithoutSuperiorAffix(string line) => SuperiorAffix.Replace(line, string.Empty).Trim(' ', ',');

/// <inheritdoc/>
public Task Initialize()
{
Expand Down Expand Up @@ -58,6 +62,8 @@ public Task Initialize()
getRegexLine(gameLanguageProvider.Language.AffixDivergent) + "|" +
getRegexLine(gameLanguageProvider.Language.AffixPhantasmal) + ")");

SuperiorAffix = new Regex("(?:" + getRegexLine(gameLanguageProvider.Language.AffixSuperior) + ")");

return Task.CompletedTask;
}

Expand Down
30 changes: 29 additions & 1 deletion tests/Sidekick.Apis.Poe.Tests/Parser/BlightParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ Natural inhabitants of this area have been removed (implicit)
Assert.True(actual.Properties.Blighted);
}

[Fact]
public void ParseSuperiorBlightedMap()
{
var actual = parser.ParseItem(@"Item Class: Maps
Rarity: Normal
Superior Blighted Shore Map
--------
Map Tier: 6
Item Quantity: +5% (augmented)
Quality: +5% (augmented)
--------
Item Level: 74
--------
Area is infested with Fungal Growths (implicit)
Map's Item Quantity Modifiers also affect Blight Chest count at 25% value (implicit)
Can be Anointed up to 3 times (implicit)
Natural inhabitants of this area have been removed (implicit)
--------
Travel to this Map by using it in a personal Map Device. Maps can only be used once.
");

Assert.Equal(Category.Map, actual.Metadata.Category);
Assert.Equal(Class.Maps, actual.Header.Class);
Assert.Equal(Rarity.Normal, actual.Metadata.Rarity);
Assert.Equal("Shore Map", actual.Metadata.Type);
Assert.Equal(6, actual.Properties.MapTier);
Assert.True(actual.Properties.Blighted);
}

[Fact]
public void ClearOil()
{
Expand Down Expand Up @@ -96,6 +125,5 @@ Players have 20% less Recovery Rate of Life and Energy Shield
Assert.Equal("Spider Forest Map", actual.Metadata.Type);
Assert.True(actual.Properties.Blighted);
}

}
}
Loading