feat(match): 同步比赛计时与装甲板扣血许可
构建客户端 / 检查(类型 + 单元测试) (push) Canceled after 0s
构建客户端 / Linux x64(deb + AppImage) (push) Canceled after 0s
构建客户端 / Windows x64(NSIS 安装包) (push) Canceled after 0s
构建客户端 / macOS 通用(.app + .dmg) (push) Canceled after 0s

- feat(client): 增加裁判比赛计时、技术暂停与选手端局域网同步
- feat(armor): 红蓝共用通用固件,按客户端选队并显示网络连接状态
- feat(armor): 仅在对局进行中允许扣血,其他阶段保留受击闪烁
- feat(client): 将计时置于血条中间并增加开赛前五秒全屏动画
- fix(client): 修复连续血条、对手镜像和图传断连灰度遮罩
- fix(client): 统一界面中文字体并整理各页面文案
- fix(maintenance): 备份迁移装甲板分区,恢复 SDK 构建与固件打包
- refactor(repo): 按 armor、vt 和 client 整理工程与脚本,移除旧参考实现
- test: 补充线路、受击许可、回环 UDP、维护和 HUD 验证
- docs: 同步构建、协议、比赛控制和硬件验证边界

验证:前端构建与 19 项相关测试通过;核心 91 项单元测试与 2 项回环 UDP 集成测试通过;装甲板规则 25 项、线路 26 项、Tauri 51 项测试通过;独立探测器 5 项与目录回归 4 项通过。完成 C3 两组阈值实际编译、导出与 ZIP 校验,检查 900×600 / 1280×720 页面、倒计时和随包中文字体。
未执行烧录、板上运行、跨电脑广播或硬件稳定性验证。
This commit is contained in:
sloray committed 2026-10-22 17:08:49 +08:00
1 parent 72901939c6
commit f7ca246b68
581 files changed
+6596 -7683

No files matched your search

