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

Grey out armor mods&is owned fix #35

Merged
merged 5 commits into from
Aug 27, 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
10 changes: 2 additions & 8 deletions src/app/routes/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import { updateProfileData } from '../../store/ProfileReducer';
import { useDispatch, useSelector } from 'react-redux';
import { generatePermutations } from '../../features/armor-optimization/generate-permutations';
import { filterPermutations } from '../../features/armor-optimization/filter-permutations';
import {
DestinyArmor,
Character,
FilteredPermutation,
DamageType,
SubclassConfig,
} from '../../types/d2l-types';
import { DestinyArmor, Character, FilteredPermutation } from '../../types/d2l-types';
import StatsTable from '../../features/armor-optimization/StatsTable';
import { RootState } from '../../store';
import HeaderComponent from '../../components/HeaderComponent';
Expand All @@ -26,7 +20,7 @@ import ArmorCustomization from '../../features/armor/components/ArmorCustomizati
import { resetLoadout, updateLoadoutCharacter, updateSubclass } from '../../store/LoadoutReducer';
import { ManifestSubclass } from '../../types/manifest-types';
import SubclassCustomizationWrapper from '../../features/subclass/SubclassCustomizationWrapper';
import { updateManifest } from '../../lib/bungie_api/Manifest';
import { updateManifest } from '../../lib/bungie_api/manifest';

