mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-25 17:35:34 +00:00
89 lines
1.6 KiB
JavaScript
89 lines
1.6 KiB
JavaScript
import lodash from 'lodash'
|
|
import Base from './Base.js'
|
|
import { Data } from '../components/index.js'
|
|
import MaterialMeta from './material-lib/MaterialMeta.js'
|
|
|
|
let data = Data.readJSON('resources/meta/material/data.json')
|
|
let mMap = {}
|
|
let getItem = (ds) => {
|
|
mMap[ds.name] = {
|
|
type: ds.type,
|
|
name: ds.name,
|
|
star: ds.star
|
|
}
|
|
return mMap[ds.name]
|
|
}
|
|
lodash.forEach(data, (ds) => {
|
|
let ret = getItem(ds)
|
|
if (ds.items) {
|
|
let items = {}
|
|
lodash.forEach(ds.items, (item) => {
|
|
getItem(item)
|
|
items[item.star] = item.title
|
|
})
|
|
ret.items = items
|
|
}
|
|
})
|
|
|
|
class Material extends Base {
|
|
constructor (name) {
|
|
super(name)
|
|
let meta = mMap[name]
|
|
if (!meta) {
|
|
return false
|
|
}
|
|
let cache = this._getCache(`material:${name}`)
|
|
if (cache) {
|
|
return cache
|
|
}
|
|
this.name = meta.name
|
|
this.meta = meta
|
|
this.type = meta.type
|
|
this.star = meta.star
|
|
return this._cache()
|
|
}
|
|
|
|
get abbr () {
|
|
if (this.type === 'talent') {
|
|
return Data.regRet(/「(.+)」/, this.name, 1) || this.name
|
|
}
|
|
return this.name
|
|
}
|
|
|
|
get title () {
|
|
return this.name
|
|
}
|
|
|
|
get label () {
|
|
let abbr = this.abbr
|
|
if (this.type === 'talent') {
|
|
return MaterialMeta.getTalentLabel(abbr)
|
|
}
|
|
return abbr
|
|
}
|
|
|
|
get img () {
|
|
return `meta/material/${this.type}/${this.name}.webp`
|
|
}
|
|
|
|
get icon () {
|
|
return this.img
|
|
}
|
|
|
|
getSource () {
|
|
if (this.type === 'talent') {
|
|
return MaterialMeta.getTalentWeek(this.name)
|
|
}
|
|
return ''
|
|
}
|
|
}
|
|
|
|
Material.get = function (name) {
|
|
if (mMap[name]) {
|
|
return new Material(name)
|
|
}
|
|
return false
|
|
}
|
|
|
|
export default Material
|