Skip to content

Commit

Permalink
Refactored logic to marking manifest mods as owned. Disallow selectio…
Browse files Browse the repository at this point in the history
…n of unowned mods
  • Loading branch information
dragoni7 committed Aug 27, 2024
1 parent 92afa3d commit adadf10
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
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
42 changes: 23 additions & 19 deletions src/features/profile/destiny-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,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 @@ -399,29 +398,34 @@ export async function getProfileData(): Promise<ProfileData> {
.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
10 changes: 8 additions & 2 deletions src/lib/bungie_api/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export async function updateManifest() {
current.itemCategoryHashes.includes(ITEM_CATEGORY_HASHES.ARMOR_MODS) &&
current.displayProperties.name &&
current.displayProperties.name !== 'Locked Armor Mod' &&
!current.displayProperties.description.includes('deprecated') &&
!current.itemTypeDisplayName.includes('Legacy') &&
!current.itemTypeDisplayName.includes('Deprecated') &&
!current.itemTypeDisplayName.includes('Artifact Mod') &&
Expand All @@ -102,7 +103,7 @@ export async function updateManifest() {
icon: urlPrefix + current.displayProperties.icon,
energyCost: current.plug.energyCost ? current.plug.energyCost.energyCost : 0,
category: current.plug.plugCategoryHash,
isOwned: false,
isOwned: true,
collectibleHash: -1,
perkName: '',
perkDescription: '',
Expand Down Expand Up @@ -145,7 +146,7 @@ export async function updateManifest() {
icon: urlPrefix + current.displayProperties.icon,
energyCost: current.plug.energyCost ? current.plug.energyCost.energyCost : 0,
category: current.plug.plugCategoryHash,
isOwned: false,
isOwned: true,
collectibleHash: -1,
perkName: '',
perkDescription: '',
Expand Down Expand Up @@ -255,6 +256,11 @@ export async function updateManifest() {
.where('itemHash')
.equals(current.itemHash)
.modify({ collectibleHash: current.hash });

await db.manifestArmorStatModDef
.where('itemHash')
.equals(current.itemHash)
.modify({ collectibleHash: current.hash });
}
}
}
Expand Down

0 comments on commit adadf10

Please sign in to comment.