Add uci menu and fix previous game viewer wrap around move index
This commit is contained in:
parent
763529e6c3
commit
21090101aa
@ -56,11 +56,29 @@ export const ManPages = () => {
|
|||||||
<ul>
|
<ul>
|
||||||
<li>Ctrl + b / Escape to return to the main menu.</li>
|
<li>Ctrl + b / Escape to return to the main menu.</li>
|
||||||
<li>Ctrl + c / Ctrl + d to exit CheSSH at any point.</li>
|
<li>Ctrl + c / Ctrl + d to exit CheSSH at any point.</li>
|
||||||
<li>Arrow keys / hjkl keybinds to move around the board.</li>
|
|
||||||
<li>
|
<li>
|
||||||
Select a piece with "enter", and move it to a square by pressing
|
Arrow keys / vim (hjkl) keybinds to move around the board and
|
||||||
|
menus.
|
||||||
|
</li>
|
||||||
|
<li>Select menu options with "enter".</li>
|
||||||
|
<li>
|
||||||
|
Select a game piece "enter", and move it to a square by pressing
|
||||||
"enter" again.
|
"enter" again.
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
In the "Previous Games" viewer, use h/l or left/right to view the
|
||||||
|
previous/next move.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>In a game board use "f" to flip the board.</li>
|
||||||
|
<li>
|
||||||
|
In the "Previous Games" viewer, use "m" to show the game's move
|
||||||
|
history in UCI notation (which you may convert to PGN{" "}
|
||||||
|
<a href="https://www.dcode.fr/uci-chess-notation" target="_blank">
|
||||||
|
here
|
||||||
|
</a>
|
||||||
|
).
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,7 +13,8 @@ defmodule Chessh.SSH.Client.PreviousGame do
|
|||||||
binbo_pid: nil,
|
binbo_pid: nil,
|
||||||
game: %Game{},
|
game: %Game{},
|
||||||
client_pid: nil,
|
client_pid: nil,
|
||||||
flipped: false
|
flipped: false,
|
||||||
|
viewing_uci: false
|
||||||
end
|
end
|
||||||
|
|
||||||
use Chessh.SSH.Client.Screen
|
use Chessh.SSH.Client.Screen
|
||||||
@ -59,6 +60,7 @@ defmodule Chessh.SSH.Client.PreviousGame do
|
|||||||
%State{
|
%State{
|
||||||
move_idx: move_idx,
|
move_idx: move_idx,
|
||||||
flipped: flipped,
|
flipped: flipped,
|
||||||
|
viewing_uci: viewing_uci,
|
||||||
game: %Game{
|
game: %Game{
|
||||||
moves: num_moves
|
moves: num_moves
|
||||||
}
|
}
|
||||||
@ -67,10 +69,10 @@ defmodule Chessh.SSH.Client.PreviousGame do
|
|||||||
new_move_idx =
|
new_move_idx =
|
||||||
case action do
|
case action do
|
||||||
:left ->
|
:left ->
|
||||||
Utils.wrap_around(move_idx, -1, num_moves)
|
Utils.wrap_around(move_idx, -1, num_moves + 1)
|
||||||
|
|
||||||
:right ->
|
:right ->
|
||||||
Utils.wrap_around(move_idx, 1, num_moves)
|
Utils.wrap_around(move_idx, 1, num_moves + 1)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
move_idx
|
move_idx
|
||||||
@ -79,7 +81,8 @@ defmodule Chessh.SSH.Client.PreviousGame do
|
|||||||
new_state = %State{
|
new_state = %State{
|
||||||
state
|
state
|
||||||
| move_idx: new_move_idx,
|
| move_idx: new_move_idx,
|
||||||
flipped: if(action == "f", do: !flipped, else: flipped)
|
flipped: if(action == "f", do: !flipped, else: flipped),
|
||||||
|
viewing_uci: if(action == "m", do: !viewing_uci, else: viewing_uci)
|
||||||
}
|
}
|
||||||
|
|
||||||
render(new_state)
|
render(new_state)
|
||||||
@ -92,15 +95,33 @@ defmodule Chessh.SSH.Client.PreviousGame do
|
|||||||
client_pid: client_pid,
|
client_pid: client_pid,
|
||||||
move_fens: move_fens,
|
move_fens: move_fens,
|
||||||
move_idx: move_idx,
|
move_idx: move_idx,
|
||||||
game: %Game{id: game_id, moves: total_moves}
|
game: %Game{id: game_id, moves: total_moves, game_moves: game_moves},
|
||||||
|
viewing_uci: viewing_uci
|
||||||
} = state
|
} = state
|
||||||
) do
|
) do
|
||||||
|
lines =
|
||||||
|
case viewing_uci do
|
||||||
|
false ->
|
||||||
{:ok, fen} = Map.fetch(move_fens, "#{move_idx}")
|
{:ok, fen} = Map.fetch(move_fens, "#{move_idx}")
|
||||||
|
|
||||||
lines =
|
[
|
||||||
["Game #{game_id} | Move #{move_idx} / #{total_moves}"] ++
|
"Game #{game_id} | Move #{move_idx} / #{total_moves}",
|
||||||
Renderer.draw_board(fen, flipped) ++
|
"| <- previous move | next move ->",
|
||||||
["<- previous | next ->"]
|
"| press 'm' to view move history",
|
||||||
|
"==="
|
||||||
|
] ++
|
||||||
|
Renderer.draw_board(fen, flipped)
|
||||||
|
|
||||||
|
true ->
|
||||||
|
[
|
||||||
|
Utils.clear_codes(),
|
||||||
|
"UCI Notation For Game #{game_id}",
|
||||||
|
"- Press 'm' to go back to the board",
|
||||||
|
"- Use https://dcode.fr/uci-chess-notation to convert to PGN",
|
||||||
|
"",
|
||||||
|
game_moves
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
send(
|
send(
|
||||||
client_pid,
|
client_pid,
|
||||||
@ -111,7 +132,7 @@ defmodule Chessh.SSH.Client.PreviousGame do
|
|||||||
fn {i, line} ->
|
fn {i, line} ->
|
||||||
[ANSI.cursor(i, 0), ANSI.clear_line(), line]
|
[ANSI.cursor(i, 0), ANSI.clear_line(), line]
|
||||||
end
|
end
|
||||||
)}
|
) ++ [ANSI.home()]}
|
||||||
)
|
)
|
||||||
|
|
||||||
state
|
state
|
||||||
|
Loading…
Reference in New Issue
Block a user