Skip to content

Commit 2f3aa9b

Browse files
committed
Rework fade function structure
1 parent 9a13b21 commit 2f3aa9b

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

src/lib/components/market/sort_listings.ts

Lines changed: 2 additions & 2 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 {

src/lib/utils/skin.ts

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

166-
export function getFadeCalculatorAndSupportedWeapon(
166+
export function getFadeParams(
167167
asset: rgAsset
168-
): [typeof FadeCalculator | typeof AcidFadeCalculator | typeof AmberFadeCalculator, string, string] | undefined {
168+
):
169+
| {
170+
calculator: typeof FadeCalculator | typeof AcidFadeCalculator | typeof AmberFadeCalculator;
171+
weaponName: string;
172+
className: string;
173+
}
174+
| undefined {
169175
const FADE_TYPE_TO_CALCULATOR = {
170176
Fade: FadeCalculator,
171177
'Acid Fade': AcidFadeCalculator,
@@ -175,7 +181,11 @@ export function getFadeCalculatorAndSupportedWeapon(
175181
for (const [fadeType, calculator] of Object.entries(FADE_TYPE_TO_CALCULATOR)) {
176182
for (const supportedWeapon of calculator.getSupportedWeapons()) {
177183
if (asset.market_hash_name.includes(`${supportedWeapon} | ${fadeType}`)) {
178-
return [calculator, supportedWeapon.toString(), fadeType.replace(' ', '-').toLowerCase()];
184+
return {
185+
calculator,
186+
weaponName: supportedWeapon.toString(),
187+
className: fadeType.replace(' ', '-').toLowerCase(),
188+
};
179189
}
180190
}
181191
}
@@ -185,14 +195,14 @@ export function getFadePercentage(
185195
asset: rgAsset,
186196
itemInfo: ItemInfo
187197
): {percentage: number; fadeType: string} | undefined {
188-
const fadeCalculatorAndSupportedWeapon = getFadeCalculatorAndSupportedWeapon(asset);
198+
const fadeInfo = getFadeParams(asset);
189199

190-
if (fadeCalculatorAndSupportedWeapon !== undefined) {
191-
const [calculator, supportedWeapon, fadeType] = fadeCalculatorAndSupportedWeapon;
200+
if (fadeInfo !== undefined) {
201+
const {calculator, weaponName, className} = fadeInfo;
192202

193203
return {
194-
percentage: calculator.getFadePercentage(supportedWeapon, itemInfo.paintseed).percentage,
195-
fadeType,
204+
percentage: calculator.getFadePercentage(weaponName, itemInfo.paintseed).percentage,
205+
fadeType: className,
196206
};
197207
}
198208
}

0 commit comments

Comments
 (0)