Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few cleanups I had on a branch #10701

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/loadout-analyzer/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
resolveLoadoutModHashes,
} from 'app/loadout-drawer/loadout-utils';
import { fullyResolveLoadout } from 'app/loadout/ingame/selectors';
import { isLoadoutBuilderItem } from 'app/loadout/item-utils';
import { isLoadoutBuilderItem } from 'app/loadout/loadout-item-utils';
import { Loadout, ResolvedLoadoutItem } from 'app/loadout/loadout-types';
import { ModMap, categorizeArmorMods, fitMostMods } from 'app/loadout/mod-assignment-utils';
import { getTotalModStatChanges } from 'app/loadout/stats';
Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout-builder/LoadoutBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
unlockedPlugSetItemsSelector,
} from '../inventory/selectors';
import ModPicker from '../loadout/ModPicker';
import { isLoadoutBuilderItem } from '../loadout/item-utils';
import { isLoadoutBuilderItem } from '../loadout/loadout-item-utils';
import styles from './LoadoutBuilder.m.scss';
import NoBuildsFoundExplainer from './NoBuildsFoundExplainer';
import EnergyOptions from './filter/EnergyOptions';
Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout-builder/filter/ExoticPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DimLanguage } from 'app/i18n';
import { t } from 'app/i18next-t';
import { DimItem } from 'app/inventory/item-types';
import { allItemsSelector } from 'app/inventory/selectors';
import { isLoadoutBuilderItem } from 'app/loadout/item-utils';
import { isLoadoutBuilderItem } from 'app/loadout/loadout-item-utils';
import { useD2Definitions } from 'app/manifest/selectors';
import { SearchInput } from 'app/search/SearchInput';
import { startWordRegexp } from 'app/search/text-utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { t } from 'app/i18next-t';
import { DimItem } from 'app/inventory/item-types';
import { DimStore } from 'app/inventory/store-types';
import { isLoadoutBuilderItem } from 'app/loadout/item-utils';
import { AddItemButton } from 'app/loadout/loadout-edit/LoadoutEditBucket';
import LoadoutEditSection from 'app/loadout/loadout-edit/LoadoutEditSection';
import { isLoadoutBuilderItem } from 'app/loadout/loadout-item-utils';
import { ItemFilter } from 'app/search/filter-types';
import { objectValues } from 'app/utils/util-types';
import _ from 'lodash';
Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout-builder/item-filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { D2ManifestDefinitions } from 'app/destiny2/d2-definitions';
import { DimItem, PluggableInventoryItemDefinition } from 'app/inventory/item-types';
import { DimStore } from 'app/inventory/store-types';
import { isPluggableItem } from 'app/inventory/store/sockets';
import { isLoadoutBuilderItem } from 'app/loadout/item-utils';
import { isLoadoutBuilderItem } from 'app/loadout/loadout-item-utils';
import { ModMap, categorizeArmorMods } from 'app/loadout/mod-assignment-utils';
import { count } from 'app/utils/collections';
import { itemCanBeEquippedBy } from 'app/utils/item-utils';
Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout-builder/loadout-builder-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
updateMods,
} from 'app/loadout-drawer/loadout-drawer-reducer';
import { findItemForLoadout, newLoadout, pickBackingStore } from 'app/loadout-drawer/loadout-utils';
import { isLoadoutBuilderItem } from 'app/loadout/item-utils';
import { isLoadoutBuilderItem } from 'app/loadout/loadout-item-utils';
import { Loadout, ResolvedLoadoutMod } from 'app/loadout/loadout-types';
import { showNotification } from 'app/notifications/notifications';
import { armor2PlugCategoryHashesByName, armorStats } from 'app/search/d2-known-values';
Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout-builder/useEquippedHashes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LoadoutParameters } from '@destinyitemmanager/dim-api-types';
import { getSubclassPlugHashes } from 'app/loadout/item-utils';
import { getSubclassPlugHashes } from 'app/loadout/loadout-item-utils';
import { ResolvedLoadoutItem } from 'app/loadout/loadout-types';
import { useMemo } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout-drawer/loadout-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { isPluggableItem } from 'app/inventory/store/sockets';
import { findItemsByBucket, getCurrentStore, getStore } from 'app/inventory/stores-helpers';
import { ArmorEnergyRules, LockableBucketHashes } from 'app/loadout-builder/types';
import { calculateAssumedItemEnergy } from 'app/loadout/armor-upgrade-utils';
import { isLoadoutBuilderItem } from 'app/loadout/item-utils';
import { UNSET_PLUG_HASH } from 'app/loadout/known-values';
import { isLoadoutBuilderItem } from 'app/loadout/loadout-item-utils';
import {
isInsertableArmor2Mod,
mapToAvailableModCostVariant,
Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout/ModPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import { produce } from 'immer';
import _ from 'lodash';
import { useCallback, useMemo } from 'react';
import { useSelector } from 'react-redux';
import { isLoadoutBuilderItem } from './item-utils';
import {
activityModPlugCategoryHashes,
knownModPlugCategoryHashes,
slotSpecificPlugCategoryHashes,
} from './known-values';
import { isLoadoutBuilderItem } from './loadout-item-utils';
import { getModExclusionGroup, isInsertableArmor2Mod, sortModGroups } from './mod-utils';
import PlugDrawer from './plug-drawer/PlugDrawer';
import { PlugSelectionType, PlugSet } from './plug-drawer/types';
Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout/ingame/ingame-loadout-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { DestinyLoadoutItemComponent } from 'bungie-api-ts/destiny2';
import { BucketHashes } from 'data/d2/generated-enums';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { getSubclassPlugHashes } from '../item-utils';
import { UNSET_PLUG_HASH } from '../known-values';
import { getSubclassPlugHashes } from '../loadout-item-utils';

/**
* Get all the real DimItems from ingame loadout items.
Expand Down
2 changes: 1 addition & 1 deletion src/app/loadout/loadout-edit/LoadoutEditSubclass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BucketHashes, SocketCategoryHashes } from 'data/d2/generated-enums';
import _ from 'lodash';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { getSubclassPlugs } from '../item-utils';
import { getSubclassPlugs } from '../loadout-item-utils';
import PlugDef from '../loadout-ui/PlugDef';
import { createGetModRenderKey } from '../mod-utils';
import styles from './LoadoutEditSubclass.m.scss';
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one doesn't already exist, may just be better to name this loadout-utils and stick any other loadout-related utils in it instead of keeping it scoped to items. Seems like the methods in here are kinda already not necessarily item-related anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's all pretty messy, especially with loadouts and loadout-drawer folders. These are definitely just random helpers that could be somewhere better.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/app/loadout/loadout-ui/LoadoutSubclassSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AppIcon, powerActionIcon } from 'app/shell/icons';
import clsx from 'clsx';
import { SocketCategoryHashes } from 'data/d2/generated-enums';
import { useMemo } from 'react';
import { getSubclassPlugs } from '../item-utils';
import { getSubclassPlugs } from '../loadout-item-utils';
import { createGetModRenderKey } from '../mod-utils';
import EmptySubclass from './EmptySubclass';
import styles from './LoadoutSubclassSection.m.scss';
Expand Down
6 changes: 4 additions & 2 deletions src/app/organizer/ItemTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import { useSelector } from 'react-redux';
import { buildStatInfo, getColumnSelectionId, getColumns } from './Columns';
import EnabledColumnsSelector from './EnabledColumnsSelector';
import ItemActions, { TagCommandInfo } from './ItemActions';
import { itemIncludesCategories } from './filtering-utils';

import { compareSelectedItems } from 'app/compare/actions';

Expand Down Expand Up @@ -112,7 +111,10 @@ export default function ItemTable({ categories }: { categories: ItemCategoryTree
categoryHashes.push(ItemCategoryHashes.Armor);
}
const items = allItems.filter(
(i) => i.comparable && itemIncludesCategories(i, categoryHashes) && searchFilter(i),
(i) =>
i.comparable &&
categoryHashes.every((h) => i.itemCategoryHashes.includes(h)) &&
searchFilter(i),
);
return items;
}, [allItems, categories, searchFilter]);
Expand Down
5 changes: 3 additions & 2 deletions src/app/organizer/ItemTypeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ItemCategoryHashes } from 'data/d2/generated-enums';
import _ from 'lodash';
import { useSelector } from 'react-redux';
import styles from './ItemTypeSelector.m.scss';
import { itemIncludesCategories } from './filtering-utils';

/**
* Each branch of the drilldown options is represented by a SelectionTreeNode
Expand Down Expand Up @@ -393,7 +392,9 @@ export default function ItemTypeSelector({
(
{
filteredItems.filter(
(i) => i.comparable && itemIncludesCategories(i, categoryHashList),
(i) =>
i.comparable &&
categoryHashList.every((h) => i.itemCategoryHashes.includes(h)),
).length
}
)
Expand Down
5 changes: 0 additions & 5 deletions src/app/organizer/filtering-utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/store-stats/CharacterStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { DimStore } from 'app/inventory/store-types';
import { StorePowerLevel, powerLevelSelector } from 'app/inventory/store/selectors';
import { statTier } from 'app/loadout-builder/utils';
import { getLoadoutStats } from 'app/loadout-drawer/loadout-utils';
import { getSubclassPlugHashes } from 'app/loadout/item-utils';
import { getSubclassPlugHashes } from 'app/loadout/loadout-item-utils';
import { Loadout, ResolvedLoadoutItem } from 'app/loadout/loadout-types';
import { useD2Definitions } from 'app/manifest/selectors';
import { getCharacterProgressions } from 'app/progress/selectors';
Expand Down
8 changes: 7 additions & 1 deletion src/app/utils/collections.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { count, objectifyArray, uniqBy, wrap } from './collections';
import { count, objectifyArray, reorder, uniqBy, wrap } from './collections';

describe('count', () => {
test('counts elements that match the predicate', () =>
Expand Down Expand Up @@ -58,3 +58,9 @@ describe('uniqBy', () => {
expect(result).toEqual([{ val: 'a' }, { val: 'b' }, { val: 'c' }]);
});
});

describe('reorder', () => {
test('reorders', () => {
expect(reorder([1, 2, 3, 4], 0, 2)).toEqual([2, 3, 1, 4]);
});
});
Loading