feat: add item name and id search
This commit is contained in:
parent
06a70c2556
commit
45128396d2
|
@ -906,25 +906,37 @@ namespace Glamaholic.Ui {
|
||||||
private string Query { get; }
|
private string Query { get; }
|
||||||
private HashSet<ClassJob> WantedJobs { get; } = new();
|
private HashSet<ClassJob> WantedJobs { get; } = new();
|
||||||
private HashSet<string> Tags { 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) {
|
internal FilterInfo(DataManager data, string filter) {
|
||||||
this.Data = data;
|
this.Data = data;
|
||||||
|
|
||||||
var queryWords = new List<string>();
|
var queryWords = new List<string>();
|
||||||
|
|
||||||
string? quotedTag = null;
|
var quoteType = -1;
|
||||||
|
string? quoted = null;
|
||||||
foreach (var immutableWord in filter.Split(' ')) {
|
foreach (var immutableWord in filter.Split(' ')) {
|
||||||
var word = immutableWord;
|
var word = immutableWord;
|
||||||
|
|
||||||
if (quotedTag != null) {
|
if (quoted != null) {
|
||||||
quotedTag += " ";
|
quoted += " ";
|
||||||
|
|
||||||
var quoteIndex = word.IndexOf('"');
|
var quoteIndex = word.IndexOf('"');
|
||||||
if (quoteIndex > -1) {
|
if (quoteIndex > -1) {
|
||||||
quotedTag += word[..quoteIndex];
|
quoted += word[..quoteIndex];
|
||||||
|
|
||||||
this.Tags.Add(quotedTag);
|
switch (quoteType) {
|
||||||
quotedTag = null;
|
case 1:
|
||||||
|
this.Tags.Add(quoted);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
this.ItemNames.Add(quoted);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
quoted = null;
|
||||||
|
quoteType = -1;
|
||||||
|
|
||||||
var rest = word[(quoteIndex + 1)..];
|
var rest = word[(quoteIndex + 1)..];
|
||||||
if (rest.Length > 0) {
|
if (rest.Length > 0) {
|
||||||
|
@ -933,7 +945,7 @@ namespace Glamaholic.Ui {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quotedTag += word;
|
quoted += word;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -958,7 +970,12 @@ namespace Glamaholic.Ui {
|
||||||
|
|
||||||
if (word.StartsWith("t:")) {
|
if (word.StartsWith("t:")) {
|
||||||
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 {
|
} else {
|
||||||
this.Tags.Add(word[2..]);
|
this.Tags.Add(word[2..]);
|
||||||
}
|
}
|
||||||
|
@ -966,6 +983,29 @@ namespace Glamaholic.Ui {
|
||||||
continue;
|
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);
|
queryWords.Add(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -979,7 +1019,7 @@ namespace Glamaholic.Ui {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there's nothing custom about this filter, this is a match
|
// 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;
|
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) {
|
foreach (var mirage in plate.Items.Values) {
|
||||||
var item = this.Data.GetExcelSheet<Item>()!.GetRow(mirage.ItemId % Util.HqItemOffset);
|
var item = this.Data.GetExcelSheet<Item>()!.GetRow(mirage.ItemId % Util.HqItemOffset);
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
|
|
Loading…
Reference in New Issue