Переключение игр из пульта и со страницы импорта

- блок «Какая игра?» в лобби: список паков с диска, текущий помечен
- кнопка «Играть» в разделе «Игры на диске» на странице импорта
- /api/packs читает паки с диска и отдаёт текущий
- при смене пака очки обнуляются, игроки остаются; разрешено в лобби и на итогах
This commit is contained in:
oskarvitalii committed 2026-11-16 15:36:20 +07:00
1 parent 5d3cd9127c
commit 05ef0213ae
8 files changed
+293 -18

No files matched your search

+51
View File
@@ -1032,3 +1032,54 @@ a.ghost {
color: #2a1f06;
background: linear-gradient(180deg, #f1d288, #d8aa47);
}
/* ─── Выбор игры ─────────────────────────────────────────────────────── */
.pack-picker {
display: flex;
flex-direction: column;
gap: 0.4rem;
width: min(560px, 92vw);
}
.pack-row {
display: flex;
align-items: center;
gap: 0.7rem;
padding: 0.55rem 0.8rem;
border-radius: 12px;
background: rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.07);
}
.pack-row.active {
border-color: var(--gold);
background: var(--gold-soft);
}
.pack-info {
flex: 1;
display: flex;
flex-direction: column;
gap: 0.1rem;
text-align: left;
min-width: 0;
}
.pack-info b {
font-size: 0.95rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.pack-info .note {
font-size: 0.72rem;
color: var(--muted);
}
.pack-row .ghost {
flex: none;
padding: 0.4em 0.9em;
font-size: 0.85rem;
}
+66
View File
@@ -39,8 +39,18 @@ const QUESTION_PHASES = ['question', 'cat_nominate', 'auction', 'answering', 're
const route = useRoute()
const { say } = useToast()
interface PackChoice {
id: string
title: string
rounds: number
cells: number
current: boolean
}
const room = ref('')
const fatal = ref('')
const packs = ref<PackChoice[]>([])
const switching = ref(false)
const showAnswer = ref(false)
const betDraft = ref<Record<string, number | undefined>>({})
const now = ref(Date.now())
@@ -72,6 +82,36 @@ const tags = computed(() => {
return []
})
async function loadPacks(): Promise<void> {
try {
const response = await fetch('/api/packs')
if (!response.ok) return
const data = (await response.json()) as { packs?: PackChoice[] }
packs.value = data.packs ?? []
} catch {
// Список не критичен: играть можно и без него.
}
}
async function choosePack(id: string): Promise<void> {
if (switching.value) return
switching.value = true
try {
const query = new URLSearchParams({ token: String(route.params.token ?? ''), id })
const response = await fetch(`/api/packs/apply?${query.toString()}`, { method: 'POST' })
const data = (await response.json()) as { ok: boolean; error?: string }
if (!data.ok) {
say(data.error ?? 'не удалось переключить игру')
return
}
await loadPacks()
} catch {
say('нет связи с сервером')
} finally {
switching.value = false
}
}
let timer: ReturnType<typeof setInterval> | undefined
onMounted(async () => {
@@ -86,6 +126,7 @@ onMounted(async () => {
return
}
game.connect({ role: 'host', room: room.value, token })
void loadPacks()
timer = setInterval(() => {
now.value = Date.now()
}, 200)
@@ -179,6 +220,31 @@ function selectCell(key: string): void {
<span v-for="player in players" :key="player.id" class="chip">{{ player.name }}</span>
</div>
<p v-if="players.length === 0" class="note">Пока никто не подключился</p>
<div v-if="packs.length" class="pack-picker">
<p class="kicker">Какая игра?</p>
<div
v-for="pack in packs"
:key="pack.id"
class="pack-row"
:class="{ active: pack.current }"
>
<span class="pack-info">
<b>{{ pack.title }}</b>
<span class="note">{{ pack.rounds }} р. · {{ pack.cells }} вопросов</span>
</span>
<span v-if="pack.current" class="tag">играем</span>
<button
v-else
class="ghost accent"
:disabled="switching"
@click="choosePack(pack.id)"
>
Выбрать
</button>
</div>
</div>
<button class="primary big" :disabled="players.length === 0" @click="act({ type: 'startGame' })">
Начать игру
</button>
+16 -5
View File
@@ -42,6 +42,7 @@ interface PackInfo {
interface Info {
packs: PackInfo[]
current: string
mediaFolders: string[]
sfx: Record<string, string>
sfxNames: string[]
@@ -60,6 +61,12 @@ const result = ref<ImportSuccess | null>(null)
const errors = ref<ImportError[]>([])
const hasFile = computed(() => payload.value !== null)
const currentId = computed(() => info.value?.current ?? '')
async function switchTo(id: string): Promise<void> {
await applyPack(id)
await refreshInfo()
}
async function refreshInfo(): Promise<void> {
try {
@@ -258,13 +265,17 @@ async function send(dry: boolean): Promise<void> {
</section>
<section v-if="info?.packs.length" class="import-card">
<p class="kicker">Паки на диске</p>
<ul class="pack-list">
<li v-for="pack in info.packs" :key="pack.id">
<p class="kicker">Игры на диске</p>
<div v-for="pack in info.packs" :key="pack.id" class="pack-row" :class="{ active: pack.id === currentId }">
<span class="pack-info">
<b>{{ pack.title }}</b>
<span class="note">{{ pack.id }} · {{ pack.rounds }} р. · {{ pack.cells }} вопросов</span>
</li>
</ul>
</span>
<span v-if="pack.id === currentId" class="tag">играем</span>
<button v-else class="ghost accent" :disabled="busy" @click="switchTo(pack.id)">
Играть
</button>
</div>
</section>
<section class="import-card">