diff --git a/apps/character/AvatarCard.js b/apps/character/AvatarCard.js index ba955c78..288f0905 100644 --- a/apps/character/AvatarCard.js +++ b/apps/character/AvatarCard.js @@ -1,5 +1,5 @@ import { Character, MysApi, Player } from '#miao.models' -import { Cfg, Common } from '#miao' +import { Cfg, Common, Meta } from '#miao' import lodash from 'lodash' import moment from 'moment' @@ -94,7 +94,9 @@ let Avatar = { message_id.push(msgRes.message_id) } for (const i of message_id) { - await redis.set(`miao:original-picture:${i}`, JSON.stringify({ type: 'character', img: bg.img }), { EX: 3600 * 3 }) + await redis.set(`miao:original-picture:${i}`, JSON.stringify({ + type: 'character', img: bg.img + }), { EX: 3600 * 3 }) } } return true @@ -114,8 +116,15 @@ let Avatar = { } let name = msg.replace(/#|老婆|老公|卡片/g, '').trim() - // cache gsCfg - Character.gsCfg = Character.gsCfg || e?.runtime?.gsCfg + if (e?.runtime?.gsCfg) { + let gsCfg = e?.runtime?.gsCfg + Meta.addAliasFn('gs', 'char', (txt) => { + let roleRet = gsCfg.getRole(txt) + if (roleRet.name) { + return roleRet.name + } + }) + } let char = Character.get(name.trim()) diff --git a/components/Meta.js b/components/Meta.js index f5b63a6b..cf38316c 100644 --- a/components/Meta.js +++ b/components/Meta.js @@ -1,65 +1,78 @@ +import { Data } from '#miao' import lodash from 'lodash' -const Store = {} +const MetaStore = {} -const Meta = { - - // 获取存储 - getStore (game, dataType) { - Store[game] = Store[game] || {} - Store[game][dataType] = Store[game][dataType] || { - meta: {}, - alias: {}, - abbr: {} - } - return Store[game][dataType] - }, +class MetaData { + constructor (game = 'gs', type = '') { + this.game = game + this.type = type + this.data = {} + this.alias = {} + this.abbr = {} + this.cfg = {} + } // 添加数据 - addMeta (game, dataType, data, pk = 'id') { - let { meta, alias } = Meta.getStore(game, dataType) - - lodash.forEach(data, (ds, id) => { + addData (datas, pk = 'id') { + let { data, alias } = this + lodash.forEach(datas, (ds, id) => { id = ds[pk] || id - meta[id] = ds - alias[id] = id - if (ds.name) { + data[id] = ds + if (ds.name && ds.name !== id) { alias[ds.name] = id } }) - }, + } + + addDataItem (id, ds) { + let { data, alias } = this + data[id] = ds + alias[id] = id + if (ds.name) { + alias[ds.name] = id + } + } // 添加简写 - addAbbr (game, dataType, data) { - let { abbr, alias } = Meta.getStore(game, dataType) - lodash.forEach(data, (abbr, id) => { - abbr[id] = abbr + addAbbr (ds) { + let { abbr, alias } = this + lodash.forEach(ds, (txt, id) => { + abbr[id] = lodash.trim(txt + '') alias[abbr] = alias[id] || id }) - }, + } // 添加别名 - addAlias (game, dataType, data) { - let { alias } = Meta.getStore(game, dataType) - lodash.forEach(data, (txt, id) => { + addAlias (ds) { + let { alias } = this + lodash.forEach(ds, (txt, id) => { lodash.forEach(txt.split(','), (t) => { - alias[lodash.trim(t.toLowerCase())] = alias[id] || id + alias[lodash.trim(t + '').toLowerCase()] = alias[id] || id }) }) - }, + } // 注册别名Fn - addAliasFn (game, dataType, fn) { - let store = Meta.getStore(game, dataType) + addAliasFn (fn) { if (fn) { - store.aliasFn = fn + this.aliasFn = fn } - }, + } - // 根据别名获取数据ID - getId (game, dataType, txt) { - txt = lodash.trim(txt.toLowerCase()) - let { alias, aliasFn } = Meta.getStore(game, dataType) + addCfg (cfgMap) { + let { cfg } = this + lodash.forEach(cfgMap, (v, k) => { + cfg[k] = v + }) + } + + getId (txt) { + txt = lodash.trim(txt + '').toLowerCase() + let { data, alias, aliasFn } = this + if (data[txt]) { + return txt + } if (alias[txt]) { return alias[txt] } @@ -70,29 +83,63 @@ const Meta = { } } return false + } + + getData (txt) { + let id = this.getId(txt) + let { data } = this + return data[id] || null + } + + getCfg (key = '') { + if (!key) { + return this.cfg + } + return this.cfg[key] + } + + getIds () { + return lodash.keys(this.data) + } +} + +const MetaFn = (fnKey) => { + return (game, type, args = '') => { + let meta = Meta.getMeta(game, type) + return meta[fnKey](args) + } +} + +const Meta = { + addAliasFn (game, type, fn) { + let meta = Meta.getMeta(game, type) + meta.addAliasFn(fn) }, + // 获取存储 + getMeta (game, type) { + let key = `${game}.${type}` + if (!MetaStore[key]) { + MetaStore[key] = new MetaData(game, type) + } + return MetaStore[key] + }, + getId: MetaFn('getId'), + getIds: MetaFn('getIds'), + getData: MetaFn('getData'), + getCfg: MetaFn('getCfg'), // 在各个游戏内匹配,以传入的game优先 - matchGame (game = 'gs', dataType, txt) { - txt = lodash.trim(txt.toLowerCase()) + matchGame (game = 'gs', type, txt) { + txt = lodash.trim(txt + '').toLowerCase() let games = game === 'gs' ? ['gs', 'sr'] : ['sr', 'gs'] for (let currGame of games) { - let id = Meta.getId(currGame, dataType, txt) + let id = Meta.getId(currGame, type, txt) if (id) { - let meta = Meta.getMeta(currGame, dataType, id) - return { game, id, meta } + let data = Meta.getData(currGame, type, id) + return { game, id, data } } } return false - }, - - // 根据别名获取数据 - getMeta (game, dataType, txt) { - txt = lodash.trim(txt.toLowerCase()) - let id = Meta.getId(game, dataType, txt) - let { meta } = Meta.getStore(game, dataType) - return meta[id] } - } export default Meta diff --git a/index.js b/index.js index 585b9ef6..f13a7646 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ import { Data, Version } from '#miao' -import fs from 'fs' +import Index from './tools/index.js' if (!global.segment) { global.segment = (await import('oicq')).segment @@ -14,31 +14,4 @@ if (Bot?.logger?.info) { console.log(`喵喵插件${Version.version}初始化~`) } -setTimeout(async function () { - let msgStr = await redis.get('miao:restart-msg') - let relpyPrivate = async function () { - } - let common = await Data.importModule('lib/common/common.js', 'root') - if (common && common.default && common.default.relpyPrivate) { - relpyPrivate = common.default.relpyPrivate - } - if (msgStr) { - let msg = JSON.parse(msgStr) - await relpyPrivate(msg.qq, msg.msg) - await redis.del('miao:restart-msg') - let msgs = [`当前喵喵版本: ${Version.version}`, '您可使用 #喵喵版本 命令查看更新信息'] - await relpyPrivate(msg.qq, msgs.join('\n')) - } - if (!Version.isV3) { - console.log('警告:miao-plugin需要V3 Yunzai,请升级至最新版Miao-Yunzai以使用miao-plugin') - } - if (!fs.existsSync(process.cwd() + '/lib/plugins/runtime.js')) { - let msg = '警告:未检测到runtime,miao-plugin可能无法正常工作。请升级至最新版Miao-Yunzai以使用miao-plugin' - if (!await redis.get('miao:runtime-warning')) { - await relpyPrivate(msg.qq, msg) - await redis.set('miao:runtime-warning', 'true', { EX: 3600 * 24 }) - } else { - console.log(msg) - } - } -}, 1000) +setTimeout(Index.init, 1000) diff --git a/models/Artifact.js b/models/Artifact.js index 9fdb6180..bb939754 100644 --- a/models/Artifact.js +++ b/models/Artifact.js @@ -3,25 +3,25 @@ * */ import Base from './Base.js' import { ArtifactSet } from './index.js' -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' +import { attrMap } from '../resources/meta/artifact/index.js' +import { abbr as abbrSR } from '../resources/meta-sr/artifact/index.js' import ArtisMark from './artis/ArtisMark.js' import ArtisAttr from './artis/ArtisAttr.js' +import { Meta } from '#miao' class Artifact extends Base { - static getAttrs - constructor (name, game = 'gs') { + constructor (data, game = 'gs') { + if (!data) { + return false + } super() + let name = data.id || data.name 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 @@ -48,16 +48,13 @@ class Artifact extends Base { if (!name) { return false } - // 传入为artis对象 if (name.id || name.name) { return Artifact.get(name.id || name.name, name.game || game) } - if (game === 'sr') { - name = idMapSR[name]?.name || name - } - if ((game === 'gs' ? artiMap : artiMapSR)[name]) { - return new Artifact(name, game) + let data = Meta.getData(game, 'arti', name) + if(data){ + return new Artifact(data, game) } return false } @@ -76,6 +73,10 @@ class Artifact extends Base { } } + static getArtisKeyTitle (game = 'gs') { + return ArtisMark.getKeyTitleMap(game) + } + getStarById (id) { return this.meta.ids[id] || '' } @@ -89,10 +90,6 @@ class Artifact extends Base { } } - static getArtisKeyTitle (game = 'gs') { - return ArtisMark.getKeyTitleMap(game) - } - // 获取圣遗物属性数据 getAttrData (arti, idx = 1, game = 'gs') { return ArtisAttr.getData(arti, idx, game) diff --git a/models/ArtifactSet.js b/models/ArtifactSet.js index 31a02931..f8ca6137 100644 --- a/models/ArtifactSet.js +++ b/models/ArtifactSet.js @@ -3,6 +3,7 @@ * */ import lodash from 'lodash' import Base from './Base.js' +import { Meta } from '#miao' import { abbr, aliasMap, artiMap, artiSetMap, calc as artisBuffs } from '../resources/meta/artifact/index.js' import { abbr as abbrSR, @@ -15,21 +16,16 @@ import { import { Artifact } from './index.js' class ArtifactSet extends Base { - constructor (name, game = 'gs') { + constructor (data, game = 'gs') { super() + if(!data){ + return false + } + let name = data.name let cache = this._getCache(`arti-set:${game}:${name}`) if (cache) { return cache } - let data = (game === 'gs' ? artiSetMap : artiSetMapSR)[name] - if (!data) { - if (artiSetMapSR[name]) { - data = artiSetMapSR[name] - game = 'sr' - } else { - return false - } - } this.game = game this.meta = data return this._cache() @@ -54,7 +50,11 @@ class ArtifactSet extends Base { return false } - static get (name) { + static get (name, game = 'gs') { + let data = Meta.matchGame(game, 'artiSet', name) + if (data) { + return new ArtifactSet(data.data, data.game) + } if (artiSetMap[name]) { return new ArtifactSet(name, 'gs') } @@ -80,14 +80,6 @@ class ArtifactSet extends Base { return ret } - getArtiName (idx = 1) { - return this.sets[idx] - } - - getArti (idx = 1) { - return Artifact.get(this.getArtiName(idx), this.game) - } - static getAliasMap (game = 'gs') { return game === 'gs' ? aliasMap : aliasMapSR } @@ -104,6 +96,14 @@ class ArtifactSet extends Base { } }) } + + getArtiName (idx = 1) { + return this.sets[idx] + } + + getArti (idx = 1) { + return Artifact.get(this.getArtiName(idx), this.game) + } } export default ArtifactSet diff --git a/models/Character.js b/models/Character.js index 2685bcb4..05b6b4f0 100644 --- a/models/Character.js +++ b/models/Character.js @@ -13,15 +13,7 @@ import CharId from './character/CharId.js' import CharMeta from './character/CharMeta.js' import CharCfg from './character/CharCfg.js' -let { wifeMap, idSort, idMap } = CharId - -let getMeta = function (name, game = 'gs') { - if (game === 'gs') { - return Data.readJSON(`resources/meta/character/${name}/data.json`, 'miao') - } else { - return CharId.getSrMeta(name) - } -} +let { wifeMap } = CharId class Character extends Base { // 默认获取的数据 @@ -39,7 +31,7 @@ class Character extends Base { this.name = name this.game = game if (!this.isCustom) { - let meta = getMeta(name, game) + let meta = Meta.getData(game, 'char', name) this.meta = meta if (this.isGs) { this.elem = Format.elem(elem || meta.elem, 'anemo') @@ -179,7 +171,7 @@ class Character extends Base { // 基于角色名获取Character static get (val, game = 'gs') { - let id = CharId.getId(val, Character.gsCfg, game) + let id = CharId.getId(val, game) if (!id) { return false } @@ -187,8 +179,9 @@ class Character extends Base { } static forEach (fn, type = 'all', game = 'gs') { - lodash.forEach(idMap, (name, id) => { - let char = Character.get({ id, name }) + let ids = Meta.getIds(game, 'char') + lodash.forEach(ids, (id) => { + let char = Character.get(id) if (char.game !== 'gs') { return true } @@ -204,7 +197,7 @@ class Character extends Base { // 获取排序ID static sortIds (arr) { - return arr.sort((a, b) => (idSort[a] || 300) - (idSort[b] || 300)) + return arr.sort((a, b) => a * 1 - b * 1) } // 获取attr列表 @@ -354,6 +347,4 @@ class Character extends Base { } } -Character.CharId = CharId - export default Character diff --git a/models/Player.js b/models/Player.js index 422ef54c..ec2388ae 100644 --- a/models/Player.js +++ b/models/Player.js @@ -11,7 +11,6 @@ import { Avatar, ProfileRank, Character } from './index.js' import MysAvatar from './avatar/MysAvatar.js' import ProfileAvatar from './avatar/ProfileAvatar.js' -import Trans from './player/PlayerTrans.js' Data.createDir('/data/UserData', 'root') Data.createDir('/data/PlayerData/gs', 'root') @@ -408,7 +407,3 @@ export default class Player extends Base { return avatarRet } } - -setTimeout(() => { - Trans.init() -}, 500) diff --git a/models/character/CharId.js b/models/character/CharId.js index cd3a71f3..38296609 100644 --- a/models/character/CharId.js +++ b/models/character/CharId.js @@ -2,160 +2,65 @@ * 角色别名及角色ID相关 * */ import lodash from 'lodash' -import { Data, Format } from '#miao' -import { charPosIdx } from './CharMeta.js' -import { aliasMap as aliasMapSR } from '../../resources/meta-sr/character/meta.js' - -// 别名表 -let aliasMap = {} -// ID表 -let idMap = {} -// 简写表 -let abbrMap = {} -// wife -let wifeMap = {} -// id排序 -let idSort = {} - -let gameMap = {} - -let srData = Data.readJSON('/resources/meta-sr/character/data.json', 'miao') +import { Data, Format, Meta } from '#miao' async function init () { - let { sysCfg, diyCfg } = await Data.importCfg('character') + let { diyCfg } = await Data.importCfg('character') - lodash.forEach(srData, (ds) => { - let { id, name } = ds - aliasMap[id] = id - aliasMap[name] = id - idMap[id] = name - gameMap[id] = 'sr' - }) - - // 添加别名 - lodash.forEach(aliasMapSR, (v, k) => { - aliasMap[k] = aliasMap[v] - }) - - lodash.forEach([diyCfg.customCharacters, sysCfg.characters], (roleIds) => { + lodash.forEach([diyCfg.customCharacters], (roleIds) => { lodash.forEach(roleIds || {}, (aliases, id) => { - aliases = aliases || [] - if (aliases.length === 0) { - return - } - // 建立别名映射 - lodash.forEach(aliases || [], (alias) => { - alias = alias.toLowerCase() - aliasMap[alias] = id - }) - aliasMap[id] = id - idMap[id] = aliases[0] - gameMap[id] = 'gs' + // TODO: 自定义角色支持 }) }) - - lodash.forEach([sysCfg.wifeData, diyCfg.wifeData], (wifeData) => { - lodash.forEach(wifeData || {}, (ids, type) => { - type = Data.def({ girlfriend: 0, boyfriend: 1, daughter: 2, son: 3 }[type], type) - if (!wifeMap[type]) { - wifeMap[type] = {} - } - Data.eachStr(ids, (id) => { - id = aliasMap[id] - if (id) { - wifeMap[type][id] = true - } - }) - }) - }) - abbrMap = sysCfg.abbr } await init() -lodash.forEach(charPosIdx, (chars, pos) => { - chars = chars.split(',') - lodash.forEach(chars, (name, idx) => { - let id = aliasMap[name] - if (id) { - idSort[id] = pos * 100 + idx - } - }) -}) - const CharId = { - aliasMap, - idMap, - gameMap, - abbrMap, - wifeMap, - idSort, - isGs (id) { - return gameMap[id] === 'gs' - }, - isSr (id) { - return gameMap[id] === 'sr' - }, - getId (ds = '', gsCfg = null, game = '') { + + getId (ds = '', game = '', elem = '') { if (!ds) { return false } - const ret = (id, elem = '') => { - if (CharId.isSr(id)) { - return { id, name: idMap[id], game: 'sr' } - } else { - return { id, elem, name: idMap[id], game: 'gs' } + if (lodash.isObject(ds)) { + let em = Format.elem(ds.elem || ds.element) + for (let key of ['id', 'name']) { + if (!ds[key]) continue + let ret = CharId.getId(ds[key], game, em || '') + if (ret) return ret } - } - if (!lodash.isObject(ds)) { - let original = lodash.trim(ds || '') - ds = original.toLowerCase() - if(game !== 'sr') { - // 尝试使用元素起始匹配 - let em = Format.matchElem(ds, '', true) - if (em && aliasMap[em.name] && CharId.isTraveler(aliasMap[em.name])) { - return ret(aliasMap[em.name], em.elem) - } - } - // 直接匹配 - if (aliasMap[ds]) { - return ret(aliasMap[ds]) - } - // 调用V3方法匹配 - if (gsCfg && gsCfg.getRole) { - let roleRet = gsCfg.getRole(original) - if (roleRet.name && aliasMap[roleRet.name]) { - return ret(aliasMap[roleRet.name]) - } - } - // 无匹配结果 return false } - // 获取字段进行匹配 - let { id = '', name = '' } = ds - let elem = Format.elem(ds.elem || ds.element) - // 直接匹配 - if (aliasMap[id || name]) { - return ret(aliasMap[id || name], elem) + + const ret = (data, game = 'gs', em = '') => { + let { id, name } = data + return { id, data, name, game, elem: em || elem } } - // 尝试解析名字 - let nId = CharId.getId(ds.name) - if (nId) { - return ret(nId.id, elem || nId.elem || '') + + if (game !== 'sr') { + // 尝试使用元素起始匹配 + let em = Format.matchElem(ds, '', true) + if (em) { + let match = Meta.getData('gs', 'char', em.name) + if (match && CharId.isTraveler(match.id)) { + return ret(match.data, 'gs', em.elem) + } + } + } + let match = Meta.matchGame(game, 'char', ds) + if (match) { + return ret(match.data, match.game) } // 无匹配结果 return false }, - isTraveler (id, game = 'gs') { + isTraveler (id) { if (id) { return [10000007, 10000005, 20000000].includes(id * 1) } return false - }, - - getSrMeta (name) { - return srData?.[aliasMap[name]] || {} } + } export default CharId diff --git a/models/index.js b/models/index.js index 65bddd2d..5d4ddf67 100644 --- a/models/index.js +++ b/models/index.js @@ -1,3 +1,5 @@ +import fs from 'node:fs' + import Base from './Base.js' import Character from './Character.js' import Artifact from './Artifact.js' @@ -12,6 +14,19 @@ import Weapon from './Weapon.js' import User from './User.js' import MysApi from './MysApi.js' +for (let game of ['meta', 'meta-sr']) { + for (let type of ['artifact', 'character', 'material', 'weapon']) { + let file = `./plugins/miao-plugin/resources/${game}/${type}/index.js` + if (fs.existsSync(file)) { + try { + await import(`file://${process.cwd()}/${file}`) + } catch (e) { + console.log(e) + } + } + } +} + export { Base, Abyss, @@ -27,3 +42,5 @@ export { MysApi, Player } + + diff --git a/resources/meta-sr/artifact/index.js b/resources/meta-sr/artifact/index.js index f9d6acef..a8177737 100644 --- a/resources/meta-sr/artifact/index.js +++ b/resources/meta-sr/artifact/index.js @@ -1,10 +1,14 @@ -import { Data } from '#miao' +import { Data, Meta } from '#miao' import lodash from 'lodash' import artisBuffs from './calc.js' +import * as metaCfg from './meta.js' let data = Data.readJSON('/resources/meta-sr/artifact/data.json', 'miao') let meta = Data.readJSON('/resources/meta-sr/artifact/meta.json', 'miao') +let setMeta = Meta.getMeta('sr', 'artiSet') +let artiMeta = Meta.getMeta('sr', 'artis') + let artiMap = {} let idMap = {} let artiSetMap = {} @@ -15,6 +19,7 @@ lodash.forEach(data, (setData) => { sets: {} } artiSetMap[setData.name] = artiSet + setMeta.addDataItem(artiSet.name, artiSet) lodash.forEach(setData.idxs, (ds, idx) => { artiMap[ds.name] = { @@ -23,6 +28,8 @@ lodash.forEach(data, (setData) => { setId: setData.id, idx } + artiMeta.addDataItem(ds.name, ds) + idMap[ds.name] = artiMap[ds.name] lodash.forEach(ds.ids, (star, id) => { idMap[id] = artiMap[ds.name] @@ -31,6 +38,12 @@ lodash.forEach(data, (setData) => { }) }) +arti + +artiMeta.addCfg({ + idMap +}) + export const metaData = meta export { artiMap, idMap, artisBuffs, artiSetMap } -export * from './meta.js' \ No newline at end of file +export * from './meta.js' diff --git a/resources/meta-sr/artifact/meta.js b/resources/meta-sr/artifact/meta.js index 15b27beb..b2ee09fe 100644 --- a/resources/meta-sr/artifact/meta.js +++ b/resources/meta-sr/artifact/meta.js @@ -53,7 +53,7 @@ lodash.forEach(attrMap, (attr, key) => { export { attrMap } -export const abbr = { +export const artisAbbr = { 快枪手的野穗毡帽: '快枪手的毡帽', 快枪手的粗革手套: '快枪手的手套', 快枪手的猎风披肩: '快枪手的披肩', @@ -80,7 +80,8 @@ export const abbr = { 泰科铵的弧光赛道: '泰科铵的赛道', 伊须磨洲的残船鲸落: '伊须磨洲的鲸落', 伊须磨洲的坼裂缆索: '伊须磨洲的缆索', - +} +const artiSetAbbr = { 盗匪荒漠的废土客: '虚数套', 繁星璀璨的天才: '量子套', 激奏雷电的乐队: '雷套', diff --git a/resources/meta-sr/character/index.js b/resources/meta-sr/character/index.js new file mode 100644 index 00000000..8e45549a --- /dev/null +++ b/resources/meta-sr/character/index.js @@ -0,0 +1,7 @@ +import { Data, Meta } from '#miao' +import { alias } from './meta.js' + +let data = Data.readJSON('resources/meta-sr/character/data.json', 'miao') +let meta = Meta.getMeta('sr', 'char') +meta.addData(data) +meta.addAlias(alias) diff --git a/resources/meta-sr/character/meta.js b/resources/meta-sr/character/meta.js index 29c7d4ce..cd1902a1 100644 --- a/resources/meta-sr/character/meta.js +++ b/resources/meta-sr/character/meta.js @@ -40,4 +40,4 @@ lodash.forEach(alias, (txt, char) => { }) }) -export { aliasMap } +export { alias, aliasMap } diff --git a/resources/meta/artifact/calc.js b/resources/meta/artifact/calc.js index 645be2c6..4d31fe40 100644 --- a/resources/meta/artifact/calc.js +++ b/resources/meta/artifact/calc.js @@ -459,4 +459,5 @@ const buffs = { } } } + export default buffs diff --git a/resources/meta/artifact/index.js b/resources/meta/artifact/index.js index c1f87ce9..6fd1291a 100644 --- a/resources/meta/artifact/index.js +++ b/resources/meta/artifact/index.js @@ -1,10 +1,14 @@ -import { Data } from '#miao' +import { Data, Meta } from '#miao' import lodash from 'lodash' import calc from './calc.js' +import * as metaData from './meta.js' let artiSetMap = {} let artiMap = {} +let setMeta = Meta.getMeta('gs', 'artiSet') +let artiMeta = Meta.getMeta('gs', 'artis') + let artis = Data.readJSON('resources/meta/artifact/data.json', 'miao') lodash.forEach(artis, (ds) => { @@ -14,17 +18,29 @@ lodash.forEach(artis, (ds) => { sets: {} } artiSetMap[ds.name] = artiSet + setMeta.addDataItem(ds.name, artiSet) + lodash.forEach(ds.sets, (as, idx) => { if (as.name) { - artiMap[as.name] = { + let tmp = { set: ds.name, name: as.name, idx } + artiMap[as.name] = tmp artiSet.sets[idx] = as.name + artiMeta.addDataItem(as.name, tmp) } }) }) export { artiMap, artiSetMap, calc } export * from './meta.js' + +setMeta.addAbbr(metaData.abbr) +setMeta.addAlias(metaData.aliasCfg) +artiMeta.addCfg({ + ...Data.getData(metaData, 'mainAttr,subAttr,attrMap,attrNameMap,mainIdMap,attrIdMap'), + calc +}) +export default artiMeta diff --git a/resources/meta/artifact/meta.js b/resources/meta/artifact/meta.js index 0b1eec65..a218faf1 100644 --- a/resources/meta/artifact/meta.js +++ b/resources/meta/artifact/meta.js @@ -48,7 +48,7 @@ export const abbr = { } -let aliasCfg = { +export const aliasCfg = { 炽烈的炎之魔女: '魔女', 昔日宗室之仪: '宗室', 翠绿之影: '风套,翠绿', diff --git a/resources/meta/character/index.js b/resources/meta/character/index.js index 5aa2f9c8..018ad189 100644 --- a/resources/meta/character/index.js +++ b/resources/meta/character/index.js @@ -1,9 +1,8 @@ import { Data, Meta } from '#miao' + import { alias } from './meta.js' let data = Data.readJSON('resources/meta/character/data.json', 'miao') -Meta.addMeta('gs', 'char', data) -Meta.addAlias('gs', 'char', alias) - -export const game = 'gs' -export const dataType = 'char' +let meta = Meta.getMeta('gs', 'char') +meta.addData(data) +meta.addAlias(alias) diff --git a/resources/meta/weapon/index.js b/resources/meta/weapon/index.js index f217d571..6777941b 100644 --- a/resources/meta/weapon/index.js +++ b/resources/meta/weapon/index.js @@ -1,4 +1,4 @@ -import { Data } from '#miao' +import { Data, Meta } from '#miao' import lodash from 'lodash' import { weaponType, abbr, alias, weaponSet } from './meta.js' @@ -33,7 +33,7 @@ for (let type in weaponType) { calc = lodash.extend(calc, typeRet) // data - let typeData = await Data.readJSON(`resources/meta/weapon/${type}/data.json`,'miao') + let typeData = await Data.readJSON(`resources/meta/weapon/${type}/data.json`, 'miao') lodash.forEach(typeData, (ds) => { data[ds.name] = { id: ds.id, @@ -64,3 +64,12 @@ export const weaponData = data export const weaponAbbr = abbr export const weaponAlias = aliasMap export { weaponType, weaponSet } + +let meta = Meta.getMeta('gs', 'weapon') +meta.addData(data) +meta.addAlias(alias) +meta.addAbbr(abbr) +meta.addCfg({ + weaponType, weaponSet, weaponBuffs +}) +export default meta diff --git a/tools/index.js b/tools/index.js new file mode 100644 index 00000000..1786903f --- /dev/null +++ b/tools/index.js @@ -0,0 +1,52 @@ +import { Data, Version } from '#miao' +import fs from 'node:fs' +import Trans from './trans.js' + +let relpyPrivate = async function () { +} +let common = await Data.importModule('lib/common/common.js', 'root') +if (common && common.default && common.default.relpyPrivate) { + relpyPrivate = common.default.relpyPrivate +} + +const Index = { + async init () { + await Index.checkVersion() + await Index.startMsg() + Index.transUserData() + }, + + // 发启动消息 + async startMsg () { + let msgStr = await redis.get('miao:restart-msg') + if (msgStr) { + let msg = JSON.parse(msgStr) + await relpyPrivate(msg.qq, msg.msg) + await redis.del('miao:restart-msg') + let msgs = [`当前喵喵版本: ${Version.version}`, '您可使用 #喵喵版本 命令查看更新信息'] + await relpyPrivate(msg.qq, msgs.join('\n')) + } + }, + + // 检查版本 + async checkVersion () { + if (!Version.isV3) { + console.log('警告:miao-plugin需要V3 Yunzai,请升级至最新版Miao-Yunzai以使用miao-plugin') + } + if (!fs.existsSync(process.cwd() + '/lib/plugins/runtime.js')) { + let msg = '警告:未检测到runtime,miao-plugin可能无法正常工作。请升级至最新版Miao-Yunzai以使用miao-plugin' + if (!await redis.get('miao:runtime-warning')) { + await relpyPrivate(msg.qq, msg) + await redis.set('miao:runtime-warning', 'true', { EX: 3600 * 24 }) + } else { + console.log(msg) + } + } + }, + + // 迁移面板数据 + transUserData () { + Trans.init() + } +} +export default Index diff --git a/models/player/PlayerTrans.js b/tools/trans.js similarity index 100% rename from models/player/PlayerTrans.js rename to tools/trans.js