+113
View File
@@ -0,0 +1,113 @@
import { useEffect, useMemo, useRef, useState } from "react";
import { Dialog } from "./Dialog";
import { api } from "../lib/ipc";
import { useAppStore } from "../lib/store";
import { MATCH_PHASE, matchTime, projectMatch } from "../lib/match-time";
import type { MatchAction, MatchClockView, Snapshot } from "../lib/types";
function useClock(view: MatchClockView) {
const { connected } = useAppStore();
const origin = useMemo(() => ({ at: performance.now(), view }), [view]);
const [now, setNow] = useState(performance.now());
useEffect(() => { const timer = window.setInterval(() => setNow(performance.now()), 100); return () => window.clearInterval(timer); }, []);
return projectMatch(origin.view, Math.max(0, now - origin.at), connected);
}
function Readout({ clock, names }: { clock: MatchClockView; names: string[] }) {
const paused = clock.phase === "paused";
const expired = paused && clock.pauseKind === "player" && clock.pauseRemainingMs === 0;
const label = !paused ? MATCH_PHASE[clock.phase] : clock.pauseKind === "player" ? `选手技术暂停 · ${names[clock.applicant ?? 0]}` : "官方技术暂停";
return <div className={`match-readout${paused ? " is-paused" : ""}${!clock.connected ? " is-stale" : ""}`}>
<div className="match-readout__phase"><i />{label}</div>
<div className="match-readout__digits num">{paused ? matchTime(clock.pauseRemainingMs ?? clock.pauseElapsedMs, clock.pauseKind === "official") : clock.phase === "idle" ? "—:—" : matchTime(clock.remainingMs)}</div>
<div className="match-readout__detail">{!clock.connected ? clock.source ? "计时同步中断 · 已冻结" : "等待裁判计时同步" : expired ? "暂停时间已到 · 等待裁判恢复" : paused ? `${clock.pauseKind === "official" ? "暂停已用时" : "暂停剩余"} · 暂停前剩余 ${matchTime(clock.remainingMs)}` : clock.phase === "running" || clock.phase === "finished" ? `对局已用时 ${matchTime(clock.elapsedMs, true)}` : clock.phase === "ready" ? "等待裁判确认开赛" : clock.phase === "countdown" ? "倒计时结束后开始对局" : "准备 3 分钟 / 对局 3 分钟"}</div>
{paused && <p className="match-readout__reason" title={clock.reason}>{clock.reason}</p>}
</div>;
}
export function TeamMatchClock({ snapshot }: { snapshot: Snapshot }) {
const clock = useClock(snapshot.matchClock);
const paused = clock.phase === "paused";
const label = !clock.connected ? clock.source ? "同步中断" : "等待裁判" : paused ? clock.pauseKind === "official" ? "官方暂停" : "选手暂停"
: clock.phase === "running" ? "对局剩余" : clock.phase === "preparation" ? "准备剩余" : clock.phase === "ready" ? "等待开赛"
: clock.phase === "countdown" ? "即将开赛" : clock.phase === "finished" ? "计时结束" : "尚未开始";
const time = clock.phase === "idle" ? "—:—" : paused
? matchTime(clock.pauseRemainingMs ?? clock.pauseElapsedMs, clock.pauseKind === "official") : matchTime(clock.remainingMs);
const detail = clock.syncError ?? (!clock.connected ? clock.source ? "计时同步中断,时间已冻结" : "等待裁判发送比赛计时" : paused
? `${clock.reason};${clock.pauseRemainingMs === 0 ? "暂停时间已到,等待裁判恢复;" : ""}对局已用时 ${matchTime(clock.elapsedMs, true)}`
: `对局已用时 ${matchTime(clock.elapsedMs, true)}`);
return <div className={`team-match-clock${paused ? " is-paused" : ""}${!clock.connected ? " is-stale" : ""}`} role="timer" aria-label={`${label} ${time},${detail}`} title={detail}>
<span className="team-match-clock__label">{label}</span>
<strong className="team-match-clock__time num">{time}</strong>
</div>;
}
/** 最后 5 秒覆盖画面;仅收到权威的开赛状态后才显示“开始”。 */
export function TeamMatchCountdown({ snapshot }: { snapshot: Snapshot }) {
const clock = useClock(snapshot.matchClock);
const previous = useRef({ phase: clock.phase, connected: clock.connected });
const [started, setStarted] = useState(false);
useEffect(() => {
const was = previous.current;
previous.current = { phase: clock.phase, connected: clock.connected };
if (was.phase === "countdown" && was.connected && clock.connected && clock.phase === "running" && clock.elapsedMs < 1500) {
setStarted(true);
} else if (!clock.connected || clock.phase !== "running") setStarted(false);
}, [clock.phase, clock.connected, clock.elapsedMs]);
useEffect(() => {
if (!started) return;
const timer = window.setTimeout(() => setStarted(false), 750);
return () => window.clearTimeout(timer);
}, [started]);
const visible = clock.connected && clock.phase === "countdown" && clock.remainingMs > 0 && clock.remainingMs <= 5000;
if (!visible && !started) return null;
const seconds = Math.max(1, Math.ceil(clock.remainingMs / 1000));
return <div className={`match-countdown${started ? " is-started" : ""}${!started && seconds <= 2 ? " is-urgent" : ""}`} aria-label="开赛全屏倒计时">
<div className="match-countdown__scan" aria-hidden="true" />
<div className="match-countdown__center">
<span className="match-countdown__label">{started ? "对局开始" : "准备开赛"}</span>
<div className="match-countdown__dial" aria-hidden="true"><i /><i /></div>
<strong key={started ? "start" : seconds} className={`match-countdown__number${started ? " match-countdown__number--start" : " num"}`} aria-live="assertive" aria-atomic="true">{started ? "开始" : seconds}</strong>
<div className="match-countdown__steps" aria-hidden="true">{[5, 4, 3, 2, 1].map(step => <i key={step} className={seconds <= step ? "is-passed" : ""} />)}</div>
<span className="match-countdown__caption">{started ? "" : "请选手就位"}</span>
</div>
<div className="match-countdown__progress" aria-hidden="true"><i style={{ transform: `scaleX(${started ? 0 : clock.remainingMs / 5000})` }} /></div>
</div>;
}
export function RefereeMatchControl({ snapshot, onError }: { snapshot: Snapshot; onError: (message: string) => void }) {
const clock = useClock(snapshot.matchClock);
const [dialog, setDialog] = useState<"player" | "official" | "end" | null>(null);
const [reason, setReason] = useState("");
const [team, setTeam] = useState(0);
const [approved, setApproved] = useState(false);
const [seconds, setSeconds] = useState(5);
const [busy, setBusy] = useState(false);
const active = ["preparation", "ready", "countdown", "running"].includes(clock.phase);
const run = async (action: MatchAction, close?: () => void) => {
if (busy) return;
setBusy(true);
try { await api.matchAction(action); close?.(); } catch (error) { onError(error instanceof Error ? error.message : String(error)); }
finally { setBusy(false); }
};
const openPause = (kind: "player" | "official") => { setReason(""); setApproved(false); setDialog(kind); };
const reasonValid = reason.trim().length > 0 && new TextEncoder().encode(reason.trim()).length <= 192 && !/[\u0000-\u001f\u007f]/.test(reason);
return <section className="match-control" aria-label="裁判比赛计时控制">
<div className="match-control__identity"><span className="label">MATCH CONTROL</span><span>{snapshot.demo ? "本机演示 · 合成计时" : "裁判计时 / 局域网同步"}</span>{!snapshot.demo && <small className={snapshot.matchClock.syncError ? "is-error" : ""}>{snapshot.matchClock.syncError ?? "仅对局进行中扣血;准备与暂停时只闪灯"}</small>}</div>
<Readout clock={clock} names={snapshot.config.teamNames} />
<div className="match-control__actions">
{clock.phase === "idle" || clock.phase === "finished" ? <button className="btn btn--primary" disabled={busy} onClick={() => void run({ type: "prepare" })}>开始 3 分钟准备</button> : clock.phase === "ready" ? <div className="match-control__start"><label>开赛倒计时 <input aria-label="开赛倒计时秒数" type="number" min="1" max="60" step="1" value={seconds} onChange={e => setSeconds(Number(e.target.value))} /> 秒</label><button className="btn btn--primary" disabled={busy || !Number.isInteger(seconds) || seconds < 1 || seconds > 60} onClick={() => void run({ type: "countdown", seconds })}>确认开赛</button></div> : clock.phase === "paused" ? <button className="btn btn--primary" disabled={busy} onClick={() => void run({ type: "resume" })}>恢复{clock.resumePhase === "preparation" ? "准备" : clock.resumePhase === "ready" ? "待开赛阶段" : clock.resumePhase === "countdown" ? "倒计时" : "对局"}</button> : <span className="match-control__hint">{clock.phase === "preparation" ? "准备结束后等待裁判确认开赛" : clock.phase === "countdown" ? "请选手就位" : "计时到零结束本局"}</span>}
<div className="match-control__buttons"><button className="btn" disabled={busy || !active} onClick={() => openPause("player")}>选手暂停</button><button className="btn" disabled={busy || !active} onClick={() => openPause("official")}>官方暂停</button>{active || clock.phase === "paused" ? <button className="btn btn--quiet" disabled={busy} onClick={() => setDialog("end")}>结束本局</button> : clock.phase === "finished" && <button className="btn btn--quiet" disabled={busy} onClick={() => void run({ type: "reset" })}>清除计时</button>}</div>
</div>
{dialog && <Dialog title={dialog === "end" ? "结束本局计时" : dialog === "player" ? "选手技术暂停" : "官方技术暂停"} closeDisabled={busy} onClose={() => setDialog(null)} className="match-dialog">
{close => <div className="match-dialog__body">{dialog === "end" ? <><p>结束当前计时并同步到选手端,同时停止装甲板扣血。比赛结果由裁判判定。</p><button className="btn btn--primary" disabled={busy} onClick={() => void run({ type: "end" }, close)}>确认结束本局</button></> : <>
<p>{dialog === "player" ? "选手技术暂停为 5 分钟,须先获得主裁判批准。时间到后,等待裁判恢复比赛。" : "官方暂停显示已用时,由裁判手动恢复。规则页未规定固定时限。"}</p>
{dialog === "player" && <label>申请队伍<select value={team} onChange={e => setTeam(Number(e.target.value))}>{snapshot.config.teamNames.map((name, i) => <option key={i} value={i}>{name}</option>)}</select></label>}
<label>暂停原因<input data-initial-focus value={reason} onChange={e => setReason(e.target.value)} maxLength={192} placeholder="例如:图传中断,需要检查接线" /></label>
<small>最多 192 个 UTF-8 字节,约 64 个汉字。</small>
{dialog === "player" && <label className="match-dialog__approval"><input type="checkbox" checked={approved} onChange={e => setApproved(e.target.checked)} />已获得主裁判批准</label>}
<button className="btn btn--primary" disabled={busy || !reasonValid || (dialog === "player" && !approved)} onClick={() => void run(dialog === "player" ? { type: "pausePlayer", team, reason, approved } : { type: "pauseOfficial", reason }, close)}>开始{dialog === "player" ? "5 分钟暂停" : "官方暂停"}</button>
</>}</div>}
</Dialog>}
</section>;
}