Files
test/src/features/broadcast/director/broadcastDirectorSlice.ts
T
DeepSeek Harness 9528307820 feat: 中文界面、键盘控制、车手名单、名次脚本与 OBS 输出
- 键盘控制:数字按名次选车、方向键移动光标、出/收字幕、圈数 +/-、计时器、
  名次脚本、快捷键总表;在输入框里打字时不触发,每次按键都有 Toast 反馈
- 车手名单编辑器(E):姓名/缩写/车号/国籍/车队/性能/黄T摄/头像均可改,
  支持调整发车顺位、单条重置、全部重置、JSON 导入导出,localStorage 持久化
- LAP 可手动 +/-,LAP 旁新增 mm:ss.mmm 计时器(零点=计时榜出现的瞬间)
- 名次脚本(J):JSON 预设,以计时器为零点,支持 swap/move/retire/restore/lap 与 order
  * 改脚本即时生效并从零重播,修掉"改完之后过期事件被一次性爆发"的问题
  * order 立即铺回赛道;写错会在状态条里报出具体原因,不再静默失败
  * localStorage 持久化,刷新不再丢失
- 合并 feature/standalone-output:OBS 透明输出页 /output 与 WebSocket 中继 server/relayServer.js
  * 修复中继晚连接的输出页只能收到最后一片补丁(缓存改为合并累加)
- 修复 react-spring 缺少 deps 导致进场动画被每次渲染重启
  (chyron、百叶窗、wipe、计时塔名次描边)
- 界面中文化(上屏的转播图形保持英文),F1 字体栈补 CJK 回退
- 新增「启动开发服务器.cmd」一键启动,.gitignore 排除本地工具目录
2026-10-20 21:26:50 +08:00

89 lines
3.0 KiB
TypeScript

import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { ChyronSettings, RootState, GridSpot } from "../../../types/state";
import { Optional } from "../../../types/util";
const initialState: RootState["broadcastDirector"] = {
selectedCars: [],
cursorGridSpot: null,
chyronSettings: {
mode: "driver",
subMode: "medium",
flagMode: "country",
showPosFlag: true,
showDriverNumber: true,
showPortrait: false,
},
};
export const broadcastDirectorSlice = createSlice({
name: "broadcastDirector",
initialState,
reducers: {
pushSelectedCars: (state, action: PayloadAction<GridSpot>) => {
if (!state.selectedCars.includes(action.payload)) {
state.selectedCars.push(action.payload);
}
},
setSelectedCars: (state, action: PayloadAction<GridSpot>) => { // Might be removed.
state.selectedCars = [action.payload];
},
removeSelectedCars: (state, action: PayloadAction<GridSpot>) => {
state.selectedCars = state.selectedCars.filter(grid => grid !== action.payload);
},
/**
* Shortcut to clear out selected cars. There is also a trick - if you
* provide a single Car it'll replace all selected cars with that single
* car.
* @param action Car (optional)
*/
clearSelectedCars: (state, action: PayloadAction<Optional<GridSpot>>) => {
if (action.payload == null) {
state.selectedCars = [];
} else {
state.selectedCars = [action.payload];
}
},
/** Replaces the whole selection in one go. Used by the keyboard layer. */
replaceSelectedCars: (state, action: PayloadAction<GridSpot[]>) => {
state.selectedCars = action.payload.filter(
(spot, index) => action.payload.indexOf(spot) === index,
);
},
/** Adds or removes a single car from the selection. Capped at two cars. */
toggleSelectedCar: (state, action: PayloadAction<GridSpot>) => {
const existing = state.selectedCars.indexOf(action.payload);
if (existing !== -1) {
state.selectedCars.splice(existing, 1);
} else {
state.selectedCars.push(action.payload);
if (state.selectedCars.length > 2) {
state.selectedCars.splice(0, state.selectedCars.length - 2);
}
}
},
/**
* Parks the keyboard cursor. Kept apart from the selection so the cursor
* can be moved around the running order without wiping a built selection.
*/
setCursorGridSpot: (state, action: PayloadAction<Optional<GridSpot>>) => {
state.cursorGridSpot = action.payload;
},
updateChyronSettings: (state, action: PayloadAction<Partial<ChyronSettings>>) => {
state.chyronSettings = { ...state.chyronSettings, ...action.payload };
},
},
});
export const {
pushSelectedCars,
setSelectedCars,
removeSelectedCars,
clearSelectedCars,
replaceSelectedCars,
toggleSelectedCar,
setCursorGridSpot,
updateChyronSettings,
} = broadcastDirectorSlice.actions;
export default broadcastDirectorSlice.reducer;