-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds functionality for "Find Traits" and "Find Names"
(Only currently works with English text.)
- Loading branch information
1 parent
26ef3a9
commit 4d0b4f1
Showing
4 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Montage.Weiss.Tools.GUI/ViewModels/Query/NameQueryViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Montage.Card.API.Utilities; | ||
using Montage.Weiss.Tools.Entities; | ||
using Montage.Weiss.Tools.Utilities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace Montage.Weiss.Tools.GUI.ViewModels.Query; | ||
internal partial class NameQueryViewModel : CardSearchQueryViewModel | ||
{ | ||
private List<string> _names; | ||
private static readonly Regex _nameMatcher = NameMatcher(); | ||
|
||
public NameQueryViewModel(WeissSchwarzCard card) | ||
{ | ||
_names = [ | ||
.. card.Effect.SelectMany(e => _nameMatcher.Matches(e).SelectMany(TranslateNameMatch)) | ||
]; | ||
|
||
|
||
var climaxesToSearchString = _names.ConcatAsString(", "); | ||
|
||
Type = QueryType.ClimaxCombo; | ||
DisplayText = climaxesToSearchString.Limit(10); | ||
ToolTip = $"Finds any cards with names containing any of the following: {climaxesToSearchString}"; | ||
} | ||
|
||
private IEnumerable<string> TranslateNameMatch(Match match) | ||
{ | ||
yield return match.Groups[2].Value; | ||
if (match.Groups[4].Success) | ||
yield return match.Groups[4].Value; | ||
} | ||
|
||
public override Func<WeissSchwarzCard, bool> ToPredicate() | ||
{ | ||
return c => _names.Any(n => (c.Name.EN?.Contains(n) ?? false) || (c.Name.JP?.Contains(n) ?? false)); | ||
} | ||
|
||
[GeneratedRegex(@"([""])((?:(?=(?:\\)*)\\.|.)*?)(\((.*)\))?\1")] | ||
private static partial Regex NameMatcher(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters