Files
AetherBags/KamiToolKit/Premade/SearchAddons/ItemSearchAddonBase.cs
T
KnackAtNite 8db4ce6094
Debug Build and Test / Build against Latest Dalamud (push) Has been cancelled
Debug Build and Test / Build against Staging Dalamud (push) Has been cancelled
Initial commit: AetherBags + KamiToolKit for FC Gitea
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 14:46:31 -05:00

38 lines
1.5 KiB
C#

using System.Text.RegularExpressions;
using KamiToolKit.Nodes;
using Lumina.Excel.Sheets;
namespace KamiToolKit.Premade.SearchAddons;
public class ItemSearchAddonBase<T> : BaseSearchAddon<Item, T> where T : ListItemNode<Item>, new() {
protected override int Comparer(Item left, Item right, string sortingString, bool reversed) {
var result = sortingString switch {
"Alphabetical" => string.CompareOrdinal(left.Name.ToString(), right.Name.ToString()),
"Id" => left.RowId.CompareTo(right.RowId),
_ => 0,
};
return reversed ? -result : result;
}
protected override bool IsMatch(Item item, string searchString) {
var isDescriptionSearch = searchString.StartsWith('$');
if (isDescriptionSearch) {
searchString = searchString[1..];
}
var regex = new Regex(searchString,RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (regex.IsMatch(item.RowId.ToString())) return true;
if (regex.IsMatch(item.Name.ToString())) return true;
if (regex.IsMatch(item.Description.ToString()) && isDescriptionSearch) return true;
if (regex.IsMatch(item.LevelEquip.ToString())) return true;
if (regex.IsMatch(item.LevelItem.RowId.ToString())) return true;
if (regex.IsMatch(item.ClassJobCategory.Value.Name.ToString())) return true;
if (regex.IsMatch(item.ItemUICategory.Value.Name.ToString())) return true;
return false;
}
}