Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
feat: support swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 20, 2023
1 parent 8323da9 commit a2c556f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
45 changes: 42 additions & 3 deletions packages/client/src/components/framework/MonitorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
</script>

Expand All @@ -96,7 +134,8 @@ function handleClick(ev: MouseEvent) {
ref="canvasEl"
:width="width"
:height="height"
@click="handleClick"
@pointerdown="handlePointerDown"
@pointerup="handlePointerUp"
></canvas>
</div>
</template>
Expand Down
25 changes: 23 additions & 2 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions packages/server/web

0 comments on commit a2c556f

Please sign in to comment.