обновил статусы удалений

This commit is contained in:
2026-09-28 16:55:33 +03:00
parent 0fc72b481d
commit 3875180638
3 changed files with 45209 additions and 36091 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -7010,17 +7010,11 @@ class HockeyDataService:
if not assigned: if not assigned:
continue continue
# BUILD96: a prepared penalty must not change numerical strength until # A complete/assigned penalty changes numerical strength immediately,
# the operator explicitly starts it. New Runtime snapshots always send # as soon as the side/infraction/preset/time are present. The countdown
# startedOnce. Legacy snapshots (without the marker) keep the old # itself may still be stopped (startedOnce=false, running=false): vMix
# assigned-immediately behaviour for backward compatibility. # strength captions and the penalty plate must already reflect the new
has_started_marker = "startedOnce" in item or "started_once" in item # 5x4 / 5x3 / 4x4 state before the operator starts the clock.
if has_started_marker:
started = bool(item.get("startedOnce", item.get("started_once", False))) or bool(item.get("running", False))
else:
started = bool(item.get("running", False)) or remaining_ms < duration_ms or assigned
if not started:
continue
if side == "home": if side == "home":
home += 1 home += 1
else: else:

View File

@@ -114,6 +114,7 @@
hockeyPenaltyMappingContextSignature: "", hockeyPenaltyMappingContextSignature: "",
hockeyPenaltyMappingContextPending: false, hockeyPenaltyMappingContextPending: false,
hockeyPenaltyMappingContextQueued: false, hockeyPenaltyMappingContextQueued: false,
hockeyPenaltyMappingContextPromise: null,
hockeyPlayerPanelSeedPending: false, hockeyPlayerPanelSeedPending: false,
hockeyPlayerPanelSeedSignature: "", hockeyPlayerPanelSeedSignature: "",
vmixFinishOverlayTimers: new Map(), vmixFinishOverlayTimers: new Map(),
@@ -4228,10 +4229,9 @@ function startCustomTooltips() {
return items; return items;
} }
// BUILD95: a prepared penalty is not an active vMix countdown yet. // Countdown running state remains separate from numerical-strength state.
// It becomes active only after the operator explicitly presses Start. // A ready penalty affects strength immediately, while this helper only tells
// Once started, a paused penalty stays active so its strength/timer plate can // whether its native vMix countdown has ever actually been started.
// remain visible without running in vMix.
function hockeyPenaltyHasStarted(event) { function hockeyPenaltyHasStarted(event) {
if (!event || event.finished) return false; if (!event || event.finished) return false;
if (event.startedOnce === true || event.running) return true; if (event.startedOnce === true || event.running) return true;
@@ -5241,19 +5241,12 @@ function startCustomTooltips() {
// countdown change. A pure coincidental 4x4 that did not originate from an // countdown change. A pure coincidental 4x4 that did not originate from an
// advantage still produces no plate. // advantage still produces no plate.
function penaltyDisplayEntriesByTargetSide(step) { function penaltyDisplayEntriesByTargetSide(step) {
// Prepared penalties may pre-fill the stopped plate, but as soon as at least // Numerical strength changes as soon as a penalty is fully assigned and has
// one penalty has actually started they MUST NOT participate in strength // a duration. Do not wait for StartCountdown: ready/stopped penalties already
// routing. Otherwise an unstarted draft on the opposite bench can make a // participate in 5x4 / 5x3 / 4x4 routing, while their vMix countdown remains
// real 4x5 look like 4x4 locally and suppress the AWAY/HOME StartCountdown. // stopped until the operator explicitly starts it.
const activeHome = sortedPenaltyEntries("home"); const home = sortedPenaltyEntries("home", { includePrepared: true });
const activeAway = sortedPenaltyEntries("away"); const away = sortedPenaltyEntries("away", { includePrepared: true });
const hasStartedPenalties = Boolean(activeHome.length || activeAway.length);
const home = hasStartedPenalties
? activeHome
: sortedPenaltyEntries("home", { includePrepared: true });
const away = hasStartedPenalties
? activeAway
: sortedPenaltyEntries("away", { includePrepared: true });
const all = [...home, ...away].sort((a, b) => { const all = [...home, ...away].sort((a, b) => {
const runningOrder = Number(Boolean(b.event?.running)) - Number(Boolean(a.event?.running)); const runningOrder = Number(Boolean(b.event?.running)) - Number(Boolean(a.event?.running));
if (runningOrder) return runningOrder; if (runningOrder) return runningOrder;
@@ -5297,7 +5290,9 @@ function startCustomTooltips() {
function rememberPenaltyAdvantagePlan(displayPlan) { function rememberPenaltyAdvantagePlan(displayPlan) {
if (!displayPlan?.routedToAdvantage || !["home", "away"].includes(String(displayPlan.advantageSide || ""))) return; if (!displayPlan?.routedToAdvantage || !["home", "away"].includes(String(displayPlan.advantageSide || ""))) return;
if (!hockeyPenaltyHasStarted(displayPlan.transitionEntry?.event)) return; // A ready penalty already creates a real numerical-advantage state for the
// scorebug, even if its countdown has not started yet. Remember that side so
// a following temporary equal-strength state keeps the same single plate.
const nextSide = String(displayPlan.advantageSide); const nextSide = String(displayPlan.advantageSide);
const changed = !state.hockeyPenaltyAdvantageCycle.hadAdvantage const changed = !state.hockeyPenaltyAdvantageCycle.hadAdvantage
|| String(state.hockeyPenaltyAdvantageCycle.lastAdvantageSide || "") !== nextSide; || String(state.hockeyPenaltyAdvantageCycle.lastAdvantageSide || "") !== nextSide;
@@ -5336,8 +5331,8 @@ function startCustomTooltips() {
const gameId = String(hockeyTimerSelectedGameId() || "").trim(); const gameId = String(hockeyTimerSelectedGameId() || "").trim();
if (!gameId) return false; if (!gameId) return false;
const home = hockeyPenaltySideMappingDetail(sortedPenaltyEntries("home")[0] || null, "home"); const home = hockeyPenaltySideMappingDetail(sortedPenaltyEntries("home", { includePrepared: true })[0] || null, "home");
const away = hockeyPenaltySideMappingDetail(sortedPenaltyEntries("away")[0] || null, "away"); const away = hockeyPenaltySideMappingDetail(sortedPenaltyEntries("away", { includePrepared: true })[0] || null, "away");
const values = { const values = {
active_home_penalty_id: home?.penalty_id || "", active_home_penalty_id: home?.penalty_id || "",
active_home_penalty_player_id: home?.player_id || "", active_home_penalty_player_id: home?.player_id || "",
@@ -5352,12 +5347,16 @@ function startCustomTooltips() {
if (!force && signature === state.hockeyPenaltyMappingContextSignature) return false; if (!force && signature === state.hockeyPenaltyMappingContextSignature) return false;
if (state.hockeyPenaltyMappingContextPending) { if (state.hockeyPenaltyMappingContextPending) {
state.hockeyPenaltyMappingContextQueued = true; const pending = state.hockeyPenaltyMappingContextPromise;
return true; if (pending) {
try { await pending; } catch (_) {}
return await hockeySyncPenaltySideMappingContext({ force: true });
}
return false;
} }
state.hockeyPenaltyMappingContextPending = true; state.hockeyPenaltyMappingContextPending = true;
try { const request = (async () => {
const response = await fetch("/api/hockey/context/batch", { const response = await fetch("/api/hockey/context/batch", {
method: "POST", cache: "no-store", credentials: "same-origin", method: "POST", cache: "no-store", credentials: "same-origin",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
@@ -5385,15 +5384,17 @@ function startCustomTooltips() {
detail: { game_id: gameId, values: clone(values) }, detail: { game_id: gameId, values: clone(values) },
})); }));
return true; return true;
})();
state.hockeyPenaltyMappingContextPromise = request;
try {
return await request;
} catch (error) { } catch (error) {
console.error("Penalty side Mapping context error", error); console.error("Penalty side Mapping context error", error);
return false; return false;
} finally { } finally {
if (state.hockeyPenaltyMappingContextPromise === request) state.hockeyPenaltyMappingContextPromise = null;
state.hockeyPenaltyMappingContextPending = false; state.hockeyPenaltyMappingContextPending = false;
if (state.hockeyPenaltyMappingContextQueued) { state.hockeyPenaltyMappingContextQueued = false;
state.hockeyPenaltyMappingContextQueued = false;
hockeySyncPenaltySideMappingContext({ force: true }).catch(() => {});
}
} }
} }
@@ -7672,16 +7673,15 @@ function openTimerQuickEditor(focusActionId = "") {
...hockeyPenaltyContext(event) ...hockeyPenaltyContext(event)
}); });
if (hockeyEventReady(event) && !event.readyEmitted) { if (hockeyEventReady(event) && !event.readyEmitted && !event.readyPending) {
event.readyEmitted = true; // The user may bind a vMix trigger to penalty_ready. Defer that trigger until
emitInteraction(component, "penalty_ready", { // the server has recalculated strength and strength.* Mapping has been sent,
item_id: event.id, // so Overlay/Input appears with the new Power Play / 5x3 / 4x4 caption.
...hockeyPenaltyContext(event) event.readyPending = true;
});
} }
if (hockeyEventReady(event) && !event.assignedEmitted) { if (hockeyEventReady(event) && !event.assignedEmitted && !event.assignedPending) {
event.assignedEmitted = true; event.assignedPending = true;
const board = ensureHockeyBoardState(component); const board = ensureHockeyBoardState(component);
addHockeyHistory( addHockeyHistory(
component, component,
@@ -7690,21 +7690,59 @@ function openTimerQuickEditor(focusActionId = "") {
event, event,
`${event.eventTime || "—:—"} · ${event.teamPenalty ? "Командное удаление" : event.player?.name || "Игрок не выбран"} · ${hockeyInfractionWebLabel(event.infraction)} · ${event.preset}` `${event.eventTime || "—:—"} · ${event.teamPenalty ? "Командное удаление" : event.player?.name || "Игрок не выбран"} · ${hockeyInfractionWebLabel(event.infraction)} · ${event.preset}`
); );
emitInteraction(component, "penalty_assigned", {
item_id: event.id,
...hockeyPenaltyContext(event)
});
} }
// When the scorebug is on air, show a completed penalty immediately with // Do not OverlayIn a newly prepared penalty before the authoritative server
// its fresh, stopped time. Filling a draft never starts either clock. // strength and strength.* Mapping arrive. The save path below performs the
if (hockeyCanControl() && hockeyEventReady(event) // ordered sequence: save -> Mapping -> penalty target/Input -> trigger event.
&& (hockeyScoreboardIsLive() || (source === "preset" && state.activeHockeyVmixTimerSteps.size > 0)) if (hockeyCanControl() && hockeyEventReady(event)) {
&& (source === "preset" || !hockeyPenaltyHasStarted(event))) {
activateConfiguredPenaltyCountdowns(); activateConfiguredPenaltyCountdowns();
rebalanceVmixPenaltyTargets({ editedEventKey: source === "preset" ? penaltyMirrorKey(component, event) : "" }) } else {
.catch((error) => console.error("Prepared penalty display error", error)); hockeySyncPenaltySideMappingContext().catch(() => {});
} }
hockeySyncPenaltySideMappingContext().catch(() => {}); }
function hockeyHasPendingPenaltyInteractions() {
return currentHockeyPenaltyEntries().some(({ event }) => Boolean(event.readyPending || event.assignedPending));
}
function hockeyReadyPenaltyCounts() {
const counts = { home: 0, away: 0 };
currentHockeyPenaltyEntries().forEach(({ side }) => {
if (side === "home" || side === "away") counts[side] += 1;
});
return counts;
}
function hockeyFlushPendingPenaltyInteractions() {
let emitted = 0;
const touchedComponents = new Set();
currentHockeyPenaltyEntries().forEach(({ component, event }) => {
if (!hockeyEventReady(event)) return;
if (event.readyPending && !event.readyEmitted) {
event.readyPending = false;
event.readyEmitted = true;
emitInteraction(component, "penalty_ready", {
item_id: event.id,
...hockeyPenaltyContext(event)
});
touchedComponents.add(component);
emitted += 1;
}
if (event.assignedPending && !event.assignedEmitted) {
event.assignedPending = false;
event.assignedEmitted = true;
emitInteraction(component, "penalty_assigned", {
item_id: event.id,
...hockeyPenaltyContext(event)
});
touchedComponents.add(component);
emitted += 1;
}
});
touchedComponents.forEach((component) => {
persistHockeyBoard(component, ensureHockeyBoardState(component), true);
});
return emitted;
} }
function createHockeyPenaltyDraft(component, seed = {}, source = "manual") { function createHockeyPenaltyDraft(component, seed = {}, source = "manual") {
@@ -7993,8 +8031,8 @@ function openTimerQuickEditor(focusActionId = "") {
const fullStrengthSide = penaltyFullStrengthSide(); const fullStrengthSide = penaltyFullStrengthSide();
board.penalties = board.penalties.filter((item) => item.id !== event.id); board.penalties = board.penalties.filter((item) => item.id !== event.id);
const side = String(event.player?.side || event.side || "").toLowerCase(); const side = String(event.player?.side || event.side || "").toLowerCase();
const remainingOnSide = board.penalties.filter((item) => !item.finished && hockeyEventReady(item) && hockeyPenaltyHasStarted(item) && String(item.player?.side || item.side || "").toLowerCase() === side).length; const remainingOnSide = board.penalties.filter((item) => !item.finished && hockeyEventReady(item) && String(item.player?.side || item.side || "").toLowerCase() === side).length;
const remainingTotal = board.penalties.filter((item) => !item.finished && hockeyEventReady(item) && hockeyPenaltyHasStarted(item)).length; const remainingTotal = board.penalties.filter((item) => !item.finished && hockeyEventReady(item)).length;
const clearCommonSelection = board.selectedEventId === event.id; const clearCommonSelection = board.selectedEventId === event.id;
const clearSideSelection = board.selectedPreviewEventIds?.[side] === event.id; const clearSideSelection = board.selectedPreviewEventIds?.[side] === event.id;
if (clearCommonSelection) board.selectedEventId = null; if (clearCommonSelection) board.selectedEventId = null;
@@ -8053,7 +8091,7 @@ function openTimerQuickEditor(focusActionId = "") {
}); });
state.vmixPenaltyMirrors.delete(penaltyMirrorKey(component, event)); state.vmixPenaltyMirrors.delete(penaltyMirrorKey(component, event));
hockeySyncPenaltySideMappingContext({ force: true }).catch(() => {}); hockeySyncPenaltySideMappingContext({ force: true }).catch(() => {});
if (!board.penalties.some((item) => !item.finished && hockeyEventReady(item) && hockeyPenaltyHasStarted(item))) { if (!board.penalties.some((item) => !item.finished && hockeyEventReady(item))) {
resetPenaltyAdvantageCycle(); resetPenaltyAdvantageCycle();
hockeyScheduleTimerSave(true); hockeyScheduleTimerSave(true);
} }
@@ -8166,7 +8204,7 @@ function openTimerQuickEditor(focusActionId = "") {
hockeySyncPenaltySideMappingContext({ force: true }).catch(() => {}); hockeySyncPenaltySideMappingContext({ force: true }).catch(() => {});
const hadAdvantage = Boolean(state.hockeyPenaltyAdvantageCycle.hadAdvantage); const hadAdvantage = Boolean(state.hockeyPenaltyAdvantageCycle.hadAdvantage);
const fullStrengthSide = penaltyFullStrengthSide(); const fullStrengthSide = penaltyFullStrengthSide();
const remainingTotal = board.penalties.filter((item) => !item.finished && hockeyEventReady(item) && hockeyPenaltyHasStarted(item)).length; const remainingTotal = board.penalties.filter((item) => !item.finished && hockeyEventReady(item)).length;
const finishBySide = new Map(); const finishBySide = new Map();
completedEvents.forEach((event) => { completedEvents.forEach((event) => {
const side = String(event.player?.side || event.side || "").toLowerCase(); const side = String(event.player?.side || event.side || "").toLowerCase();
@@ -8176,7 +8214,7 @@ function openTimerQuickEditor(focusActionId = "") {
.catch((error) => console.error("Penalty target ticker rebalance error", error)) .catch((error) => console.error("Penalty target ticker rebalance error", error))
.finally(() => { .finally(() => {
finishBySide.forEach((event, side) => { finishBySide.forEach((event, side) => {
const remainingOnSide = board.penalties.filter((item) => !item.finished && hockeyEventReady(item) && hockeyPenaltyHasStarted(item) && String(item.player?.side || item.side || "").toLowerCase() === side).length; const remainingOnSide = board.penalties.filter((item) => !item.finished && hockeyEventReady(item) && String(item.player?.side || item.side || "").toLowerCase() === side).length;
fireConfiguredTimerFinishActions("penalty", { fireConfiguredTimerFinishActions("penalty", {
side, component, event, side, component, event,
remaining_on_side: remainingOnSide, remaining_on_side: remainingOnSide,
@@ -13126,18 +13164,33 @@ function renderHockeyPenaltyDashboard(node, component, runtime) {
hockeyBackupPlayerSelectionValues(gameId, payload?.values || {}); hockeyBackupPlayerSelectionValues(gameId, payload?.values || {});
const strengthChanged = !previousControl const strengthChanged = !previousControl
|| hockeyStrengthMappingSignature(previousControl) !== hockeyStrengthMappingSignature(payload); || hockeyStrengthMappingSignature(previousControl) !== hockeyStrengthMappingSignature(payload);
if (strengthChanged) { const readyPenaltyCounts = hockeyReadyPenaltyCounts();
hockeyRefreshVmixMappingForStrength(gameId, previousControl, payload).catch(() => {}); const payloadStrength = payload?.strength && typeof payload.strength === "object" ? payload.strength : {};
// BUILD89: keep a second rebalance after the authoritative control payload const pendingPenaltyTrigger = hockeyHasPendingPenaltyInteractions()
// arrives. The single penalty plate then follows the real advantage side && Number(payloadStrength.home_penalties || 0) === readyPenaltyCounts.home
// and the globally shortest timer that can change the numerical strength. && Number(payloadStrength.away_penalties || 0) === readyPenaltyCounts.away;
if (state.activeHockeyVmixTimerSteps.size) { if (strengthChanged || pendingPenaltyTrigger) {
// Build87 compatibility marker: rebalanceVmixPenaltyTargets({ force: true, hideUnused: true }) // Ordered vMix update for a newly assigned penalty:
// BUILD95 uses a non-forced pass so a merely prepared penalty cannot // 1) server already recalculated strength in `payload`;
// unnecessarily restart an already running vMix countdown. // 2) push strength.* Mapping;
rebalanceVmixPenaltyTargets({ force: false, hideUnused: true }) // 3) route/show the correct penalty Input with a stopped countdown;
.catch((error) => console.error("Penalty strength rebalance error", error)); // 4) only then emit penalty_ready/penalty_assigned triggers.
} // This prevents an OverlayIn trigger from rendering the previous caption.
Promise.resolve()
.then(async () => {
if (pendingPenaltyTrigger) await hockeySyncPenaltySideMappingContext({ force: true });
await hockeyRefreshVmixMappingForStrength(gameId, previousControl, payload);
if (state.activeHockeyVmixTimerSteps.size) {
// Build87 compatibility marker: rebalanceVmixPenaltyTargets({ force: true, hideUnused: true })
await rebalanceVmixPenaltyTargets({
force: false,
hideUnused: true,
forceOverlay: pendingPenaltyTrigger,
});
}
if (pendingPenaltyTrigger) hockeyFlushPendingPenaltyInteractions();
})
.catch((error) => console.error("Penalty strength rebalance error", error));
} }
if (previousControl && hockeyTeamStateFlagSignature(previousControl) !== hockeyTeamStateFlagSignature(payload) && hockeyTeamStateScoreboardIsLive()) { if (previousControl && hockeyTeamStateFlagSignature(previousControl) !== hockeyTeamStateFlagSignature(payload) && hockeyTeamStateScoreboardIsLive()) {
hockeySyncTeamStateOverlays({ force: true }).catch((error) => console.error("vMix team-state overlay sync error", error)); hockeySyncTeamStateOverlays({ force: true }).catch((error) => console.error("vMix team-state overlay sync error", error));
@@ -13529,9 +13582,10 @@ function renderHockeyPenaltyDashboard(node, component, runtime) {
state.hockeyTimerDirty = true; state.hockeyTimerDirty = true;
state.hockeyTimerRevision += 1; state.hockeyTimerRevision += 1;
if (state.hockeyTimerSaveTimer) clearTimeout(state.hockeyTimerSaveTimer); if (state.hockeyTimerSaveTimer) clearTimeout(state.hockeyTimerSaveTimer);
const delayMs = hockeyHasPendingPenaltyInteractions() ? 0 : (force ? 40 : 850);
state.hockeyTimerSaveTimer = setTimeout( state.hockeyTimerSaveTimer = setTimeout(
() => hockeyPersistGameTimers(gameId, { force }), () => hockeyPersistGameTimers(gameId, { force }),
force ? 40 : 850 delayMs
); );
} }