diff --git a/packages/client/src/components/framework/MonitorView.vue b/packages/client/src/components/framework/MonitorView.vue index cef2848..6c78be5 100644 --- a/packages/client/src/components/framework/MonitorView.vue +++ b/packages/client/src/components/framework/MonitorView.vue @@ -84,8 +84,46 @@ function sendClick(x: number, y: number) { }) } -function handleClick(ev: MouseEvent) { - sendClick(ev.offsetX, ev.offsetY) +function sendSwipe( + x1: number, + y1: number, + x2: number, + y2: number, + dur: number +) { + send({ + action: 'swipe', + x1, + y1, + x2, + y2, + dur + }) +} + +const pointerDownTrack = ref<[number, number] | null>(null) + +function handlePointerDown(ev: PointerEvent) { + console.log(ev) + if (ev.pointerId !== 1) { + return + } + pointerDownTrack.value = [ev.offsetX, ev.offsetY] +} + +function handlePointerUp(ev: PointerEvent) { + console.log(ev) + if (ev.pointerId !== 1) { + return + } + if (pointerDownTrack.value) { + const [ox, oy] = pointerDownTrack.value + if (Math.abs(ox - ev.offsetX) + Math.abs(oy - ev.offsetY) > 5) { + sendSwipe(ox, oy, ev.offsetX, ev.offsetY, 100) + } else { + sendClick(ev.offsetX, ev.offsetY) + } + } } @@ -96,7 +134,8 @@ function handleClick(ev: MouseEvent) { ref="canvasEl" :width="width" :height="height" - @click="handleClick" + @pointerdown="handlePointerDown" + @pointerup="handlePointerUp" > diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 19fb7ec..583bb37 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -106,15 +106,36 @@ async function main() { console.log(`/api/controller ${id} connected`) ws.on('message', async data => { const action = JSON.parse(data.toString('utf-8')) as { - action: 'click' + action: 'click' | 'swipe' x: number y: number + x1: number + y1: number + x2: number + y2: number + dur: number } // console.log(action) if (controller) { switch (action.action) { case 'click': { controller.click(action.x, action.y) + break + } + case 'swipe': { + controller.swipe([ + { + x: action.x1, + y: action.y1, + delay: action.dur + }, + { + x: action.x2, + y: action.y2, + delay: 0 + } + ]) + break } } } @@ -273,7 +294,7 @@ async function prepareController() { loader, config.maaframework.adb, config.maaframework.address, - MaaAdbControllerTypeEnum.Input_Preset_Adb | + MaaAdbControllerTypeEnum.Input_Preset_Minitouch | MaaAdbControllerTypeEnum.Screencap_MinicapStream, await fs.readFile( path.join(config.maaframework.root, 'controller_config.json'), diff --git a/packages/server/web b/packages/server/web new file mode 120000 index 0000000..f3f7e28 --- /dev/null +++ b/packages/server/web @@ -0,0 +1 @@ +../client/dist \ No newline at end of file