feat(match): 添加画面上下镜像、跳过准备和装甲板整局复位

This commit is contained in:
sloray committed 2026-10-31 09:27:26 +08:00
1 parent 235fb1c73b
commit 338efa5c2e
39 files changed
+1094 -54

No files matched your search

+18 -3
View File
@@ -113,11 +113,13 @@ interface PreviewState {
/** 两边显示的名字,与后端配置里的 `teamNames` 对应。 */
teamNames: [string, string];
mirror: boolean;
mirrorVertical: boolean;
unlocked: boolean;
password: string | null;
calibrating: boolean;
recordings: { camera: number; frames: number; startedMs: number }[];
hp: [number, number];
matchControlled: boolean;
}
const state: PreviewState = {
@@ -128,13 +130,16 @@ const state: PreviewState = {
team: 0,
teamNames: wideLayoutPreview ? ["用户端长队名布局验证一队", "用户端长队名布局验证二队"] : ["队伍一", "队伍二"],
mirror: true,
mirrorVertical: false,
// 预览里直接是已解锁状态,免得每次刷新都要输密码。
unlocked: false,
password: "1234",
calibrating: false,
recordings: [],
hp: [100, 100],
matchControlled: new URLSearchParams(location.search).has("match"),
};
if (new URLSearchParams(location.search).get("match") === "finished") state.hp = [0, 76];
// ---------------------------------------------------------------------------
// 假的命令实现
@@ -148,10 +153,14 @@ export async function previewInvoke<T>(command: string, args?: Record<string, un
function handle(command: string, args: Record<string, unknown>): unknown {
switch (command) {
case "match_action":
case "match_action": {
if (state.role !== "referee") throw new Error("只有裁判端可以控制比赛计时");
previewMatchAction(args.action as MatchAction);
const action = args.action as MatchAction;
previewMatchAction(action);
state.matchControlled = true;
if (action.type === "reset") state.hp = [100, 100];
return;
}
case "release_match_source": return;
case "stream_info":
return { url: "preview://", port: 0, clients: 1 };
@@ -201,6 +210,9 @@ function handle(command: string, args: Record<string, unknown>): unknown {
case "set_mirror":
state.mirror = Boolean(args.mirror);
return configView();
case "set_mirror_vertical":
state.mirrorVertical = Boolean(args.mirrorVertical);
return configView();
case "save_hud":
state.hud = args.hud as HudView;
return configView();
@@ -258,6 +270,7 @@ function configView(): ConfigView {
armorId: state.armorId,
armorIdText: state.armorId === null ? null : hex(state.armorId),
mirror: state.mirror,
mirrorVertical: state.mirrorVertical,
passwordSet: needsPassword ? false : state.password !== null,
hud: structuredClone(state.hud),
recordingDir: "/预览模式/recordings",
@@ -374,6 +387,7 @@ function snapshot(): Snapshot {
role: state.role,
team: state.team,
mirrored: state.mirror,
mirroredVertical: state.mirrorVertical,
matchClock: previewMatch(),
demo: true,
diagnostics: true,
@@ -453,11 +467,12 @@ export function startPreview(client: StreamClient, emit: (msg: WireMsg) => void)
let tick = 0;
const hitTimer = window.setInterval(() => {
if (offlinePreview) return;
if (state.matchControlled && previewMatch().phase !== "running") return;
tick += 1;
const team = tick % 2;
if (state.hp[team] === 0) {
state.hp[team] = 100;
if (!state.matchControlled) state.hp[team] = 100;
return;
}