优化use.ts的性能表现

This commit is contained in:
unanmed 2023-04-30 22:15:54 +08:00
parent 11eb6ebd61
commit b2cb89a7f6
3 changed files with 43 additions and 22 deletions

View File

@ -8,8 +8,28 @@
*/
export function getNeedCalculateDir(x, y, floorId) {}
/**
* 获得怪物属性
* @param {EnemyIds | Partial<Enemy>} enemy
* @param {Partial<HeroStatus>?} hero
* @param {number?} x
* @param {number?} y
* @param {FloorIds?} floorId
*/
export function getEnemyInfo(enemy, hero, x, y, floorId) {}
/**
* 获得怪物伤害
* @param {EnemyIds | Partial<Enemy>} enemy
* @param {Partial<HeroStatus>?} hero
* @param {number?} x
* @param {number?} y
* @param {FloorIds?} floorId
*/
export function getDamageInfo(enemy, hero, x, y, floorId) {}
/**
* 计算地图伤害与光环效果
* @param {FloorIds} floorId
*/
export function checkBlock(floorId) {}

View File

@ -140,7 +140,6 @@ const skills = {
index: 11,
title: '学习',
desc: [
'<span style="color: lightcoral">当前版本此技能无效!</span>',
'<span style="color: gold">主动技能</span>可以消耗500智慧学习一个怪物的技能',
'持续5场战斗每学习一次消耗的智慧点增加250每次升级使持续的战斗次数增加3次。更多信息可在学习后在百科全书查看。'
],

View File

@ -32,14 +32,34 @@ export function useDrag(
onup?: (e: MouseEvent | TouchEvent) => void,
global: boolean = false
) {
let down = false;
const touchFn = (e: TouchEvent) => {
const ele = global ? document : e.target;
if (ele) {
(ele as HTMLElement).removeEventListener('touchmove', touchFn);
}
fn(e.touches[0].clientX, e.touches[0].clientY, e);
};
const mouseUp = (e: MouseEvent) => {
const ele = global ? document : e.target;
if (ele) {
(ele as HTMLElement).removeEventListener('mousemove', mouseFn);
}
onup && onup(e);
};
const md = (e: MouseEvent) => {
down = true;
const ele = global ? document : e.target;
if (ele) {
(ele as HTMLElement).addEventListener('mousemove', mouseFn);
}
if (ondown) ondown(e.clientX, e.clientY, e);
};
const td = (e: TouchEvent) => {
down = true;
const ele = global ? document : e.target;
if (ele) {
(ele as HTMLElement).addEventListener('touchmove', touchFn);
}
if (ondown) ondown(e.touches[0].clientX, e.touches[0].clientY, e);
};
@ -56,39 +76,21 @@ export function useDrag(
const target = global ? document : ele;
const mouseFn = (e: MouseEvent) => {
if (!down) return;
fn(e.clientX, e.clientY, e);
};
const touchFn = (e: TouchEvent) => {
if (!down) return;
fn(e.touches[0].clientX, e.touches[0].clientY, e);
};
const mouseUp = (e: MouseEvent) => {
if (!down) return;
onup && onup(e);
down = false;
};
const touchUp = (e: TouchEvent) => {
if (!down) return;
onup && onup(e);
down = false;
};
if (target instanceof Array) {
target.forEach(v => {
v.addEventListener('mouseup', mouseUp);
v.addEventListener('touchend', touchUp);
v.addEventListener('mousemove', mouseFn);
v.addEventListener('touchmove', touchFn);
});
} else {
target.addEventListener('mouseup', mouseUp as EventListener);
target.addEventListener('touchend', touchUp as EventListener);
target.addEventListener('mousemove', mouseFn as EventListener);
target.addEventListener('touchmove', touchFn as EventListener);
}
dragFnMap.set(fn, [mouseFn, touchFn, mouseUp, touchUp]);
}