2022-11-23 20:26:07 +00:00
|
|
|
/**
|
2022-11-25 08:14:25 +00:00
|
|
|
* 角色照片及角色图像资源相关
|
|
|
|
* */
|
2022-09-03 21:08:57 +00:00
|
|
|
import fs from 'fs'
|
|
|
|
import lodash from 'lodash'
|
|
|
|
import sizeOf from 'image-size'
|
2023-10-19 07:46:08 +00:00
|
|
|
import { Cfg } from '#miao'
|
2022-09-03 21:08:57 +00:00
|
|
|
|
2022-11-29 20:55:50 +00:00
|
|
|
const rPath = `${process.cwd()}/plugins/miao-plugin/resources`
|
2022-09-03 21:08:57 +00:00
|
|
|
const CharImg = {
|
2022-09-04 09:33:14 +00:00
|
|
|
|
|
|
|
// 获取角色的插画
|
2022-09-04 06:15:00 +00:00
|
|
|
getCardImg (names, se = false, def = true) {
|
2022-09-03 21:08:57 +00:00
|
|
|
let list = []
|
|
|
|
let addImg = function (charImgPath, disable = false) {
|
|
|
|
let dirPath = `./plugins/miao-plugin/resources/${charImgPath}`
|
|
|
|
|
|
|
|
if (!fs.existsSync(dirPath)) {
|
|
|
|
fs.mkdirSync(dirPath)
|
|
|
|
}
|
|
|
|
if (disable) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let imgs = fs.readdirSync(dirPath)
|
|
|
|
imgs = imgs.filter((img) => /\.(png|jpg|webp|jpeg)/i.test(img))
|
|
|
|
lodash.forEach(imgs, (img) => {
|
|
|
|
list.push(`${charImgPath}/${img}`)
|
|
|
|
})
|
|
|
|
}
|
2022-09-04 06:15:00 +00:00
|
|
|
if (!lodash.isArray(names)) {
|
|
|
|
names = [names]
|
|
|
|
}
|
|
|
|
for (let name of names) {
|
|
|
|
addImg(`character-img/${name}`)
|
|
|
|
addImg(`character-img/${name}/upload`)
|
|
|
|
addImg(`character-img/${name}/se`, !se)
|
|
|
|
const plusPath = './plugins/miao-plugin/resources/miao-res-plus/'
|
|
|
|
if (fs.existsSync(plusPath)) {
|
|
|
|
addImg(`miao-res-plus/character-img/${name}`)
|
|
|
|
addImg(`miao-res-plus/character-img/${name}/se`, !se)
|
|
|
|
}
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
|
|
|
let img = lodash.sample(list)
|
|
|
|
if (!img) {
|
|
|
|
if (def) {
|
|
|
|
img = '/character-img/default/01.jpg'
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let ret = sizeOf(`./plugins/miao-plugin/resources/${img}`)
|
|
|
|
ret.img = img
|
|
|
|
ret.mode = ret.width > ret.height ? 'left' : 'bottom'
|
|
|
|
return ret
|
|
|
|
},
|
|
|
|
|
2022-11-29 20:55:50 +00:00
|
|
|
getRandomImg (imgPaths, defImgs = []) {
|
|
|
|
for (let imgPath of imgPaths) {
|
|
|
|
let ret = []
|
|
|
|
for (let type of ['webp', 'png']) {
|
|
|
|
if (fs.existsSync(`${rPath}/${imgPath}.${type}`)) {
|
|
|
|
ret.push(imgPath + '.webp')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fs.existsSync(`${rPath}/${imgPath}`)) {
|
|
|
|
let imgs = fs.readdirSync(`${rPath}/${imgPath}`).filter((file) => {
|
|
|
|
return /\.(png|webp)$/.test(file)
|
|
|
|
})
|
|
|
|
for (let img of imgs) {
|
2022-12-03 19:45:50 +00:00
|
|
|
ret.push(`${imgPath}/${encodeURIComponent(img)}`)
|
2022-11-29 20:55:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret.length > 0) {
|
|
|
|
return lodash.sample(ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let defImg of defImgs) {
|
|
|
|
if (fs.existsSync(`${rPath}/${defImg}`)) {
|
|
|
|
return defImg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-09-04 09:33:14 +00:00
|
|
|
// 获取角色的图像资源数据
|
2023-04-13 18:56:44 +00:00
|
|
|
getImgs (name, costumeIdx = '', travelerElem = '', weaponType = 'sword', talentCons) {
|
|
|
|
let fileType = 'webp'
|
2023-02-12 11:56:47 +00:00
|
|
|
costumeIdx = costumeIdx === '2' ? '2' : ''
|
2022-09-03 21:08:57 +00:00
|
|
|
let imgs = {}
|
2022-09-04 09:33:14 +00:00
|
|
|
if (!['空', '荧', '旅行者'].includes(name)) {
|
|
|
|
travelerElem = ''
|
|
|
|
}
|
2022-09-04 08:17:04 +00:00
|
|
|
const nPath = `/meta/character/${name}/`
|
2022-09-04 09:33:14 +00:00
|
|
|
const tPath = `/meta/character/旅行者/${travelerElem}/`
|
2022-09-10 19:59:45 +00:00
|
|
|
let add = (key, path, path2) => {
|
2022-09-29 13:21:52 +00:00
|
|
|
if (path2 && fs.existsSync(`${rPath}/${nPath}/${path2}.${fileType}`)) {
|
|
|
|
imgs[key] = `${nPath}${path2}.${fileType}`
|
2022-09-10 19:59:45 +00:00
|
|
|
} else {
|
2022-09-29 13:21:52 +00:00
|
|
|
imgs[key] = `${nPath}${path}.${fileType}`
|
2022-09-10 19:59:45 +00:00
|
|
|
}
|
2022-09-04 08:17:04 +00:00
|
|
|
}
|
|
|
|
let tAdd = (key, path) => {
|
2022-09-29 13:21:52 +00:00
|
|
|
imgs[key] = `${travelerElem ? tPath : nPath}${path}.${fileType}`
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
2023-02-12 11:56:47 +00:00
|
|
|
add('face', 'imgs/face', `imgs/face${costumeIdx}`)
|
2023-02-19 02:38:51 +00:00
|
|
|
add('qFace', 'imgs/face', 'imgs/face-q')
|
2023-02-12 11:56:47 +00:00
|
|
|
add('side', 'imgs/side', `imgs/side${costumeIdx}`)
|
2022-09-03 21:08:57 +00:00
|
|
|
add('gacha', 'imgs/gacha')
|
2023-02-12 11:56:47 +00:00
|
|
|
add('splash', 'imgs/splash', `imgs/splash${costumeIdx}`)
|
2022-09-04 08:17:04 +00:00
|
|
|
tAdd('card', 'imgs/card')
|
|
|
|
tAdd('banner', 'imgs/banner')
|
2022-09-03 21:08:57 +00:00
|
|
|
for (let i = 1; i <= 6; i++) {
|
2022-09-04 08:17:04 +00:00
|
|
|
tAdd(`cons${i}`, `icons/cons-${i}`)
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
|
|
|
for (let i = 0; i <= 3; i++) {
|
2022-09-04 08:17:04 +00:00
|
|
|
tAdd(`passive${i}`, `icons/passive-${i}`)
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
2023-04-13 18:56:44 +00:00
|
|
|
imgs.a = `/common/item/atk-${weaponType}.webp`
|
2023-08-15 19:51:08 +00:00
|
|
|
for (let t of ['e', 'q']) {
|
|
|
|
imgs[t] = talentCons[t] > 0 ? imgs[`cons${talentCons[t]}`] : `${nPath}icons/talent-${t}.webp`
|
|
|
|
}
|
2022-09-03 21:08:57 +00:00
|
|
|
return imgs
|
2023-05-14 20:19:33 +00:00
|
|
|
},
|
2023-10-19 07:46:08 +00:00
|
|
|
|
|
|
|
// 获取星铁角色图像资源
|
2023-05-14 20:19:33 +00:00
|
|
|
getImgsSr (name, talentCons) {
|
|
|
|
let fileType = 'webp'
|
|
|
|
const nPath = `/meta-sr/character/${name}/`
|
|
|
|
let imgs = {}
|
|
|
|
let add = (key, path, path2) => {
|
|
|
|
imgs[key] = `${nPath}${path}.${fileType}`
|
|
|
|
}
|
|
|
|
add('face', 'imgs/face')
|
|
|
|
add('splash', 'imgs/splash')
|
|
|
|
add('preview', 'imgs/preview')
|
|
|
|
for (let i = 1; i <= 3; i++) {
|
|
|
|
add(`tree${i}`, `imgs/tree-${i}`)
|
|
|
|
}
|
2023-08-11 03:47:34 +00:00
|
|
|
for (let key of ['a', 'e', 'q', 't', 'z', 'a2', 'e2']) {
|
2023-05-14 20:19:33 +00:00
|
|
|
add(key, `imgs/talent-${key}`)
|
|
|
|
}
|
|
|
|
for (let i = 1; i <= 6; i++) {
|
2023-08-11 03:47:34 +00:00
|
|
|
if (i !== 3 && i !== 5) {
|
2023-05-14 20:19:33 +00:00
|
|
|
add(`cons${i}`, `imgs/cons-${i}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
imgs.cons3 = imgs[talentCons[3]]
|
|
|
|
imgs.cons5 = imgs[talentCons[5]]
|
|
|
|
return imgs
|
2023-10-19 07:46:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getCostumeSplash (profile) {
|
|
|
|
let {char, name} = profile
|
|
|
|
if (!Cfg.get('costumeSplash', true)) {
|
|
|
|
return char.getImgs(profile._costume).splash
|
|
|
|
}
|
|
|
|
|
|
|
|
let costume = profile._costume
|
|
|
|
costume = profile.char.checkCostume(costume) ? '2' : ''
|
|
|
|
if (!Cfg.get('costumeSplash', true)) {
|
|
|
|
return this.char.getImgs(profile._costume).splash
|
|
|
|
}
|
|
|
|
|
|
|
|
let nPath = `meta/character/${name}`
|
|
|
|
let isSuper = false
|
|
|
|
let talent = profile.talent ? lodash.map(profile.talent, (ds) => ds.original).join('') : ''
|
|
|
|
if (profile.cons === 6 || ['ACE', 'MAX'].includes(profile.artis?.markClass) || talent === '101010') {
|
|
|
|
isSuper = true
|
|
|
|
}
|
|
|
|
if (isSuper) {
|
|
|
|
return CharImg.getRandomImg(
|
|
|
|
[`profile/super-character/${name}`, `profile/normal-character/${name}`],
|
|
|
|
[`${nPath}/imgs/splash0.webp`, `${nPath}/imgs/splash${costume}.webp`, `/${nPath}/imgs/splash.webp`]
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return CharImg.getRandomImg(
|
|
|
|
[`profile/normal-character/${name}`],
|
|
|
|
[`${nPath}/imgs/splash${costume}.webp`, `/${nPath}/imgs/splash.webp`]
|
|
|
|
)
|
|
|
|
}
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default CharImg
|