feat: add item name and id search

This commit is contained in:
Anna 2021-12-13 05:00:14 -05:00
parent 06a70c2556
commit 45128396d2
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
1 changed files with 89 additions and 20 deletions

View File

@ -906,25 +906,37 @@ namespace Glamaholic.Ui {
private string Query { get; }
private HashSet<ClassJob> WantedJobs { get; } = new();
private HashSet<string> Tags { get; } = new();
private HashSet<uint> ItemIds { get; } = new();
private HashSet<string> ItemNames { get; } = new();
internal FilterInfo(DataManager data, string filter) {
this.Data = data;
var queryWords = new List<string>();
string? quotedTag = null;
var quoteType = -1;
string? quoted = null;
foreach (var immutableWord in filter.Split(' ')) {
var word = immutableWord;
if (quotedTag != null) {
quotedTag += " ";
if (quoted != null) {
quoted += " ";
var quoteIndex = word.IndexOf('"');
if (quoteIndex > -1) {
quotedTag += word[..quoteIndex];
quoted += word[..quoteIndex];
this.Tags.Add(quotedTag);
quotedTag = null;
switch (quoteType) {
case 1:
this.Tags.Add(quoted);
break;
case 2:
this.ItemNames.Add(quoted);
break;
}
quoted = null;
quoteType = -1;
var rest = word[(quoteIndex + 1)..];
if (rest.Length > 0) {
@ -933,7 +945,7 @@ namespace Glamaholic.Ui {
continue;
}
} else {
quotedTag += word;
quoted += word;
continue;
}
}
@ -958,7 +970,12 @@ namespace Glamaholic.Ui {
if (word.StartsWith("t:")) {
if (word.StartsWith("t:\"")) {
quotedTag = word[3..];
if (word.EndsWith('"') && word.Length >= 5) {
this.Tags.Add(word[3..^1]);
} else {
quoteType = 1;
quoted = word[3..];
}
} else {
this.Tags.Add(word[2..]);
}
@ -966,6 +983,29 @@ namespace Glamaholic.Ui {
continue;
}
if (word.StartsWith("id:")) {
if (uint.TryParse(word[3..], out var id)) {
this.ItemIds.Add(id);
}
continue;
}
if (word.StartsWith("i:")) {
if (word.StartsWith("i:\"")) {
if (word.EndsWith('"') && word.Length >= 5) {
this.ItemNames.Add(word[3..^1]);
} else {
quoteType = 2;
quoted = word[3..];
}
} else {
this.ItemNames.Add(word[2..]);
}
continue;
}
queryWords.Add(word);
}
@ -979,7 +1019,7 @@ namespace Glamaholic.Ui {
}
// if there's nothing custom about this filter, this is a match
if (this.MaxLevel == 0 && this.WantedJobs.Count == 0 && this.Tags.Count == 0) {
if (this.MaxLevel == 0 && this.WantedJobs.Count == 0 && this.Tags.Count == 0 && this.ItemIds.Count == 0 && this.ItemNames.Count == 0) {
return true;
}
@ -989,6 +1029,35 @@ namespace Glamaholic.Ui {
}
}
if (this.ItemIds.Count > 0) {
var matching = plate.Items.Values
.Select(mirage => mirage.ItemId)
.Intersect(this.ItemIds)
.Count();
if (matching != this.ItemIds.Count) {
return false;
}
}
if (this.ItemNames.Count > 0) {
var sheet = this.Data.GetExcelSheet<Item>()!;
var names = plate.Items.Values
.Select(mirage => sheet.GetRow(mirage.ItemId % Util.HqItemOffset))
.Where(item => item != null)
.Cast<Item>()
.Select(item => item.Name.RawString.ToLowerInvariant())
.ToArray();
foreach (var needle in this.ItemNames) {
var lower = needle.ToLowerInvariant();
if (!names.Any(name => name.Contains(lower))) {
return false;
}
}
}
foreach (var mirage in plate.Items.Values) {
var item = this.Data.GetExcelSheet<Item>()!.GetRow(mirage.ItemId % Util.HqItemOffset);
if (item == null) {