Skip to content

Commit

Permalink
Merge pull request #281 from LittleLightForDestiny/search_fixes
Browse files Browse the repository at this point in the history
makes search filters more relevant
  • Loading branch information
joaopmarquesini authored Jul 28, 2023
2 parents a176d8c + 8f727a4 commit fdec373
Show file tree
Hide file tree
Showing 29 changed files with 334 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class DuplicatedItemsBloc extends ChangeNotifier {
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);
final map = <int, Map<int, List<DestinyItemInfo>>>{};
final genericItems = _genericItems ??= {};
final flatItemList = <DestinyItemInfo>[];
for (final itemHash in hashes) {
final def = defs[itemHash];
final bucketHash = def?.inventory?.bucketTypeHash;
Expand All @@ -108,9 +109,10 @@ class DuplicatedItemsBloc extends ChangeNotifier {
final items = sortedItems.where((i) => i.itemHash == itemHash);
if (items.length <= 1) continue;
if (def != null) genericItems[itemHash] ??= DefinitionItemInfo.fromDefinition(def);
for (final item in items) filterBloc.addValue(item);
flatItemList.addAll(items);
bucketHashMap[itemHash] = items.toList();
}
filterBloc.addValues(flatItemList);
_unfilteredItems = map;
_filter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ItemBucketTypeFilterOptions extends BaseFilterOptions<Set<EquipmentBucketG
);

@override
bool get available => availableValues.length > 1;
bool get available => true;

@override
set value(Set<EquipmentBucketGroup> value) {
Expand Down
15 changes: 10 additions & 5 deletions lib/modules/search/blocs/filters/ammo_type_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ class AmmoTypeFilter extends BaseItemFilter<AmmoTypeFilterOptions> with Manifest
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final hash = item.itemHash;
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(hash);
final ammoType = def?.equippingBlock?.ammoType ?? DestinyAmmunitionType.Unknown;
data.availableValues.add(ammoType);
Future<void> addValues(List<DestinyItemInfo> items) async {
final hashes = items.map((i) => i.itemHash).whereType<int>();
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);
final ammoTypes = defs.values.map((d) => d.equippingBlock?.ammoType ?? DestinyAmmunitionType.Unknown);
data.availableValues.addAll(ammoTypes);
}

@override
void clearAvailable() {
data.availableValues.clear();
}
}
39 changes: 24 additions & 15 deletions lib/modules/search/blocs/filters/armor_stats_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,29 @@ class ArmorStatsFilter extends BaseItemFilter<ArmorStatsFilterOptions> with Mani
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final hash = item.itemHash;
final instanceId = item.instanceId;
if (hash == null) return;
if (instanceId == null) return;
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(hash);
final isArmor = def?.isArmor ?? false;
if (!isArmor) return;
final total = item.stats?.values.fold<int>(0, (t, v) => t + (v.value ?? 0));
if (total == null) return;
_itemTotalStatsMap[instanceId] = total;
int min = math.min(data.availableValues.min, total);
int max = math.max(data.availableValues.max, total);
data.value.min = data.availableValues.min = min;
data.value.max = data.availableValues.max = max;
Future<void> addValues(List<DestinyItemInfo> items) async {
items = items.where((i) => i.instanceId != null).toList();
final hashes = items.map((i) => i.itemHash);
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);

for (final item in items) {
final instanceId = item.instanceId;
if (instanceId == null) continue;
final def = defs[item.itemHash];
final isArmor = def?.isArmor ?? false;
if (!isArmor) continue;
final total = item.stats?.values.fold<int>(0, (t, v) => t + (v.value ?? 0));
if (total == null) continue;
_itemTotalStatsMap[instanceId] = total;
int min = math.min(data.availableValues.min, total);
int max = math.max(data.availableValues.max, total);
data.value.min = data.availableValues.min = min;
data.value.max = data.availableValues.max = max;
}
}

