-
Notifications
You must be signed in to change notification settings - Fork 9
Если кому-то интересно, то можно обновить/улучшить Словотрон, добавив возможность запуска в локальном режиме. #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Соло-режим: игра без Twitch. Открывайте solo.html. | ||
| // Вместо init.js: сам инициализирует игру и принимает слова из поля ввода. | ||
|
|
||
| const SOLO_USER = { username: 'solo', 'display-name': 'Я' }; | ||
| const SOLO_COLOR = '#00FF00'; | ||
|
|
||
| const soloInput = document.getElementById('solo-input'); | ||
| const soloSubmit = document.getElementById('solo-submit'); | ||
|
|
||
| let solo_ready = false; // игра инициализирована: секретное слово получено | ||
|
|
||
| function setSoloControlsEnabled(enabled) { | ||
| if (soloInput) soloInput.disabled = !enabled; | ||
| if (soloSubmit) soloSubmit.disabled = !enabled; | ||
| } | ||
|
|
||
| async function runQueue() { | ||
| // Always shift the processed item, even if process_message throws. | ||
| // Otherwise the queue stalls forever and guesses stop being handled. | ||
| while (wordQueue.length > 0) { | ||
| const { user, color, msg } = wordQueue[0]; | ||
| try { | ||
| await process_message(user, color, msg); | ||
| } catch (e) { | ||
| console.error('process_message failed:', e); | ||
| } finally { | ||
| wordQueue.shift(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Своя версия app(): те же шаги, что в init.js, но без подключения к Twitch | ||
| // и без аналитики. init.js на этой странице не подключён, поэтому его задачу | ||
| // выполняет этот файл. | ||
| async function app() { | ||
| try { | ||
| loadSettings(); // канал Twitch для соло не обязателен, возвращаемое значение игнорируем | ||
|
|
||
| reset_round(); | ||
|
|
||
| // Блокируем ввод, пока не получено секретное слово: иначе угадывание | ||
| // уйдёт в API с пустым challenge_id и слово потеряется. | ||
| setSoloControlsEnabled(false); | ||
|
|
||
| // получение секретного слова для отгадывания | ||
| secret_word_id = await generate_secret_word(); | ||
| console.log('Ключ игры: ', secret_word_id); | ||
|
|
||
| solo_ready = true; | ||
| setSoloControlsEnabled(true); | ||
| addTextToLastWords('🎯 Слово загадано! Введите свой вариант ниже'); | ||
|
Comment on lines
+45
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 6 '\bcreateGame\s*\(|\bgameId\b' --glob '*.js'Repository: AnnaCodit/Slovotron Length of output: 157 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'Tracked JavaScript files:\n'
git ls-files '*.js' | sed -n '1,120p'
printf '\nAPI-related identifiers:\n'
rg -n -C 4 'generate_secret_word|create_game|gameId|solo_ready|solo_guess|secret_word_id' -g '*.js' . || true
printf '\nFile sizes:\n'
wc -l js/*.js 2>/dev/null || trueRepository: AnnaCodit/Slovotron Length of output: 13510 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'js/api.js createGame implementations and generate_secret_word:\n'
sed -n '130,275p' js/api.js | cat -n
printf '\n'
sed -n '285,365p' js/api.js | cat -n
printf '\njs/solo.js initialization path:\n'
sed -n '35,70p' js/solo.js | cat -nRepository: AnnaCodit/Slovotron Length of output: 12209 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '150,200p' js/api.js | cat -n
printf '\nBehavioral probe for solo initialization with empty game IDs:\n'
node - <<'JS'
const initialValues = {
secret_word_id: '',
solo_ready: false
};
function generate_secret_word(payloadId = '') {
return payloadId; // matches game.gameId passthrough
}
function setSoloControlsEnabled(enabled) {}
const result = {
secret_word_id: generate_secret_word(''),
console_log: 'Ключ игры: ',
solo_ready: true,
controls_enabled: true,
message: '🎯 Слово загадано! Введите свой вариант ниже'
};
const canGuess = (message2) => result.solo_ready && !!(message2 || '').trim() !== '' && result.secret_word_id;
console.log(JSON.stringify({ result, guess_rejected_when_submitted: !canGuess('пример') }, null, 2));
JSRepository: AnnaCodit/Slovotron Length of output: 2585 Validate The current backends accept 🧰 Tools🪛 ast-grep (0.45.0)[error] 49-49: React's useState should not be directly called (usestate-direct-usage) 🤖 Prompt for AI Agents |
||
| } catch (error) { | ||
| console.error(error); | ||
| // Управление остаётся заблокированным: раунд не запущен. | ||
| addTextToLastWords('⚠️ Не удалось начать игру. Проверьте интернет и настройки бэкенда (⚙️), затем нажмите 🔄'); | ||
| } | ||
| } | ||
|
|
||
| function solo_guess() { | ||
| if (is_game_finished) return; | ||
|
|
||
| let message = (soloInput.value || '').trim(); | ||
|
|
||
| // Слово ещё загадывается (или инициализация не удалась) — не отправляем | ||
| // запрос без валидного ключа игры, текст в поле сохраняем. | ||
| if (!solo_ready || !secret_word_id) { | ||
| if (message) addTextToLastWords('Подождите, слово ещё загадывается...'); | ||
| return; | ||
| } | ||
|
|
||
| soloInput.value = ''; | ||
|
|
||
| if (!message) return; | ||
|
|
||
| // проверка на подсказку, дальше не идем | ||
| if (message.toLowerCase().startsWith('!подска')) { | ||
| if (backend_supports_tips()) use_tip('', true); | ||
| return; | ||
| } | ||
|
|
||
| // Проверяем пасхалки | ||
| if (typeof check_easter_egg === 'function' && check_easter_egg(message)) { | ||
| return; | ||
| } | ||
|
|
||
| // если больше одного слова, слишком короткое или длинное, или число — игнорируем | ||
| if (message.split(' ').length > 1 || message.length > 20 || message.length <= 1 || !isNaN(message)) { | ||
| addTextToLastWords('Введите одно слово (2–20 букв)'); | ||
| return; | ||
| } | ||
|
|
||
| // Приводим ЛЕД и ЛЁД к одному виду | ||
| message = message.replace(/ё/gi, 'е'); | ||
|
|
||
| // числа и прочие символы убираем тоже (как в init.js) | ||
| message = message.replace(/[^a-zA-Zа-яА-Я]/g, ''); | ||
|
|
||
| if (message.length < 2) { | ||
| addTextToLastWords('Введите одно слово (2–20 букв)'); | ||
| return; | ||
| } | ||
|
|
||
| if (words_count === 0) { | ||
| document.getElementById('info').style.display = 'none'; | ||
| document.getElementById('settings').style.display = 'none'; | ||
| } | ||
| words_count++; | ||
| wordQueue.push({ 'user': SOLO_USER, 'color': SOLO_COLOR, 'msg': message }); | ||
| if (wordQueue.length === 1) { | ||
| runQueue(); | ||
| } | ||
| } | ||
|
|
||
| if (soloSubmit) { | ||
| soloSubmit.addEventListener('click', solo_guess); | ||
| } | ||
|
|
||
| if (soloInput) { | ||
| soloInput.addEventListener('keydown', (e) => { | ||
| if (e.key === 'Enter') { | ||
| e.preventDefault(); | ||
| solo_guess(); | ||
| } | ||
| }); | ||
| soloInput.focus(); | ||
| } | ||
|
|
||
| app(); | ||
Uh oh!
There was an error while loading. Please reload this page.