Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions chros/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,10 @@ small {
background: #fff0d7;
color: #a67835;
}
.status-void {
background: #f3e3e1;
color: #a2564b;
}
.game-tabs {
display: flex;
border-bottom: 1px solid var(--line);
Expand Down
15 changes: 11 additions & 4 deletions chros/components/MatchEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use client';

import type { SendCommand } from '@/lib/control-types';
import { evaluateMatch, playerName } from '@chros/scoring';
import { matchResult, playerName } from '@chros/scoring';
import { type ControlState, type Match } from '@chros/shared';
import { MatchControls } from './matches/MatchControls';
export const statusLabels: Record<string, string> = {
pending: '未開始',
running: '対戦中',
finished: '確定',
replay: '再試合待ち',
void: '無効試合',
};

export default function MatchEditor({
Expand All @@ -20,7 +21,7 @@ export default function MatchEditor({
match: Match;
send: SendCommand;
}) {
const result = evaluateMatch(match, state.profile);
const result = matchResult(state, match);
return (
<div className="match-editor">
<div className="section-heading">
Expand All @@ -38,15 +39,21 @@ export default function MatchEditor({
再試合 {match.attempt - 1} 回目 · 以前の結果は無効として保管しています。
</div>
)}
{result.voided && (
<div className="notice warning">
棄権者を含むため無効試合です。どちらにも勝敗・得点を加算しません。
</div>
)}
{result.winnerId && (
<div className="result-summary">
<span className="result-trophy">↗</span>
<div>
<small>MATCH WINNER</small>
<strong>{playerName(state, result.winnerId)}</strong>
<span>
{result.decidedBy}で勝利 · 特殊P {result.a.special}–{result.b.special} / 合計得点{' '}
{result.a.points}–{result.b.points}
{result.forfeited
? `${result.decidedBy} · 次戦へ進出`
: `${result.decidedBy}で勝利 · 特殊P ${result.a.special}–${result.b.special} / 合計得点 ${result.a.points}–${result.b.points}`}
</span>
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions chros/components/board/Bracket.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { evaluateMatch, playerName } from '@chros/scoring';
import { matchResult, playerName } from '@chros/scoring';
import { BRACKET_MATCHES_PER_PAGE } from '@/lib/board-pages';
import { type ControlState } from '@chros/shared';

Expand Down Expand Up @@ -43,7 +43,7 @@ export function Bracket({
{matches
.filter((match) => match.round === round)
.map((match) => {
const result = evaluateMatch(match, state.profile);
const result = matchResult(state, match);
return (
<div className="bracket-match" key={match.id}>
<small>
Expand All @@ -54,7 +54,10 @@ export function Bracket({
const playerId = match[side];
const isWinner = result.winnerId === playerId && !!playerId;
const emptySlotLabel = match.bye ? '不戦枠' : '対戦者未定';
const pointsLabel = match.games.length ? result[side].points : '–';
let pointsLabel: string | number = match.games.length
? result[side].points
: '–';
if (result.absentSides.includes(side)) pointsLabel = '棄権';
return (
<div key={side} className={isWinner ? 'bracket-winner' : ''}>
<span>{playerId ? playerName(state, playerId) : emptySlotLabel}</span>
Expand Down
7 changes: 4 additions & 3 deletions chros/components/board/MatchScene.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { evaluateMatch, playerName } from '@chros/scoring';
import { matchResult, playerName, type MatchResult } from '@chros/scoring';
import { reasonLabels, type ControlState } from '@chros/shared';

import type { Match } from '@chros/shared';

function progressLabel(match: Match, result: ReturnType<typeof evaluateMatch>) {
function progressLabel(match: Match, result: MatchResult) {
if (result.voided) return '棄権により無効試合';
if (result.winnerId) return '試合確定';
if (result.tied) return '同点 · 再試合待ち';
if (match.games.length) return `第${match.games.length}戦 終了時点`;
Expand All @@ -17,7 +18,7 @@ function coolPlayerId(match: Match, gameNumber: 1 | 2) {
}

export function MatchScene({ state, match }: { state: ControlState; match: Match }) {
const result = evaluateMatch(match, state.profile);
const result = matchResult(state, match);
return (
<>
<div className="board-kicker">
Expand Down
6 changes: 2 additions & 4 deletions chros/components/board/OverviewScenes.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { boardPages, STANDINGS_ROWS_PER_CARD } from '@/lib/board-pages';
import { evaluateMatch } from '@chros/scoring';
import { matchResult } from '@chros/scoring';
import { phaseLabels, type ControlState } from '@chros/shared';

import { Bracket } from './Bracket';
import { StandingsTable } from './StandingsTable';

export function StandingsScene({ state }: { state: ControlState }) {
const qualifying = state.matches.filter((match) => match.stage === 'qualifying');
const completed = qualifying.filter(
(match) => evaluateMatch(match, state.profile).winnerId,
).length;
const completed = qualifying.filter((match) => matchResult(state, match).settled).length;
const pages = boardPages(state);
return (
<>
Expand Down
6 changes: 2 additions & 4 deletions chros/components/console/TournamentOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use client';

import { evaluateMatch } from '@chros/scoring';
import { matchResult } from '@chros/scoring';
import { phaseLabels, type ControlState } from '@chros/shared';

export function TournamentOverview({ state }: { state: ControlState }) {
const match = state.matches.find((candidate) => candidate.id === state.currentMatchId);
const qualifying = state.matches.filter((candidate) => candidate.stage === 'qualifying');
const finished = qualifying.filter(
(candidate) => evaluateMatch(candidate, state.profile).winnerId,
).length;
const finished = qualifying.filter((candidate) => matchResult(state, candidate).settled).length;
const progressPercent = qualifying.length ? (finished / qualifying.length) * 100 : 0;
return (
<div className="overview-strip">
Expand Down
17 changes: 9 additions & 8 deletions chros/components/management/FinalsSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FormEvent } from 'react';

import type { ControlProps } from '@/lib/control-types';
import { suggestedQualifiers } from '@/lib/tournament';
import { evaluateMatch, groupNames, standings } from '@chros/scoring';
import { groupNames, matchResult, standings, withdrawalOf } from '@chros/scoring';
import { useState } from 'react';
import { useConfirmation } from '../Confirmation';

Expand All @@ -13,8 +13,7 @@ export function FinalsSetup({ state, send }: ControlProps) {
const [justification, setJustification] = useState('');
const qualifying = state.matches.filter((match) => match.stage === 'qualifying');
const qualifyingComplete =
qualifying.length > 0 &&
qualifying.every((match) => evaluateMatch(match, state.profile).winnerId);
qualifying.length > 0 && qualifying.every((match) => matchResult(state, match).settled);
const hasTiedQualifiers = groupNames(state).some((group) =>
standings(state, group).some((row) => row.tied && row.rank <= state.advancePerGroup),
);
Expand Down Expand Up @@ -59,11 +58,13 @@ export function FinalsSetup({ state, send }: ControlProps) {
)
}
>
{state.players.map((player) => (
<option value={player.id} key={player.id}>
{player.group}組 · {player.name}
</option>
))}
{state.players
.filter((player) => !withdrawalOf(state, player.id))
.map((player) => (
<option value={player.id} key={player.id}>
{player.group}組 · {player.name}
</option>
))}
</select>
</label>
))}
Expand Down
30 changes: 18 additions & 12 deletions chros/components/management/Matches.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import type { ControlProps } from '@/lib/control-types';
import { evaluateMatch, groupNames, playerName } from '@chros/scoring';
import { groupNames, matchResult, playerName, withdrawalOf } from '@chros/scoring';
import { useState } from 'react';
import { Bracket, StandingsTable } from '../Board';
import MatchEditor, { statusLabels } from '../MatchEditor';
Expand Down Expand Up @@ -52,7 +52,7 @@ export function Matches({ state, send }: ControlProps) {
{state.matches
.filter((match) => filter === 'all' || match.stage === filter)
.map((match) => {
const result = evaluateMatch(match, state.profile);
const result = matchResult(state, match);
return (
<button
type="button"
Expand All @@ -67,16 +67,24 @@ export function Matches({ state, send }: ControlProps) {
</span>
</span>
<span className="match-row-players">
<strong>{playerName(state, match.a)}</strong>
<strong>
{playerName(state, match.a)}
{withdrawalOf(state, match.a) ? '(棄権)' : ''}
</strong>
<span>vs</span>
<strong>{match.bye ? '不戦枠' : playerName(state, match.b)}</strong>
<strong>
{match.bye ? '不戦枠' : playerName(state, match.b)}
{withdrawalOf(state, match.b) ? '(棄権)' : ''}
</strong>
</span>
<small>
{match.games.length
? `${match.games.length}/2戦記録 · 得点 ${result.a.points}–${result.b.points} · 特殊P ${result.a.special}–${result.b.special}`
: match.bye
? '次の試合へ進出'
: '先攻・後攻は未登録'}
{result.absentSides.length && !match.games.length
? result.decidedBy
: match.games.length
? `${match.games.length}/2戦記録 · 得点 ${result.a.points}–${result.b.points} · 特殊P ${result.a.special}–${result.b.special}`
: match.bye
? '次の試合へ進出'
: '先攻・後攻は未登録'}
{state.currentMatchId === match.id ? ' · 掲示対象' : ''}
</small>
</button>
Expand Down Expand Up @@ -135,9 +143,7 @@ export function Matches({ state, send }: ControlProps) {
</section>
) : (
<FinalsSetup
key={
state.matches.filter((match) => evaluateMatch(match, state.profile).winnerId).length
}
key={state.matches.filter((match) => matchResult(state, match).settled).length}
state={state}
send={send}
/>
Expand Down
82 changes: 81 additions & 1 deletion chros/components/management/Players.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FormEvent } from 'react';

import { clientId } from '@/lib/client-id';
import type { ControlProps } from '@/lib/control-types';
import { groupNames } from '@chros/scoring';
import { groupNames, withdrawalOf } from '@chros/scoring';
import type { Player } from '@chros/shared';
import { useState } from 'react';
import { useConfirmation } from '../Confirmation';
Expand All @@ -13,11 +13,38 @@ export function Players({ state, send }: ControlProps) {
const fresh = (): Player => ({ id: clientId(), name: '', affiliation: '', group: 'A' });
const [draft, setDraft] = useState<Player>(fresh);
const editing = state.players.some((player) => player.id === draft.id);
const [withdrawing, setWithdrawing] = useState<Player | null>(null);
const [withdrawReason, setWithdrawReason] = useState('');
const finalsExist = state.matches.some((match) => match.stage === 'finals');
const canWithdraw = (player: Player) =>
!finalsExist ||
state.matches.some(
(match) => match.stage === 'finals' && (match.a === player.id || match.b === player.id),
);
async function removePlayer(player: Player) {
if (await confirm(`${player.name}を参加者から削除しますか?`))
void send({ type: 'remove-player', playerId: player.id });
}

async function withdrawPlayer(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
if (!withdrawing) return;
const sent = await send({
type: 'withdraw-player',
playerId: withdrawing.id,
reason: withdrawReason,
});
if (sent) {
setWithdrawing(null);
setWithdrawReason('');
}
}

async function reinstatePlayer(player: Player) {
if (await confirm(`${player.name}の棄権を取り消し、記録済みの結果を有効に戻しますか?`))
void send({ type: 'reinstate-player', playerId: player.id });
}

async function createQualifyingMatches() {
if (
await confirm(
Expand Down Expand Up @@ -60,6 +87,9 @@ export function Players({ state, send }: ControlProps) {
<tr key={player.id}>
<td>
<strong>{player.name}</strong>
{withdrawalOf(state, player.id) && (
<span className="status status-void">棄権</span>
)}
</td>
<td>{player.affiliation || '–'}</td>
<td>
Expand All @@ -73,6 +103,26 @@ export function Players({ state, send }: ControlProps) {
>
編集
</button>
{!!state.matches.length &&
(withdrawalOf(state, player.id) ? (
<button
className="text-button"
type="button"
onClick={() => reinstatePlayer(player)}
>
棄権を取消
</button>
) : (
canWithdraw(player) && (
<button
className="text-button danger-text"
type="button"
onClick={() => setWithdrawing(player)}
>
棄権
</button>
)
))}
{!state.matches.length && (
<button
className="text-button danger-text"
Expand All @@ -94,6 +144,36 @@ export function Players({ state, send }: ControlProps) {
<small>グループをすべて「A」にすると、全員で総当たりになります。</small>
</div>
)}
{withdrawing && (
<div className="replay-area">
<form onSubmit={withdrawPlayer}>
<label>
{withdrawing.name}の棄権理由
<input
required
autoFocus
maxLength={300}
value={withdrawReason}
onChange={(event) => setWithdrawReason(event.target.value)}
placeholder="当日欠席、体調不良など"
/>
</label>
<p>
{finalsExist
? '未決着の本戦試合を相手の不戦勝にします。決着済みの試合と予選順位は変わりません。'
: 'この参加者を含む予選試合を、記録済みのものも含めてすべて無効試合にし、順位表から外します。'}
</p>
<div className="form-bottom">
<button className="text-button" type="button" onClick={() => setWithdrawing(null)}>
やめる
</button>
<button className="button danger" type="submit">
理由を記録して棄権にする
</button>
</div>
</form>
</div>
)}
<div className="panel-footer">
<p>
{state.matches.length
Expand Down
9 changes: 8 additions & 1 deletion chros/components/matches/MatchControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { FormEvent } from 'react';

import type { SendCommand } from '@/lib/control-types';
import { playerName } from '@chros/scoring';
import { matchResult, playerName } from '@chros/scoring';
import { type ControlState, type Match } from '@chros/shared';
import { useState } from 'react';
import GameForm from './GameForm';
Expand Down Expand Up @@ -39,6 +39,13 @@ export function MatchControls({
if (match.bye) {
return <p className="muted">不戦進出として次の試合へ反映済みです。</p>;
}
if (matchResult(state, match).absentSides.length) {
return (
<p className="muted">
棄権者を含むため、先攻登録と得点入力はできません。取り消す場合は「参加者」画面で操作してください。
</p>
);
}
if (!match.a || !match.b) {
return <div className="empty-state">前の試合の勝者が確定すると、対戦者が入ります。</div>;
}
Expand Down
Loading
Loading