Skip to content

Commit 2678a49

Browse files
authored
Gradients for Acid / Amber Fades (#311)
* Add gradients for Acid / Amber Fades * Rework fade function structure * chore: run prettier * refactor: update variable naming
1 parent cf2e4b2 commit 2678a49

5 files changed

Lines changed: 49 additions & 21 deletions

File tree

src/lib/components/common/item_holder_metadata.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,24 @@ export abstract class ItemHolderMetadata extends FloatElement {
3232
font-size: 12px;
3333
}
3434
35-
.fade {
36-
background: -webkit-linear-gradient(0deg, #d9bba5 0%, #e5903b 33%, #db5977 66%, #6775e1 100%);
35+
.fade-base {
3736
-webkit-background-clip: text;
3837
background-clip: text;
3938
-webkit-text-fill-color: transparent;
4039
}
4140
41+
.fade {
42+
background-image: -webkit-linear-gradient(0deg, #d9bba5 0%, #e5903b 33%, #db5977 66%, #6775e1 100%);
43+
}
44+
45+
.amber-fade {
46+
background-image: -webkit-linear-gradient(0deg, #627d66 0%, #896944 50%, #7e4201 100%);
47+
}
48+
49+
.acid-fade {
50+
background-image: -webkit-linear-gradient(0deg, #2b441b 0%, #3e6b2f 11%, #82a64a 66%, #c1a16c 100%);
51+
}
52+
4253
.csfloat-shine-fade-text {
4354
font-weight: 1000;
4455
-webkit-text-stroke: 1px black;
@@ -81,9 +92,9 @@ export abstract class ItemHolderMetadata extends FloatElement {
8192
if (!this.itemInfo || !this.asset) return html``;
8293

8394
if (isSkin(this.asset)) {
84-
const fadePercentage = this.asset && getFadePercentage(this.asset, this.itemInfo);
95+
const fadeDetails = this.asset && getFadePercentage(this.asset, this.itemInfo);
8596

86-
if (fadePercentage === 100) {
97+
if (fadeDetails?.percentage === 100) {
8798
$J(this).parent().addClass('full-fade-border');
8899
}
89100

@@ -94,9 +105,12 @@ export abstract class ItemHolderMetadata extends FloatElement {
94105
<span class="float">${formatFloatWithRank(this.itemInfo, 6)}</span>
95106
<span class="seed">
96107
${formatSeed(this.itemInfo)}
97-
${fadePercentage !== undefined
98-
? html`<span class="fade ${rank && rank <= 5 ? 'csfloat-shine-fade-text' : ''}"
99-
>(${floor(fadePercentage, 1)}%)</span
108+
${fadeDetails !== undefined
109+
? html`<span
110+
class="fade-base ${fadeDetails.className} ${rank && rank <= 5
111+
? 'csfloat-shine-fade-text'
112+
: ''}"
113+
>(${floor(fadeDetails.percentage, 1)}%)</span
100114
>`
101115
: nothing}
102116
${this.bluegemData

src/lib/components/inventory/selected_item_info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class SelectedItemInfo extends FloatElement {
115115
containerChildren.push(html`<div>Paint Seed: ${formatSeed(this.itemInfo)}</div>`);
116116

117117
// Fade skins
118-
const fadePercentage = getFadePercentage(this.asset.description, this.itemInfo);
118+
const fadePercentage = getFadePercentage(this.asset.description, this.itemInfo)?.percentage;
119119
if (fadePercentage !== undefined) {
120120
containerChildren.push(html`<div>Fade: ${floor(fadePercentage, 5)}%</div>`);
121121
}

src/lib/components/market/item_row_wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class ItemRowWrapper extends FloatElement {
222222
}
223223

224224
if (this.itemInfo && isSkin(this.asset)) {
225-
const fadePercentage = this.asset && getFadePercentage(this.asset, this.itemInfo);
225+
const fadePercentage = this.asset && getFadePercentage(this.asset, this.itemInfo)?.percentage;
226226

227227
return html`
228228
<div class="float-row-wrapper">

src/lib/components/market/sort_listings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {state} from 'lit/decorators.js';
66
import {gFloatFetcher} from '../../services/float_fetcher';
77
import {getMarketInspectLink} from './helpers';
88
import {ItemInfo} from '../../bridge/handlers/fetch_inspect_info';
9-
import {getFadeCalculatorAndSupportedWeapon, getFadePercentage} from '../../utils/skin';
9+
import {getFadeParams, getFadePercentage} from '../../utils/skin';
1010
import {AppId, ContextId} from '../../types/steam_constants';
1111

1212
enum SortType {
@@ -39,7 +39,7 @@ export class SortListings extends FloatElement {
3939

4040
const asset = g_rgAssets[AppId.CSGO][ContextId.PRIMARY][listingInfo.asset.id];
4141

42-
return getFadeCalculatorAndSupportedWeapon(asset) !== undefined;
42+
return getFadeParams(asset) !== undefined;
4343
}
4444

4545
computeButtonText(sortType: SortType): string {
@@ -129,7 +129,7 @@ export class SortListings extends FloatElement {
129129
info,
130130
listingId: listingId!,
131131
converted_price: listingInfo?.converted_price || 0,
132-
fadePercentage: (asset && getFadePercentage(asset, info)) || 0,
132+
fadePercentage: (asset && getFadePercentage(asset, info)?.percentage) || 0,
133133
};
134134
});
135135

src/lib/utils/skin.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ export function isBlueSkin(itemInfo: ItemInfo): boolean {
163163
);
164164
}
165165

166-
export function getFadeCalculatorAndSupportedWeapon(
167-
asset: rgAsset
168-
): [typeof FadeCalculator | typeof AcidFadeCalculator | typeof AmberFadeCalculator, string] | undefined {
166+
export function getFadeParams(asset: rgAsset):
167+
| {
168+
calculator: typeof FadeCalculator | typeof AcidFadeCalculator | typeof AmberFadeCalculator;
169+
weaponName: string;
170+
className: string;
171+
}
172+
| undefined {
169173
const FADE_TYPE_TO_CALCULATOR = {
170174
Fade: FadeCalculator,
171175
'Acid Fade': AcidFadeCalculator,
@@ -175,19 +179,29 @@ export function getFadeCalculatorAndSupportedWeapon(
175179
for (const [fadeType, calculator] of Object.entries(FADE_TYPE_TO_CALCULATOR)) {
176180
for (const supportedWeapon of calculator.getSupportedWeapons()) {
177181
if (asset.market_hash_name.includes(`${supportedWeapon} | ${fadeType}`)) {
178-
return [calculator, supportedWeapon.toString()];
182+
return {
183+
calculator,
184+
weaponName: supportedWeapon.toString(),
185+
className: fadeType.replace(' ', '-').toLowerCase(),
186+
};
179187
}
180188
}
181189
}
182190
}
183191

184-
export function getFadePercentage(asset: rgAsset, itemInfo: ItemInfo): number | undefined {
185-
const fadeCalculatorAndSupportedWeapon = getFadeCalculatorAndSupportedWeapon(asset);
192+
export function getFadePercentage(
193+
asset: rgAsset,
194+
itemInfo: ItemInfo
195+
): {percentage: number; className: string} | undefined {
196+
const fadeInfo = getFadeParams(asset);
186197

187-
if (fadeCalculatorAndSupportedWeapon !== undefined) {
188-
const [calculator, supportedWeapon] = fadeCalculatorAndSupportedWeapon;
198+
if (fadeInfo !== undefined) {
199+
const {calculator, weaponName, className} = fadeInfo;
189200

190-
return calculator.getFadePercentage(supportedWeapon, itemInfo.paintseed).percentage;
201+
return {
202+
percentage: calculator.getFadePercentage(weaponName, itemInfo.paintseed).percentage,
203+
className,
204+
};
191205
}
192206
}
193207

0 commit comments

Comments
 (0)