dragon-item-parser: introduce item parser library
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { readFile, existsSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { promisify } from 'util'
|
||||
import { parseItemStats, type ItemStats } from 'dragon-item-parser'
|
||||
|
||||
const readFileAsync = promisify(readFile)
|
||||
|
||||
@@ -78,14 +79,20 @@ async function fetchFromCache<T>(
|
||||
}
|
||||
|
||||
/**
|
||||
* Get items data from cache
|
||||
* Get items data from cache with parsed stats
|
||||
*/
|
||||
async function getItems(patch?: string): Promise<CDragonItem[]> {
|
||||
return fetchFromCache<CDragonItem[]>(
|
||||
async function getItems(patch?: string): Promise<CDragonItemWithStats[]> {
|
||||
const items = await fetchFromCache<CDragonItem[]>(
|
||||
'items.json',
|
||||
'plugins/rcp-be-lol-game-data/global/default/v1/items.json',
|
||||
{ patch }
|
||||
)
|
||||
|
||||
// Parse stats from description for each item
|
||||
return items.map(item => ({
|
||||
...item,
|
||||
stats: parseItemStats(item.description || '')
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,6 +155,10 @@ interface CDragonItem {
|
||||
}
|
||||
}
|
||||
|
||||
interface CDragonItemWithStats extends CDragonItem {
|
||||
stats: ItemStats
|
||||
}
|
||||
|
||||
interface CDragonPerk {
|
||||
id: number
|
||||
name: string
|
||||
@@ -197,6 +208,7 @@ export {
|
||||
|
||||
export type {
|
||||
CDragonItem,
|
||||
CDragonItemWithStats,
|
||||
CDragonPerk,
|
||||
CDragonPerkStyle,
|
||||
CDragonPerkStyles,
|
||||
|
||||
Reference in New Issue
Block a user