Skip to content

Commit

Permalink
player's hand only show cards from played suits
Browse files Browse the repository at this point in the history
  • Loading branch information
ZabGo committed Jun 6, 2024
1 parent e1cc5a1 commit e163e6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/copi/cornucopia.ex
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,13 @@ defmodule Copi.Cornucopia do
Card |> order_by(:id) |> Repo.all()
end

def list_cards_shuffled(edition) do
Card |> where(edition: ^edition) |> order_by(fragment("RANDOM()")) |> Repo.all()
end
def list_cards_shuffled(edition, suits) do
all_cards = Card |> where(edition: ^edition) |> order_by(fragment("RANDOM()")) |> Repo.all()

Enum.filter(all_cards, fn card ->
card.category in suits
end)
end

@doc """
Gets a single card.
Expand Down
2 changes: 1 addition & 1 deletion lib/copi_web/live/game_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule CopiWeb.GameLive.Show do
if game.started_at do
# Do nothing, game's already started
else
all_cards = Copi.Cornucopia.list_cards_shuffled(game.edition)
all_cards = Copi.Cornucopia.list_cards_shuffled(game.edition, game.suits)
players = game.players

all_cards
Expand Down

0 comments on commit e163e6d

Please sign in to comment.