Skip to content

Commit

Permalink
Merge pull request #10828 from DestinyItemManager/stat-bar-width-fix
Browse files Browse the repository at this point in the history
Item Stat Bars: fix length capping logic
  • Loading branch information
chainrez authored Dec 6, 2024
2 parents ad312a2 + 6a132b0 commit dba3339
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
6 changes: 5 additions & 1 deletion src/app/item-popup/ItemStat.m.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
}

.statBarSegment {
order: 1;
display: block;
height: 100%;
float: left;
Expand All @@ -65,12 +66,13 @@

&.negative {
background-color: #7a2727;
order: 1; // Push negative segments to the right side of the bar
order: 5; // Push negative segments to the right side of the bar
}

// An assumption: never more than 4 part effects in a single stat?
// 3 have been observed on weapons with a barrel + mag + grip.
&.parts {
order: 2;
opacity: 0.88;
& + &.parts {
opacity: 0.76;
Expand All @@ -84,6 +86,7 @@
}

&.mod {
order: 3;
background-color: $stat-modded;
& + &.mod {
opacity: 0.8;
Expand All @@ -95,6 +98,7 @@

// Colors for the stat bars
&.masterwork {
order: 4;
background-color: $stat-masterworked;
}
}
Expand Down
42 changes: 23 additions & 19 deletions src/app/item-popup/ItemStat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,29 @@ function StatBar({ segments, stat }: { segments: StatSegments; stat: DimStat })
className={styles.barContainer}
tooltip={<StatBarTooltip segments={segments} stat={stat} />}
>
{segments.map(([val, statType], index) => {
let segmentLength = Math.abs(val) / stat.maximumValue;
if (val < 0) {
segmentLength = Math.min(segmentLength, remainingEmpty);
remainingEmpty -= segmentLength;
} else {
segmentLength = Math.min(segmentLength, remainingFilled);
remainingFilled -= segmentLength;
}
return (
<div
key={index}
className={clsx(styles.statBarSegment, statStyles[statType][0], {
[styles.negative]: val < 0 && statType !== 'masterwork',
})}
style={{ width: percent(segmentLength) }}
/>
);
})}
{segments
// Process base stats last, letting them be the most likely to hit cap and lose display length
.toSorted(([, statType]) => (statType === 'base' ? 1 : 0))
.map(([val, statType], index) => {
let segmentLength = Math.abs(val);
if (val < 0) {
segmentLength = Math.min(segmentLength, remainingEmpty);
remainingEmpty -= segmentLength;
} else {
segmentLength = Math.min(segmentLength, remainingFilled);
remainingFilled -= segmentLength;
}
return (
<div
key={index}
className={clsx(
styles.statBarSegment,
val < 0 && statType !== 'masterwork' ? styles.negative : statStyles[statType][0],
)}
style={{ width: percent(segmentLength / stat.maximumValue) }}
/>
);
})}
</PressTip>
</div>
);
Expand Down

0 comments on commit dba3339

Please sign in to comment.