mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Show colour and whether it's your turn
This commit is contained in:
parent
35d1f33f76
commit
ba70cb5f30
10
assets/css/_game_list.scss
Normal file
10
assets/css/_game_list.scss
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.player-indicator {
|
||||||
|
img {
|
||||||
|
height: 1.5em;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.your-turn {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
@ -6,4 +6,6 @@
|
|||||||
|
|
||||||
@import "layout";
|
@import "layout";
|
||||||
@import "nav";
|
@import "nav";
|
||||||
|
|
||||||
|
@import "game_list";
|
||||||
@import "board";
|
@import "board";
|
||||||
|
|||||||
@ -3,10 +3,14 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<%= for game <- @games do %>
|
<%= for game <- @games do %>
|
||||||
<tr>
|
<tr class="<%= if your_turn?(@conn, game), do: "your-turn" %>">
|
||||||
<td>
|
<td>
|
||||||
|
<span class="player-indicator"><img src="images/pawn_<%= player_colour(@conn, game) %>.svg"></span>
|
||||||
<%= link "Game with #{opponent(@conn, game).name}", to: game_path(@conn, :show, game), class: "btn btn-default btn-xs" %>
|
<%= link "Game with #{opponent(@conn, game).name}", to: game_path(@conn, :show, game), class: "btn btn-default btn-xs" %>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= if your_turn?(@conn, game) do %>Your turn<% end %>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
Started on <%= Timex.format!(game.inserted_at, "%b %e at %I:%M %P", :strftime) %>
|
Started on <%= Timex.format!(game.inserted_at, "%b %e at %I:%M %P", :strftime) %>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@ -3,6 +3,17 @@ defmodule ChessWeb.GameView do
|
|||||||
|
|
||||||
import Chess.Auth, only: [current_user: 1]
|
import Chess.Auth, only: [current_user: 1]
|
||||||
|
|
||||||
|
def your_turn?(conn, game) do
|
||||||
|
player_colour(conn, game) == game.turn
|
||||||
|
end
|
||||||
|
|
||||||
|
def player_colour(conn, game) do
|
||||||
|
cond do
|
||||||
|
current_user(conn).id == game.user_id -> "white"
|
||||||
|
current_user(conn).id == game.opponent_id -> "black"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def opponent(conn, game) do
|
def opponent(conn, game) do
|
||||||
if current_user(conn).id == game.user_id do
|
if current_user(conn).id == game.user_id do
|
||||||
game.opponent
|
game.opponent
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user