You've already forked tf2wikipricing
feat: add support for festive weapon variants
on schema update, festive variants are linked. on content injection, if if finds a festive variant, it adds price rows for Festive and Strange Festive.
This commit is contained in:
@@ -237,6 +237,42 @@ async function inject() {
|
||||
}))
|
||||
}
|
||||
|
||||
// Check item schema for Festive variant of current defindex
|
||||
if(itemSchema[itemIndex].festiveVariant != null) {
|
||||
promises.push(new Promise(async (resolve) => {
|
||||
logDebug(`Fetching price for Festive ${itemName}`)
|
||||
var data: ItemPriceData | null
|
||||
try {
|
||||
data = await fetchPrice(token, `${itemSchema[itemIndex].festiveVariant};6`, currentTime);
|
||||
updateTime = new Date(data.update)
|
||||
} catch {
|
||||
log(`Festive ${itemName} is unpriced or unavailable, skipping...`)
|
||||
}
|
||||
|
||||
const priceRow = createPriceRow($T("Festive"), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Festive_weapons")
|
||||
|
||||
priceRows.push({quality: 97, row: priceRow})
|
||||
resolve()
|
||||
return
|
||||
}))
|
||||
promises.push(new Promise(async (resolve) => {
|
||||
logDebug(`Fetching price for Strange Festive ${itemName}`)
|
||||
var data: ItemPriceData | null
|
||||
try {
|
||||
data = await fetchPrice(token, `${itemSchema[itemIndex].festiveVariant};11`, currentTime);
|
||||
updateTime = new Date(data.update)
|
||||
} catch {
|
||||
log(`Strange Festive ${itemName} is unpriced or unavailable, skipping...`)
|
||||
}
|
||||
|
||||
const priceRow = createPriceRow($T("Strange Festive"), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Festive_weapons")
|
||||
|
||||
priceRows.push({quality: 98, row: priceRow})
|
||||
resolve()
|
||||
return
|
||||
}))
|
||||
}
|
||||
|
||||
Promise.all(promises).then(() => {
|
||||
priceRows.sort((a, b) => {
|
||||
// Sort 6 first always, then numerically
|
||||
|
||||
@@ -38,6 +38,7 @@ export class ItemSchema {
|
||||
slot: ItemSlot,
|
||||
tradable: Boolean,
|
||||
hasAustraliumVariant: Boolean,
|
||||
festiveVariant: number | null
|
||||
canKillstreakify: Boolean
|
||||
};
|
||||
}
|
||||
@@ -70,6 +71,25 @@ export function getTradableStatusByName(schema: ItemSchema, name: string, exclud
|
||||
return true
|
||||
}
|
||||
|
||||
export function linkFestiveVariants(items: Array<{item_class: string, defindex: number, item_name: string}>, schema: ItemSchema): void {
|
||||
if(!schema) return
|
||||
items.filter(item =>
|
||||
item.item_class != null &&
|
||||
item.item_class.startsWith('tf_weapon') &&
|
||||
item.item_name.startsWith('Festive ')
|
||||
).forEach(festive => {
|
||||
const originalName = festive.item_name.slice(8); // "Festive " is 8 chars
|
||||
const original = items.find(item => item.item_name === originalName && item.defindex > 30 && (item.defindex < 15000 || item.defindex >= 16000));
|
||||
|
||||
if (original) {
|
||||
if(schema[original.defindex]) {
|
||||
schema[original.defindex].festiveVariant = festive.defindex;
|
||||
console.log(`original:${original.defindex},festive:${festive.defindex}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function wipeSchema(): Promise<void> {
|
||||
await setStorageValue(storage_version, __VERSION__)
|
||||
await setStorageValue(storage_schema, null)
|
||||
@@ -149,6 +169,8 @@ export async function prepareSchema(): Promise<ItemSchema> {
|
||||
}
|
||||
});
|
||||
|
||||
linkFestiveVariants(responseItems, cacheItems)
|
||||
|
||||
await setStorageValue(storage_schema, (cacheItems));
|
||||
itemSchema = cacheItems
|
||||
await setStorageValue(storage_version, __VERSION__);
|
||||
|
||||
Reference in New Issue
Block a user