style: format code for better readability and consistency
All checks were successful
CI / Get Changed Files (pull_request) Successful in 10s
CI / Docker backend validation (pull_request) Successful in 17s
CI / Docker frontend validation (pull_request) Successful in 48s
CI / Checkstyle Main (pull_request) Has been skipped
CI / oxlint (pull_request) Successful in 27s
CI / eslint (pull_request) Successful in 31s
CI / prettier (pull_request) Successful in 36s
CI / test-build (pull_request) Successful in 1m1s

This commit is contained in:
Jan-Marlon Leibl 2025-05-07 14:57:24 +02:00
commit c7f26c4df3
Signed by: jleibl
GPG key ID: 300B2F906DC6F1D5
9 changed files with 175 additions and 135 deletions

View file

@ -308,7 +308,9 @@ body {
.animation-fade {
opacity: 0;
transform: translateY(10px);
transition: opacity 0.5s ease-out, transform 0.5s ease-out;
transition:
opacity 0.5s ease-out,
transform 0.5s ease-out;
transition-delay: 0.5s;
}

View file

@ -2,53 +2,60 @@
<div class="container mx-auto px-4 py-6 space-y-8">
<h1 class="text-3xl font-bold text-white mb-6">Lootbox Öffnen</h1>
<div *ngIf="isLoading" class="flex justify-center">
<div class="loader"></div>
</div>
<div *ngIf="error" class="bg-red-500 text-white p-4 rounded mb-6">
{{ error }}
</div>
<div *ngIf="!isLoading && lootbox" class="grid grid-cols-1 lg:grid-cols-4 gap-6">
<div class="lg:col-span-3">
<div class="card bg-deep-blue-light rounded-lg overflow-hidden shadow-lg">
<div class="relative" *ngIf="!isOpen">
<img [src]="getBoxImage(lootbox.id)" [alt]="lootbox.name" class="w-full h-48 object-cover">
<img
[src]="getBoxImage(lootbox.id)"
[alt]="lootbox.name"
class="w-full h-48 object-cover"
/>
<div class="absolute top-2 right-2 bg-deep-blue px-2 py-1 rounded-full text-white">
{{ lootbox.price | currency:'EUR' }}
{{ lootbox.price | currency: 'EUR' }}
</div>
</div>
<div class="p-6">
<h2 class="text-xl font-bold text-white mb-4">{{ lootbox.name }}</h2>
<div *ngIf="!isOpening && !isOpen" class="mb-6">
<button
(click)="openLootbox()"
class="button-primary w-full py-3 text-lg font-semibold rounded">
<button
(click)="openLootbox()"
class="button-primary w-full py-3 text-lg font-semibold rounded"
>
Öffnen
</button>
</div>
<div *ngIf="isOpening" class="flex flex-col items-center py-8">
<div class="loader mb-4"></div>
<div class="text-white text-lg">Öffne Lootbox...</div>
</div>
<div *ngIf="isOpen && !isOpening" class="space-y-6">
<div class="text-center mb-8 animation-fade"
[class.visible]="animationCompleted">
<div class="text-center mb-8 animation-fade" [class.visible]="animationCompleted">
<h2 class="text-xl font-bold text-white mb-2">Dein Gewinn:</h2>
<div class="text-3xl font-bold" [ngClass]="getRewardClass()">
{{ wonReward?.value | currency: 'EUR' }}
</div>
</div>
<div class="relative w-full overflow-hidden bg-deep-blue rounded-lg p-4 h-32 mb-6">
<div class="absolute left-1/2 top-0 bottom-0 w-0.5 bg-white z-10 transform -translate-x-0" style="margin-left: 0px;"></div>
<div
class="absolute left-1/2 top-0 bottom-0 w-0.5 bg-white z-10 transform -translate-x-0"
style="margin-left: 0px"
></div>
<div class="relative h-full flex items-center overflow-hidden">
<div class="flex case-items">
<div
@ -57,9 +64,11 @@
[class.case-item-won]="isWonReward(reward) && animationCompleted"
[id]="isWonReward(reward) ? 'winning-item' : ''"
>
<div class="case-item-inner"
[class.winning-prize]="isWonReward(reward)"
[class.highlight]="isWonReward(reward) && animationCompleted">
<div
class="case-item-inner"
[class.winning-prize]="isWonReward(reward)"
[class.highlight]="isWonReward(reward) && animationCompleted"
>
<div class="amount" [ngClass]="getRewardRarityClass(reward)">
{{ reward.value | currency: 'EUR' }}
</div>
@ -71,13 +80,12 @@
</div>
</div>
</div>
<div class="flex justify-center gap-4 mt-8 animation-fade"
[class.visible]="animationCompleted">
<button
(click)="openAgain()"
class="button-primary px-6 py-2 font-semibold rounded"
>
<div
class="flex justify-center gap-4 mt-8 animation-fade"
[class.visible]="animationCompleted"
>
<button (click)="openAgain()" class="button-primary px-6 py-2 font-semibold rounded">
Nochmal Öffnen
</button>
<button
@ -89,7 +97,7 @@
</div>
</div>
</div>
<div class="px-6 pb-6">
<div class="text-sm text-text-secondary">
<p>Fairness garantiert - Alle Ergebnisse werden transparent berechnet.</p>
@ -97,18 +105,23 @@
</div>
</div>
</div>
<div class="lg:col-span-1">
<div class="card bg-deep-blue-light rounded-lg overflow-hidden shadow-lg p-6">
<h3 class="text-lg font-semibold text-white mb-4">Mögliche Gewinne:</h3>
<ul class="space-y-3">
<li *ngFor="let reward of lootbox.rewards" class="flex justify-between">
<span [ngClass]="getRewardRarityClass(reward)">{{ reward.value | currency:'EUR' }}</span>
<span [ngClass]="getRewardRarityClass(reward)">{{
reward.value | currency: 'EUR'
}}</span>
<span class="text-white">{{ reward.probability * 100 | number: '1.0-0' }}%</span>
</li>
</ul>
<div *ngIf="isOpen && wonReward && animationCompleted" class="mt-6 pt-6 border-t border-deep-blue-contrast">
<div
*ngIf="isOpen && wonReward && animationCompleted"
class="mt-6 pt-6 border-t border-deep-blue-contrast"
>
<h3 class="text-lg font-semibold text-white mb-4">Gewinn-Details:</h3>
<div class="space-y-3">
<div class="flex justify-between items-center">
@ -121,8 +134,12 @@
</div>
<div class="flex justify-between items-center">
<span class="text-text-secondary">Profit:</span>
<span [ngClass]="wonReward.value > (lootbox.price || 0) ? 'text-emerald' : 'text-accent-red'">
{{ (wonReward.value - (lootbox.price || 0)) | currency: 'EUR' }}
<span
[ngClass]="
wonReward.value > (lootbox.price || 0) ? 'text-emerald' : 'text-accent-red'
"
>
{{ wonReward.value - (lootbox.price || 0) | currency: 'EUR' }}
</span>
</div>
</div>
@ -130,4 +147,4 @@
</div>
</div>
</div>
</div>
</div>

View file

@ -38,7 +38,7 @@ export default class LootboxOpeningComponent {
this.isLoading = false;
return;
}
const lootboxId = parseInt(idParam, 10);
this.lootboxService.getAllLootBoxes().subscribe({
next: (lootboxes) => {
@ -56,9 +56,9 @@ export default class LootboxOpeningComponent {
openLootbox(): void {
if (!this.lootbox || this.isOpening) return;
this.resetState(true);
setTimeout(() => {
this.lootboxService.purchaseLootBox(this.lootbox!.id).subscribe({
next: this.handleRewardSuccess.bind(this),
@ -77,7 +77,7 @@ export default class LootboxOpeningComponent {
private handleRewardError(): void {
if (!this.lootbox) return;
const rewards = this.lootbox.rewards;
const fallback = rewards[Math.floor(Math.random() * rewards.length)];
this.handleRewardSuccess(fallback);
@ -99,17 +99,17 @@ export default class LootboxOpeningComponent {
const winningPosition = Math.floor(prizeCount / 2);
const possibleRewards = this.lootbox.rewards;
const items: Reward[] = [];
for (let i = 0; i < prizeCount; i++) {
if (i === winningPosition) {
items.push({...wonReward});
items.push({ ...wonReward });
} else {
items.push(this.getWeightedRandomReward(possibleRewards));
}
}
this.prizeList = items;
setTimeout(() => {
this.animationCompleted = true;
this.cdr.detectChanges();
@ -120,14 +120,14 @@ export default class LootboxOpeningComponent {
const totalProbability = rewards.reduce((sum, reward) => sum + reward.probability, 0);
const randomValue = Math.random() * totalProbability;
let cumulativeProbability = 0;
for (const reward of rewards) {
cumulativeProbability += reward.probability;
if (randomValue <= cumulativeProbability) {
return { ...reward };
}
}
return { ...rewards[0] };
}
@ -146,27 +146,26 @@ export default class LootboxOpeningComponent {
isWonReward(reward: Reward): boolean {
if (!this.wonReward || !this.prizeList.length) return false;
const middleIndex = Math.floor(this.prizeList.length / 2);
return this.prizeList.indexOf(reward) === middleIndex;
}
getRewardRarityClass(reward: Reward): string {
if (!reward) return 'text-common';
const probability = reward.probability;
if (probability < 0.01) return 'text-mythic';
if (probability < 0.05) return 'text-legendary';
if (probability < 0.10) return 'text-epic';
if (probability < 0.20) return 'text-rare';
if (probability < 0.40) return 'text-uncommon';
if (probability < 0.1) return 'text-epic';
if (probability < 0.2) return 'text-rare';
if (probability < 0.4) return 'text-uncommon';
return 'text-common';
}
getRewardClass(): string {
if (!this.wonReward || !this.lootbox) return '';
return this.wonReward.value > (this.lootbox.price || 0) ? 'text-emerald' : 'text-accent-red';
}
}