Pass fen #1

Merged
owenrees merged 3 commits from pass-fen into main 2026-06-20 18:34:35 +00:00
2 changed files with 13 additions and 9 deletions
Showing only changes of commit 014ca0d18c - Show all commits
+2 -3
View File
@@ -34,12 +34,11 @@ export const ChessBoard = {
const move = this.chess.move({ from: orig, to: dest, promotion: 'q' }); const move = this.chess.move({ from: orig, to: dest, promotion: 'q' });
if (move) { if (move) {
const san = move.san
this.pushEvent("move_played", { this.pushEvent("move_played", {
from: orig, from: orig,
to: dest, to: dest,
san: san, fen: this.chess.fen(),
fen: this.chess.fen() san: move.san,
}); });
const nextTurnColor = this.chess.turn() === 'w' ? 'white' : 'black'; const nextTurnColor = this.chess.turn() === 'w' ? 'white' : 'black';
+11 -6
View File
@@ -3,7 +3,7 @@ defmodule ChesstrainerWeb.ChessTestLive do
@impl true @impl true
def mount(_params, _session, socket) do def mount(_params, _session, socket) do
{:ok, assign(socket, last_move: "None yet", total_moves: 0, san: "None yet")} {:ok, assign(socket, last_move: "None yet", san: "None yet", move_list: [])}
end end
@impl true @impl true
@@ -17,10 +17,13 @@ defmodule ChesstrainerWeb.ChessTestLive do
<p class="text-sm text-gray-600 font-semibold">Last Played Move:</p> <p class="text-sm text-gray-600 font-semibold">Last Played Move:</p>
<p class="text-lg font-mono text-blue-600">{@last_move}</p> <p class="text-lg font-mono text-blue-600">{@last_move}</p>
<p class="text-lg font-mono text-blue-600">{@san}</p> <p class="text-lg font-mono text-blue-600">{@san}</p>
</div> <p class="text-lg font-mono text-emerald-600">
<div> {if length(@move_list) == 0 do
<p class="text-sm text-gray-600 font-semibold">Total Moves:</p> "No Moves"
<p class="text-lg font-bold">{@total_moves}</p> else
Enum.reverse(@move_list) |> Enum.join(", ")
end}
</p>
</div> </div>
</div> </div>
@@ -43,10 +46,12 @@ defmodule ChesstrainerWeb.ChessTestLive do
%{"from" => from, "to" => to, "fen" => _fen, "san" => san}, %{"from" => from, "to" => to, "fen" => _fen, "san" => san},
socket socket
) do ) do
current_moves = socket.assigns.move_list
{:noreply, {:noreply,
socket socket
|> assign(:last_move, "#{from}#{to}") |> assign(:last_move, "#{from}#{to}")
|> assign(:san, san) |> assign(:san, san)
|> assign(:total_moves, socket.assigns.total_moves + 1)} |> assign(:move_list, [san | current_moves])}
end end
end end