feat(control): 添加选手 FPS 键鼠操作与 C3 用户 UART 输出
This commit is contained in:
43 files changed
+2389
-77
No files matched your search
@@ -28,7 +28,7 @@
|
||||
|
||||
import { DEFAULT_TEAM_NAMES } from "./format";
|
||||
import { previewMatch, previewMatchAction } from "./match-preview";
|
||||
import type { MatchAction } from "./types";
|
||||
import type { MatchAction, OperatorControlView, OperatorInput } from "./types";
|
||||
import type { StreamClient } from "./stream";
|
||||
import type {
|
||||
ConfigView,
|
||||
@@ -166,8 +166,28 @@ export async function previewInvoke<T>(command: string, args?: Record<string, un
|
||||
return value as T;
|
||||
}
|
||||
|
||||
let previewCapture = 0;
|
||||
let previewCaptureAt = 0;
|
||||
let previewInputSequence = 0;
|
||||
let previewOperator: OperatorControlView = { active: false, captureId: null, mode: null, reason: "预览 · 未发送真实操作" };
|
||||
|
||||
function handle(command: string, args: Record<string, unknown>): unknown {
|
||||
switch (command) {
|
||||
case "operator_start": {
|
||||
if (state.role !== "team") throw new Error("只有选手端可以开启操作");
|
||||
const mode = args.mode === "debug" ? "debug" : "match";
|
||||
previewInputSequence = 0;
|
||||
previewCaptureAt = performance.now();
|
||||
previewOperator = { active: true, captureId: ++previewCapture, mode, reason: "预览 · 合成输入,不发送到装甲板" };
|
||||
return previewCapture;
|
||||
}
|
||||
case "operator_input": {
|
||||
const input = args.input as OperatorInput;
|
||||
if (input.captureId !== previewOperator.captureId || input.sequence <= previewInputSequence) return;
|
||||
previewInputSequence = input.sequence;
|
||||
if (!input.active) previewOperator = { ...previewOperator, active: false, reason: "预览操作已停止" };
|
||||
return;
|
||||
}
|
||||
case "match_action": {
|
||||
if (state.role !== "referee") throw new Error("只有裁判端可以控制比赛计时");
|
||||
const action = args.action as MatchAction;
|
||||
@@ -320,6 +340,11 @@ function hex(id: number): string {
|
||||
}
|
||||
|
||||
function snapshot(): Snapshot {
|
||||
// 合成联动场景:显式开启调试后 3 秒切入倒数,检查自动释放输入。
|
||||
if (params.get("control") === "debug-to-countdown" && previewOperator.active && previewOperator.mode === "debug"
|
||||
&& performance.now() - previewCaptureAt > 3000 && ["idle", "preparation", "ready"].includes(previewMatch().phase)) {
|
||||
previewMatchAction({ type: "countdown", seconds: 10 });
|
||||
}
|
||||
finishPreviewKnockout();
|
||||
const cameraOffline = videoOffline();
|
||||
const cameras = [
|
||||
@@ -408,6 +433,7 @@ function snapshot(): Snapshot {
|
||||
mirrored: state.mirror,
|
||||
mirroredVertical: state.mirrorVertical,
|
||||
matchClock: previewMatch(),
|
||||
operatorControl: { ...previewOperator },
|
||||
demo: true,
|
||||
diagnostics: true,
|
||||
unlocked: state.unlocked || state.role === "referee",
|
||||
|
||||
Reference in new issue
Block a user