增加角色查看功能

This commit is contained in:
yoimiya-kokomi 2022-03-27 05:34:33 +08:00
parent 7540e6b433
commit 89355f03e4
14 changed files with 306 additions and 117 deletions

View File

@ -1,19 +1,17 @@
import fetch from "node-fetch";
import { segment } from "oicq";
import lodash from "lodash";
import { Character } from "../components/models.js"
import fs from "fs";
import sizeOf from "image-size";
let getUrl, getServer;
import { Character } from "../components/models.js";
//角色昵称
let nameID = "";
let genshin = {};
await init();
export async function init(isUpdate = false) {
let _path = "file://" + process.cwd();
console.log(_path + "config/gen");
@ -23,26 +21,19 @@ export async function init(isUpdate = false) {
nameID = "";
}
//#神里
// 查看当前角色
export async function character(e, { render, MysApi }) {
let roleId = roleIdToName(e.msg.replace(/#|老婆|老公|[1|2|5][0-9]{8}/g, "").trim());
let hutao = Character.get("胡桃");
console.log(hutao.a)
return true;
if (!roleId) return false;
let name = e.msg.replace(/#|老婆|老公|[1|2|5][0-9]{8}/g, "").trim();
let char = Character.get(name);
if (!char) {
return false;
}
let roleId = char.id;
getUrl = MysApi.getUrl;
getServer = MysApi.getServer;
let uidRes = await getUid(e);
if (!uidRes.uid && uidRes.isSelf) {
e.reply("请先发送#+你游戏的uid");
return true;
@ -93,16 +84,20 @@ export async function character(e, { render, MysApi }) {
avatars = avatars[roleId];
let skill = await getSkill(e, uid, avatars);
let type = "character";
let base64 = await render("miao-plugin", type, {
let talent = await getTalent(e, uid, avatars);
let crownNum = lodash.filter(lodash.map(talent, (d) => d.level_original), (d) => d >= 10).length
let base64 = await render("miao-plugin", "character", {
_plugin: true,
save_id: uid,
uid: uid,
skill,
...get_character(avatars),
talent,
crownNum,
talentMap: { a: "普攻", e: "战技", q: "爆发" },
bg: getCharacterImg(char.name),
...getCharacterData(avatars),
ds: char.getData("name,id,title,desc"),
}, "png");
if (base64) {
@ -112,9 +107,13 @@ export async function character(e, { render, MysApi }) {
return true; //事件结束不再往下
}
// 设置角色图像
export async function setCharacterImg(e, render) {
}
//获取角色技能数据
async function getSkill(e, uid, avatars) {
async function getTalent(e, uid, avatars) {
let skill = {};
if (NoteCookie && NoteCookie[e.user_id] && NoteCookie[e.user_id].uid == uid && NoteCookie[e.user_id].cookie.includes("cookie_token")) {
@ -161,14 +160,12 @@ async function getSkill(e, uid, avatars) {
return skill;
}
function get_character(avatars) {
function getCharacterData(avatars) {
let list = [];
let set = {};
let setArr = [];
let text1 = "";
let text2 = "";
let bg = 2;
let weapon = {
type: "weapon",
@ -232,7 +229,6 @@ function get_character(avatars) {
weapon,
text1,
text2,
bg,
reliquaries,
set: setArr,
};
@ -523,3 +519,13 @@ function getDayEnd() {
return dayEnd - parseInt(now.getTime() / 1000);
}
function getCharacterImg(name) {
let imgs = fs.readdirSync(`./plugins/miao-plugin/resources/characterImg/${name}/`);
imgs = imgs.filter((img) => /\.(png|jpg|webp)/.test(img));
let img = lodash.sample(imgs);
let ret = sizeOf(`./plugins/miao-plugin/resources/characterImg/${name}/${img}`);
ret.img = `/characterImg/${name}/${img}`;
ret.mode = ret.width > ret.height ? "left" : "bottom";
return ret;
}

View File

@ -7,7 +7,6 @@ let Data = {
* 根据指定的path依次检查与创建目录
* */
createDir(rootPath = "", path, includeFile = false) {
console.log(rootPath, path)
let pathList = path.split("/"),
nowPath = rootPath;
pathList.forEach((name, idx) => {
@ -16,7 +15,6 @@ let Data = {
nowPath += name + "/";
if (name) {
if (!fs.existsSync(nowPath)) {
console.log(nowPath)
fs.mkdirSync(nowPath);
}
}
@ -79,7 +77,6 @@ let Data = {
keyRet = keyTo;
if (cfg.lowerFirstKey) {
keyRet = lodash.lowerFirst(keyRet);
console.log('keyRet', keyRet)
}
if (cfg.keyPrefix) {
keyRet = cfg.keyPrefix + keyRet;

View File

@ -1 +1,3 @@
export Data from "./Data.js";
import Data from "./Data.js";
export { Data }

View File

@ -1,5 +1,3 @@
import Character from "./models/Character.js";
export {Character};
export { Character };

View File

@ -32,14 +32,6 @@ class Character extends Base {
lodash.extend(this, getMetaData(name))
}
get id() {
for (let id in roleId) {
if (roleId[id] && role[id][0] === this.name) {
return id;
}
}
}
async checkImgCache(resDir) {
// 处理img信息
let chcheDir = resDir + "/cache/";
@ -101,7 +93,6 @@ let getMetaData = function (name) {
cons[key.replace("Constellation")] = Data.getData(data, "Name,icon:Source,desc:Description", metaCfg);
})
ret.cons = cons;
return ret;
}

View File

@ -1,3 +1,5 @@
export default{
export default {
apps: {
character: true, // 查询角色
}
}

View File

@ -1,13 +1,16 @@
export const rule = {
character: {
reg: "^#(.*)$",
reg: "^#(.*)(#.*)?$",
priority: 208,
describe: "【#刻晴】角色详情",
}
},
setCharacterImg: {
reg: "^#(添加|更新)(.*)图片(#.*)?(上|右|下|左)?$",
priority: 208,
},
};
import { character, setCharacterImg } from "./apps/character.js";
export { character } from "./apps/character.js";
export { character, setCharacterImg };

View File

@ -1,13 +1,13 @@
@font-face {
font-family: "HWZhongSong";
src: url("../../font/华文中宋.TTF");
src: url("../font/华文中宋.TTF");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "tttgbnumber";
src: url("../../font/tttgbnumber.ttf");
src: url("../font/tttgbnumber.ttf");
font-weight: normal;
font-style: normal;
}
@ -26,14 +26,10 @@
user-select: none;
}
html, body {
width: 500px;
}
body {
font-size: 16px;
color: #fff;
font-family: "tttgbnumber";
transform: scale(1.40);
transform-origin: 0 0;
}
@ -47,6 +43,7 @@ body {
.container img.bg {
width: 100%;
margin-bottom: -1px;
display: block;
}
.info {
@ -56,7 +53,10 @@ body {
left: 0px;
right: 0px;
box-shadow: 0 -5px 10px 0 #000;
padding:35px 10px 10px 35px;
padding: 35px 10px 10px 35px;
text-shadow: 0 0 1px #000, 1px 1px 3px #000;
font-family: tttgbnumber;
}
.role_box {
@ -69,20 +69,20 @@ body {
font-size: 36px;
}
.role_name {
.char_name {
font-family: "NZBZ";
font-size: 80px;
letter-spacing: 5px;
line-height: 90px;
height: 100px;
text-shadow: 0 0 1px #000, 3px 3px 6px #000;
text-shadow: 0 0 3px #000, 3px 3px 5px #000;
display: inline-block;
position:absolute;
top:-70px;
left:20px;
position: absolute;
top: -60px;
left: 20px;
}
.role_name:after {
.char_name:after {
content: "";
display: block;
position: absolute;
@ -96,39 +96,71 @@ body {
transition: width 0.3s 0.1s, opacity 0.3s 0.1s;
}
.weapon {
text-align: center;
font-size: 20px;
padding: 3px;
background: rgba(0, 0, 0, 0.6);
border-radius: 5px;
height: 100px;
width: 100px;
.char_name .uid {
font-size: 24px;
position: absolute;
overflow: hidden;
right:15px;
top:45px;
height: 25px;
line-height: 25px;
top: -25px;
left: 15px;
letter-spacing: 0;
}
.lv {
font-family: "tttgbnumber";
.crown {
width: 35px;
height: 35px;
margin-top: -3px;
margin-left: 15px;
display: inline-block;
background-size: contain;
vertical-align: bottom;
background-image: url("./imgs/crown.png");
}
.crown.crown_0 {
background-image: none;
}
.crown.crown_1 {
}
.crown.crown_2 {
width: 70px;
}
.crown.crown_3 {
width: 105px;
}
.detail {
font-size: 26px;
margin: 10px 5px 2px 5px;
}
.weapon .num {
.weapon {
text-align: center;
font-size: 20px;
width: 100px;
position: absolute;
background: rgba(0, 0, 0, 0.2);
}
.weapon_lv {
position: absolute;
bottom: 0px;
font-size: 12px;
right: 0;
font-size: 18px;
border-radius: 5px;
padding: 1px 5px;
background-color: rgba(0, 0, 0, var(--bg-opacity));
--bg-opacity: 0.75;
}
.weapon_num {
.weapon_affix {
position: absolute;
top: 0;
right: 0;
@ -142,9 +174,19 @@ body {
padding: 1px 3px;
}
.weapon img {
.weapon_cont {
position: relative;
}
.weapon_cont img {
width: 100%;
transform: scale(1.2, 1.2);
height: 100%;
}
.weapon_name {
height: 30px;
line-height: 30px;
font-size: 15px;
}
.equiv .img_box {
@ -170,12 +212,13 @@ body {
position: relative;
}
.skill {
.talent {
margin-left: 5px;
width: 300px;
padding-bottom: 6px;
padding: 5px 5px 8px;
display: flex;
position: relative;
font-size: 20px;
}
.text_box::before {
@ -219,7 +262,7 @@ body {
}
.detail p,
.skill p {
.talent div {
margin-right: 4px;
line-height: 16px;
width: 90px;
@ -256,7 +299,7 @@ body {
height: 52px;
width: 52px;
position: relative;
display:flex;
display: flex;
}
.equiv .num {
@ -292,6 +335,7 @@ body {
border-radius: 10px;
background: linear-gradient(0deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2)), rgba(114, 102, 104, 0.3);
margin-left: 5px;
margin-top: 5px;
}
.equiv_info .text {
@ -302,3 +346,154 @@ body {
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
body.bottom_mode {
width: 500px;
}
.bottom_mode .info {
padding-left: 150px;
}
.bottom_mode .weapon {
left: 0;
bottom: 0;
top: 40px;
padding-top: 120px;
width: 140px;
}
.bottom_mode .weapon_affix {
display: none;
}
.bottom_mode .weapon_cont {
position: absolute;
top: 0;
width: 100%;
}
.bottom_mode .weapon_lv {
border-radius: 8px 0 0 0;
padding-left: 8px;
background: rgba(0, 0, 0, .5);
bottom: 2px;
font-size: 15px;
}
.bottom_mode .weapon_cont img {
width: 110px;
height: 110px;
}
.bottom_mode .weapon_name {
background: rgba(0, 0, 0, .5);
height: 35px;
line-height: 35px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
.equiv_info {
width: calc(100% - 20px);
}
.bottom_mode .detail {
font-family: NZBZ;
}
.bottom_mode .for_left {
display: none;
}
/******** left mode **********/
.left_mode {
width: 800px;
transform: scale(1);
}
.left_mode .info {
bottom: 0;
right: initial;
padding: 10px 10px 5px 10px;
border-radius: 0 20px 0 0;
}
.left_mode .char_name {
position: fixed;
top: 10px;
font-size: 60px;
padding-left: 20px;
left: 0;
height: 85px;
text-shadow: 0 0 3px #000, 3px 3px 5px #000;
}
.left_mode .char_name:after {
box-shadow: 0 0 2px 0 #000;
}
.left_mode .char_name:after {
bottom: 1px;
}
.left_mode .char_name .uid {
top: 90px;
}
.left_mode .weapon {
top: -170px;
width: 110px;
padding: 0 0 3px 0;
left: 0;
border-radius: 0 10px 10px 0;
background: rgba(0, 0, 0, 0.8);
}
.left_mode .weapon_cont {
padding: 3px 10px 0 0;
border-radius: 0 10px 0 0;
border-bottom: 0.5px solid rgba(0, 0, 0, 0.3);
}
.left_mode .for_bottom,
.left_mode .weapon_lv,
.left_mode .weapon_affix {
display: none;
}
.left_mode .for_left {
display: block;
}
.left_mode .weapon_name {
height: 50px;
padding: 5px 0 0;
line-height: 20px;
}
.left_mode .detail {
width: auto;
margin-top: -5px;
}
.left_mode .talent {
padding-left: 0;
margin-right: -5px;
}
.left_mode .info,
.left_mode .weapon {
background: rgba(0, 0, 0, 0.5);
box-shadow: 0 0 5px 1px #000;
}
.left_mode .equiv_info {
padding: 0;
background: none;
}

View File

@ -3,52 +3,47 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<link rel="shortcut icon" href="#"/>
<link rel="stylesheet" type="text/css" href="{{_res_path}}/MiaoPlugin/character/character.css?v=1.0"/>
<link rel="preload" href="{{_res_path}}/font/tttgbnumber.ttf" as="font">
<link rel="preload" href="{{_res_path}}/font/华文中宋.TTF" as="font">
<link rel="preload" href="{{_res_path}}/genshin/logo/bg/{{name}}1.png" as="image">
<link rel="preload" href="{{_res_path}}/genshin/logo/bg/{{name}}2.png" as="image">
<link rel="stylesheet" type="text/css" href="{{_app_res_path}}/character/character.css?v=1.0"/>
</head>
<body>
<body class="{{bg.mode}}_mode">
<div class="container" id="container">
<div class="info">
<div class="role_name">
{{"神里凌华"}}
<div class="char_name">
<div class="uid">ID:{{uid}}</div>
<span>{{ds.name}}</span>
</div>
<div class="detail"> Lv.{{level}} ❤{{fetter}}
<span class="crown crown_{{crownNum}}"></span>
</div>
<div class="lv">ID:{{uid}} Lv.{{level}} ❤{{fetter}}</div>
<div class="weapon">
<div class="img_box">
<img src="{{_res_path}}/genshin/logo/weapon/{{weapon.name}}.png"/>
<div class="weapon_cont">
<img title="{{weapon.name}}" src="{{_res_path}}/genshin/logo/weapon/{{weapon.name}}.png"/>
<p class="weapon_lv">Lv.{{weapon.level}}</p>
<p class="weapon_affix">{{weapon.affix_level}}</p>
</div>
<p class="num">lv{{weapon.level}}</p>
<p class="weapon_num">{{weapon.affix_level}}</p>
<p class="weapon_name">
<span class="for_left">Lv.{{weapon.level}} 精{{weapon.affix_level}}</span>
<span class="for_bottom">精{{weapon.affix_level}} </span>
{{weapon.name}}
</p>
</div>
{{ if skill.a }}
<div class="skill">
<p> 爆发:<span>{{ skill.q.level_current}}</span></p>
<p> 战技:<span>{{ skill.e.level_current}}</span></p>
<p> 普攻:<span>{{ skill.a.level_current}}</span></p>
{{ if talent.a }}
<div class="talent">
{{each talentMap name key}}
<div class="talent_{{key}}"> {{name}}<span>{{ talent[key].level_current}}</span></div>
{{/each}}
</div>
{{/if}}
<div class="equiv">
<div class="item">
<div class="img_box">
<img src="{{_res_path}}/genshin/logo/{{reliquaries.type}}/{{reliquaries.name}}.png"/>
</div>
<p class="num">+{{reliquaries.level}}</p>
</div>
</div>
<div class="equiv_info">
<div class="text">{{text1}}</div>
<div class="text">{{text2}}</div>
</div>
</div>
<div>
<img src="{{_res_path}}/MiaoPlugin/characterImg/刻晴/1.jpg" class="bg"></div>
<img src="{{_app_res_path}}{{bg.img}}" title="{{name}}" class="bg"></div>
</div>
</body>
<script type="text/javascript"></script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 344 B

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

Binary file not shown.

Binary file not shown.