const PageContainer = styled('div')({
display: 'flex',
Expand Down
2 changes: 1 addition & 1 deletion src/components/ArmorIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, styled } from '@mui/system';
import { styled } from '@mui/system';
import { DestinyArmor } from '../types/d2l-types';

const MasterworkedIconContainer = styled('img')({
Expand Down
9 changes: 7 additions & 2 deletions src/features/armor/components/ArmorModSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ interface ModSelectorProps {
onSelectMod: (mod: ManifestArmorMod | ManifestArmorStatMod) => void;
}

const lockedModIcon =
'https://www.bungie.net/common/destiny2_content/icons/1426b518acd10943c31171c99222e6fd.png';

const ArmorModSelector: React.FC<ModSelectorProps> = ({ selected, mods, onSelectMod }) => {
return (
<Box
Expand All @@ -20,9 +23,11 @@ const ArmorModSelector: React.FC<ModSelectorProps> = ({ selected, mods, onSelect
<div
key={mod.itemHash}
className="submenu-item"
style={{ backgroundImage: `url(${mod.icon})` }}
style={{
backgroundImage: `url(${mod.isOwned ? mod.icon : lockedModIcon})`,
}}
onClick={() => {
if (selected.itemHash !== mod.itemHash) {
if (selected.itemHash !== mod.itemHash && mod.isOwned) {
onSelectMod(mod);
}
}}
Expand Down
144 changes: 23 additions & 121 deletions src/features/profile/destiny-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import {
PRIMARY_STATS,
SOCKET_HASH,
STAT_HASH,
SUBCLASS_PLUG_SETS,
} from '../../lib/bungie_api/constants';
import { getProfileDataRequest } from '../../lib/bungie_api/requests';
import { db } from '../../store/db';
import {
Character,
CharacterClass,
DamageType,
DestinyArmor,
Emblem,
Plug,
ProfileData,
Subclass,
} from '../../types/d2l-types';
Expand All @@ -36,7 +33,6 @@ export async function getProfileData(): Promise<ProfileData> {
const characterInventories = response.data.Response.characterInventories.data;
const characterEquipment = response.data.Response.characterEquipment.data;
const characterData = response.data.Response.characters.data;
const profilePlugSets = response.data.Response.profilePlugSets.data.plugs;
const profileCollectibles = response.data.Response.profileCollectibles.data.collectibles;

for (const key in characterData) {
Expand Down Expand Up @@ -313,16 +309,6 @@ export async function getProfileData(): Promise<ProfileData> {
}
}

// check character plugs for stasis grenade state
if (plugSets[SUBCLASS_PLUG_SETS.GRENADES.STASIS]) {
for (const plug of plugSets[SUBCLASS_PLUG_SETS.GRENADES.STASIS]) {
await db.manifestSubclassModDef
.where('itemHash')
.equals(plug.plugItemHash)
.modify({ isOwned: true });
}
}

profile.characters.push(character);
}

Expand Down Expand Up @@ -405,125 +391,41 @@ export async function getProfileData(): Promise<ProfileData> {
}
}

// iterate profile plugs
let abilityPlugSets: number[] = [
SUBCLASS_PLUG_SETS.FRAGMENTS.ARC,
SUBCLASS_PLUG_SETS.FRAGMENTS.SOLAR,
SUBCLASS_PLUG_SETS.FRAGMENTS.VOID,
SUBCLASS_PLUG_SETS.FRAGMENTS.STASIS,
SUBCLASS_PLUG_SETS.FRAGMENTS.STRAND,
SUBCLASS_PLUG_SETS.FRAGMENTS.PRISMATIC,

SUBCLASS_PLUG_SETS.GRENADES.ARC,
SUBCLASS_PLUG_SETS.GRENADES.SOLAR,
SUBCLASS_PLUG_SETS.GRENADES.VOID,
SUBCLASS_PLUG_SETS.GRENADES.STASIS,
SUBCLASS_PLUG_SETS.GRENADES.STRAND,
SUBCLASS_PLUG_SETS.GRENADES.PRISMATIC_HUNTER,
SUBCLASS_PLUG_SETS.GRENADES.PRISMATIC_WARLOCK,

SUBCLASS_PLUG_SETS.ASPECTS.HUNTER.ARC,
SUBCLASS_PLUG_SETS.ASPECTS.HUNTER.VOID,
SUBCLASS_PLUG_SETS.ASPECTS.HUNTER.SOLAR,
SUBCLASS_PLUG_SETS.ASPECTS.HUNTER.PRISMATIC,

SUBCLASS_PLUG_SETS.ASPECTS.TITAN.ARC,
SUBCLASS_PLUG_SETS.ASPECTS.TITAN.VOID,
SUBCLASS_PLUG_SETS.ASPECTS.TITAN.SOLAR,

SUBCLASS_PLUG_SETS.ASPECTS.WARLOCK.ARC,
SUBCLASS_PLUG_SETS.ASPECTS.WARLOCK.VOID,
SUBCLASS_PLUG_SETS.ASPECTS.WARLOCK.SOLAR,
SUBCLASS_PLUG_SETS.ASPECTS.WARLOCK.STASIS,
SUBCLASS_PLUG_SETS.ASPECTS.WARLOCK.STRAND,
SUBCLASS_PLUG_SETS.ASPECTS.WARLOCK.PRISMATIC,

SUBCLASS_PLUG_SETS.SUPERS.HUNTER.ARC,
SUBCLASS_PLUG_SETS.SUPERS.HUNTER.VOID,
SUBCLASS_PLUG_SETS.SUPERS.HUNTER.SOLAR,
SUBCLASS_PLUG_SETS.SUPERS.HUNTER.PRISMATIC,

SUBCLASS_PLUG_SETS.SUPERS.TITAN.ARC,
SUBCLASS_PLUG_SETS.SUPERS.TITAN.VOID,
SUBCLASS_PLUG_SETS.SUPERS.TITAN.SOLAR,

SUBCLASS_PLUG_SETS.SUPERS.WARLOCK.ARC,
SUBCLASS_PLUG_SETS.SUPERS.WARLOCK.VOID,
SUBCLASS_PLUG_SETS.SUPERS.WARLOCK.SOLAR,
SUBCLASS_PLUG_SETS.SUPERS.WARLOCK.STASIS,
SUBCLASS_PLUG_SETS.SUPERS.WARLOCK.STRAND,
SUBCLASS_PLUG_SETS.SUPERS.WARLOCK.PRISMATIC,

SUBCLASS_PLUG_SETS.MELEE_ABILITIES.HUNTER.ARC,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.HUNTER.VOID,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.HUNTER.SOLAR,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.HUNTER.PRISMATIC,

SUBCLASS_PLUG_SETS.MELEE_ABILITIES.TITAN.ARC,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.TITAN.VOID,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.TITAN.SOLAR,

SUBCLASS_PLUG_SETS.MELEE_ABILITIES.WARLOCK.ARC,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.WARLOCK.VOID,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.WARLOCK.SOLAR,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.WARLOCK.STASIS,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.WARLOCK.STRAND,
SUBCLASS_PLUG_SETS.MELEE_ABILITIES.WARLOCK.PRISMATIC,
];

for (const key of abilityPlugSets) {
if (profilePlugSets[key]) {
for (const plug of profilePlugSets[key]) {
if (plug.enabled) {
await db.manifestSubclassModDef
.where('itemHash')
.equals(plug.plugItemHash)
.modify({ isOwned: true });

await db.manifestSubclassAspectsDef
.where('itemHash')
.equals(plug.plugItemHash)
.modify({ isOwned: true });

await db.manifestSubclassFragmentsDef
.where('itemHash')
.equals(plug.plugItemHash)
.modify({ isOwned: true });
}
}
}
}

// iterate profile collectibles
for (const collectible in profileCollectibles) {
const exoticCollectable = await db.manifestExoticArmorCollection
.where('collectibleHash')
.equals(Number(collectible))
.first();

if (
exoticCollectable &&
COLLECTIBLE_OWNED.includes(Number(profileCollectibles[collectible].state))
) {
await db.manifestExoticArmorCollection
.where('collectibleHash')
.equals(Number(collectible))
.modify({ isOwned: true });
}

const armorModDef = await db.manifestArmorModDef
.where('collectibleHash')
.equals(Number(collectible))
.first();

if (
armorModDef &&
COLLECTIBLE_OWNED.includes(Number(profileCollectibles[collectible].state))
) {
await db.manifestArmorModDef
.where('collectibleHash')
.equals(Number(collectible))
.modify({ isOwned: true });
const armorStatModDef = await db.manifestArmorStatModDef
.where('collectibleHash')
.equals(Number(collectible))
.first();

if (exoticCollectable) {
if (COLLECTIBLE_OWNED.includes(Number(profileCollectibles[collectible].state)))
await db.manifestExoticArmorCollection
.where('collectibleHash')
.equals(Number(collectible))
.modify({ isOwned: true });
} else if (armorModDef) {
if (!COLLECTIBLE_OWNED.includes(Number(profileCollectibles[collectible].state)))
await db.manifestArmorModDef
.where('collectibleHash')
.equals(Number(collectible))
.modify({ isOwned: false });
} else if (armorStatModDef) {
if (!COLLECTIBLE_OWNED.includes(Number(profileCollectibles[collectible].state)))
await db.manifestArmorStatModDef
.where('collectibleHash')
.equals(Number(collectible))
.modify({ isOwned: false });
}
}

Expand Down
Loading