Skip to content

Commit a37c3b0

Browse files
committed
Fix the zoom issue and handle touchStart event
1 parent 87c24a7 commit a37c3b0

File tree

5 files changed

+43
-23
lines changed

5 files changed

+43
-23
lines changed

src/app/components/keyboard/keyboard.component.html

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
<t-button className="blue btn-md"
44
[active$]="keyboardQuery.up$"
55
[arrowButton]="ArrowButton.UP"
6-
(mousedown)="mouseDown('Up')"
7-
(mouseup)="mouseUp('Up')"
6+
(mousedown)="mouseDown($event, 'Up')"
7+
(mouseup)="mouseUp($event, 'Up')"
8+
(touchstart)="mouseDown($event, 'Up')"
9+
(touchend)="mouseUp($event, 'Up')"
810
[top]="0"
911
[left]="374"
1012
[isAbsolute]="true">
@@ -13,58 +15,72 @@
1315
<t-button className="blue btn-md"
1416
[active$]="keyboardQuery.down$"
1517
[arrowButton]="ArrowButton.DOWN"
16-
(mousedown)="mouseDown('Down')"
17-
(mouseup)="mouseUp('Down')"
18+
(mousedown)="mouseDown($event, 'Down')"
19+
(mouseup)="mouseUp($event, 'Down')"
20+
(touchstart)="mouseDown($event, 'Down')"
21+
(touchend)="mouseUp($event, 'Down')"
1822
[top]="180"
1923
[left]="374">
2024
Down
2125
</t-button>
2226
<t-button className="blue btn-md"
2327
[active$]="keyboardQuery.left$"
2428
[arrowButton]="ArrowButton.LEFT"
25-
(mousedown)="mouseDown('Left')"
26-
(mouseup)="mouseUp('Left')"
29+
(mousedown)="mouseDown($event, 'Left')"
30+
(mouseup)="mouseUp($event, 'Left')"
31+
(touchstart)="mouseDown($event, 'Left')"
32+
(touchend)="mouseUp($event, 'Left')"
2733
[top]="90"
2834
[left]="284">
2935
Left
3036
</t-button>
3137
<t-button className="blue btn-md"
3238
[active$]="keyboardQuery.right$"
3339
[arrowButton]="ArrowButton.RIGHT"
34-
(mousedown)="mouseDown('Right')"
35-
(mouseup)="mouseUp('Right')"
40+
(mousedown)="mouseDown($event, 'Right')"
41+
(mouseup)="mouseUp($event, 'Right')"
42+
(touchstart)="mouseDown($event, 'Right')"
43+
(touchend)="mouseUp($event, 'Right')"
3644
[top]="90"
3745
[left]="464">
3846
Right
3947
</t-button>
4048
<t-button className="blue btn-lg"
4149
[active$]="keyboardQuery.drop$"
42-
(mousedown)="mouseDown('Space')"
43-
(mouseup)="mouseUp('Space')"
50+
(mousedown)="mouseDown($event, 'Space')"
51+
(mouseup)="mouseUp($event, 'Space')"
52+
(touchstart)="mouseDown($event, 'Space')"
53+
(touchend)="mouseUp($event, 'Space')"
4454
[top]="100"
4555
[left]="52">
4656
Drop (SPACE)
4757
</t-button>
4858
<t-button className="red btn-sm"
4959
[active$]="keyboardQuery.reset$"
50-
(mousedown)="mouseDown('Reset')"
51-
(mouseup)="mouseUp('Reset')"
60+
(mousedown)="mouseDown($event, 'Reset')"
61+
(mouseup)="mouseUp($event, 'Reset')"
62+
(touchstart)="mouseDown($event, 'Reset')"
63+
(touchend)="mouseUp($event, 'Reset')"
5264
[top]="0"
5365
[left]="196">
5466
Reset (R)
5567
</t-button>
5668
<t-button className="green btn-sm"
5769
[active$]="keyboardQuery.sound$"
58-
(mousedown)="mouseDown('Sound')"
59-
(mouseup)="mouseUp('Sound')"
70+
(mousedown)="mouseDown($event, 'Sound')"
71+
(mouseup)="mouseUp($event, 'Sound')"
72+
(touchstart)="mouseDown($event, 'Sound')"
73+
(touchend)="mouseUp($event, 'Sound')"
6074
[top]="0"
6175
[left]="106">
6276
Sound (S)
6377
</t-button>
6478
<t-button className="green btn-sm"
6579
[active$]="keyboardQuery.pause$"
66-
(mousedown)="mouseDown('Pause')"
67-
(mouseup)="mouseUp('Pause')"
80+
(mousedown)="mouseDown($event, 'Pause')"
81+
(mouseup)="mouseUp($event, 'Pause')"
82+
(touchstart)="mouseDown($event, 'Pause')"
83+
(touchend)="mouseUp($event, 'Pause')"
6884
[top]="0"
6985
[left]="16">
7086
Pause (P)

