web: zadávání z telefonu a zápisník na notebooku
Flask, server-rendered HTML, formuláře přes POST/redirect/GET. Žádný build step, žádný JS framework. - / zakládá hru výběrem známých hráčů v pořadí u stolu - /game/<id> je zadávací pohled: kdo je na tahu, skóre, x/xx, průběžné pořadí, vrácení posledního zápisu - /board/<id> je zápisník po kolech; tahy před vynulováním se škrtnou červeně, sloupec hráče na tahu drží zvýrazňovač - tabule se doptává serveru každé dvě vteřiny a vyměňuje jen hlavičku a zápisník, QR s adresou zůstává mimo obnovovanou část - adresa pro telefon se hledá za běhu, QR se skládá ze čtverečků přímo do SVG, takže není potřeba Pillow - 16 funkčních testů přes Flask test client Vizuálně to stojí na tom, co appka nahrazuje: čtverečkovaný papír, modrá propiska zapisuje, červená škrtá, zvýrazňovač drží tah. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a45a82ae0e
commit
bcbbede258
11 files changed
+1149
No files matched your search
@@ -0,0 +1,3 @@
|
||||
<p class="eyebrow">Zápisník · hra {{ game_id }}</p>
|
||||
<h1>{% if winner %}Konec hry{% else %}Na tahu {{ current }}{% endif %}</h1>
|
||||
<p class="meta">do {{ game.final_score|cislo }} bodů · kolo {{ game.round_number }}</p>
|
||||
@@ -0,0 +1,3 @@
|
||||
{# Fragment pro tabuli: obě části, které se během hry mění. #}
|
||||
<div id="head">{% include "_head.html" %}</div>
|
||||
<div id="sheet">{% include "_sheet.html" %}</div>
|
||||
@@ -0,0 +1,57 @@
|
||||
{% if winner %}
|
||||
<div class="win">
|
||||
<p class="eyebrow">Konec hry</p>
|
||||
<h2>{{ winner }}</h2>
|
||||
<p>Vyhrává s {{ totals[winner]|cislo }} body z cílových {{ game.final_score|cislo }}.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="sheet-wrap">
|
||||
<table class="sheet">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="label">Kolo</th>
|
||||
{% for name in game.names %}
|
||||
<th class="{{ 'marked' if name == current }}">{{ name }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in rows %}
|
||||
<tr>
|
||||
<td class="label">{{ row.round }}</td>
|
||||
{% for cell in row.cells %}
|
||||
<td class="{{ 'marked' if game.names[loop.index0] == current }}
|
||||
{{ 'struck' if cell.struck }} {{ 'wiped' if cell.reset }}">
|
||||
{%- if cell.value is none -%}
|
||||
<span class="empty">·</span>
|
||||
{%- elif cell.reset -%}
|
||||
0<small>vynulováno</small>
|
||||
{%- else -%}
|
||||
{{ cell.value|cislo }}
|
||||
{%- endif -%}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td class="label">1</td>
|
||||
{% for name in game.names %}
|
||||
<td class="{{ 'marked' if name == current }}"><span class="empty">·</span></td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td class="label">Celkem</td>
|
||||
{% for name in game.names %}
|
||||
<td class="{{ 'marked' if name == current }}">
|
||||
{{ totals[name]|cislo }}
|
||||
{%- if streaks[name] %} <span class="ticks">{{ '✕' * streaks[name] }}</span>{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="cs">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}Kostky{% endblock %}</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
{% block body %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,37 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Zápisník — hra {{ game_id }}{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="board">
|
||||
<header class="masthead">
|
||||
<div id="head">{% include "_head.html" %}</div>
|
||||
<div class="join">
|
||||
{{ qr }}
|
||||
<p class="address"><span>Zapisuje se z telefonu</span>{{ address }}</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div id="sheet">{% include "_sheet.html" %}</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Tabule se doptává serveru; není co udržovat na klientovi.
|
||||
// QR kód a adresa se needitují, takže zůstávají mimo obnovovanou část.
|
||||
const url = "{{ url_for('board_panel', game_id=game_id) }}";
|
||||
|
||||
setInterval(async () => {
|
||||
try {
|
||||
const response = await fetch(url, { cache: "no-store" });
|
||||
if (!response.ok) return;
|
||||
|
||||
const fresh = new DOMParser().parseFromString(await response.text(), "text/html");
|
||||
for (const id of ["head", "sheet"]) {
|
||||
const updated = fresh.getElementById(id);
|
||||
if (updated) document.getElementById(id).replaceWith(updated);
|
||||
}
|
||||
} catch (error) {
|
||||
// Server je pryč — zkusíme to za dvě vteřiny znovu.
|
||||
}
|
||||
}, 2000);
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,14 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Zápisník{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="board idle">
|
||||
<p class="eyebrow">Zápisník</p>
|
||||
<h1>Zatím se nehraje</h1>
|
||||
<p class="hint">Naskenuj kód telefonem a založ hru.</p>
|
||||
<div class="join">
|
||||
{{ qr }}
|
||||
<p class="address"><span>Adresa počitadla</span>{{ address }}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,78 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{% if winner %}Konec hry{% else %}Na tahu {{ game.current_player }}{% endif %}{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="phone">
|
||||
<header class="masthead">
|
||||
<div>
|
||||
<p class="eyebrow">Hra {{ game_id }}</p>
|
||||
<h1>Kostky</h1>
|
||||
</div>
|
||||
<p class="meta">do {{ game.final_score|cislo }} · kolo {{ game.round_number }}</p>
|
||||
</header>
|
||||
|
||||
{% if chyba %}
|
||||
<p class="error">{{ chyba }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% if winner %}
|
||||
<div class="win">
|
||||
<p class="eyebrow">Konec hry</p>
|
||||
<h2>{{ winner }}</h2>
|
||||
<p>Vyhrává s {{ totals[winner]|cislo }} body z cílových {{ game.final_score|cislo }}.</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="turn">
|
||||
<p class="eyebrow">Na tahu</p>
|
||||
<h2>{{ game.current_player }}</h2>
|
||||
<p class="progress">
|
||||
<strong>{{ totals[game.current_player]|cislo }}</strong> / {{ game.final_score|cislo }}
|
||||
{%- if streaks[game.current_player] %}
|
||||
<span class="ticks">{{ '✕' * streaks[game.current_player] }}</span>
|
||||
{%- endif %}
|
||||
</p>
|
||||
{% if streaks[game.current_player] == 2 %}
|
||||
<p class="warning">Ještě jedna nula a skóre jde pryč.</p>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="{{ url_for('add_turn', game_id=game_id) }}" style="margin-top: 1.2rem">
|
||||
<div class="field">
|
||||
<label for="value">Skóre za tah</label>
|
||||
<input type="number" name="value" id="value" inputmode="numeric" autofocus required>
|
||||
</div>
|
||||
<button class="btn" type="submit">Zapsat</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<p class="eyebrow">Průběžné pořadí</p>
|
||||
<table class="standings">
|
||||
{% for rank, name, total in standings %}
|
||||
<tr>
|
||||
<td class="rank">{{ rank }}.</td>
|
||||
<td class="self">{{ name }}</td>
|
||||
<td>
|
||||
{{ total|cislo }}
|
||||
{%- if streaks[name] %} <span class="ticks">{{ '✕' * streaks[name] }}</span>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
<div class="actions">
|
||||
<form method="post" action="{{ url_for('undo', game_id=game_id) }}">
|
||||
<button class="btn-quiet" type="submit" {{ 'disabled' if not game.turns }}>Vrátit poslední zápis</button>
|
||||
</form>
|
||||
{% if not winner %}
|
||||
<form method="post" action="{{ url_for('abandon', game_id=game_id) }}">
|
||||
<button class="btn-quiet btn-danger" type="submit">Ukončit hru</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<p class="footer">
|
||||
<a href="{{ url_for('board', game_id=game_id) }}">Zápisník</a>
|
||||
<a href="{{ url_for('index') }}">Nová hra</a>
|
||||
</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,109 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Nová hra{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="phone">
|
||||
<header class="masthead">
|
||||
<div>
|
||||
<p class="eyebrow">Počitadlo</p>
|
||||
<h1>Kostky</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if request.args.get('chyba') %}
|
||||
<p class="error">{{ request.args.get('chyba') }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% if running %}
|
||||
<div class="notice">
|
||||
<span>Rozehraná hra {{ running }} čeká.</span>
|
||||
<a href="{{ url_for('game_view', game_id=running) }}">Pokračovat</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="{{ url_for('new_game') }}">
|
||||
<p class="eyebrow">Kdo hraje</p>
|
||||
<p class="hint">Ťukej jména v pořadí, jak sedíte kolem stolu.</p>
|
||||
|
||||
<div class="chips" id="chips">
|
||||
{% for player in players %}
|
||||
<button type="button" class="chip" aria-pressed="false" data-name="{{ player.name }}">
|
||||
{{ player.name }}<span class="seat"></span>
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="add-player">
|
||||
<input type="text" id="new-name" placeholder="Nový hráč" autocomplete="off">
|
||||
<button type="button" id="add">Přidat</button>
|
||||
</div>
|
||||
|
||||
<div class="field" style="margin-top: 1.5rem">
|
||||
<label for="final">Cílové skóre</label>
|
||||
<input type="number" name="final_score" id="final" value="{{ final_score }}" inputmode="numeric">
|
||||
</div>
|
||||
|
||||
<div id="chosen"></div>
|
||||
<button class="btn" type="submit">Začít hru</button>
|
||||
</form>
|
||||
|
||||
<p class="footer"><a href="{{ url_for('board_redirect') }}">Zápisník</a></p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const chips = document.getElementById("chips");
|
||||
const chosen = [];
|
||||
|
||||
function render() {
|
||||
for (const chip of chips.querySelectorAll(".chip")) {
|
||||
const seat = chosen.indexOf(chip.dataset.name);
|
||||
chip.setAttribute("aria-pressed", seat > -1);
|
||||
chip.querySelector(".seat").textContent = seat > -1 ? seat + 1 : "";
|
||||
}
|
||||
|
||||
// Pořadí odeslaných polí je pořadí u stolu.
|
||||
document.getElementById("chosen").replaceChildren(...chosen.map(name => {
|
||||
const field = document.createElement("input");
|
||||
field.type = "hidden";
|
||||
field.name = "player";
|
||||
field.value = name;
|
||||
return field;
|
||||
}));
|
||||
}
|
||||
|
||||
chips.addEventListener("click", event => {
|
||||
const chip = event.target.closest(".chip");
|
||||
if (!chip) return;
|
||||
|
||||
const seat = chosen.indexOf(chip.dataset.name);
|
||||
if (seat > -1) chosen.splice(seat, 1);
|
||||
else chosen.push(chip.dataset.name);
|
||||
render();
|
||||
});
|
||||
|
||||
const field = document.getElementById("new-name");
|
||||
|
||||
function addPlayer() {
|
||||
const name = field.value.trim();
|
||||
if (!name) return;
|
||||
|
||||
if (!chips.querySelector(`[data-name="${CSS.escape(name)}"]`)) {
|
||||
const chip = document.createElement("button");
|
||||
chip.type = "button";
|
||||
chip.className = "chip";
|
||||
chip.dataset.name = name;
|
||||
chip.append(name, Object.assign(document.createElement("span"), { className: "seat" }));
|
||||
chips.append(chip);
|
||||
}
|
||||
|
||||
if (!chosen.includes(name)) chosen.push(name);
|
||||
field.value = "";
|
||||
render();
|
||||
}
|
||||
|
||||
document.getElementById("add").addEventListener("click", addPlayer);
|
||||
field.addEventListener("keydown", event => {
|
||||
if (event.key === "Enter") { event.preventDefault(); addPlayer(); }
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user