- 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 页面、倒计时和随包中文字体。 未执行烧录、板上运行、跨电脑广播或硬件稳定性验证。
188 lines
5.6 KiB
TypeScript
188 lines
5.6 KiB
TypeScript
/**
|
|
* 画面上的叠加图形:瞄准器、网格,以及"图像落在哪"的那一道换算。
|
|
*
|
|
* # 为什么单独拆出来
|
|
*
|
|
* 这三段代码现在有两个使用者:`VideoSurface` 里的真画面,和设置面板里的小预览窗。预览窗
|
|
* 存在的意义就是"改完立刻看见",如果它另写一套绘制,两边迟早会不一样——而出现差异时,
|
|
* 用户看到的是预览里对、画面上偏,这比没有预览更糟。
|
|
*
|
|
* 所以这里只放**纯函数**:给 ctx 和数字,画完就退出。不碰 React、不碰请求、不认识 store。
|
|
*/
|
|
|
|
import type { CrosshairConfig, GridConfig } from "./types";
|
|
|
|
/** 图像在窗格里的落点与大小(CSS 像素)。 */
|
|
export interface Geometry {
|
|
left: number;
|
|
top: number;
|
|
drawWidth: number;
|
|
drawHeight: number;
|
|
}
|
|
|
|
export interface Box {
|
|
clientWidth: number;
|
|
clientHeight: number;
|
|
}
|
|
|
|
/**
|
|
* 把一帧按 `contain` 放进窗格,再乘缩放。
|
|
*
|
|
* 平移是**屏幕像素**而不是画面比例:拖动时手感必须是 1:1 的,否则放大之后拖动会变黏。
|
|
*/
|
|
export function computeLayout(
|
|
box: Box,
|
|
frameWidth: number,
|
|
frameHeight: number,
|
|
view: { zoom: number; x: number; y: number },
|
|
): Geometry {
|
|
const width = box.clientWidth;
|
|
const height = box.clientHeight;
|
|
|
|
if (frameWidth <= 0 || frameHeight <= 0) {
|
|
return { left: 0, top: 0, drawWidth: 0, drawHeight: 0 };
|
|
}
|
|
|
|
const fit = Math.min(width / frameWidth, height / frameHeight);
|
|
const drawWidth = frameWidth * fit * view.zoom;
|
|
const drawHeight = frameHeight * fit * view.zoom;
|
|
|
|
return {
|
|
left: (width - drawWidth) / 2 + view.x,
|
|
top: (height - drawHeight) / 2 + view.y,
|
|
drawWidth,
|
|
drawHeight,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 瞄准点的屏幕位置。
|
|
*
|
|
* 图像坐标系里的 `(0.5 + offsetX, 0.5 + offsetY)` 再换到屏幕。镜像时横向要翻过来,
|
|
* 否则准星会站在画面的另一边——偏移量是相对**摄像头光轴**定的,光轴在镜像之后换了位置。
|
|
*/
|
|
export function aimPoint(
|
|
geometry: Geometry,
|
|
crosshair: CrosshairConfig | null,
|
|
mirrored: boolean,
|
|
canvasWidth: number,
|
|
canvasHeight: number,
|
|
): { 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;
|
|
return {
|
|
x: mirrored ? canvasWidth - rawX : rawX,
|
|
y: geometry.top + (0.5 + crosshair.offsetY) * geometry.drawHeight,
|
|
};
|
|
}
|
|
|
|
/** 画网格。网格画在**图像矩形**里:它标的是画面里的比例,用来估距离。 */
|
|
export function paintGrid(
|
|
ctx: CanvasRenderingContext2D,
|
|
geometry: Geometry,
|
|
grid: GridConfig,
|
|
): void {
|
|
if (geometry.drawWidth <= 0 || geometry.drawHeight <= 0) return;
|
|
|
|
ctx.save();
|
|
ctx.strokeStyle = `rgba(255, 255, 255, ${grid.opacity})`;
|
|
ctx.lineWidth = 1;
|
|
|
|
const x0 = geometry.left;
|
|
const y0 = geometry.top;
|
|
const x1 = x0 + geometry.drawWidth;
|
|
const y1 = y0 + geometry.drawHeight;
|
|
|
|
if (grid.style === "thirds") {
|
|
for (const fraction of [1 / 3, 2 / 3]) {
|
|
line(ctx, x0 + geometry.drawWidth * fraction, y0, x0 + geometry.drawWidth * fraction, y1);
|
|
line(ctx, x0, y0 + geometry.drawHeight * fraction, x1, y0 + geometry.drawHeight * fraction);
|
|
}
|
|
} else if (grid.style === "squares") {
|
|
const divisions = Math.max(2, grid.divisions);
|
|
for (let i = 1; i < divisions; i += 1) {
|
|
const fraction = i / divisions;
|
|
line(ctx, x0 + geometry.drawWidth * fraction, y0, x0 + geometry.drawWidth * fraction, y1);
|
|
line(ctx, x0, y0 + geometry.drawHeight * fraction, x1, y0 + geometry.drawHeight * fraction);
|
|
}
|
|
} else {
|
|
line(ctx, x0 + geometry.drawWidth / 2, y0, x0 + geometry.drawWidth / 2, y1);
|
|
line(ctx, x0, y0 + geometry.drawHeight / 2, x1, y0 + geometry.drawHeight / 2);
|
|
}
|
|
|
|
ctx.restore();
|
|
}
|
|
|
|
/**
|
|
* 画瞄准器。
|
|
*
|
|
* 两遍描边:先一圈半透明的深色(光环),再画本体。浅色背景下亮绿准星会消失,这一圈让
|
|
* 它在任何画面上都看得见——这是可读性要求,不是装饰。
|
|
*/
|
|
export function paintCrosshair(
|
|
ctx: CanvasRenderingContext2D,
|
|
cx: number,
|
|
cy: number,
|
|
shortSide: number,
|
|
config: CrosshairConfig,
|
|
): void {
|
|
const arm = Math.max(3, config.size * shortSide);
|
|
const gap = config.gap * shortSide;
|
|
const thickness = Math.max(1, config.thickness * shortSide);
|
|
|
|
const stroke = (color: string, width: number, radius: number) => {
|
|
ctx.strokeStyle = color;
|
|
ctx.lineWidth = width;
|
|
ctx.beginPath();
|
|
|
|
if (config.style === "circle-dot") {
|
|
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
|
|
} else {
|
|
ctx.moveTo(cx - radius, cy);
|
|
ctx.lineTo(cx - gap, cy);
|
|
ctx.moveTo(cx + gap, cy);
|
|
ctx.lineTo(cx + radius, cy);
|
|
ctx.moveTo(cx, cy - radius);
|
|
ctx.lineTo(cx, cy - gap);
|
|
ctx.moveTo(cx, cy + gap);
|
|
ctx.lineTo(cx, cy + radius);
|
|
}
|
|
|
|
ctx.stroke();
|
|
};
|
|
|
|
stroke("rgba(0, 0, 0, 0.55)", thickness + 2, arm + 1);
|
|
stroke(config.color, thickness, arm);
|
|
|
|
if (config.style !== "cross") {
|
|
const dot = Math.max(1.2, thickness * 0.9);
|
|
|
|
ctx.fillStyle = "rgba(0, 0, 0, 0.55)";
|
|
ctx.beginPath();
|
|
ctx.arc(cx, cy, dot + 1, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
|
|
ctx.fillStyle = config.color;
|
|
ctx.beginPath();
|
|
ctx.arc(cx, cy, dot, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
}
|
|
}
|
|
|
|
/** 半像素偏移,让 1px 的线落在像素中心而不是跨两个像素发虚。 */
|
|
function line(
|
|
ctx: CanvasRenderingContext2D,
|
|
x0: number,
|
|
y0: number,
|
|
x1: number,
|
|
y1: number,
|
|
): void {
|
|
ctx.beginPath();
|
|
ctx.moveTo(Math.round(x0) + 0.5, Math.round(y0) + 0.5);
|
|
ctx.lineTo(Math.round(x1) + 0.5, Math.round(y1) + 0.5);
|
|
ctx.stroke();
|
|
}
|