feat(match): 添加画面上下镜像、跳过准备和装甲板整局复位
This commit is contained in:
39 files changed
+1094
-54
No files matched your search
@@ -19,12 +19,13 @@ function load(path, overrides) {
|
||||
}
|
||||
|
||||
const format = { teamColor: team => team === 0 ? "red" : "blue", teamName: team => `队伍${team}`, idText: String, firmwareLabel: () => "测试固件" };
|
||||
const icon = { Icon: () => null };
|
||||
const healthModule = load("../src/components/HealthBar.tsx", { "../lib/format": format });
|
||||
const videoModule = load("../src/components/VideoSurface.tsx", { "../lib/store": {}, "../lib/reticle": {} });
|
||||
const videoModule = load("../src/components/VideoSurface.tsx", { "../lib/store": {}, "../lib/reticle": {}, "./Icon": icon });
|
||||
let connected = true;
|
||||
const matchTime = load("../src/lib/match-time.ts", {});
|
||||
const matchModule = load("../src/components/MatchClock.tsx", {
|
||||
"./Dialog": {}, "../lib/ipc": {},
|
||||
"./Dialog": {}, "./Icon": icon, "../lib/ipc": {},
|
||||
"../lib/store": { useAppStore: () => ({ connected }) },
|
||||
"../lib/match-time": matchTime,
|
||||
});
|
||||
@@ -141,3 +142,35 @@ test("an armor outage alone does not gray the live video", () => {
|
||||
value.armorBoards[0].online = false;
|
||||
assert.doesNotMatch(renderTeam(value), /vsurface--signal-lost|vsurface__signal-mask/);
|
||||
});
|
||||
|
||||
const renderControl = (phase, health = []) => renderToStaticMarkup(createElement(matchModule.RefereeMatchControl, {
|
||||
snapshot: { ...snapshot(), config: { teamNames: ["红队", "蓝队"] }, matchClock: { ...snapshot().matchClock, phase }, health },
|
||||
onError() {},
|
||||
}));
|
||||
|
||||
test("skip preparation is available only while preparing and ready still requires confirmation", () => {
|
||||
assert.match(renderControl("preparation"), /跳过准备倒计时/);
|
||||
for (const phase of ["idle", "ready", "countdown", "running", "paused", "finished"]) {
|
||||
assert.doesNotMatch(renderControl(phase), /跳过准备倒计时/);
|
||||
}
|
||||
assert.match(renderControl("ready"), /确认开赛/);
|
||||
});
|
||||
|
||||
test("a verdict exposes one-click reset even before the clock finishes, while ongoing play cannot reset", () => {
|
||||
assert.doesNotMatch(renderControl("running"), /重置到未开始/);
|
||||
assert.match(renderControl("finished"), /重置到未开始/);
|
||||
const verdict = renderControl("running", [{ outcome: "defeat" }, { outcome: "victory" }]);
|
||||
assert.match(verdict, /重置到未开始/);
|
||||
assert.doesNotMatch(verdict, /开始 3 分钟准备|结束本局/);
|
||||
});
|
||||
|
||||
test("the operator feed reports horizontal and vertical mirroring independently", () => {
|
||||
const value = snapshot();
|
||||
value.mirrored = true;
|
||||
assert.match(renderTeam(value), /左右镜像/);
|
||||
assert.doesNotMatch(renderTeam(value), /上下镜像/);
|
||||
value.mirrored = false;
|
||||
value.mirroredVertical = true;
|
||||
assert.match(renderTeam(value), /上下镜像/);
|
||||
assert.doesNotMatch(renderTeam(value), /左右镜像/);
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import ts from "typescript";
|
||||
|
||||
const exports = {};
|
||||
new Function("exports", ts.transpileModule(readFileSync(new URL("../src/lib/reticle.ts", import.meta.url), "utf8"), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
|
||||
}).outputText)(exports);
|
||||
const { aimPoint, computeLayout } = exports;
|
||||
|
||||
test("calibrated aim follows the same image point through all four mirror combinations", () => {
|
||||
const geometry = computeLayout({ clientWidth: 800, clientHeight: 600 }, 640, 480, { zoom: 2, x: 40, y: -30 });
|
||||
const crosshair = { offsetX: 0.1, offsetY: -0.2 };
|
||||
for (const horizontal of [false, true]) {
|
||||
for (const vertical of [false, true]) {
|
||||
const aim = aimPoint(geometry, crosshair, horizontal, 800, 600, vertical);
|
||||
assert.equal(aim.x, horizontal ? 200 : 600);
|
||||
assert.equal(aim.y, vertical ? 570 : 30);
|
||||
// 校准时向右下拖动 16/12 像素,镜像不改变屏幕上的移动方向。
|
||||
const moved = aimPoint(geometry, {
|
||||
offsetX: crosshair.offsetX + (horizontal ? -16 : 16) / geometry.drawWidth,
|
||||
offsetY: crosshair.offsetY + (vertical ? -12 : 12) / geometry.drawHeight,
|
||||
}, horizontal, 800, 600, vertical);
|
||||
assert.ok(Math.abs(moved.x - aim.x - 16) < 1e-9);
|
||||
assert.ok(Math.abs(moved.y - aim.y - 12) < 1e-9);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("missing frames keep the aim centered regardless of mirror or offsets", () => {
|
||||
const empty = computeLayout({ clientWidth: 800, clientHeight: 600 }, 0, 0, { zoom: 2, x: 40, y: -30 });
|
||||
assert.deepEqual(aimPoint(empty, { offsetX: 0.2, offsetY: -0.1 }, true, 800, 600, true), { x: 400, y: 300 });
|
||||
});
|
||||
Reference in new issue
Block a user