Files
bettergi-scripts-list/repo/js/OCRArtifacts/lib/Artifact.js
coderzhlh 8cc27e288c 添加通过ocr识别圣遗物并解析为json格式的js脚本 (#2119)
* Create README.md

* Create settings.json

* Create manifest.json

* Create main.js

* Create Artifact.js

* Create Constants.js

* Create Parser.js

* Create a.txt

* Delete repo/js/OCRArtifacts/records/a.txt

* Create a.txt

* Create a.txt
2025-10-11 20:00:00 +08:00

74 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
class _Artifact {
constructor(arr) {
this.number = parseInt(arr.shift())
this.name = arr.shift()
this.slot = arr.shift()
this.main = arr.shift()
this.mainVal = arr.shift().replace(',', '')
const last = arr.pop()
if (last.includes('已装备')) {
this.equip = last.replace('已装备', '')
}
const index = findIndex(arr, '2件套')
arr = arr.slice(0, index)
this.setType = arr.pop().replace(/[:]/, '')
this.getStar()
this.getSource(arr)
this.getLv(arr)
this.getAttr(arr)
}
getStar() {
const { setType } = this
if (STAR_3_SET_TYPE.includes(setType)) this.star = 3
else if (STAR_4_SET_TYPE.includes(setType)) this.star = 4
else this.star = 5
}
getSource(arr) {
if (findIndex(arr, '祝圣之霜定义') !== -1) this.source = 'SEDefinition'
}
getLv(arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i].startsWith('+')) {
let str = arr.splice(i, 1)[0]
this.lv = str.replace('+', '') || 0
}
}
}
getAttr(arr) {
let r = []
for (let i = 0; i < arr.length; i++) {
let str = arr[i]
for (let n of ATTR_NAMES) {
if (str.includes(n)) {
let t = {}
if (str.includes('待激活')) {
t['active'] = false
}
if (str.includes('%') && ['攻击力', '防御力', '生命值'].includes(n)) {
t['isPercent'] = true
}
t[n] = str.match(/\+([.0-9%]+)/)[1]
r.push(t)
}
}
}
this.attr = r
}
}
function findIndex(arr, target) {
for (let i = 0; i < arr.length; i++) {
if (arr[i].includes(target)) return i
}
return -1
}
var Artifact = _Artifact