@override
void clearAvailable() {
data.availableValues = ArmorStatsConstraints();
}
}
4 changes: 3 additions & 1 deletion lib/modules/search/blocs/filters/base_item_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class BaseItemFilter<T extends BaseFilterOptions> {

Future<bool> filterItem(DestinyItemInfo item);

Future<void> addValue(DestinyItemInfo item) async {}
Future<void> addValues(List<DestinyItemInfo> item);

void updateValue(T t) {
data.value = t.value;
Expand All @@ -29,4 +29,6 @@ abstract class BaseItemFilter<T extends BaseFilterOptions> {
void updateEnabled(bool enabled) {
data.enabled = enabled;
}

void clearAvailable();
}
15 changes: 10 additions & 5 deletions lib/modules/search/blocs/filters/class_type_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ class ClassTypeFilter extends BaseItemFilter<ClassTypeFilterOptions> with Manife
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final hash = item.itemHash;
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(hash);
final classType = def?.classType ?? DestinyClass.Unknown;
data.availableValues.add(classType);
Future<void> addValues(List<DestinyItemInfo> item) async {
final hashes = item.map((i) => i.itemHash);
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);
final classTypes = defs.values.map((d) => d.classType ?? DestinyClass.Unknown);
data.availableValues.addAll(classTypes);
}

@override
void clearAvailable() {
data.availableValues.clear();
}
}
11 changes: 8 additions & 3 deletions lib/modules/search/blocs/filters/crafted_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ class CraftedFilter extends BaseItemFilter<CraftedFilterOptions> with ManifestCo
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final isCrafted = item.state?.contains(ItemState.Crafted) ?? false;
data.availableValues.add(isCrafted);
Future<void> addValues(List<DestinyItemInfo> items) async {
final isCrafted = items.map((i) => i.state?.contains(ItemState.Crafted) ?? false);
data.availableValues.addAll(isCrafted);
}

@override
void clearAvailable() {
data.availableValues.clear();
}
}
26 changes: 23 additions & 3 deletions lib/modules/search/blocs/filters/damage_type_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:bungie_api/destiny2.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:little_light/models/item_info/destiny_item_info.dart';
import 'package:little_light/modules/search/blocs/filter_options/damage_type_filter_options.dart';
import 'package:little_light/services/bungie_api/enums/inventory_bucket_hash.enum.dart';
import 'package:little_light/services/manifest/manifest.consumer.dart';
import 'base_item_filter.dart';

Expand All @@ -18,12 +19,31 @@ class DamageTypeFilter extends BaseItemFilter<DamageTypeFilterOptions> with Mani

@override
Future<bool> filterItem(DestinyItemInfo item) async {
if (item.bucketHash == InventoryBucket.subclass) {
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(item.itemHash);
final damageType = def?.talentGrid?.hudDamageType;
return data.value.contains(damageType);
}
return data.value.contains(item.damageType);
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final damageType = item.damageType ?? DamageType.None;
data.availableValues.add(damageType);
Future<void> addValues(List<DestinyItemInfo> items) async {
final subclassHashes = items.where((i) => i.bucketHash == InventoryBucket.subclass).map((i) => i.itemHash);
final subclassDefs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(subclassHashes);
final damageType = items.map((i) {
if (i.bucketHash == InventoryBucket.subclass) {
final def = subclassDefs[i.itemHash];
final damageType = def?.talentGrid?.hudDamageType;
return damageType ?? DamageType.None;
}
return i.damageType ?? DamageType.None;
});
data.availableValues.addAll(damageType);
}

@override
void clearAvailable() {
data.availableValues.clear();
}
}
15 changes: 10 additions & 5 deletions lib/modules/search/blocs/filters/deepsight_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ class DeepsightFilter extends BaseItemFilter<DeepsightFilterOptions> with Manife
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final hash = item.itemHash;
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(hash);
final isDeepsight = isItemDeepsight(item, def);
data.availableValues.add(isDeepsight);
Future<void> addValues(List<DestinyItemInfo> items) async {
final hashes = items.map((i) => i.itemHash);
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);
final isDeepsight = items.map((i) => isItemDeepsight(i, defs[i.itemHash]));
data.availableValues.addAll(isDeepsight);
}

@override
void clearAvailable() {
data.availableValues.clear();
}
}
39 changes: 23 additions & 16 deletions lib/modules/search/blocs/filters/energy_level_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@ class EnergyLevelFilter extends BaseItemFilter<EnergyLevelFilterOptions> with Ma
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final hash = item.itemHash;
if (hash == null) return;
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(hash);
if (def?.itemType != DestinyItemType.Armor) return;
Future<void> addValues(List<DestinyItemInfo> items) async {
final hashes = items.map((i) => i.itemHash);
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);
for (final item in items) {
final def = defs[item.itemHash];
if (def?.itemType != DestinyItemType.Armor) return;

final energy = item.energyCapacity;
if (energy == null) {
data.availableValues.includeEnergylessItems = true;
data.value.includeEnergylessItems = true;
return;
final energy = item.energyCapacity;
if (energy == null) {
data.availableValues.includeEnergylessItems = true;
data.value.includeEnergylessItems = true;
return;
}
final min = math.min(data.availableValues.min, energy);
final max = math.max(data.availableValues.max, energy);
data.availableValues.min = min;
data.availableValues.max = max;
data.value.min = min;
data.value.max = max;
}
final min = math.min(data.availableValues.min, energy);
final max = math.max(data.availableValues.max, energy);
data.availableValues.min = min;
data.availableValues.max = max;
data.value.min = min;
data.value.max = max;
}

