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'
|
2023-12-06 20:58:41 +00:00
|
|
|
import { Data, Meta } from '#miao'
|
2022-09-04 21:03:23 +00:00
|
|
|
|
2023-12-06 20:58:41 +00:00
|
|
|
let data = Data.readJSON('resources/meta-gs/material/data.json', 'miao')
|
2023-10-24 19:34:36 +00:00
|
|
|
let abbr = await Data.importDefault('resources/meta-gs/material/abbr.js', 'miao')
|
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 {
|
2023-12-06 20:58:41 +00:00
|
|
|
constructor (data) {
|
|
|
|
super()
|
|
|
|
let cache = this._getCache(`material:${data.name}`)
|
2022-09-04 21:03:23 +00:00
|
|
|
if (cache) {
|
|
|
|
return cache
|
|
|
|
}
|
2023-12-06 20:58:41 +00:00
|
|
|
this.name = data.name
|
|
|
|
this.meta = data
|
|
|
|
this.type = data.type
|
|
|
|
this.star = data.star
|
2022-09-08 20:34:32 +00:00
|
|
|
return this._cache()
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
2023-12-06 20:58:41 +00:00
|
|
|
static get (name, game = 'gs') {
|
|
|
|
let data = Meta.getData(game, 'material', name)
|
|
|
|
if (data) {
|
|
|
|
return new Material(data)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-01-27 18:13:15 +00:00
|
|
|
static forEach (type = 'all', fn, filter = false, game = 'gs') {
|
2023-12-06 20:58:41 +00:00
|
|
|
if (!lodash.isFunction(filter)) {
|
|
|
|
filter = () => true
|
|
|
|
}
|
|
|
|
lodash.forEach(mMap, (ds, name) => {
|
|
|
|
if (type !== 'all' && type !== ds.type) {
|
|
|
|
return true
|
|
|
|
}
|
2024-01-27 18:13:15 +00:00
|
|
|
let obj = Material.get(name, game)
|
2023-12-06 20:58:41 +00:00
|
|
|
if (filter(obj)) {
|
|
|
|
return fn(obj) !== false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
static forEachDaily (type = 'talent', fn) {
|
|
|
|
const dailyData = Meta.getMeta('gs', 'material')
|
|
|
|
lodash.forEach(dailyData[type] || {}, (name, city) => {
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2023-12-06 20:58:41 +00:00
|
|
|
if (this.type === 'weapon') {
|
|
|
|
return name.slice(0, 4)
|
|
|
|
}
|
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
|
2023-12-06 20:58:41 +00:00
|
|
|
if (this.city) {
|
|
|
|
return `${this.city}·${this.abbr}`
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
return abbr
|
|
|
|
}
|
|
|
|
|
|
|
|
get img () {
|
2023-10-24 19:34:36 +00:00
|
|
|
return `meta-gs/material/${this.type}/${this.name}.webp`
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get icon () {
|
|
|
|
return this.img
|
|
|
|
}
|
|
|
|
|
2023-12-06 20:58:41 +00:00
|
|
|
get source () {
|
|
|
|
return this.week ? ['周一/周四', '周二/周五', '周三/周六'][this.week - 1] : ''
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Material
|