miao-plugin/models/Artifact.js

94 lines
1.8 KiB
JavaScript
Raw Normal View History

/*
* 圣遗物
* */
import Base from './Base.js'
import { ArtifactSet } from './index.js'
2023-10-18 13:19:12 +00:00
import ArtisMark from './artis/ArtisMark.js'
2023-10-18 17:01:11 +00:00
import ArtisAttr from './artis/ArtisAttr.js'
2023-10-20 08:59:06 +00:00
import { Meta } from '#miao'
class Artifact extends Base {
2023-10-20 08:59:06 +00:00
constructor (data, game = 'gs') {
if (!data) {
return false
}
super()
2023-10-20 08:59:06 +00:00
let name = data.id || data.name
let cache = this._getCache(`arti:${game}:${name}`)
if (cache) {
return cache
}
this.game = game
this.id = data.id || ''
this.name = data.name
this.meta = data
return this._cache()
}
2022-08-18 10:13:42 +00:00
get artiSet () {
return ArtifactSet.get(this.set, this.game)
}
2022-08-18 10:13:42 +00:00
get setName () {
return this.set
}
2022-08-18 10:13:42 +00:00
2023-05-21 18:13:38 +00:00
get abbr () {
2023-05-21 18:13:38 +00:00
}
get img () {
return this.isGs ?
2023-10-24 19:34:36 +00:00
`meta-gs/artifact/imgs/${this.setName}/${this.idx}.webp` :
`meta-sr/artifact/${this.setName}/arti-${this.idx}.webp`
}
static get (name, game = 'gs') {
if (!name) {
return false
}
2023-10-18 17:01:11 +00:00
// 传入为artis对象
if (name.id || name.name) {
return Artifact.get(name.id || name.name, name.game || game)
2023-10-18 17:01:11 +00:00
}
2023-10-20 08:59:06 +00:00
let data = Meta.getData(game, 'arti', name)
if(data){
return new Artifact(data, game)
2022-08-18 10:13:42 +00:00
}
return false
}
2022-08-18 10:13:42 +00:00
static getSetNameByArti (name) {
let arti = Artifact.get(name)
if (arti) {
return arti.setName
}
return ''
}
2022-09-07 19:48:03 +00:00
2023-10-20 08:59:06 +00:00
static getArtisKeyTitle (game = 'gs') {
return ArtisMark.getKeyTitleMap(game)
}
getStarById (id) {
return this.meta.ids[id] || ''
}
getIdByStar (star = 5) {
let ids = this.meta.ids || {}
for (let key in ids) {
if (ids[key] * 1 === star) {
return key
}
}
}
2023-10-18 13:19:12 +00:00
// 获取圣遗物属性数据
2023-10-18 17:01:11 +00:00
getAttrData (arti, idx = 1, game = 'gs') {
return ArtisAttr.getData(arti, idx, game)
}
2022-08-18 10:13:42 +00:00
}
2022-08-18 10:13:42 +00:00
export default Artifact