src/app/components/keyboard/keyboard.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ export class KeyboardComponent implements OnInit {
1313
@Output() onMouseDown = new EventEmitter<string>();
1414
@Output() onMouseUp = new EventEmitter<string>();
1515

16-
constructor(public keyboardQuery: KeyboardQuery) {}
16+
constructor(public keyboardQuery: KeyboardQuery) { }
1717

18-
ngOnInit(): void {}
18+
ngOnInit(): void { }
1919

20-
mouseDown(key: string) {
20+
mouseDown(e: Event, key: string) {
21+
e.preventDefault();
2122
this.onMouseDown.emit(key);
2223
}
2324

24-
mouseUp(key: string) {
25+
mouseUp(e: Event, key: string) {
26+
e.preventDefault();
2527
this.onMouseUp.emit(key);
2628
}
2729
}

src/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<base href="/">
1717
<script>(function () { var w = parseInt(window.screen.width), s = w / 640, u = navigator.userAgent.toLowerCase(), m = '<meta name="viewport" content="width=640,'; if (/android (\d+\.\d+)/.test(u)) { if (parseFloat(RegExp.$1) > 2.3) m += 'minimum-scale=' + s + ',maximum-scale=' + s + ','; } else { m += 'user-scalable=no,'; } m += 'target-densitydpi=device-dpi">'; document.write(m); }());</script>
1818
<!-- Primary Meta Tags -->
19-
<title>Angular Tetris built with Angular and Akita - by trungk18</title>
2019
<meta name="title" content="Angular Tetris built with Angular and Akita - by trungk18">
2120
<meta name="description" content="A childhood memory Tetris game built with Angular 10 and Akita.">
2221

src/index.prod.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<base href="/">
1717
<script>(function () { var w = parseInt(window.screen.width), s = w / 640, u = navigator.userAgent.toLowerCase(), m = '<meta name="viewport" content="width=640,'; if (/android (\d+\.\d+)/.test(u)) { if (parseFloat(RegExp.$1) > 2.3) m += 'minimum-scale=' + s + ',maximum-scale=' + s + ','; } else { m += 'user-scalable=no,'; } m += 'target-densitydpi=device-dpi">'; document.write(m); }());</script>
1818
<!-- Primary Meta Tags -->
19-
<title>Angular Tetris built with Angular and Akita - by trungk18</title>
2019
<meta name="title" content="Angular Tetris built with Angular and Akita - by trungk18">
2120
<meta name="description" content="A childhood memory Tetris game built with Angular 10 and Akita.">
2221

src/styles.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
@import "../src/app/styles/tetris.scss";
1+
@import '../src/app/styles/tetris.scss';
2+
3+
t-keyboard, t-button {
4+
touch-action: pan-x pan-y pinch-zoom;
5+
}

0 commit comments

Comments
 (0)