@override
void clearAvailable() {
data.availableValues = EnergyLevelConstraints();
}
}
1 change: 0 additions & 1 deletion lib/modules/search/blocs/filters/export.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export 'item_subtype_filter.dart';
export 'item_tag_filter.dart';
export 'loadout_filter.dart';
export 'power_level_filter.dart';
export 'season_slot_filter.dart';
export 'text_filter.dart';
export 'tier_type_filter.dart';
export 'wishlist_tag_filter.dart';
16 changes: 10 additions & 6 deletions lib/modules/search/blocs/filters/item_bucket_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ class ItemBucketFilter extends BaseItemFilter<ItemBucketFilterOptions> with Mani
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final hash = item.itemHash;
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(hash);
final bucketHash = def?.inventory?.bucketTypeHash;
if (bucketHash == null) return;
data.availableValues.add(bucketHash);
Future<void> addValues(List<DestinyItemInfo> items) async {
final hashes = items.map((i) => i.itemHash);
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);
final bucketHashes = defs.values.map((d) => d.inventory?.bucketTypeHash).whereType<int>();
data.availableValues.addAll(bucketHashes);
}

@override
void clearAvailable() {
data.availableValues.clear();
}
}
24 changes: 16 additions & 8 deletions lib/modules/search/blocs/filters/item_bucket_type_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ class ItemBucketTypeFilter extends BaseItemFilter<ItemBucketTypeFilterOptions> w
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final hash = item.itemHash;
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(hash);
final bucketHash = def?.inventory?.bucketTypeHash;
final value = EquipmentBucketGroup.values.firstWhereOrNull((element) => element.bucketHashes.contains(bucketHash));
if (value != null) {
data.availableValues.add(value);
}
Future<void> addValues(List<DestinyItemInfo> items) async {
final hashes = items.map((i) => i.itemHash);
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);
final bucketHashes = defs.values.map((d) => d.inventory?.bucketTypeHash);
final values = EquipmentBucketGroup.values.where(
(element) => element.bucketHashes.any(
(h) => bucketHashes.contains(h),
),
);

data.availableValues.addAll(values);
}

@override
void clearAvailable() {
data.availableValues.clear();
}
}
27 changes: 17 additions & 10 deletions lib/modules/search/blocs/filters/item_owner_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,24 @@ class ItemOwnerFilter extends BaseItemFilter<ItemOwnerFilterOptions> {
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final characterId = item.characterId;
if (characterId != null) {
data.availableValues.characters.add(characterId);
return;
}
if (item.bucketHash == InventoryBucket.general) {
data.availableValues.vault = true;
return;
Future<void> addValues(List<DestinyItemInfo> items) async {
for (final item in items) {
final characterId = item.characterId;
if (characterId != null) {
data.availableValues.characters.add(characterId);
continue;
}
if (item.bucketHash == InventoryBucket.general) {
data.availableValues.vault = true;
continue;
}

data.availableValues.profile = true;
}
}

data.availableValues.profile = true;
@override
void clearAvailable() {
data.availableValues.clear();
}
}
14 changes: 9 additions & 5 deletions lib/modules/search/blocs/filters/item_subtype_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ class ItemSubtypeFilter extends BaseItemFilter<ItemSubtypeFilterOptions> with Ma
}

@override
Future<void> addValue(DestinyItemInfo item) async {
final hash = item.itemHash;
final def = await manifest.getDefinition<DestinyInventoryItemDefinition>(hash);
final categoryHashes = def?.itemCategoryHashes;
if (categoryHashes == null) return;
Future<void> addValues(List<DestinyItemInfo> items) async {
final hashes = items.map((i) => i.itemHash);
final defs = await manifest.getDefinitions<DestinyInventoryItemDefinition>(hashes);
final categoryHashes = defs.values.map((d) => d.itemCategoryHashes).whereType<int>();
final categoryDefs = await manifest.getDefinitions<DestinyItemCategoryDefinition>(categoryHashes);
for (final category in categoryDefs.values) {
final subtype = category.grantDestinySubType ?? DestinyItemSubType.None;
Expand All @@ -38,4 +37,9 @@ class ItemSubtypeFilter extends BaseItemFilter<ItemSubtypeFilterOptions> with Ma
this.data.availableValues.add(hash);
}
}

@override
void clearAvailable() {
data.availableValues.clear();
}
}
Loading

0 comments on commit fdec373

Please sign in to comment.