From b2cb89a7f653145c3dc53d9c806d09907f003bf3 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 30 Apr 2023 22:15:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96use.ts=E7=9A=84=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E8=A1=A8=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/project/plugin/damage.js | 20 ++++++++++++++ public/project/plugin/skillTree.js | 1 - src/plugin/use.ts | 44 ++++++++++++++++-------------- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/public/project/plugin/damage.js b/public/project/plugin/damage.js index c2c3609..0a471a9 100644 --- a/public/project/plugin/damage.js +++ b/public/project/plugin/damage.js @@ -8,8 +8,28 @@ */ export function getNeedCalculateDir(x, y, floorId) {} +/** + * 获得怪物属性 + * @param {EnemyIds | Partial} enemy + * @param {Partial?} hero + * @param {number?} x + * @param {number?} y + * @param {FloorIds?} floorId + */ export function getEnemyInfo(enemy, hero, x, y, floorId) {} +/** + * 获得怪物伤害 + * @param {EnemyIds | Partial} enemy + * @param {Partial?} 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) {} diff --git a/public/project/plugin/skillTree.js b/public/project/plugin/skillTree.js index 4e11f0b..5f73b50 100644 --- a/public/project/plugin/skillTree.js +++ b/public/project/plugin/skillTree.js @@ -140,7 +140,6 @@ const skills = { index: 11, title: '学习', desc: [ - '当前版本此技能无效!', '主动技能,可以消耗500智慧学习一个怪物的技能,', '持续5场战斗,每学习一次消耗的智慧点增加250,每次升级使持续的战斗次数增加3次。更多信息可在学习后在百科全书查看。' ], diff --git a/src/plugin/use.ts b/src/plugin/use.ts index bea32cf..55e5c84 100644 --- a/src/plugin/use.ts +++ b/src/plugin/use.ts @@ -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]); }