Skip to content

Commit 25e1414

Browse files
committed
(#53) Refactored Movement class into separate functions
1 parent 1ed8ddf commit 25e1414

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/movement.function.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { NativeAdapter } from "./adapter/native.adapter.class";
2+
import { Point } from "./point.class";
3+
import { LineHelper } from "./util/linehelper.class";
4+
5+
export const createMovementApi = (native: NativeAdapter, lineHelper: LineHelper) => {
6+
return ({
7+
down: async (px: number): Promise<Point[]> => {
8+
const pos = await native.currentMousePosition();
9+
return lineHelper.straightLine(pos, new Point(pos.x, pos.y + px));
10+
},
11+
left: async (px: number): Promise<Point[]> => {
12+
const pos = await native.currentMousePosition();
13+
return lineHelper.straightLine(pos, new Point(pos.x - px, pos.y));
14+
},
15+
right: async (px: number): Promise<Point[]> => {
16+
const pos = await native.currentMousePosition();
17+
return lineHelper.straightLine(pos, new Point(pos.x + px, pos.y));
18+
},
19+
straightTo: async (target: Point | Promise<Point>): Promise<Point[]> => {
20+
const targetPoint = await target;
21+
const origin = await native.currentMousePosition();
22+
return lineHelper.straightLine(origin, targetPoint);
23+
},
24+
up: async (px: number): Promise<Point[]> => {
25+
const pos = await native.currentMousePosition();
26+
return lineHelper.straightLine(pos, new Point(pos.x, pos.y - px));
27+
},
28+
});
29+
};

0 commit comments

Comments
 (0)