second human fight fixes

This commit is contained in:
Dorian
2026-03-11 10:58:03 +00:00
parent ea72c097c4
commit 45216e5dfc
+11 -25
View File
@@ -199,6 +199,9 @@ function wireSSE() {
} }
}, },
onRoundStart(data) { onRoundStart(data) {
// For human fights, don't preview the question in the log — it spoils the
// challenge before the input area shows it. The round_end handler adds the full result.
if (!isHumanFight.value) {
liveLogItems.value.push({ liveLogItems.value.push({
type: 'challenge', type: 'challenge',
round: data.round, round: data.round,
@@ -206,6 +209,7 @@ function wireSSE() {
color: 'neon-green', color: 'neon-green',
}) })
scrollLiveLog() scrollLiveLog()
}
}, },
onHumanChallenge(sseData) { onHumanChallenge(sseData) {
// SSE now includes choices directly — no secondary fetch needed // SSE now includes choices directly — no secondary fetch needed
@@ -454,16 +458,9 @@ watch(() => route.params.fightId, async (newId) => {
if (isLive.value) { if (isLive.value) {
startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling(), keepLive: isHumanFight.value }) startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling(), keepLive: isHumanFight.value })
wireSSE() wireSSE()
if (isHumanFight.value) { // Scene init handled by liveFightData watcher to avoid double init
startHumanPolling() if (!isHumanFight.value && !liveFightData.value) {
await nextTick() await loadFight()
await nextTick()
if (liveFightData.value) await initLiveScene()
} else {
if (!liveFightData.value) await loadFight()
await nextTick()
await nextTick()
if (liveFightData.value) await initLiveScene()
} }
} }
}) })
@@ -526,17 +523,8 @@ onMounted(async () => {
startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling(), keepLive: isHumanFight.value }) startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling(), keepLive: isHumanFight.value })
if (isHumanFight.value) { if (isHumanFight.value) {
wireSSE() wireSSE()
// Init scene first, then start challenge polling — ensures entrance // Scene init + human polling are handled by the liveFightData watcher
// plays before the first question appears (characters invisible otherwise) // (avoids double init if loadFight already set liveFightData)
if (liveFightData.value) {
await nextTick()
await nextTick()
await initLiveScene()
}
// Only start polling after scene is ready (or watcher will start it when liveFightData arrives)
if (liveSceneReady.value) {
startHumanPolling()
}
} }
} }
}) })
@@ -586,15 +574,13 @@ async function fightAgain(botId: string) {
startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling(), keepLive: isHumanFight.value }) startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling(), keepLive: isHumanFight.value })
if (isHumanFight.value) { if (isHumanFight.value) {
wireSSE() wireSSE()
// Poll until fight data arrives — the liveFightData watcher handles scene init
// (don't call initLiveScene directly, it causes double kaplay init + double TTS)
for (let i = 0; i < 20; i++) { for (let i = 0; i < 20; i++) {
await loadFight() await loadFight()
if (liveFightData.value) break if (liveFightData.value) break
await sleep(300) await sleep(300)
} }
await nextTick()
await nextTick()
if (liveFightData.value) await initLiveScene()
startHumanPolling()
} }
} else { } else {
fightError.value = `Failed to start fight (${res.status})` fightError.value = `Failed to start fight (${res.status})`