feat(match): 添加画面上下镜像、跳过准备和装甲板整局复位
This commit is contained in:
39 files changed
+1094
-54
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ export const api = {
|
||||
setRole: (role: Role, password?: string) =>
|
||||
call<ConfigView>("set_role", { role, password: password ?? null }),
|
||||
setMirror: (mirror: boolean) => call<ConfigView>("set_mirror", { mirror }),
|
||||
setMirrorVertical: (mirrorVertical: boolean) => call<ConfigView>("set_mirror_vertical", { mirrorVertical }),
|
||||
saveHud: (hud: HudView) => call<ConfigView>("save_hud", { hud }),
|
||||
/** 改一边的队名(0 = 队伍一,1 = 队伍二)。一次只改一边,避免覆盖另一边的改动。 */
|
||||
setTeamName: (team: number, name: string, password?: string) =>
|
||||
|
||||
@@ -31,6 +31,9 @@ export function previewMatchAction(action: MatchAction) {
|
||||
previewMatch();
|
||||
switch (action.type) {
|
||||
case "prepare": view = { ...blank(), phase: "preparation", remainingMs: 180_000 }; break;
|
||||
case "skipPreparation":
|
||||
if (view.phase !== "preparation" && view.phase !== "ready") throw new Error("当前阶段不能跳过准备");
|
||||
view.phase = "ready"; view.remainingMs = 0; break;
|
||||
case "countdown": view.phase = "countdown"; view.remainingMs = action.seconds * 1000; break;
|
||||
case "pausePlayer":
|
||||
if (!action.approved) throw new Error("选手技术暂停须经主裁判批准");
|
||||
|
||||
@@ -58,7 +58,7 @@ export function computeLayout(
|
||||
/**
|
||||
* 瞄准点的屏幕位置。
|
||||
*
|
||||
* 图像坐标系里的 `(0.5 + offsetX, 0.5 + offsetY)` 再换到屏幕。镜像时横向要翻过来,
|
||||
* 图像坐标系里的 `(0.5 + offsetX, 0.5 + offsetY)` 再换到屏幕。镜像时对应轴要翻过来,
|
||||
* 否则准星会站在画面的另一边——偏移量是相对**摄像头光轴**定的,光轴在镜像之后换了位置。
|
||||
*/
|
||||
export function aimPoint(
|
||||
@@ -67,15 +67,17 @@ export function aimPoint(
|
||||
mirrored: boolean,
|
||||
canvasWidth: number,
|
||||
canvasHeight: number,
|
||||
mirroredVertical = false,
|
||||
): { x: number; y: number } {
|
||||
if (!crosshair || geometry.drawWidth <= 0) {
|
||||
return { x: canvasWidth / 2, y: canvasHeight / 2 };
|
||||
}
|
||||
|
||||
const rawX = geometry.left + (0.5 + crosshair.offsetX) * geometry.drawWidth;
|
||||
const rawY = geometry.top + (0.5 + crosshair.offsetY) * geometry.drawHeight;
|
||||
return {
|
||||
x: mirrored ? canvasWidth - rawX : rawX,
|
||||
y: geometry.top + (0.5 + crosshair.offsetY) * geometry.drawHeight,
|
||||
y: mirroredVertical ? canvasHeight - rawY : rawY,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,9 @@ function handleMessage(msg: WireMsg) {
|
||||
return; // Consumed by StreamClient before reaching application state.
|
||||
case "snapshot": {
|
||||
const { t: _tag, ...snapshot } = msg;
|
||||
emit({ snapshot: snapshot as Snapshot });
|
||||
const reset = snapshot.matchClock.phase === "idle" && (store.snapshot?.matchClock.phase !== "idle"
|
||||
|| store.snapshot?.health.some(health => health.outcome != null));
|
||||
emit({ snapshot: snapshot as Snapshot, ...(reset ? { lastHit: null } : {}) });
|
||||
return;
|
||||
}
|
||||
case "hit":
|
||||
|
||||
@@ -89,6 +89,7 @@ export interface ConfigView {
|
||||
armorId: number | null;
|
||||
armorIdText: string | null;
|
||||
mirror: boolean;
|
||||
mirrorVertical: boolean;
|
||||
passwordSet: boolean;
|
||||
hud: HudView;
|
||||
recordingDir: string;
|
||||
@@ -210,6 +211,7 @@ export interface Snapshot {
|
||||
role: Role;
|
||||
team: number;
|
||||
mirrored: boolean;
|
||||
mirroredVertical: boolean;
|
||||
demo: boolean;
|
||||
diagnostics: boolean;
|
||||
unlocked: boolean;
|
||||
@@ -242,7 +244,7 @@ export interface MatchClockView {
|
||||
source: string | null;
|
||||
syncError: string | null;
|
||||
}
|
||||
export type MatchAction = { type: "prepare" | "resume" | "end" | "reset" }
|
||||
export type MatchAction = { type: "prepare" | "skipPreparation" | "resume" | "end" | "reset" }
|
||||
| { type: "countdown"; seconds: number }
|
||||
| { type: "pausePlayer"; team: number; reason: string; approved: boolean }
|
||||
| { type: "pauseOfficial"; reason: string };
|
||||
|
||||
Reference in new issue
Block a user