Skip to content

Commit 93f9495

Browse files
committed
add key: ctrl
1 parent ac98e0a commit 93f9495

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
+ 鼠标单击或按 Enter 进行下一步。
1919
+ 按 p 切换自动运行模式。
2020
+ 按 + 和 - 增减速度因子
21+
+ 按 ctrl 以较大步长改变速度因子
2122

2223
## 开发
2324

src/app/Board.css

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@
1212
box-shadow: 0 5px 12px 4px rgba(0, 0, 0, 0.09), 0 -5px 12px 4px rgba(0, 0, 0, 0.09);
1313
transition: box-shadow 0.2s ease-out;
1414
}
15+
16+
.info-message{
17+
margin-top: 80vh;
18+
}

src/app/Board.tsx

+30-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React, { useState, useEffect, useCallback, useRef, useMemo, CSSProperties
88
import FlipMove from "react-flip-move";
99
import { StickyContainer, Sticky } from "react-sticky";
1010
import { Transition } from "react-transition-group";
11-
import { Tooltip } from "antd";
11+
import { Tooltip, message } from "antd";
1212

1313
function cvtColor(state: vo.ProblemStateKind): string | undefined {
1414
if (state === vo.ProblemStateKind.Passed) {
@@ -23,6 +23,10 @@ function cvtColor(state: vo.ProblemStateKind): string | undefined {
2323
return undefined;
2424
}
2525

26+
function messageInfo(content: string): void {
27+
void message.info({ content, className: "info-message", duration: 0.4 });
28+
}
29+
2630
interface BoardProps {
2731
data: dto.Contest;
2832
options: vo.BoardOptions;
@@ -70,12 +74,12 @@ const Board: React.FC<BoardProps> = ({ data, options }: BoardProps) => {
7074
setHighlightItem(value);
7175

7276
let delay;
73-
delay = options.shiningBeforeReveal ? 1200 : (autoReveal ? 400 : 0);
77+
delay = options.shiningBeforeReveal ? 600 : (autoReveal ? 200 : 0);
7478
console.log("delay", delay / speedFactor);
7579
await util.delay(delay / speedFactor); // wait for shining
7680
handleNextStep();
7781

78-
delay = autoReveal ? (value.accepted ? 800 : 300) : (0);
82+
delay = autoReveal ? (value.accepted ? 500 : 200) : (0);
7983
console.log("delay", delay / speedFactor);
8084
await util.delay(delay / speedFactor); // wait for showing result
8185

@@ -85,7 +89,7 @@ const Board: React.FC<BoardProps> = ({ data, options }: BoardProps) => {
8589
const curRank = team?.rank;
8690

8791
if (prevRank !== curRank) {
88-
delay = 2000;
92+
delay = vo.FLIP_MOVE_DURATION;
8993
console.log("delay", delay / speedFactor);
9094
await util.delay(delay / speedFactor); // wait for moving up
9195
}
@@ -148,28 +152,36 @@ const Board: React.FC<BoardProps> = ({ data, options }: BoardProps) => {
148152
handleNextStep();
149153
}
150154
if (e.key === "p") {
151-
setAutoReveal(a => {
152-
if (a) {
153-
console.log("disable autoReveal");
154-
} else {
155-
console.log("enable autoReveal");
156-
}
157-
return !a;
158-
});
155+
if (autoReveal) {
156+
console.log("disable autoReveal");
157+
messageInfo("禁用自动运行");
158+
} else {
159+
console.log("enable autoReveal");
160+
messageInfo("启用自动运行");
161+
}
162+
setAutoReveal(a => !a);
159163
}
160164
if (e.key === "+") {
161-
const s = speedFactor + 0.1;
162-
if (s > 10) { return; }
165+
const s = Math.min(speedFactor + 0.1, vo.MAX_SPEED_FACTOR);
163166
setSpeedFactor(s);
164167
console.log("speedFactor", s);
168+
messageInfo(`速度因子:${s.toFixed(1)}`);
165169
}
166170
if (e.key === "-") {
167-
const s = speedFactor - 0.1;
168-
if (s < 0.1) { return; }
171+
const s = Math.max(speedFactor - 0.1, vo.MIN_SPEED_FACTOR);
172+
setSpeedFactor(s);
173+
console.log("speedFactor", s);
174+
messageInfo(`速度因子:${s.toFixed(1)}`);
175+
}
176+
if (e.key === "Control") {
177+
let s = speedFactor + 3;
178+
if (s > vo.MAX_SPEED_FACTOR) { s -= vo.MAX_SPEED_FACTOR; }
179+
if (s < vo.MIN_SPEED_FACTOR) { s = vo.MIN_SPEED_FACTOR; }
169180
setSpeedFactor(s);
170181
console.log("speedFactor", s);
182+
messageInfo(`速度因子:${s.toFixed(1)}`);
171183
}
172-
}, [handleNextStep, keyLock, speedFactor, state.cursor]);
184+
}, [handleNextStep, keyLock, speedFactor, state.cursor, autoReveal]);
173185

174186
useEffect(() => {
175187
document.addEventListener("keydown", handleKeydown);
@@ -299,7 +311,7 @@ const Board: React.FC<BoardProps> = ({ data, options }: BoardProps) => {
299311
textAlign: "center",
300312
transformStyle: "preserve-3d"
301313
}}
302-
duration={2000 / speedFactor}
314+
duration={vo.FLIP_MOVE_DURATION / speedFactor}
303315
onFinish={handleMovingFinished}
304316
>
305317

src/app/Loader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const Loader: React.FC<LoaderProps> = ({ onLoad, onStart }: LoaderProps) => {
168168
<Switch />
169169
</Form.Item>
170170
<Form.Item name="speedFactor" label="速度因子">
171-
<InputNumber min={0.1} max={10} step={0.1} />
171+
<InputNumber min={vo.MIN_SPEED_FACTOR} max={vo.MAX_SPEED_FACTOR} step={0.1} />
172172
</Form.Item>
173173
{data.medal === undefined ? null : (
174174
<Form.Item name="showMedal" label="显示奖牌" valuePropName="checked">

src/app/vo.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,9 @@ export interface BoardOptions {
195195
shiningBeforeReveal: boolean;
196196
speedFactor: number;
197197
showMedal: boolean;
198-
}
198+
}
199+
200+
export const MIN_SPEED_FACTOR = 0.1;
201+
export const MAX_SPEED_FACTOR = 10;
202+
203+
export const FLIP_MOVE_DURATION = 800;

0 commit comments

Comments
 (0)