Skip to content

Commit

Permalink
Refactored loadout equipping and armor config to new loadout types
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoni7 committed Aug 22, 2024
1 parent 2e8474a commit 937be52
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
11 changes: 6 additions & 5 deletions src/features/armor-optimization/StatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,21 @@ const StatsTable: React.FC<StatsTableProps> = ({ permutations, onPermutationClic
{paginatedData.map((perm, index) => (
<Card
key={index}
onClick={() => {
onClick={async () => {
dispatch(resetLoadoutArmorMods());
dispatch(updateLoadoutArmor(perm.permutation));
let requiredMods: ManifestArmorStatMod[] = [];

Object.entries(perm.modsArray).forEach(([stat, costs]) => {
costs.forEach(async (cost: number) => {
for (const [stat, costs] of Object.entries(perm.modsArray)) {
for (const cost of costs) {
const mod = await db.manifestArmorStatModDef
.where(stat + 'Mod')
.equals(cost)
.first();
if (mod !== undefined) requiredMods.push(mod);
});
});
}
}

dispatch(updateRequiredStatMods(requiredMods));
onPermutationClick();
}}
Expand Down
8 changes: 4 additions & 4 deletions src/features/armor/components/ArmorConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface ArmorConfigProps {
}

const ArmorConfig: React.FC<ArmorConfigProps> = ({ armor, statMods, artificeMods }) => {
const [armorMods, setArmorMods] = useState<ManifestArmorMod[]>([]);
const [selectedMods, setSelectedMods] = useState<{ [key: number]: Plug }>(
const [armorMods, setArmorMods] = useState<(ManifestArmorMod | ManifestArmorStatMod)[]>([]);
const [selectedMods, setSelectedMods] = useState<(ManifestArmorMod | ManifestArmorStatMod)[]>(
getSelectedModsBySlot(armor.type)
);
const dispatch = useDispatch();
Expand All @@ -43,10 +43,10 @@ const ArmorConfig: React.FC<ArmorConfigProps> = ({ armor, statMods, artificeMods
for (const key in selectedMods) {
if (Number(key) !== slot) {
let statEnergyCost = armorMods.find(
(mod) => String(mod.itemHash) === selectedMods[key].plugItemHash
(mod) => mod.itemHash === selectedMods[key].itemHash
)?.energyCost;
let armorEnergyCost = statMods.find(
(mod) => String(mod.itemHash) === selectedMods[key].plugItemHash
(mod) => mod.itemHash === selectedMods[key].itemHash
)?.energyCost;

totalCost += statEnergyCost ? statEnergyCost : armorEnergyCost ? armorEnergyCost : 0;
Expand Down
8 changes: 4 additions & 4 deletions src/features/armor/components/ArmorModSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Box } from '@mui/system';
import { Plug } from '../../../types/d2l-types';
import { ManifestArmorMod } from '../../../types/manifest-types';
import { ManifestArmorMod, ManifestArmorStatMod } from '../../../types/manifest-types';

interface ModSelectorProps {
selected: Plug;
selected: ManifestArmorMod | ManifestArmorStatMod;
mods: ManifestArmorMod[];
onSelectMod: (mod: ManifestArmorMod) => void;
}
Expand All @@ -15,7 +15,7 @@ const ArmorModSelector: React.FC<ModSelectorProps> = ({ selected, mods, onSelect
style={{
backgroundImage: `url(${
mods.find((mod) => {
return mod.itemHash === Number(selected.plugItemHash);
return mod.itemHash === selected.itemHash;
})?.icon
})`,
}}
Expand All @@ -27,7 +27,7 @@ const ArmorModSelector: React.FC<ModSelectorProps> = ({ selected, mods, onSelect
className="submenu-item"
style={{ backgroundImage: `url(${mod.icon})` }}
onClick={() => {
if (selected.plugItemHash !== String(mod.itemHash)) {
if (selected.itemHash !== mod.itemHash) {
onSelectMod(mod);
}
}}
Expand Down
2 changes: 1 addition & 1 deletion src/features/armor/components/LoadoutArmor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const LoadoutArmor: React.FC = () => {
let matches: ManifestArmorMod[] = [];

for (const mod of requiredStatMods) {
const found = allStatMods.find((statMod) => String(statMod.itemHash) === mod.itemHash);
const found = allStatMods.find((statMod) => statMod.itemHash === mod.itemHash);
if (found) matches.push(found);
}

Expand Down
6 changes: 3 additions & 3 deletions src/features/armor/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { db } from '../../store/db';
import { PLUG_CATEGORY_HASH } from '../../lib/bungie_api/constants';
import { ManifestArmorMod, Plug } from '../../types/d2l-types';
import { store } from '../../store';
import { ManifestArmorMod, ManifestArmorStatMod } from '../../types/manifest-types';

export async function getModsBySlot(slot: string): Promise<ManifestArmorMod[]> {
const slotMods = await db.manifestArmorModDef
Expand All @@ -24,7 +24,7 @@ export async function getModsBySlot(slot: string): Promise<ManifestArmorMod[]> {
return slotMods;
}

export function getSelectedModsBySlot(slot: string): { [key: number]: Plug } {
export function getSelectedModsBySlot(slot: string): (ManifestArmorMod | ManifestArmorStatMod)[] {
switch (slot) {
case 'helmet': {
return store.getState().loadoutConfig.loadout.helmetMods;
Expand All @@ -42,7 +42,7 @@ export function getSelectedModsBySlot(slot: string): { [key: number]: Plug } {
return store.getState().loadoutConfig.loadout.classArmorMods;
}
default: {
return {};
return [];
}
}
}
11 changes: 6 additions & 5 deletions src/types/d2l-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ManifestArmorMod,
ManifestArmorStatMod,
ManifestAspect,
ManifestPlug,
Expand Down Expand Up @@ -63,11 +64,11 @@ export type Loadout = {
legArmor: DestinyArmor;
classArmor: DestinyArmor;
requiredStatMods: ManifestArmorStatMod[];
helmetMods: ManifestPlug[] | ManifestArmorStatMod[];
gauntletMods: ManifestPlug[] | ManifestArmorStatMod[];
chestArmorMods: ManifestPlug[] | ManifestArmorStatMod[];
legArmorMods: ManifestPlug[] | ManifestArmorStatMod[];
classArmorMods: ManifestPlug[] | ManifestArmorStatMod[];
helmetMods: (ManifestArmorMod | ManifestArmorStatMod)[];
gauntletMods: (ManifestArmorMod | ManifestArmorStatMod)[];
chestArmorMods: (ManifestArmorMod | ManifestArmorStatMod)[];
legArmorMods: (ManifestArmorMod | ManifestArmorStatMod)[];
classArmorMods: (ManifestArmorMod | ManifestArmorStatMod)[];
characterId: number;
subclassConfig: SubclassConfig;
};
Expand Down

0 comments on commit 937be52

Please sign in to comment.