mirror of
				https://github.com/unanmed/HumanBreak.git
				synced 2025-10-31 20:32:58 +08:00 
			
		
		
		
	优化use.ts的性能表现
This commit is contained in:
		
							parent
							
								
									11eb6ebd61
								
							
						
					
					
						commit
						b2cb89a7f6
					
				| @ -8,8 +8,28 @@ | |||||||
|  */ |  */ | ||||||
| export function getNeedCalculateDir(x, y, floorId) {} | 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) {} | 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) {} | export function getDamageInfo(enemy, hero, x, y, floorId) {} | ||||||
| 
 | 
 | ||||||
|  | /** | ||||||
|  |  * 计算地图伤害与光环效果 | ||||||
|  |  * @param {FloorIds} floorId | ||||||
|  |  */ | ||||||
| export function checkBlock(floorId) {} | export function checkBlock(floorId) {} | ||||||
|  | |||||||
| @ -140,7 +140,6 @@ const skills = { | |||||||
|             index: 11, |             index: 11, | ||||||
|             title: '学习', |             title: '学习', | ||||||
|             desc: [ |             desc: [ | ||||||
|                 '<span style="color: lightcoral">当前版本此技能无效!</span>', |  | ||||||
|                 '<span style="color: gold">主动技能</span>,可以消耗500智慧学习一个怪物的技能,', |                 '<span style="color: gold">主动技能</span>,可以消耗500智慧学习一个怪物的技能,', | ||||||
|                 '持续5场战斗,每学习一次消耗的智慧点增加250,每次升级使持续的战斗次数增加3次。更多信息可在学习后在百科全书查看。' |                 '持续5场战斗,每学习一次消耗的智慧点增加250,每次升级使持续的战斗次数增加3次。更多信息可在学习后在百科全书查看。' | ||||||
|             ], |             ], | ||||||
|  | |||||||
| @ -32,14 +32,34 @@ export function useDrag( | |||||||
|     onup?: (e: MouseEvent | TouchEvent) => void, |     onup?: (e: MouseEvent | TouchEvent) => void, | ||||||
|     global: boolean = false |     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) => { |     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); |         if (ondown) ondown(e.clientX, e.clientY, e); | ||||||
|     }; |     }; | ||||||
|     const td = (e: TouchEvent) => { |     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); |         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 target = global ? document : ele; | ||||||
| 
 | 
 | ||||||
|     const mouseFn = (e: MouseEvent) => { |     const mouseFn = (e: MouseEvent) => { | ||||||
|         if (!down) return; |  | ||||||
|         fn(e.clientX, e.clientY, e); |         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) => { |     const touchUp = (e: TouchEvent) => { | ||||||
|         if (!down) return; |  | ||||||
|         onup && onup(e); |         onup && onup(e); | ||||||
|         down = false; |  | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     if (target instanceof Array) { |     if (target instanceof Array) { | ||||||
|         target.forEach(v => { |         target.forEach(v => { | ||||||
|             v.addEventListener('mouseup', mouseUp); |             v.addEventListener('mouseup', mouseUp); | ||||||
|             v.addEventListener('touchend', touchUp); |             v.addEventListener('touchend', touchUp); | ||||||
|             v.addEventListener('mousemove', mouseFn); |  | ||||||
|             v.addEventListener('touchmove', touchFn); |  | ||||||
|         }); |         }); | ||||||
|     } else { |     } else { | ||||||
|         target.addEventListener('mouseup', mouseUp as EventListener); |         target.addEventListener('mouseup', mouseUp as EventListener); | ||||||
|         target.addEventListener('touchend', touchUp 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]); |     dragFnMap.set(fn, [mouseFn, touchFn, mouseUp, touchUp]); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user