You've already forked tf2wikipricing
fix: prioritize non-stock/non-decorated items
Changed schema lookups to prioritize non-stock/non-decorated item defindexes when names collide Modified unit tests to include example (stock Flame Thrower)
This commit is contained in:
@@ -16,10 +16,13 @@ function isDateAfterOneDay(date1: Date, date2: Date): boolean {
|
||||
|
||||
export class ItemSchema { [key: string]: {name: string, tradable: Boolean}; }
|
||||
|
||||
export function getItemIndexByName(schema: ItemSchema, name: string) {
|
||||
export function getItemIndexByName(schema: ItemSchema, name: string, excludeStock: Boolean = true, excludeDecorated: Boolean = true) {
|
||||
for (const [defindex, value] of Object.entries(schema)) {
|
||||
if (value['name'] == name) {
|
||||
return parseInt(defindex)
|
||||
const index = parseInt(defindex)
|
||||
if(excludeStock && index <= 30) continue
|
||||
if(excludeDecorated && (index >= 15000 && index < 16000)) continue
|
||||
return index
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -29,9 +32,12 @@ export function getTradableStatusByDefindex(schema: ItemSchema, defindex: number
|
||||
return schema[defindex.toString()].tradable
|
||||
}
|
||||
|
||||
export function getTradableStatusByName(schema: ItemSchema, name: string) {
|
||||
export function getTradableStatusByName(schema: ItemSchema, name: string, excludeStock: Boolean = true, excludeDecorated = true,) {
|
||||
for (const [defindex, value] of Object.entries(schema)) {
|
||||
if (value['name'] == name) {
|
||||
const index = parseInt(defindex)
|
||||
if(excludeStock && index <= 30) continue
|
||||
if(excludeDecorated && (index >= 15000 && index < 16000)) continue
|
||||
return value.tradable
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user