|
|
|
|
@@ -181,6 +181,7 @@ function Seats({ v, me, players, live }: { v: TypingView; me: string | null; pla
|
|
|
|
|
const surv = v.options.mode === 'survival';
|
|
|
|
|
const lives = surv && v.options.elimination === 'wrong';
|
|
|
|
|
const unit = v.options.mode === 'first' ? '점' : '승';
|
|
|
|
|
const practice = v.options.mode === 'practice';
|
|
|
|
|
return (
|
|
|
|
|
<ul className="ty-seats" aria-label="참가자">
|
|
|
|
|
{v.seats.map((s) => {
|
|
|
|
|
@@ -197,8 +198,7 @@ function Seats({ v, me, players, live }: { v: TypingView; me: string | null; pla
|
|
|
|
|
{tag && <span className="small muted"> · {tag}</span>}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="sc">
|
|
|
|
|
{lives && s.alive && <Hearts n={s.lives} max={v.options.lives} />} {s.points}
|
|
|
|
|
{unit}
|
|
|
|
|
{lives && s.alive && <Hearts n={s.lives} max={v.options.lives} />} {practice ? `${s.roundKpm}타` : `${s.points}${unit}`}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="ty-bar" role="progressbar" aria-label={`${nick(players, s.id)} 진행`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(bar * 100)}>
|
|
|
|
|
<i data-s={state} style={{ width: `${Math.round(bar * 100)}%` }} />
|
|
|
|
|
@@ -269,8 +269,10 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
const laneDone = !shared && v.total !== null && myIdx >= v.total;
|
|
|
|
|
const canType = !!mine && mine.alive && !mine.left && v.phase === 'playing' && !!item && !(shared && mine.solved) && !(!shared && (mine.finished || laneDone));
|
|
|
|
|
const itemKey = `${v.round}:${myIdx}`;
|
|
|
|
|
const practice = v.options.mode === 'practice';
|
|
|
|
|
// When the current item's clock started (연습: at its first key, 0 = not yet).
|
|
|
|
|
const startedAt = useRef<{ key: string; at: number }>({ key: '', at: 0 });
|
|
|
|
|
if (startedAt.current.key !== itemKey && item) startedAt.current = { key: itemKey, at: shared ? Math.max(v.curAt, now) : now };
|
|
|
|
|
if (startedAt.current.key !== itemKey && item) startedAt.current = { key: itemKey, at: practice ? 0 : shared ? Math.max(v.curAt, now) : now };
|
|
|
|
|
|
|
|
|
|
// A new item: empty box, focus on it.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
@@ -390,11 +392,14 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const ck = item ? correctKeys(item.text, typed) : 0;
|
|
|
|
|
const elapsed = item ? Math.max(0, now - startedAt.current.at) : 0;
|
|
|
|
|
const elapsed = item && startedAt.current.at ? Math.max(0, now - startedAt.current.at) : 0;
|
|
|
|
|
const curKpm = typed && elapsed > 500 ? kpm(ck, elapsed) : 0;
|
|
|
|
|
const langWarn = typed.length >= 2 && wrongLang(v.options.lang, typed);
|
|
|
|
|
const surv = v.options.mode === 'survival';
|
|
|
|
|
const roundLabel = `라운드 ${v.round}/${v.options.rounds}`;
|
|
|
|
|
const roundLabel = practice ? null : `라운드 ${v.round}/${v.options.rounds}`;
|
|
|
|
|
// 연습: how long I have been at it (like 한컴 타자연습's 경과 시간).
|
|
|
|
|
const spent = practice && v.phase === 'playing' && mine && !mine.finished && !laneDone ? Math.max(0, now - v.roundStartedAt) : null;
|
|
|
|
|
const progressPct = v.total ? Math.round((Math.min(myIdx, v.total) / v.total) * 100) : 0;
|
|
|
|
|
const itemLabel = shared ? (v.total ? `${Math.min(v.cur + 1, v.total)}/${v.total}번째` : `${v.cur + 1}번째`) : v.total ? `${Math.min(myIdx + 1, v.total)}/${v.total}줄` : `${myIdx + 1}번째 줄`;
|
|
|
|
|
const lastRound = v.rounds.at(-1);
|
|
|
|
|
const alive = v.seats.filter((s) => s.alive).length;
|
|
|
|
|
@@ -412,7 +417,7 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
<div className="ty">
|
|
|
|
|
<style>{CSS}</style>
|
|
|
|
|
<div className="ty-top">
|
|
|
|
|
<span className="ty-pill">{roundLabel}</span>
|
|
|
|
|
{roundLabel && <span className="ty-pill">{roundLabel}</span>}
|
|
|
|
|
<span className="ty-pill">{MODE_KO[v.options.mode]}</span>
|
|
|
|
|
{v.phase === 'playing' && <span className="ty-pill">{itemLabel}</span>}
|
|
|
|
|
{surv && v.phase === 'playing' && <span className="ty-pill">남은 사람 {alive}명</span>}
|
|
|
|
|
@@ -421,6 +426,11 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
⏱ {surv && !shared ? `탈락까지 ${clock(left)}` : clock(left)}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{spent !== null && (
|
|
|
|
|
<span className="ty-pill" aria-label={`걸린 시간 ${clock(spent)}`}>
|
|
|
|
|
⏱ {clock(spent)}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="ty-card">
|
|
|
|
|
{v.passage && (
|
|
|
|
|
@@ -447,7 +457,9 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
) : (
|
|
|
|
|
<div className="ty-target" style={{ color: 'var(--text-sub)', fontSize: '1.15rem' }}>
|
|
|
|
|
{v.phase === 'ended'
|
|
|
|
|
? '게임 끝!'
|
|
|
|
|
? practice
|
|
|
|
|
? '연습 끝!'
|
|
|
|
|
: '게임 끝!'
|
|
|
|
|
: v.phase === 'countdown'
|
|
|
|
|
? '곧 시작해요!'
|
|
|
|
|
: gap
|
|
|
|
|
@@ -496,6 +508,7 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const t = e.target.value;
|
|
|
|
|
if (t.length > typed.length && !composing.current) tySound.key();
|
|
|
|
|
if (practice && !startedAt.current.at && normalize(t)) startedAt.current.at = socket.now();
|
|
|
|
|
setTyped(t);
|
|
|
|
|
sendProgress(t);
|
|
|
|
|
}}
|
|
|
|
|
@@ -525,7 +538,26 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
{note.text}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{mine && v.phase === 'playing' && (
|
|
|
|
|
{mine && v.phase === 'playing' && practice && (
|
|
|
|
|
<div className="ty-stats">
|
|
|
|
|
<span>지금 {curKpm}타</span>
|
|
|
|
|
<span>평균 {mine.roundKpm}타</span>
|
|
|
|
|
<span>최고 {mine.bestKpm}타</span>
|
|
|
|
|
<span>정확도 {mine.roundTried ? `${mine.roundAcc}%` : '-'}</span>
|
|
|
|
|
<span>진행 {progressPct}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{mine && v.phase === 'ended' && practice && (
|
|
|
|
|
<div className="ty-stats" role="status" style={{ fontSize: '1.05rem' }}>
|
|
|
|
|
<span>평균 {mine.roundKpm}타</span>
|
|
|
|
|
<span>최고 {mine.bestKpm}타</span>
|
|
|
|
|
<span>정확도 {mine.roundTried ? `${mine.roundAcc}%` : '-'}</span>
|
|
|
|
|
<span>
|
|
|
|
|
{mine.done}줄 중 틀린 줄 {mine.wrong}개
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{mine && v.phase === 'playing' && !practice && (
|
|
|
|
|
<div className="ty-stats">
|
|
|
|
|
<span>지금 {curKpm}타</span>
|
|
|
|
|
<span>이번 라운드 {mine.roundKpm}타</span>
|
|
|
|
|
@@ -538,7 +570,7 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
<div className="ty-over" aria-hidden>
|
|
|
|
|
<b key={countdown}>{countdown}</b>
|
|
|
|
|
<small>
|
|
|
|
|
{v.round > 1 ? `라운드 ${v.round} · ` : ''}
|
|
|
|
|
{v.round > 1 && !practice ? `라운드 ${v.round} · ` : ''}
|
|
|
|
|
{CATEGORY_KO[v.options.category]} · {MODE_KO[v.options.mode]}
|
|
|
|
|
</small>
|
|
|
|
|
</div>
|
|
|
|
|
@@ -563,6 +595,7 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
|
|
|
|
|
function TypingSide({ view: v, players }: BoardProps<TypingView>) {
|
|
|
|
|
const rows = [...v.seats].sort((a, b) => Number(a.left) - Number(b.left) || b.points - a.points || b.kpm - a.kpm);
|
|
|
|
|
const unit = v.options.mode === 'first' ? '점' : '승';
|
|
|
|
|
const practice = v.options.mode === 'practice';
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="card stack" style={{ gap: 6, padding: 12 }}>
|
|
|
|
|
@@ -580,10 +613,12 @@ function TypingSide({ view: v, players }: BoardProps<TypingView>) {
|
|
|
|
|
<span className="small muted" style={{ fontVariantNumeric: 'tabular-nums' }}>
|
|
|
|
|
{s.kpm}타 · {s.tried ? `${s.acc}%` : '-'}
|
|
|
|
|
</span>
|
|
|
|
|
<strong style={{ fontVariantNumeric: 'tabular-nums' }}>
|
|
|
|
|
{s.points}
|
|
|
|
|
{unit}
|
|
|
|
|
</strong>
|
|
|
|
|
{!practice && (
|
|
|
|
|
<strong style={{ fontVariantNumeric: 'tabular-nums' }}>
|
|
|
|
|
{s.points}
|
|
|
|
|
{unit}
|
|
|
|
|
</strong>
|
|
|
|
|
)}
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ol>
|
|
|
|
|
@@ -595,7 +630,7 @@ function TypingSide({ view: v, players }: BoardProps<TypingView>) {
|
|
|
|
|
{v.rounds.map((r) => (
|
|
|
|
|
<div key={r.round} className="stack" style={{ gap: 4 }}>
|
|
|
|
|
<span className="small" style={{ fontWeight: 700 }}>
|
|
|
|
|
라운드 {r.round} · {r.winners.length ? r.winners.map((w) => nick(players, w)).join(', ') : '승자 없음'}
|
|
|
|
|
{practice ? '연습 기록' : `라운드 ${r.round} · ${r.winners.length ? r.winners.map((w) => nick(players, w)).join(', ') : '승자 없음'}`}
|
|
|
|
|
</span>
|
|
|
|
|
<RoundTable r={r} players={players} mode={v.options.mode} />
|
|
|
|
|
</div>
|
|
|
|
|
@@ -612,8 +647,7 @@ function TypingSide({ view: v, players }: BoardProps<TypingView>) {
|
|
|
|
|
{r.rank}등 {nick(players, r.id)}
|
|
|
|
|
<span className="muted small">
|
|
|
|
|
{' '}
|
|
|
|
|
· {r.points}
|
|
|
|
|
{unit} · 평균 {r.kpm}타 · 정확도 {r.acc}%{r.left ? ' · 나감' : ''}
|
|
|
|
|
· {practice ? '' : `${r.points}${unit} · `}평균 {r.kpm}타 · 정확도 {r.acc}%{r.left ? ' · 나감' : ''}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
))}
|
|
|
|
|
@@ -635,10 +669,10 @@ function isMyTurn(v: TypingView, me: string | null): boolean {
|
|
|
|
|
|
|
|
|
|
function statusText(v: TypingView, me: string | null, players: Record<string, PublicUser>): string {
|
|
|
|
|
if (v.phase === 'ended') return v.result?.summary ?? '게임이 끝났어요';
|
|
|
|
|
if (v.phase === 'countdown') return `라운드 ${v.round} 곧 시작! 나오는 글을 그대로 쳐요`;
|
|
|
|
|
if (v.phase === 'countdown') return `${v.options.mode === 'practice' ? '연습' : `라운드 ${v.round}`} 곧 시작! 나오는 글을 그대로 쳐요`;
|
|
|
|
|
if (v.phase === 'roundEnd') return v.rounds.at(-1)?.summary ?? '라운드 끝';
|
|
|
|
|
const s = v.seats.find((x) => x.id === me);
|
|
|
|
|
if (!s) return `${MODE_KO[v.options.mode]} · 라운드 ${v.round}/${v.options.rounds}`;
|
|
|
|
|
if (!s) return v.options.mode === 'practice' ? MODE_KO.practice : `${MODE_KO[v.options.mode]} · 라운드 ${v.round}/${v.options.rounds}`;
|
|
|
|
|
if (s.left) return '게임에서 나갔어요';
|
|
|
|
|
if (!s.alive) return '탈락했어요 · 다음 라운드를 기다려요';
|
|
|
|
|
if (v.flow === 'shared') {
|
|
|
|
|
@@ -647,7 +681,7 @@ function statusText(v: TypingView, me: string | null, players: Record<string, Pu
|
|
|
|
|
return v.options.mode === 'first' ? '가장 먼저 정확하게 치면 1점!' : '제한 시간 안에 정확하게 쳐요!';
|
|
|
|
|
}
|
|
|
|
|
if (s.finished) return '다 쳤어요! 다른 사람을 기다려요';
|
|
|
|
|
return v.options.mode === 'timeAttack' ? '시간 안에 최대한 많이 쳐요!' : '한 줄씩 치고 Enter!';
|
|
|
|
|
return v.options.mode === 'timeAttack' ? '시간 안에 최대한 많이 쳐요!' : v.options.mode === 'practice' ? '한 줄씩 치고 Enter! 천천히 정확하게 연습해요' : '한 줄씩 치고 Enter!';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------- options
|
|
|
|
|
@@ -670,6 +704,7 @@ const MODE_HELP: Record<Mode, string> = {
|
|
|
|
|
speed: '각자 자기 속도로 글을 치고, 라운드의 타수(1분에 친 타 수, 오타는 빼고)가 가장 높은 사람이 1점이에요.',
|
|
|
|
|
accuracy: '각자 글을 치고, 정확도가 가장 높은 사람이 1점이에요. 정확도가 같으면 타수가 높은 사람이 이겨요.',
|
|
|
|
|
timeAttack: '정해진 시간 동안 끝없이 나오는 글을 쳐요. 정확하게 친 타 수가 가장 많은 사람이 1점이에요.',
|
|
|
|
|
practice: '한컴 타자연습처럼 혼자(또는 함께) 제 속도로 연습해요. 제한 시간과 점수 없이 짧은글은 10문장, 단어는 20개, 긴글은 한 편을 처음부터 끝까지 쳐요. 문장마다 첫 글자를 친 때부터 타수를 재요.',
|
|
|
|
|
};
|
|
|
|
|
const ELIM_HELP: Record<Elim, string> = {
|
|
|
|
|
wrong: '틀린 채로 Enter를 누르거나 시간 안에 못 치면 목숨이 하나 줄고, 목숨을 다 쓰면 탈락해요.',
|
|
|
|
|
@@ -688,7 +723,8 @@ function Options({ value: o, onChange }: OptionsProps<TypingOptions>) {
|
|
|
|
|
set({ topics: [...others, ...next] });
|
|
|
|
|
};
|
|
|
|
|
const timeLabel = o.mode === 'speed' || o.mode === 'accuracy' ? '라운드 제한 시간' : '한 문제 제한 시간';
|
|
|
|
|
const showTime = o.mode !== 'timeAttack' && !(o.mode === 'survival' && o.elimination === 'interval');
|
|
|
|
|
const practice = o.mode === 'practice';
|
|
|
|
|
const showTime = o.mode !== 'timeAttack' && !practice && !(o.mode === 'survival' && o.elimination === 'interval');
|
|
|
|
|
return (
|
|
|
|
|
<div className="stack" style={{ gap: 16 }}>
|
|
|
|
|
<div className="stack" style={{ gap: 6 }}>
|
|
|
|
|
@@ -720,8 +756,8 @@ function Options({ value: o, onChange }: OptionsProps<TypingOptions>) {
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="stack" style={{ gap: 6 }}>
|
|
|
|
|
<strong>대결 종목</strong>
|
|
|
|
|
<Seg label="대결 종목" value={o.category} options={(['word', 'short', 'long'] as Category[]).map((c) => [c, CATEGORY_KO[c]])} onChange={(category) => set({ category })} />
|
|
|
|
|
<strong>{practice ? '연습 종목' : '대결 종목'}</strong>
|
|
|
|
|
<Seg label={practice ? '연습 종목' : '대결 종목'} value={o.category} options={(['word', 'short', 'long'] as Category[]).map((c) => [c, CATEGORY_KO[c]])} onChange={(category) => set({ category })} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="stack" style={{ gap: 6 }}>
|
|
|
|
|
<strong>주제 (여러 개 고를 수 있어요)</strong>
|
|
|
|
|
@@ -737,13 +773,15 @@ function Options({ value: o, onChange }: OptionsProps<TypingOptions>) {
|
|
|
|
|
</div>
|
|
|
|
|
<span className="small muted">
|
|
|
|
|
{picked.length === 0 ? `전체 ${topics.length}개 주제에서 골고루 나와요.` : `${picked.map((id) => topics.find((t) => t.id === id)?.name).join(', ')}에서 나와요.`}
|
|
|
|
|
{o.category === 'long' ? ' 긴글은 라운드마다 한 단락(8줄 안팎)씩 이어서 쳐요.' : ''}
|
|
|
|
|
{o.category === 'long' ? (practice ? ' 연습은 그중 한 편을 처음부터 끝까지 쳐요.' : ' 긴글은 라운드마다 한 단락(8줄 안팎)씩 이어서 쳐요.') : ''}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="stack" style={{ gap: 6 }}>
|
|
|
|
|
<strong>라운드</strong>
|
|
|
|
|
<Seg label="라운드" value={o.rounds} options={Array.from({ length: 10 }, (_, i) => [i + 1, `${i + 1}`] as [number, string])} onChange={(rounds) => set({ rounds })} />
|
|
|
|
|
</div>
|
|
|
|
|
{!practice && (
|
|
|
|
|
<div className="stack" style={{ gap: 6 }}>
|
|
|
|
|
<strong>라운드</strong>
|
|
|
|
|
<Seg label="라운드" value={o.rounds} options={Array.from({ length: 10 }, (_, i) => [i + 1, `${i + 1}`] as [number, string])} onChange={(rounds) => set({ rounds })} />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{showTime && (
|
|
|
|
|
<div className="stack" style={{ gap: 6 }}>
|
|
|
|
|
<strong>{timeLabel}</strong>
|
|
|
|
|
@@ -778,7 +816,7 @@ function optionsSummary(o: TypingOptions): string {
|
|
|
|
|
const topics = topicsFor(o.lang, o.category);
|
|
|
|
|
const picked = topics.filter((t) => o.topics.includes(t.id)).map((t) => t.name);
|
|
|
|
|
const sub = o.mode === 'survival' ? `(${ELIM_KO[o.elimination].replace(/\(.*\)/, '')}${o.elimination === 'wrong' ? ` · 목숨 ${o.lives}` : ''})` : '';
|
|
|
|
|
return `${LANG_KO[o.lang]} · ${MODE_KO[o.mode]}${sub} · ${CATEGORY_KO[o.category]}(${picked.length ? picked.join(', ') : '전체 주제'}) · ${o.rounds}라운드`;
|
|
|
|
|
return `${LANG_KO[o.lang]} · ${MODE_KO[o.mode]}${sub} · ${CATEGORY_KO[o.category]}(${picked.length ? picked.join(', ') : '전체 주제'})${o.mode === 'practice' ? '' : ` · ${o.rounds}라운드`}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------- rules
|
|
|
|
|
@@ -808,6 +846,9 @@ function Rules({ options: o }: { options?: TypingOptions }) {
|
|
|
|
|
<li>
|
|
|
|
|
<strong>타임어택</strong>: 정해진 시간 동안 끝없이 나오는 글을 쳐서, 정확하게 친 타 수가 가장 많은 사람이 1점.
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<strong>연습</strong>: 한컴 타자연습처럼 제한 시간·점수 없이 제 속도로 쳐요. 짧은글 10문장, 단어 20개, 긴글은 한 편 전체. 지금·평균·최고 타수, 정확도, 진행률과 걸린 시간을 보여 줘요.
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p>
|
|
|
|
|
라운드는 1~10번(기본 3번)이에요. 모두 끝나면 점수가 가장 높은 사람이 이기고, 같으면 평균 타수가 높은 사람이 앞서요. 한국어·영어, 단어·짧은글·긴글과 주제(여러 개)를 방 설정에서 골라요. 혼자서도, 컴퓨터와도 할 수
|
|
|
|
|
|