fix: Fix claude mirrored text
Some checks failed
CI / Get Changed Files (pull_request) Successful in 18s
CI / Checkstyle Main (pull_request) Has been skipped
CI / Docker backend validation (pull_request) Has been skipped
CI / eslint (pull_request) Successful in 49s
CI / oxlint (pull_request) Successful in 47s
CI / prettier (pull_request) Failing after 49s
CI / Docker frontend validation (pull_request) Successful in 1m10s
CI / test-build (pull_request) Successful in 38s

This commit is contained in:
Jan K9f 2025-05-21 10:52:10 +02:00
commit 0d9b0ad987
3 changed files with 82 additions and 64 deletions

View file

@ -53,21 +53,23 @@
background: linear-gradient(45deg, #ffd700, #ffb700); background: linear-gradient(45deg, #ffd700, #ffb700);
color: #333; color: #333;
z-index: 2; z-index: 2;
transform: rotateY(0);
} }
.back { .back {
transform: rotateY(180deg);
background: linear-gradient(45deg, #5a5a5a, #333333); background: linear-gradient(45deg, #5a5a5a, #333333);
color: white; color: white;
z-index: 1; z-index: 1;
/* Fix text display on the back of the coin */ transform: rotateY(180deg);
backface-visibility: hidden;
} }
/* Fix reversed text on tails side by applying a counter-rotation to just the text */ /* We apply transform directly to the SVG element in HTML */
.back > span {
display: inline-block; /* Text for both sides */
transform: rotateY(180deg); /* Counter-rotate the text so it appears correctly */ .coin-text {
/* Ensure text is readable */
user-select: none;
pointer-events: none;
} }
/* Animation classes */ /* Animation classes */

View file

@ -5,55 +5,62 @@
@if (gameResult()) { @if (gameResult()) {
<div class="mb-6 text-center result-text"> <div class="mb-6 text-center result-text">
<h2 class="text-2xl font-bold mb-2" [class]="getResultClass()"> <h2 class="text-2xl font-bold mb-2" [class]="getResultClass()">
{{ (gameResult()?.isWin || gameResult()?.win) ? 'You Won!' : 'You Lost' }} {{ gameResult()?.isWin ? 'You Won!' : 'You Lost' }}
</h2> </h2>
<p class="text-lg"> <p class="text-lg">
Coin landed on: <span class="font-bold">{{ gameResult()?.coinSide === 'HEAD' ? 'HEAD' : 'TAILS' }}</span> Coin landed on:
<span class="font-bold">{{
gameResult()?.coinSide === 'HEAD' ? 'HEAD' : 'TAILS'
}}</span>
</p> </p>
@if (gameResult()?.isWin || gameResult()?.win) { @if (gameResult()?.isWin) {
<p class="text-xl mt-2"> <p class="text-xl mt-2">
<span class="text-emerald-500">+{{ gameResult()?.payout | currency: 'EUR' }}</span> <span class="text-emerald-500">+{{ gameResult()?.payout | currency: 'EUR' }}</span>
</p> </p>
} }
</div> </div>
} }
<!-- Error message display --> <!-- Error message display -->
@if (errorMessage()) { @if (errorMessage()) {
<div class="mb-6 text-center"> <div class="mb-6 text-center">
<p class="text-accent-red font-bold">{{ errorMessage() }}</p> <p class="text-accent-red font-bold">{{ errorMessage() }}</p>
</div> </div>
} }
<!-- Coin animation area --> <!-- Coin animation area -->
<div class="coin-container mx-auto mb-8"> <div class="coin-container mx-auto mb-8">
<div #coinElement id="coin" class="coin"> <div #coinElement id="coin" class="coin">
<!-- Head side -->
<div <div
class="front coin-side bg-yellow-500 flex items-center justify-center text-2xl font-bold" class="front coin-side bg-yellow-500 flex items-center justify-center text-2xl font-bold"
> >
HEAD <div class="coin-text">HEAD</div>
</div> </div>
<!-- Tails side with non-mirrored text -->
<div <div
class="back coin-side bg-gray-700 flex items-center justify-center text-2xl font-bold text-white" class="back coin-side bg-gray-700 flex items-center justify-center text-2xl font-bold text-white"
> >
<span>TAILS</span> <!-- Using direct inline transform to counter the mirroring effect -->
<span style="display: inline-block; transform: scaleX(1)">TAILS</span>
</div> </div>
</div> </div>
</div> </div>
<!-- Game controls --> <!-- Game controls -->
<div class="flex gap-4 mt-3 mx-auto"> <div class="flex gap-4 mt-3 mx-auto">
<button <button
(click)="betTails()" (click)="betTails()"
[disabled]="gameInProgress()" [disabled]="gameInProgress()"
class="button-primary py-3 px-6 relative text-lg" class="button-primary py-3 px-6 relative text-lg"
[class.opacity-50]="gameInProgress()" [class.opacity-50]="gameInProgress()"
> >
Bet TAILS Bet TAILS
</button> </button>
<button <button
(click)="betHeads()" (click)="betHeads()"
[disabled]="gameInProgress()" [disabled]="gameInProgress()"
class="button-primary py-3 px-6 relative text-lg" class="button-primary py-3 px-6 relative text-lg"
[class.opacity-50]="gameInProgress()" [class.opacity-50]="gameInProgress()"
> >
@ -61,7 +68,7 @@
</button> </button>
</div> </div>
</div> </div>
<!-- Game information panel --> <!-- Game information panel -->
<div class="col-span-1"> <div class="col-span-1">
<div class="card p-4"> <div class="card p-4">
@ -74,7 +81,7 @@
<app-animated-number [value]="currentBet()" [duration]="0.5"></app-animated-number> <app-animated-number [value]="currentBet()" [duration]="0.5"></app-animated-number>
</span> </span>
</div> </div>
<!-- Available balance --> <!-- Available balance -->
<div class="flex justify-between items-center"> <div class="flex justify-between items-center">
<span class="text-text-secondary">Your Balance:</span> <span class="text-text-secondary">Your Balance:</span>
@ -109,7 +116,7 @@
[placeholder]="balance() | currency: 'EUR'" [placeholder]="balance() | currency: 'EUR'"
/> />
</div> </div>
<!-- Rules/info section --> <!-- Rules/info section -->
<div class="mt-6 pt-4 border-t border-gray-700"> <div class="mt-6 pt-4 border-t border-gray-700">
<h4 class="text-lg font-semibold mb-2">How to Play</h4> <h4 class="text-lg font-semibold mb-2">How to Play</h4>

View file

@ -1,7 +1,15 @@
import { CurrencyPipe } from '@angular/common'; import { CurrencyPipe } from '@angular/common';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { ChangeDetectionStrategy, Component, ElementRef, inject, OnInit, signal, ViewChild } from '@angular/core'; import {
ChangeDetectionStrategy,
Component,
ElementRef,
inject,
OnInit,
signal,
ViewChild,
} from '@angular/core';
import { AnimatedNumberComponent } from '@blackjack/components/animated-number/animated-number.component'; import { AnimatedNumberComponent } from '@blackjack/components/animated-number/animated-number.component';
import { catchError, finalize } from 'rxjs/operators'; import { catchError, finalize } from 'rxjs/operators';
import { of } from 'rxjs'; import { of } from 'rxjs';
@ -25,13 +33,13 @@ export default class CoinflipComponent implements OnInit {
gameResult = signal<CoinflipGame | null>(null); gameResult = signal<CoinflipGame | null>(null);
betInputValue = signal(10); betInputValue = signal(10);
errorMessage = signal(''); errorMessage = signal('');
@ViewChild('coinElement') coinElement?: ElementRef; @ViewChild('coinElement') coinElement?: ElementRef;
audioService = inject(AudioService); audioService = inject(AudioService);
authService = inject(AuthService); authService = inject(AuthService);
private http = inject(HttpClient); private http = inject(HttpClient);
private coinflipSound?: HTMLAudioElement; private coinflipSound?: HTMLAudioElement;
ngOnInit(): void { ngOnInit(): void {
@ -41,21 +49,21 @@ export default class CoinflipComponent implements OnInit {
this.balance.set(user.balance); this.balance.set(user.balance);
} }
}); });
// Initialize coinflip sound // Initialize coinflip sound
this.coinflipSound = new Audio('/sounds/coinflip.mp3'); this.coinflipSound = new Audio('/sounds/coinflip.mp3');
} }
setBetAmount(percentage: number) { setBetAmount(percentage: number) {
const newBet = Math.floor(this.balance() * percentage); const newBet = Math.floor(this.balance() * percentage);
this.betInputValue.set(newBet > 0 ? newBet : 1); this.betInputValue.set(newBet > 0 ? newBet : 1);
this.currentBet.set(this.betInputValue()); this.currentBet.set(this.betInputValue());
} }
updateBet(event: Event) { updateBet(event: Event) {
const inputElement = event.target as HTMLInputElement; const inputElement = event.target as HTMLInputElement;
const value = Number(inputElement.value); const value = Number(inputElement.value);
if (value <= 0) { if (value <= 0) {
this.betInputValue.set(1); this.betInputValue.set(1);
this.currentBet.set(1); this.currentBet.set(1);
@ -71,43 +79,44 @@ export default class CoinflipComponent implements OnInit {
betHeads() { betHeads() {
this.placeBet('HEAD'); this.placeBet('HEAD');
} }
betTails() { betTails() {
this.placeBet('TAILS'); this.placeBet('TAILS');
} }
private placeBet(side: 'HEAD' | 'TAILS') { private placeBet(side: 'HEAD' | 'TAILS') {
if (this.gameInProgress() || this.isActionInProgress()) return; if (this.gameInProgress() || this.isActionInProgress()) return;
// Reset previous result // Reset previous result
this.gameResult.set(null); this.gameResult.set(null);
this.errorMessage.set(''); this.errorMessage.set('');
// Set game state // Set game state
this.gameInProgress.set(true); this.gameInProgress.set(true);
this.isActionInProgress.set(true); this.isActionInProgress.set(true);
// Play bet sound // Play bet sound
this.audioService.playBetSound(); this.audioService.playBetSound();
// Create bet request // Create bet request
const request: CoinflipRequest = { const request: CoinflipRequest = {
betAmount: this.currentBet(), betAmount: this.currentBet(),
coinSide: side coinSide: side,
}; };
// Call API // Call API
this.http.post<CoinflipGame>('/backend/coinflip', request) this.http
.post<CoinflipGame>('/backend/coinflip', request)
.pipe( .pipe(
catchError(error => { catchError((error) => {
console.error('Error playing coinflip:', error); console.error('Error playing coinflip:', error);
if (error.status === 400 && error.error.message.includes('insufficient')) { if (error.status === 400 && error.error.message.includes('insufficient')) {
this.errorMessage.set('Insufficient funds'); this.errorMessage.set('Insufficient funds');
} else { } else {
this.errorMessage.set('An error occurred. Please try again.'); this.errorMessage.set('An error occurred. Please try again.');
} }
this.gameInProgress.set(false); this.gameInProgress.set(false);
return of(null); return of(null);
}), }),
@ -115,35 +124,35 @@ export default class CoinflipComponent implements OnInit {
this.isActionInProgress.set(false); this.isActionInProgress.set(false);
}) })
) )
.subscribe(result => { .subscribe((result) => {
if (!result) return; if (!result) return;
console.log('API response:', result); console.log('API response:', result);
// Fix potential property naming inconsistency from the backend // Fix potential property naming inconsistency from the backend
const fixedResult: CoinflipGame = { const fixedResult: CoinflipGame = {
isWin: result.isWin ?? result.win, isWin: result.isWin ?? result.win,
payout: result.payout, payout: result.payout,
coinSide: result.coinSide coinSide: result.coinSide,
}; };
console.log('Fixed result:', fixedResult); console.log('Fixed result:', fixedResult);
// Play coin flip animation and sound // Play coin flip animation and sound
this.playCoinFlipAnimation(fixedResult.coinSide); this.playCoinFlipAnimation(fixedResult.coinSide);
// Set result after animation completes // Set result after animation completes
setTimeout(() => { setTimeout(() => {
this.gameResult.set(fixedResult); this.gameResult.set(fixedResult);
// Update balance with new value from auth service // Update balance with new value from auth service
this.authService.loadCurrentUser(); this.authService.loadCurrentUser();
// Play win sound if player won // Play win sound if player won
if (fixedResult.isWin) { if (fixedResult.isWin) {
this.audioService.playWinSound(); this.audioService.playWinSound();
} }
// Reset game state after showing result // Reset game state after showing result
setTimeout(() => { setTimeout(() => {
this.gameInProgress.set(false); this.gameInProgress.set(false);
@ -151,37 +160,37 @@ export default class CoinflipComponent implements OnInit {
}, 1100); // Just after animation ends }, 1100); // Just after animation ends
}); });
} }
private playCoinFlipAnimation(result: 'HEAD' | 'TAILS') { private playCoinFlipAnimation(result: 'HEAD' | 'TAILS') {
if (!this.coinElement) return; if (!this.coinElement) return;
const coinEl = this.coinElement.nativeElement; const coinEl = this.coinElement.nativeElement;
// Reset any existing animations // Reset any existing animations
coinEl.classList.remove('animate-to-heads', 'animate-to-tails'); coinEl.classList.remove('animate-to-heads', 'animate-to-tails');
// Reset any inline styles from previous animations // Reset any inline styles from previous animations
coinEl.style.transform = ''; coinEl.style.transform = '';
// Force a reflow to restart animation // Force a reflow to restart animation
void coinEl.offsetWidth; void coinEl.offsetWidth;
// Play flip sound // Play flip sound
if (this.coinflipSound) { if (this.coinflipSound) {
this.coinflipSound.currentTime = 0; this.coinflipSound.currentTime = 0;
this.coinflipSound.play().catch(err => console.error('Error playing sound:', err)); this.coinflipSound.play().catch((err) => console.error('Error playing sound:', err));
} }
// Add appropriate animation class based on result // Add appropriate animation class based on result
if (result === 'HEAD') { if (result === 'HEAD') {
coinEl.classList.add('animate-to-heads'); coinEl.classList.add('animate-to-heads');
} else { } else {
coinEl.classList.add('animate-to-tails'); coinEl.classList.add('animate-to-tails');
} }
console.log(`Animation applied for result: ${result}`); console.log(`Animation applied for result: ${result}`);
} }
getResultClass() { getResultClass() {
if (!this.gameResult()) return ''; if (!this.gameResult()) return '';
const result = this.gameResult(); const result = this.gameResult();