More import changes and more options

This commit is contained in:
Zeffuro
2025-12-22 05:42:36 +01:00
parent 5561305af8
commit c198663184
6 changed files with 174 additions and 21 deletions
+22 -3
View File
@@ -56,6 +56,8 @@ public static unsafe class InventoryState
private static readonly List<CategorizedInventory> FilteredCategories = new(capacity: 256);
private static readonly List<UserCategoryDefinition> UserCategoriesSortedScratch = new(capacity: 64);
private static readonly List<uint> RemoveKeysScratch = new(capacity: 256);
private const uint UserCategoryKeyFlag = 0x8000_0000;
@@ -149,9 +151,22 @@ public static unsafe class InventoryState
if (userCategoriesEnabled && userCategories.Count > 0)
{
for (int c = 0; c < userCategories.Count; c++)
UserCategoriesSortedScratch.Clear();
UserCategoriesSortedScratch.AddRange(userCategories);
UserCategoriesSortedScratch.Sort((a, b) =>
{
UserCategoryDefinition category = userCategories[c];
int p = b.Priority.CompareTo(a.Priority);
if (p != 0) return p;
int o = a.Order.CompareTo(b.Order);
if (o != 0) return o;
return string.Compare(a.Id, b.Id, StringComparison.OrdinalIgnoreCase);
});
for (int c = 0; c < UserCategoriesSortedScratch.Count; c++)
{
UserCategoryDefinition category = UserCategoriesSortedScratch[c];
uint key = MakeUserCategoryKey(category.Order);
if (!BucketsByKey.TryGetValue(key, out CategoryBucket? bucket))
@@ -182,11 +197,15 @@ public static unsafe class InventoryState
foreach (var itemKvp in ItemInfoByItemId)
{
ItemInfo item = itemKvp.Value;
uint itemId = item.Item.ItemId;
if (claimedItemIds.Contains(itemId))
continue;
if (UserCategoryMatcher.Matches(item, category))
{
bucket.Items.Add(item);
claimedItemIds.Add(item.Item.ItemId);
claimedItemIds.Add(itemId);
}
}
+6
View File
@@ -47,6 +47,12 @@ public sealed class ItemInfo : IEquatable<ItemInfo>
public RowRef<ItemUICategory> UiCategory => Row.ItemUICategory;
public bool IsUntradable => Row.IsUntradable;
public bool IsUnique => Row.IsUnique;
public bool IsCollectable => Row.IsCollectable;
public bool IsDyeable => Row.DyeCount > 0;
public bool IsRepairable => Row.ItemRepair.RowId != 0;
private string Description => _description ??= Row.Description.ToString();
public bool IsRegexMatch(string searchTerms)
@@ -24,12 +24,21 @@ internal static class UserCategoryMatcher
if (rules.AllowedRarities.Count > 0 && !rules.AllowedRarities.Contains(item.Rarity))
return false;
if (rules.Level.Enabled && !InRange(item.Level, rules.Level.Min, rules.Level.Max))
return false;
if (rules.ItemLevel.Enabled && !InRange(item.ItemLevel, rules.ItemLevel.Min, rules.ItemLevel.Max))
return false;
if (rules.VendorPrice.Enabled && !InRange(item.VendorPrice, rules.VendorPrice.Min, rules.VendorPrice.Max))
return false;
if (!MatchesToggle(rules.Untradable, item.IsUntradable)) return false;
if (!MatchesToggle(rules.Unique, item.IsUnique)) return false;
if (!MatchesToggle(rules.Collectable, item.IsCollectable)) return false;
if (!MatchesToggle(rules.Dyeable, item.IsDyeable)) return false;
if (!MatchesToggle(rules.Repairable, item.IsRepairable)) return false;
if (rules.AllowedItemNamePatterns.Count > 0)
{
bool any = false;
@@ -63,4 +72,13 @@ internal static class UserCategoryMatcher
private static bool InRange<T>(T value, T min, T max) where T : struct, IComparable<T>
=> value.CompareTo(min) >= 0 && value.CompareTo(max) <= 0;
private static bool MatchesToggle(StateFilter filter, bool itemHasProperty)
=> filter.ToggleState switch
{
ToggleFilterState.Ignored => true,
ToggleFilterState.Allow => itemHasProperty,
ToggleFilterState.Disallow => !itemHasProperty,
_ => true
};
}