miao-plugin/models/Artifact.js

103 lines
2.1 KiB
JavaScript
Raw Normal View History

/*
* 圣遗物
* */
import Base from './Base.js'
import { ArtifactSet } from './index.js'
2023-10-18 17:01:11 +00:00
import { artiMap, attrMap } from '../resources/meta/artifact/index.js'
import { idMap as idMapSR, artiMap as artiMapSR, abbr as abbrSR } from '../resources/meta-sr/artifact/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'
class Artifact extends Base {
static getAttrs
constructor (name, game = 'gs') {
super()
let cache = this._getCache(`arti:${game}:${name}`)
if (cache) {
return cache
}
this.game = game
let data = (this.isGs ? artiMap : artiMapSR)[name]
if (!data) {
return false
}
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 () {
return (abbrSR && abbrSR[this.name]) || this.name
}
get img () {
2023-05-18 20:23:19 +00:00
return this.isGs ? `meta/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
}
if (game === 'sr') {
name = idMapSR[name]?.name || name
}
if ((game === 'gs' ? artiMap : artiMapSR)[name]) {
return new Artifact(name, 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
static getMeta () {
2022-08-18 10:13:42 +00:00
return {
attrMap
}
}
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
static getArtisKeyTitle (game = 'gs') {
return ArtisMark.getKeyTitleMap(game)
}
// 获取圣遗物属性数据
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