-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create gameroom state and use in UI
- Loading branch information
1 parent
90ee4ba
commit 84ece4a
Showing
11 changed files
with
169 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule ViralSpiral.Canon.Card do | ||
alias ViralSpiral.Canon.Card.Bias | ||
alias ViralSpiral.Affinity | ||
|
||
@type t :: Affinity.t() | Bias.t() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule ViralSpiralWeb.Atoms do | ||
use ViralSpiralWeb, :html | ||
|
||
attr :card, :map, required: true | ||
|
||
def card(assigns) do | ||
~H""" | ||
<div class="p-2 border-2 rounded-lg bg-slate-400"> | ||
<p><%= @card.headline %></p> | ||
</div> | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
defmodule ViralSpiralWeb.GameRoom do | ||
import ViralSpiralWeb.Atoms | ||
alias ViralSpiral.Canon.Card | ||
alias ViralSpiral.Entity.Player | ||
alias ViralSpiral.Canon.Deck | ||
alias ViralSpiral.Gameplay.Factory | ||
alias ViralSpiral.Room.Actions | ||
alias ViralSpiral.Room.Reducer | ||
alias ViralSpiral.Room.State | ||
alias ViralSpiral.Entity.Room | ||
use ViralSpiralWeb, :live_view | ||
|
||
def mount(params, session, socket) do | ||
room = | ||
Room.new() | ||
|> Room.start(4) | ||
room = Room.new() |> Room.start(4) | ||
state = State.new(room, ["adhiraj", "krys", "aman", "farah"]) | ||
requirements = Factory.draw_type(state) | ||
draw_type = Deck.draw_type(requirements) | ||
state = Reducer.reduce(state, Actions.draw_card(draw_type)) | ||
|
||
root = State.new(room, ["adhiraj", "krys", "aman", "farah"]) | ||
IO.inspect(root) | ||
IO.puts("hi") | ||
gameroom_state = Factory.make_gameroom(state) | ||
|
||
{:ok, assign(socket, :root, root)} | ||
{:ok, assign(socket, :state, gameroom_state)} | ||
end | ||
|
||
def handle_event("start_game", _params, socket) do | ||
{:noreply, socket} | ||
end | ||
|
||
def handle_event("pass_to", params, socket) do | ||
# card = socket.assigns.card | ||
|
||
# state = Reducers.reduce(state, Actions.pass_card()) | ||
|
||
{:noreply, socket} | ||
end | ||
|
||
def player_options(state, player) do | ||
pass_to_ids = state.turn.pass_to | ||
|
||
pass_to_names = | ||
pass_to_ids | ||
|> Enum.map(&state.players[&1].name) | ||
|
||
pass_to_names | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,61 @@ | ||
<div class="p-4 border-red-200 border-2 rounded-2xl flex flex-row justify-between "> | ||
<span><%= @root.room.name %></span> | ||
<span><%= @root.room.id %></span> | ||
<span><%= @root.room.state %></span> | ||
<span><%= @root.room.chaos_counter %></span> | ||
<span><%= @state.room.name %></span> | ||
<%!-- <span><%= @state.room.id %></span> | ||
<span><%= @state.room.state %></span> --%> | ||
<span><%= @state.room.chaos %></span> | ||
</div> | ||
|
||
<div class="p-4 mt-2 border-red-200 border-2 rounded-2xl flex flex-row justify-between"> | ||
<%= for player <- Enum.map(@root.players, fn {_id, player} -> player end) do %> | ||
<div class={[ | ||
"p-2 border-2 w-full rounded-xl", | ||
if(@root.turn.current == player.id, | ||
<div class="mt-2 flex flex-row justify-between"> | ||
<div | ||
:for={player <- @state.players} | ||
class={[ | ||
"p-2 border-2 w-full rounded-xl m-2", | ||
if(player.is_active, | ||
do: "border-red-400", | ||
else: "border-red-100" | ||
) | ||
]}> | ||
<%= player.name %> | ||
]} | ||
> | ||
<span><%= player.name %></span> | ||
|
||
<%!-- <span class="ml-6"><%= player.identity %></span> --%> | ||
<div class="h-2"></div> | ||
<div> | ||
<h2 class="font-semibold">Clout</h2> | ||
<span><%= player.clout %></span> | ||
</div> | ||
<% end %> | ||
<div class="h-2"></div> | ||
<div> | ||
<h2 class="font-semibold">Affinities</h2> | ||
<div :for={affinity <- player.affinities}> | ||
<span><%= elem(affinity, 0) %></span> | ||
<span><%= elem(affinity, 1) %></span> | ||
</div> | ||
|
||
<div class="h-2"></div> | ||
<h2 class="font-semibold">Bias</h2> | ||
<div :for={bias <- player.biases}> | ||
<span><%= elem(bias, 0) %></span> | ||
<span><%= elem(bias, 1) %></span> | ||
</div> | ||
|
||
<div class="h-4"></div> | ||
|
||
<div :for={card <- player.cards} :if={player.is_active}> | ||
<.card card={card}></.card> | ||
</div> | ||
</div> | ||
|
||
<%!-- <div class="h-4"></div> | ||
<%= if current_player?(@state, player) do %> | ||
<.card> | ||
<p><%= card(@state, player).headline %></p> | ||
</.card> | ||
<h3>Pass to</h3> | ||
<%= for pass_to <- player_options(@state, player) do %> | ||
<span class="mr-4"><%= pass_to %></span> | ||
<% end %> | ||
<% end %> --%> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule ViralSpiralWeb.GameRoomState do | ||
defstruct room: %{}, players: [] | ||
|
||
@type t :: %__MODULE__{ | ||
room: %{ | ||
name: String.t(), | ||
chaos: integer() | ||
}, | ||
players: | ||
list(%{ | ||
name: String.t(), | ||
affinities: %{atom() => integer()} | ||
}) | ||
} | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.