refactor: 移动鼠标定点查看

This commit is contained in:
AncTe committed 2023-11-12 22:54:19 +08:00
1 parent 5b36d8977f
commit 5e4a8c1eb3
15 files changed
+264 -165

No files matched your search

+4
View File
@@ -74,6 +74,10 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
this.extract();
}
get(x: number, y: number) {
return this.list.find(v => v.x === x && v.y === y);
}
/**
* 解析本地图的怪物信息
*/
+1 -1
View File
@@ -11,7 +11,7 @@ export {};
function openItemShop(itemShopId) {
if (!core.isReplaying()) {
mota.ui.main.open('shop', void 0, {
mota.ui.main.open('shop', {
shopId: itemShopId
});
}
+33 -33
View File
@@ -5,46 +5,46 @@ import { ToShowEnemy, detailInfo } from './book';
import { DamageEnemy } from '../game/enemy/damage';
import { isMobile } from '../use';
export const showFixed = ref(false);
// export const showFixed = ref(false);
let lastId: EnemyIds;
// let lastId: EnemyIds;
const show = debounce((ev: MouseEvent) => {
if (!window.flags) return;
if (!flags.mouseLoc) return;
flags.clientLoc = [ev.clientX, ev.clientY];
const [mx, my] = getLocFromMouseLoc(...flags.mouseLoc);
// const show = debounce((ev: MouseEvent) => {
// if (!window.flags) return;
// if (!flags.mouseLoc) return;
// flags.clientLoc = [ev.clientX, ev.clientY];
// const [mx, my] = getLocFromMouseLoc(...flags.mouseLoc);
const e = core.status.thisMap.enemy.list.find(v => {
return v.x === mx && v.y === my;
});
// const e = core.status.thisMap.enemy.list.find(v => {
// return v.x === mx && v.y === my;
// });
if (!e) return;
// if (!e) return;
lastId = e.id;
const detail = getDetailedEnemy(e);
detailInfo.enemy = detail;
showFixed.value = true;
}, 200);
// lastId = e.id;
// const detail = getDetailedEnemy(e);
// detailInfo.enemy = detail;
// showFixed.value = true;
// }, 200);
export default function init() {
const data = core.canvas.data.canvas;
data.addEventListener('mousemove', ev => {
if (!core.isPlaying() || core.status.lockControl) return;
const [mx, my] = getLocFromMouseLoc(...flags.mouseLoc);
const e = core.getBlockId(mx, my);
if (e !== lastId) showFixed.value = false;
if (!e) return;
show(ev);
});
data.addEventListener('mousedown', ev => {
showFixed.value = false;
});
// export default function init() {
// const data = core.canvas.data.canvas;
// data.addEventListener('mousemove', ev => {
// if (!core.isPlaying() || core.status.lockControl) return;
// const [mx, my] = getLocFromMouseLoc(...flags.mouseLoc);
// const e = core.getBlockId(mx, my);
// if (e !== lastId) showFixed.value = false;
// if (!e) return;
// show(ev);
// });
// data.addEventListener('mousedown', ev => {
// showFixed.value = false;
// });
return {
showFixed
};
}
// return {
// showFixed
// };
// }
export function getLocFromMouseLoc(x: number, y: number): LocArr {
const mx = Math.round(x + core.bigmap.offsetX / 32);