feat(dice): enhance game UI and add sound effects
All checks were successful
CI / Get Changed Files (pull_request) Successful in 8s
CI / Checkstyle Main (pull_request) Has been skipped
CI / Docker backend validation (pull_request) Has been skipped
CI / oxlint (pull_request) Successful in 18s
CI / eslint (pull_request) Successful in 25s
CI / prettier (pull_request) Successful in 25s
CI / Docker frontend validation (pull_request) Successful in 45s
CI / test-build (pull_request) Successful in 45s

This commit is contained in:
Jan-Marlon Leibl 2025-05-21 13:52:16 +02:00
commit 1849500d74
Signed by: jleibl
GPG key ID: 300B2F906DC6F1D5
4 changed files with 374 additions and 108 deletions

View file

@ -0,0 +1,39 @@
import { Directive, ElementRef, HostListener, inject, Input, OnInit } from '@angular/core';
import { AudioService } from '../services/audio.service';
import { AbstractControl } from '@angular/forms';
@Directive({
selector: '[appDragSound]',
standalone: true,
})
export class DragSoundDirective implements OnInit {
private audioService = inject(AudioService);
private elementRef = inject(ElementRef);
private lastValue: number | null = null;
@Input('appDragSound') formControl: AbstractControl | null = null;
ngOnInit() {
if (this.formControl) {
this.lastValue = this.formControl.value;
this.formControl.valueChanges.subscribe((newValue) => {
if (this.lastValue !== newValue) {
this.playSound();
this.lastValue = newValue;
}
});
}
}
private playSound() {
this.audioService.playDragStepSound();
}
@HostListener('input')
onInput() {
if (!this.formControl) {
this.playSound();
}
}
}

View file

@ -27,4 +27,15 @@ export class AudioService {
audio.currentTime = 0;
audio.play().catch((error) => console.error('Error playing win sound:', error));
}
getDragSound(): HTMLAudioElement {
return this.getAudio('drag.mp3');
}
playDragStepSound(): void {
const audio = this.getAudio('drag.mp3');
audio.currentTime = 0;
audio.volume = 0.5;
audio.play().catch((error) => console.error('Error playing drag step sound:', error));
}
}