Skip to content

Commit

Permalink
feat: refactor CardShare to Playable protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyabrain committed Sep 12, 2024
1 parent 3db2d1c commit ec23250
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 8 additions & 6 deletions lib/viral_spiral/card_share.ex → lib/viral_spiral/playable.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defprotocol ViralSpiral.CardShare do
defprotocol ViralSpiral.Playable do
@moduledoc """
Returns Changes to be made when a card action takes place.
A protocol for cards to implement.
"""

@fallback_to_any true
Expand All @@ -13,7 +15,7 @@ defprotocol ViralSpiral.CardShare do
def discard(card, state, from)
end

defimpl ViralSpiral.CardShare, for: ViralSpiral.Canon.Card.Bias do
defimpl ViralSpiral.Playable, for: ViralSpiral.Canon.Card.Bias do
def pass(_card, _state, _from, _to) do
IO.inspect("returning changes for Bias card")
end
Expand All @@ -25,7 +27,7 @@ defimpl ViralSpiral.CardShare, for: ViralSpiral.Canon.Card.Bias do
end
end

defimpl ViralSpiral.CardShare, for: ViralSpiral.Canon.Card.Affinity do
defimpl ViralSpiral.Playable, for: ViralSpiral.Canon.Card.Affinity do
# Increase the player's affinity by 1
# Increase player's clout by 1
def pass(card, state, from, to) do
Expand Down Expand Up @@ -60,7 +62,7 @@ defimpl ViralSpiral.CardShare, for: ViralSpiral.Canon.Card.Affinity do
end
end

defimpl ViralSpiral.CardShare, for: ViralSpiral.Canon.Card.Topical do
defimpl ViralSpiral.Playable, for: ViralSpiral.Canon.Card.Topical do
alias ViralSpiral.Room.State.Root

# Increase passing player's clout
Expand All @@ -80,7 +82,7 @@ defimpl ViralSpiral.CardShare, for: ViralSpiral.Canon.Card.Topical do
end
end

defimpl ViralSpiral.CardShare, for: ViralSpiral.Canon.Card.Conflated do
defimpl ViralSpiral.Playable, for: ViralSpiral.Canon.Card.Conflated do
def pass(_card, _state, _from, _to) do
# IO.inspect("returning changes for Bias card")
end
Expand All @@ -92,7 +94,7 @@ defimpl ViralSpiral.CardShare, for: ViralSpiral.Canon.Card.Conflated do
end
end

defimpl ViralSpiral.CardShare, for: Any do
defimpl ViralSpiral.Playable, for: Any do
def pass(_card, state, _from, _to) do
state
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ViralSpiral.CardShareTest do
defmodule ViralSpiral.PlayableTest do
alias ViralSpiral.Room.State.Root
alias ViralSpiral.CardShare
alias ViralSpiral.Playable
alias ViralSpiral.Affinity
alias ViralSpiral.Canon.Deck
use ExUnit.Case
Expand All @@ -18,14 +18,14 @@ defmodule ViralSpiral.CardShareTest do
next_player_id = turn.pass_to |> Enum.at(1)

affinity_card = CardFixtures.affinity_card_true_anti_cat()
changes = CardShare.pass(affinity_card, game_state, current_player_id, next_player_id)
changes = Playable.pass(affinity_card, game_state, current_player_id, next_player_id)
new_state = Root.apply_changes(game_state, changes)

assert new_state.players[current_player_id].affinities.cat == -1
assert new_state.players[current_player_id].clout == 1

affinity_card = CardFixtures.affinity_card_true_pro_cat()
changes = CardShare.pass(affinity_card, game_state, current_player_id, next_player_id)
changes = Playable.pass(affinity_card, game_state, current_player_id, next_player_id)
new_state = Root.apply_changes(game_state, changes)

assert new_state.players[current_player_id].affinities.cat == 1
Expand All @@ -41,7 +41,7 @@ defmodule ViralSpiral.CardShareTest do

affinity_card = CardFixtures.affinity_card_true_anti_cat()

changes = CardShare.keep(affinity_card, game_state, current_player_id)
changes = Playable.keep(affinity_card, game_state, current_player_id)
new_state = Root.apply_changes(game_state, changes)
assert new_state.turn.current == next_turn_player_id
assert new_state.round.current == 1
Expand All @@ -56,7 +56,7 @@ defmodule ViralSpiral.CardShareTest do

affinity_card = CardFixtures.affinity_card_true_anti_cat()

changes = CardShare.keep(affinity_card, game_state, current_player_id)
changes = Playable.keep(affinity_card, game_state, current_player_id)
new_state = Root.apply_changes(game_state, changes)

assert new_state.turn.current == next_turn_player_id
Expand Down

0 comments on commit ec23250

Please sign in to comment.