From 4b92bd2558d52512eba5c9bd8ac669a09fd63f86 Mon Sep 17 00:00:00 2001 From: jahlib <60108339+jahlib@users.noreply.github.com> Date: Wed, 5 Nov 2025 21:24:05 +0300 Subject: [PATCH] move settings buttons move settings buttons from game desk to setting modal --- client/game.js | 85 +++++++++++++++----------- client/index.html | 77 +++++++++++++++++++----- client/style.css | 148 +++++++++++++++------------------------------- 3 files changed, 163 insertions(+), 147 deletions(-) diff --git a/client/game.js b/client/game.js index eddbb52..8f0c30f 100644 --- a/client/game.js +++ b/client/game.js @@ -89,23 +89,13 @@ class CardGame { } toggleSound() { - this.soundEnabled = !this.soundEnabled; + this.soundEnabled = this.soundToggle.checked; localStorage.setItem('soundEnabled', this.soundEnabled); - this.updateSoundButton(); } - updateSoundButton() { - const btn = document.getElementById('toggle-sound-btn'); - const icon = btn.querySelector('.sound-icon'); - if (this.soundEnabled) { - btn.classList.remove('muted'); - icon.textContent = 'π'; - btn.title = 'ΠΡΠΊΠ»ΡΡΠΈΡΡ Π·Π²ΡΠΊ'; - } else { - btn.classList.add('muted'); - icon.textContent = 'π'; - btn.title = 'ΠΠΊΠ»ΡΡΠΈΡΡ Π·Π²ΡΠΊ'; - } + toggleAnimations() { + this.animationsEnabled = this.animationsToggle.checked; + localStorage.setItem('animationsEnabled', this.animationsEnabled); } showAlert(message) { @@ -223,8 +213,14 @@ class CardGame { this.lobbyRulesContent = document.getElementById('lobby-rules-content'); // ΠΠ»Π°Π²Π½Π°Ρ ΡΡΡΠ°Π½ΠΈΡΠ° this.closeRulesBtn = document.getElementById('close-rules-btn'); - // Sound button - this.toggleSoundBtn = document.getElementById('toggle-sound-btn'); + // Settings elements + this.settingsBtn = document.getElementById('settings-btn'); + this.settingsModal = document.getElementById('settings-modal'); + this.closeSettingsBtn = document.getElementById('close-settings-btn'); + this.fullscreenToggle = document.getElementById('fullscreen-toggle'); + this.soundToggle = document.getElementById('sound-toggle'); + this.animationsToggle = document.getElementById('animations-toggle'); + this.logToggle = document.getElementById('log-toggle'); // Leave game button and modal this.leaveGameBtn = document.getElementById('leave-game-btn'); @@ -237,8 +233,9 @@ class CardGame { this.playWith2BotsBtn = document.getElementById('play-with-2-bots-btn'); this.playWith3BotsBtn = document.getElementById('play-with-3-bots-btn'); - // ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·ΠΈΡΡΠ΅ΠΌ ΡΠΎΡΡΠΎΡΠ½ΠΈΠ΅ ΠΊΠ½ΠΎΠΏΠΊΠΈ Π·Π²ΡΠΊΠ° - this.updateSoundButton(); + // ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·ΠΈΡΡΠ΅ΠΌ ΡΠΎΡΡΠΎΡΠ½ΠΈΠ΅ Π°Π½ΠΈΠΌΠ°ΡΠΈΠΉ + const savedAnimations = localStorage.getItem('animationsEnabled'); + this.animationsEnabled = savedAnimations !== null ? savedAnimations === 'true' : true; } initEventListeners() { @@ -261,26 +258,19 @@ class CardGame { this.drawCardBtn.addEventListener('click', () => this.drawCard()); this.skipTurnBtn.addEventListener('click', () => this.skipTurn()); - // Sound toggle - this.toggleSoundBtn.addEventListener('click', () => this.toggleSound()); + // Settings modal + this.settingsBtn.addEventListener('click', () => this.openSettings()); + this.closeSettingsBtn.addEventListener('click', () => this.closeSettings()); + this.fullscreenToggle.addEventListener('change', () => this.toggleFullscreen()); + this.soundToggle.addEventListener('change', () => this.toggleSound()); + this.animationsToggle.addEventListener('change', () => this.toggleAnimations()); + this.logToggle.addEventListener('change', () => this.toggleLog()); // Leave game button this.leaveGameBtn.addEventListener('click', () => this.showLeaveConfirm()); this.leaveConfirmBtn.addEventListener('click', () => this.confirmLeaveGame()); this.leaveCancelBtn.addEventListener('click', () => this.cancelLeaveGame()); - // Fullscreen button - const fullscreenBtn = document.getElementById('fullscreen-btn'); - if (fullscreenBtn) { - fullscreenBtn.addEventListener('click', () => this.toggleFullscreen()); - } - - // Toggle log button - const toggleLogBtn = document.getElementById('toggle-log-btn'); - if (toggleLogBtn) { - toggleLogBtn.addEventListener('click', () => this.toggleLog()); - } - // Suit selection document.querySelectorAll('.suit-btn').forEach(btn => { btn.addEventListener('click', (e) => { @@ -1207,17 +1197,38 @@ class CardGame { } toggleFullscreen() { - if (!document.fullscreenElement) { + if (this.fullscreenToggle.checked) { // ΠΡ ΠΎΠ΄ΠΈΠΌ Π² ΠΏΠΎΠ»Π½ΠΎΡΠΊΡΠ°Π½Π½ΡΠΉ ΡΠ΅ΠΆΠΈΠΌ document.documentElement.requestFullscreen().catch(err => { console.log('Error attempting to enable fullscreen:', err); + this.fullscreenToggle.checked = false; }); } else { // ΠΡΡ ΠΎΠ΄ΠΈΠΌ ΠΈΠ· ΠΏΠΎΠ»Π½ΠΎΡΠΊΡΠ°Π½Π½ΠΎΠ³ΠΎ ΡΠ΅ΠΆΠΈΠΌΠ° - document.exitFullscreen(); + if (document.fullscreenElement) { + document.exitFullscreen(); + } } } + openSettings() { + // Π‘ΠΈΠ½Ρ ΡΠΎΠ½ΠΈΠ·ΠΈΡΡΠ΅ΠΌ ΡΠΎΡΡΠΎΡΠ½ΠΈΠ΅ ΠΏΠ΅ΡΠ΅ΠΊΠ»ΡΡΠ°ΡΠ΅Π»Π΅ΠΉ Ρ ΡΠ΅ΠΊΡΡΠΈΠΌΠΈ Π½Π°ΡΡΡΠΎΠΉΠΊΠ°ΠΌΠΈ + this.soundToggle.checked = this.soundEnabled; + this.animationsToggle.checked = this.animationsEnabled; + this.fullscreenToggle.checked = !!document.fullscreenElement; + + // Π‘ΠΈΠ½Ρ ΡΠΎΠ½ΠΈΠ·ΠΈΡΡΠ΅ΠΌ ΡΠΎΡΡΠΎΡΠ½ΠΈΠ΅ Π»ΠΎΠ³Π° (ΠΏΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ Π΅ΡΡΡ Π»ΠΈ ΠΊΠ»Π°ΡΡ hidden) + if (this.gameLog) { + this.logToggle.checked = !this.gameLog.classList.contains('hidden'); + } + + this.settingsModal.classList.add('active'); + } + + closeSettings() { + this.settingsModal.classList.remove('active'); + } + toggleLog() { if (!this.gameLog) return; @@ -1491,6 +1502,9 @@ class CardGame { // ΠΠ½ΠΈΠΌΠ°ΡΠΈΡ ΠΏΠΎΠ»Π΅ΡΠ° ΠΊΠ°ΡΡΡ ΠΎΡ ΡΠΎΡΠΊΠΈ A Π΄ΠΎ ΡΠΎΡΠΊΠΈ B animateFlyingCard(fromElement, toElement, count = 1, delay = 0) { + // ΠΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ Π²ΠΊΠ»ΡΡΠ΅Π½Ρ Π»ΠΈ Π°Π½ΠΈΠΌΠ°ΡΠΈΠΈ + if (!this.animationsEnabled) return; + setTimeout(() => { for (let i = 0; i < count; i++) { setTimeout(() => { @@ -1585,6 +1599,9 @@ class CardGame { // ΠΠ½ΠΈΠΌΠ°ΡΠΈΡ ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠΈΠ²Π°Π½ΠΈΡ ΠΊΠΎΠ»ΠΎΠ΄Ρ (ΠΊΠ°ΡΡΡ Π»Π΅ΡΡΡ ΠΈΠ· ΡΠ±ΡΠΎΡΠ° Π² ΠΊΠΎΠ»ΠΎΠ΄Ρ) animateDeckShuffle() { + // ΠΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ Π²ΠΊΠ»ΡΡΠ΅Π½Ρ Π»ΠΈ Π°Π½ΠΈΠΌΠ°ΡΠΈΠΈ + if (!this.animationsEnabled) return; + const discardPile = this.discardPile; const deck = document.getElementById('deck'); diff --git a/client/index.html b/client/index.html index e4d04b3..fad45f8 100644 --- a/client/index.html +++ b/client/index.html @@ -116,10 +116,8 @@ - - + + @@ -127,16 +125,6 @@ - - - - - -