chore(snek): remove keyboard activation

This commit is contained in:
waterplea
2022-03-26 17:51:59 +03:00
committed by Lucy C
parent d7bdc15e49
commit a143e2581e

View File

@@ -6,17 +6,10 @@ import { SnakePage } from '../../modals/snake/snake.page'
import { PatchDbService } from '../../services/patch-db/patch-db.service'
import { ApiService } from '../../services/api/embassy-api.service'
const SNEK = ['s', 'n', 'e', 'k']
@Directive({
selector: 'img[appSnek]',
})
export class SnekDirective {
private readonly code = new Map<string, boolean>([
...SNEK.map<[string, boolean]>(char => [char, false]),
['unlocked', false],
])
constructor(
private readonly modalCtrl: ModalController,
private readonly loadingCtrl: LoadingController,
@@ -25,30 +18,8 @@ export class SnekDirective {
private readonly patch: PatchDbService,
) {}
@HostListener('document:keyup', ['$event.key'])
onKeyUp(key: string) {
this.code.set(key, false)
}
@HostListener('document:keypress', ['$event'])
async onKeyPress({ repeat, key }: KeyboardEvent) {
if (repeat || this.code.get('unlocked')) return
this.code.set(key, true)
if (SNEK.every(char => this.code.get(char))) {
await this.openSnek()
}
}
@HostListener('click')
async onClick() {
await this.openSnek()
}
private async openSnek() {
this.code.set('unlocked', true)
const modal = await this.modalCtrl.create({
component: SnakePage,
cssClass: 'snake-modal',
@@ -56,8 +27,6 @@ export class SnekDirective {
})
modal.onDidDismiss().then(async ({ data }) => {
this.code.set('unlocked', false)
const highScore =
this.patch.getData().ui.gaming?.snake?.['high-score'] || 0