@@ -209,7 +209,6 @@ const fetchMods = async (subclass: ManifestSubclass) => {
209
209
return modsData ;
210
210
}
211
211
} ;
212
-
213
212
const AbilitiesModification : React . FC < AbilitiesModificationProps > = ( { subclass } ) => {
214
213
const [ mods , setMods ] = useState < {
215
214
[ key : string ] : ( ManifestPlug | ManifestAspect | ManifestStatPlug ) [ ] ;
@@ -237,6 +236,10 @@ const AbilitiesModification: React.FC<AbilitiesModificationProps> = ({ subclass
237
236
}
238
237
} , [ subclass ] ) ;
239
238
239
+ const calculateAvailableFragmentSlots = useCallback ( ( ) => {
240
+ return loadout . aspects . reduce ( ( total , aspect ) => total + ( aspect . energyCapacity || 0 ) , 0 ) ;
241
+ } , [ loadout . aspects ] ) ;
242
+
240
243
const handleModSelect = (
241
244
category : string ,
242
245
mod : ManifestPlug | ManifestAspect | ManifestStatPlug ,
@@ -246,23 +249,22 @@ const AbilitiesModification: React.FC<AbilitiesModificationProps> = ({ subclass
246
249
247
250
switch ( category ) {
248
251
case 'ASPECTS' :
249
- updatedMods = [ ...loadout . aspects ] ;
252
+ updatedMods = [ ...loadout . aspects ] as ManifestAspect [ ] ;
250
253
break ;
251
254
case 'FRAGMENTS' :
252
- updatedMods = [ ...loadout . fragments ] ;
255
+ updatedMods = [ ...loadout . fragments ] as ManifestStatPlug [ ] ;
253
256
break ;
254
257
case 'SUPERS' :
255
258
case 'CLASS_ABILITIES' :
256
259
case 'MOVEMENT_ABILITIES' :
257
260
case 'MELEE_ABILITIES' :
258
261
case 'GRENADES' :
259
- updatedMods = [ mod ] ;
262
+ updatedMods = [ mod ] as ManifestPlug [ ] ;
260
263
break ;
261
264
default :
262
265
return ;
263
266
}
264
267
265
- // Check if the mod already exists in another slot and replace it with an empty mod
266
268
if ( category === 'ASPECTS' || category === 'FRAGMENTS' ) {
267
269
const modIndex = updatedMods . findIndex (
268
270
( existingMod ) => existingMod . itemHash === mod . itemHash
@@ -272,13 +274,39 @@ const AbilitiesModification: React.FC<AbilitiesModificationProps> = ({ subclass
272
274
updatedMods [ modIndex ] = category === 'ASPECTS' ? EMPTY_ASPECT : EMPTY_FRAGMENT ;
273
275
}
274
276
275
- // Assign the mod to the selected slot
276
- updatedMods [ index ! ] = mod ;
277
- } else {
278
- // Directly assign the mod for SUPERS and abilities
279
- updatedMods [ 0 ] = mod ;
277
+ updatedMods [ index ! ] = mod as ( typeof updatedMods ) [ number ] ;
278
+
279
+ // If updating aspects, we need to check if we need to empty any fragment slots
280
+ if ( category === 'ASPECTS' ) {
281
+ const newAspects = updatedMods as ManifestAspect [ ] ;
282
+ const newAvailableSlots = newAspects . reduce (
283
+ ( total , aspect ) => total + ( aspect . energyCapacity || 0 ) ,
284
+ 0
285
+ ) ;
286
+
287
+ // Update fragments, emptying any that exceed the new available slots
288
+ const updatedFragments = loadout . fragments . map ( ( fragment , idx ) =>
289
+ idx < newAvailableSlots ? fragment : EMPTY_FRAGMENT
290
+ ) ;
291
+
292
+ // Dispatch updates for both aspects and fragments
293
+ dispatch (
294
+ updateSubclassMods ( {
295
+ category : 'ASPECTS' ,
296
+ mods : newAspects ,
297
+ } )
298
+ ) ;
299
+ dispatch (
300
+ updateSubclassMods ( {
301
+ category : 'FRAGMENTS' ,
302
+ mods : updatedFragments ,
303
+ } )
304
+ ) ;
305
+ return ; // Exit the function early as we've already dispatched the updates
306
+ }
280
307
}
281
308
309
+ // For all other cases, dispatch the update as before
282
310
dispatch (
283
311
updateSubclassMods ( {
284
312
category,
@@ -312,21 +340,26 @@ const AbilitiesModification: React.FC<AbilitiesModificationProps> = ({ subclass
312
340
313
341
const SlotComponent = category === 'SUPERS' ? SuperModSlot : ModSlot ;
314
342
343
+ const availableFragmentSlots = calculateAvailableFragmentSlots ( ) ;
344
+ const isDisabled = category === 'FRAGMENTS' && index ! >= availableFragmentSlots ;
345
+
315
346
return (
316
347
< Box key = { slotId } position = "relative" display = "inline-block" >
317
348
< div onMouseEnter = { ( e ) => handleMouseEnter ( e , slotId ) } onMouseLeave = { handleMouseLeave } >
318
349
< SlotComponent
319
350
style = { {
320
351
backgroundImage : currentMod ? `url(${ currentMod . icon } )` : 'none' ,
352
+ opacity : isDisabled ? 0.5 : 1 ,
353
+ pointerEvents : isDisabled ? 'none' : 'auto' ,
321
354
} }
322
355
>
323
356
{ isEmptyMod && (
324
357
< Typography variant = "caption" style = { { color : 'rgba(255, 255, 255, 0.7)' } } >
325
- Empty
358
+ { isDisabled ? 'Locked' : ' Empty' }
326
359
</ Typography >
327
360
) }
328
361
</ SlotComponent >
329
- { isHovered && (
362
+ { isHovered && ! isDisabled && (
330
363
< SubmenuContainer
331
364
style = { {
332
365
top : submenuPosition . top ,
@@ -347,7 +380,7 @@ const AbilitiesModification: React.FC<AbilitiesModificationProps> = ({ subclass
347
380
</ Box >
348
381
) ;
349
382
} ,
350
- [ mods , handleModSelect , hoveredSlot , submenuPosition ]
383
+ [ mods , handleModSelect , hoveredSlot , submenuPosition , calculateAvailableFragmentSlots ]
351
384
) ;
352
385
353
386
if ( loading ) {
@@ -413,9 +446,13 @@ const AbilitiesModification: React.FC<AbilitiesModificationProps> = ({ subclass
413
446
< Box marginBottom = { 2 } >
414
447
< StyledTitle variant = "h6" > FRAGMENTS</ StyledTitle >
415
448
< Box display = "flex" flexWrap = "wrap" gap = { 2 } >
416
- { loadout . fragments . map ( ( fragment , index ) => (
449
+ { Array . from ( { length : 5 } ) . map ( ( _ , index ) => (
417
450
< React . Fragment key = { index } >
418
- { renderModCategory ( 'FRAGMENTS' , fragment , index ) }
451
+ { renderModCategory (
452
+ 'FRAGMENTS' ,
453
+ loadout . fragments [ index ] || EMPTY_FRAGMENT ,
454
+ index
455
+ ) }
419
456
</ React . Fragment >
420
457
) ) }
421
458
</ Box >
0 commit comments