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
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# direnv (https://direnv.net) を使う場合はこのファイルを `direnv allow` する。
# nix-direnv を入れておくと devShell がキャッシュされて高速になる。
use flake
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ packages/scoring/ スコア計算の純粋ロジック(I/O を持たない)
## 環境構築

Node.js 22以降とpnpmで起動できます。今回の試作はファイル保存のためDBを必要としません。
### Nix

[Nix](https://nixos.org/download/) と flakes が有効なら、`nix develop` で
Node 22 / pnpm 9.12.0 / PostgreSQL クライアント 17 / OpenSSL が揃ったシェルに入れます。
ツールを用意するだけなので、以降の手順は下の「Docker」「素の pnpm」と同じです。

pnpm は `package.json` の `packageManager` と同じバージョンを固定しています。
更新する場合は [nix/pnpm.nix](./nix/pnpm.nix) 冒頭の手順を参照してください。

[direnv](https://direnv.net) を入れている場合は `direnv allow` でディレクトリに入るだけで
シェルが有効になります(`.envrc` 同梱)。

### Docker

リポジトリのルートで `docker compose up -d` を実行してください。
`app` (Next.js, :3000) と `db` (PostgreSQL 17, :5432) が立ち上がります。

### 素の pnpm

```sh
pnpm install
Expand All @@ -41,4 +59,4 @@ Dockerでは `docker compose up -d --build` でアプリと永続化用volumeを

Viewer は `GET /api/stream` の SSE を購読します。接続直後に全状態のスナップショットが
1件届き、以降も保存のたびに最新の全状態が流れます。WebSocketは使用しません。
これは掲示状態の即時反映であり、試合の得点入力は各戦終了後に行います。
これは掲示状態の即時反映であり、試合のスコア入力は各戦終了後に行います。
162 changes: 137 additions & 25 deletions chros/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,107 @@ small {
.full-width {
width: 100%;
}
.choice-group > legend {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
padding: 0;
margin-bottom: 9px;
font-size: 12px;
font-weight: 600;
}
.choice-clear {
margin-left: auto;
padding: 2px 4px;
font-size: 10px;
white-space: nowrap;
}
.choice-group > legend small {
margin-left: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 400;
}
.choice-options {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
gap: 8px;
}
.choice-sections {
display: grid;
gap: 8px;
}
.choice-sections > .choice-options:not(:only-child) {
grid-auto-flow: column;
grid-auto-columns: minmax(0, 1fr);
grid-template-columns: none;
}
.choice {
position: relative;
align-items: center;
justify-content: center;
gap: 2px;
min-height: 43px;
padding: 8px 12px;
border: 1px solid #d8e0d8;
border-radius: 7px;
background: white;
text-align: center;
cursor: pointer;
transition: background 0.15s;
}
.choice:hover {
background: #f0f5ec;
}
.choice.selected {
border-color: #8cab5d;
background: #edf5df;
box-shadow: 0 0 0 1px #8cab5d;
}
.choice strong {
font-size: 12px;
font-weight: 650;
line-height: 1.3;
}
.choice small {
font-size: 9px;
}
.choice-icon {
width: 25px;
height: 25px;
color: #6c8a5f;
}
.choice.selected .choice-icon {
color: #5a7a36;
}
.choice-group:disabled .choice,
.choice-group:disabled .choice:hover {
background: white;
opacity: 0.5;
cursor: not-allowed;
}
.choice input,
.scene-button input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
min-height: 0;
margin: 0;
padding: 0;
border: 0;
border-radius: inherit;
background: none;
opacity: 0;
appearance: none;
cursor: pointer;
}
.choice:has(input:focus-visible),
.scene-button:has(input:focus-visible) {
outline: 3px solid #64b7ad;
outline-offset: 3px;
}
.text-button {
font-size: 11px;
color: var(--green);
Expand Down Expand Up @@ -527,31 +628,24 @@ small {
font-size: 9px;
}
.scene-controls {
display: flex;
flex-direction: column;
gap: 16px;
padding: 17px 20px 20px;
border-top: 1px solid var(--line);
}
.scene-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
gap: 10px;
}
.scene-toolbar > b {
font-size: 11px;
}
.scene-toolbar label {
flex-direction: row;
align-items: center;
gap: 8px;
.scene-toolbar > small {
color: var(--muted);
font-size: 10px;
font-weight: 400;
}
.scene-toolbar select {
min-height: 30px;
padding: 4px 7px;
font-size: 10px;
width: 105px;
}
.scene-grid {
display: grid;
Expand All @@ -560,6 +654,7 @@ small {
}
.scene-button {
position: relative;
cursor: pointer;
border: 1px solid #e0e7db;
background: #fcfdfb;
border-radius: 6px;
Expand Down Expand Up @@ -831,6 +926,9 @@ small {
flex-direction: column;
gap: 17px;
}
.game-form .notice {
margin-bottom: 0;
}
.game-form-top {
display: flex;
justify-content: space-between;
Expand All @@ -849,23 +947,31 @@ small {
gap: 15px;
}
.score-input {
background: #f2f7f2;
border: 1px solid #dfe9dc;
border: 1px solid var(--line);
border-radius: 7px;
padding: 14px;
gap: 9px;
}
.score-input-b {
background: #fcf4ee;
border-color: #eee2d9;
.score-input-cool {
background: #eef4fb;
border-color: #d2e0f0;
}
.score-input-hot {
background: #fdf2ef;
border-color: #f0d7d0;
}
.side-badge {
color: #518a81;
color: var(--muted);
font-size: 8px;
letter-spacing: 1px;
}
.score-input-b .side-badge {
color: #b58268;
.score-input-cool .side-badge,
.side-badge-cool {
color: #2f6099;
}
.score-input-hot .side-badge,
.side-badge-hot {
color: #b0453a;
}
.score-input strong {
font-size: 13px;
Expand Down Expand Up @@ -931,18 +1037,18 @@ small {
.replay-area {
border-top: 1px solid var(--line);
margin-top: 22px;
padding-top: 10px;
}
.replay-area > .text-button {
font-size: 10px;
color: #929d88;
padding-top: 16px;
}
.replay-area form {
display: flex;
flex-direction: column;
align-items: stretch;
gap: 12px;
padding-top: 10px;
}
.replay-area form > .button {
align-self: flex-end;
}
.replay-area p {
color: #947457;
font-size: 11px;
Expand Down Expand Up @@ -2149,6 +2255,12 @@ small {
.game-tabs {
gap: 13px;
}
.choice-sections > .choice-options:not(:only-child) .choice {
padding: 8px 6px;
}
.choice-sections > .choice-options:not(:only-child) .choice strong {
font-size: 11px;
}
.score-input {
padding: 12px;
}
Expand Down
2 changes: 1 addition & 1 deletion chros/components/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function Board({ state }: { state: ControlState }) {
? 'SAMPLE TOURNAMENT · 架空の参加者によるデモ'
: 'CHASER PROGRESSION CONTROL SYSTEM'}
</span>
<span>得点は各戦の終了後に更新</span>
<span>スコアは各戦の終了後に更新</span>
<b>CHroS / {String(state.revision).padStart(3, '0')}</b>
</div>
</div>
Expand Down
78 changes: 78 additions & 0 deletions chros/components/ChoiceGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use client';

import type { ReactNode } from 'react';

export type Choice<Value extends string> = {
value: Value;
label: string;
icon?: ReactNode;
note?: ReactNode;
};

type Common<Value extends string> = {
legend: ReactNode;
name: string;
selected: Value | null;
required?: boolean;
disabled?: boolean;
onSelect: (value: Value) => void;
onClear?: () => void;
};
type Grouping<Value extends string> =
| { choices: readonly Choice<Value>[]; sections?: never }
| { sections: readonly (readonly Choice<Value>[])[]; choices?: never };

export default function ChoiceGroup<Value extends string>({
legend,
name,
selected,
required = false,
disabled = false,
onSelect,
onClear,
...grouping
}: Common<Value> & Grouping<Value>) {
const sections = grouping.sections ?? [grouping.choices ?? []];
return (
<fieldset className="choice-group" disabled={disabled}>
<legend>
<span>{legend}</span>
{onClear && (
<button
type="button"
className="text-button choice-clear"
disabled={selected === null}
onClick={onClear}
>
選択を解除
</button>
)}
</legend>
<div className="choice-sections">
{sections.map((section) => (
<div className="choice-options" key={section.map((choice) => choice.value).join('-')}>
{section.map((choice) => (
<label
className={`choice ${choice.value === selected ? 'selected' : ''}`}
key={choice.value}
>
<input
type="radio"
name={name}
value={choice.value}
required={required}
checked={choice.value === selected}
onChange={() => onSelect(choice.value)}
onClick={() => choice.value === selected && onClear?.()}
/>
{choice.icon}
{choice.note}
<strong>{choice.label}</strong>
</label>
))}
</div>
))}
</div>
</fieldset>
);
}
2 changes: 1 addition & 1 deletion chros/components/MatchEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function MatchEditor({
<small>MATCH WINNER</small>
<strong>{playerName(state, result.winnerId)}</strong>
<span>
{result.decidedBy}で勝利 · 特殊P {result.a.special}–{result.b.special} / 合計得点{' '}
{result.decidedBy}で勝利 · 特殊P {result.a.special}–{result.b.special} / 合計スコア{' '}
{result.a.points}–{result.b.points}
</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion chros/components/board/MatchScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function MatchScene({ state, match }: { state: ControlState; match: Match
<div className="competitor-score">
<strong>{match.games.length ? result[side].points : '–'}</strong>
<div>
<span>{state.profile === 'asahikawa' ? '換算得点' : '合計得点'}</span>
<span>{state.profile === 'asahikawa' ? '換算スコア' : '合計スコア'}</span>
<b>
{state.profile === 'kushiro'
? `特殊P ${result[side].special}`
Expand Down
2 changes: 1 addition & 1 deletion chros/components/board/StandingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function StandingsTable({
<th>参加者</th>
<th>勝–敗</th>
<th>特殊P</th>
<th>{state.profile === 'asahikawa' ? '換算得点' : '得点'}</th>
<th>{state.profile === 'asahikawa' ? '換算スコア' : 'スコア'}</th>
</tr>
</thead>
<tbody>
Expand Down
Loading
Loading