Repository: DestinyItemManager/DIM
Pull request #8543 (2022-07-03 07:20:10)

Added Enhanced Perk Filter
Issue: https://github.com/DestinyItemManager/DIM/issues/8387

Added a range filter for enhanced perks.


Patch:
diff --git a/config/i18n.json b/config/i18n.json
index 4a62cb6b7..0c776690b 100644
--- a/config/i18n.json
+++ b/config/i18n.json
@@ -207,6 +207,7 @@
     "DupeLower": "Duplicate items, including reissues, that are not the highest power dupe. Only one duplicate is chosen as the highest, and the rest are considered lower.",
     "Energy": "Shows items that have energy capacity (Armor 2.0).",
     "Engrams": "Shows engrams.",
+    "EnhancedPerk": "Shows weapons that have the specified number of enhanced perks.",
     "Equipment": "Items that can be equipped.",
     "Equipped": "Items that are currently equipped on a character.",
     "Event": "Shows items from which event in Destiny 2 they appeared in.",
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index e0d4069f4..b69267330 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -3,6 +3,7 @@
 * If you have a title equipped on your character, it will replace your character's race in the character headers.
 * Fixed a crash when trying to assign deprecated Combat Style mods.
 * The "Move other items away" loadout toggle no longer clears ghosts, ships, or sparrows.
+* Added filter for enhanced perks.
 
 ### Beta Only
 
diff --git a/src/app/search/search-filters/sockets.tsx b/src/app/search/search-filters/sockets.tsx
index 889e944d7..2bbb2ee7c 100644
--- a/src/app/search/search-filters/sockets.tsx
+++ b/src/app/search/search-filters/sockets.tsx
@@ -6,7 +6,7 @@ import {
   modSlotTags,
   modTypeTags,
 } from 'app/utils/item-utils';
-import { getSocketsByCategoryHash } from 'app/utils/socket-utils';
+import { getSocketsByCategoryHash, isEnhancedPerk } from 'app/utils/socket-utils';
 import { DestinyItemSubType, DestinyRecordState } from 'bungie-api-ts/destiny2';
 import craftingMementos from 'data/d2/crafting-mementos.json';
 import {
@@ -21,6 +21,7 @@ import {
   emptySocketHashes,
 } from '../d2-known-values';
 import { FilterDefinition } from '../filter-types';
+import { rangeStringToComparator } from './range-numeric';
 
 export const modslotFilter: FilterDefinition = {
   keywords: 'modslot',
@@ -245,6 +246,27 @@ const socketFilters: FilterDefinition[] = [
         );
     },
   },
+  {
+    keywords: 'enhancedperk',
+    description: tl('Filter.EnhancedPerk'),
+    format: 'range',
+    destinyVersion: 2,
+    filter: ({ filterValue }) => {
+      const compare = rangeStringToComparator(filterValue);
+      return (item: DimItem) => {
+        let enhancedPerkCount = 0;
+        if (item.sockets) {
+          // count enhanced perks
+          for (const socket of item.sockets.allSockets) {
+            if (socket.plugged && isEnhancedPerk(socket.plugged)) {
+              enhancedPerkCount++;
+            }
+          }
+        }
+        return compare(enhancedPerkCount);
+      };
+    },
+  },
 ];
 
 export default socketFilters;
diff --git a/src/locale/en.json b/src/locale/en.json
index 9e75d8e93..f7134e4e6 100644
--- a/src/locale/en.json
+++ b/src/locale/en.json
@@ -202,6 +202,7 @@
     "DupeLower": "Duplicate items, including reissues, that are not the highest power dupe. Only one duplicate is chosen as the highest, and the rest are considered lower.",
     "Energy": "Shows items that have energy capacity (Armor 2.0).",
     "Engrams": "Shows engrams.",
+    "EnhancedPerk": "Shows weapons that have the specified number of enhanced perks.",
     "Equipment": "Items that can be equipped.",
     "Equipped": "Items that are currently equipped on a character.",
     "Event": "Shows items from which event in Destiny 2 they appeared in.",


Test patch:
diff --git a/src/app/search/__snapshots__/search-config.test.ts.snap b/src/app/search/__snapshots__/search-config.test.ts.snap
index 866eca9c1..54d96039a 100644
--- a/src/app/search/__snapshots__/search-config.test.ts.snap
+++ b/src/app/search/__snapshots__/search-config.test.ts.snap
@@ -135,6 +135,7 @@ Array [
   "deepsight",
   "description",
   "energycapacity",
+  "enhancedperk",
   "hash",
   "holdsmod",
   "id",