human fight sequence fix
This commit is contained in:
@@ -23,6 +23,7 @@ export function useHumanChallenge(
|
||||
const roundCooldown = ref(0)
|
||||
const pendingChallengeData = ref<{ data: any; receivedAt: number } | null>(null)
|
||||
const entrancePlaying = ref(false)
|
||||
const animatingRound = ref(false)
|
||||
|
||||
let humanPollHandle: ReturnType<typeof setInterval> | null = null
|
||||
let timerHandle: ReturnType<typeof setInterval> | null = null
|
||||
@@ -118,8 +119,8 @@ export function useHumanChallenge(
|
||||
const data = await res.json()
|
||||
|
||||
if (data.pending) {
|
||||
// Queue if entrance is playing or cooldown active
|
||||
if (entrancePlaying.value || roundCooldown.value > 0) {
|
||||
// Queue if entrance is playing, round animating, or cooldown active
|
||||
if (entrancePlaying.value || animatingRound.value || roundCooldown.value > 0) {
|
||||
if (!pendingChallengeData.value || (data.roundNumber && data.roundNumber > (pendingChallengeData.value.data.roundNumber || 0))) {
|
||||
pendingChallengeData.value = { data, receivedAt: Date.now() }
|
||||
}
|
||||
@@ -159,6 +160,8 @@ export function useHumanChallenge(
|
||||
}
|
||||
|
||||
function startCooldown(seconds: number) {
|
||||
// Clear any existing cooldown interval to prevent double-decrement
|
||||
if (cooldownHandle) { clearInterval(cooldownHandle); cooldownHandle = null }
|
||||
roundCooldown.value = seconds
|
||||
cooldownHandle = setInterval(() => {
|
||||
roundCooldown.value--
|
||||
@@ -178,6 +181,11 @@ export function useHumanChallenge(
|
||||
if (timerHandle) { clearInterval(timerHandle); timerHandle = null }
|
||||
}
|
||||
|
||||
function stopCooldown() {
|
||||
roundCooldown.value = 0
|
||||
if (cooldownHandle) { clearInterval(cooldownHandle); cooldownHandle = null }
|
||||
}
|
||||
|
||||
function resetState() {
|
||||
humanChallenge.value = null
|
||||
humanAnswer.value = ''
|
||||
@@ -186,6 +194,7 @@ export function useHumanChallenge(
|
||||
roundCooldown.value = 0
|
||||
pendingChallengeData.value = null
|
||||
entrancePlaying.value = false
|
||||
animatingRound.value = false
|
||||
}
|
||||
|
||||
/** Mark entrance as playing — queues any challenges that arrive during animation */
|
||||
@@ -199,8 +208,8 @@ export function useHumanChallenge(
|
||||
}
|
||||
|
||||
function handleSSEChallenge(sseData: any) {
|
||||
// Queue challenges during entrance animation or round cooldown
|
||||
if (entrancePlaying.value || roundCooldown.value > 0) {
|
||||
// Queue challenges during entrance animation, round animation, or cooldown
|
||||
if (entrancePlaying.value || animatingRound.value || roundCooldown.value > 0) {
|
||||
pendingChallengeData.value = { data: sseData, receivedAt: Date.now() }
|
||||
} else {
|
||||
applyChallenge(sseData)
|
||||
@@ -216,6 +225,7 @@ export function useHumanChallenge(
|
||||
roundCooldown,
|
||||
pendingChallengeData,
|
||||
entrancePlaying,
|
||||
animatingRound,
|
||||
applyChallenge,
|
||||
submitHumanAnswer,
|
||||
submitChoice,
|
||||
@@ -224,6 +234,7 @@ export function useHumanChallenge(
|
||||
stopHumanPolling,
|
||||
startCooldown,
|
||||
clearChallenge,
|
||||
stopCooldown,
|
||||
resetState,
|
||||
setEntrancePlaying,
|
||||
handleSSEChallenge,
|
||||
|
||||
Reference in New Issue
Block a user