2022-09-25 13:56:10 +00:00
|
|
|
/*
|
|
|
|
* 角色培养及天赋材料
|
|
|
|
* */
|
2022-09-04 21:03:23 +00:00
|
|
|
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')
|
2022-09-23 22:57:42 +00:00
|
|
|
let abbr = await Data.importDefault('resources/meta/material/abbr.js')
|
2022-09-04 21:03:23 +00:00
|
|
|
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
|
2022-10-07 13:13:46 +00:00
|
|
|
if (this.type === 'talent') {
|
|
|
|
let talentData = MaterialMeta.getTalentData(this.name)
|
|
|
|
lodash.extend(this, talentData)
|
|
|
|
}
|
2022-09-08 20:34:32 +00:00
|
|
|
return this._cache()
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get abbr () {
|
2022-09-23 22:57:42 +00:00
|
|
|
let name = this.name
|
2022-09-04 21:03:23 +00:00
|
|
|
if (this.type === 'talent') {
|
2022-09-23 22:57:42 +00:00
|
|
|
return Data.regRet(/「(.+)」/, name, 1) || name
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
2022-09-23 22:57:42 +00:00
|
|
|
return abbr[name] || name
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ''
|
|
|
|
}
|
|
|
|
|
2022-10-07 13:13:46 +00:00
|
|
|
static get (name) {
|
|
|
|
if (mMap[name]) {
|
|
|
|
return new Material(name)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
static forEach (type = 'all', fn, filter = false) {
|
|
|
|
if (!lodash.isFunction(filter)) {
|
|
|
|
filter = () => true
|
|
|
|
}
|
|
|
|
lodash.forEach(mMap, (ds, name) => {
|
|
|
|
if (type !== 'all' && type !== ds.type) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
let obj = new Material(name)
|
|
|
|
if (filter(obj)) {
|
|
|
|
return fn(obj) !== false
|
|
|
|
}
|
|
|
|
})
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Material
|