-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add new join_quick_game/3 function to game_launcher API * Add new endpoint for quick games and also its websocket handler * Refactor the fill with bots and game creation behavior * Fix bug in list appending action * Create required callback for quick game ws handler * Add quick_game entrypoint in game_client app and also improve its code and view * Modify core components styles for game client * Format elixir code
- Loading branch information
1 parent
5dd7000
commit ec59584
Showing
10 changed files
with
110 additions
and
48 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
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,53 @@ | ||
defmodule Arena.QuickGameHandler do | ||
@moduledoc """ | ||
Module that handles cowboy websocket requests | ||
""" | ||
alias Arena.GameLauncher | ||
alias Arena.Serialization.GameState | ||
|
||
@behaviour :cowboy_websocket | ||
|
||
@impl true | ||
def init(req, _opts) do | ||
client_id = :cowboy_req.binding(:client_id, req) | ||
character_name = :cowboy_req.binding(:character_name, req) | ||
player_name = :cowboy_req.binding(:player_name, req) | ||
{:cowboy_websocket, req, %{client_id: client_id, character_name: character_name, player_name: player_name}} | ||
end | ||
|
||
@impl true | ||
def websocket_init(state) do | ||
GameLauncher.join_quick_game(state.client_id, state.character_name, state.player_name) | ||
|
||
game_state = | ||
GameState.encode(%GameState{ | ||
game_id: nil, | ||
players: %{}, | ||
projectiles: %{} | ||
}) | ||
|
||
{:reply, {:binary, game_state}, state} | ||
end | ||
|
||
@impl true | ||
def websocket_info(:leave_waiting_game, state) do | ||
{:stop, state} | ||
end | ||
|
||
@impl true | ||
def websocket_info({:join_game, game_id}, state) do | ||
game_state = | ||
GameState.encode(%GameState{ | ||
game_id: game_id, | ||
players: %{}, | ||
projectiles: %{} | ||
}) | ||
|
||
{:reply, {:binary, game_state}, state} | ||
end | ||
|
||
@impl true | ||
def websocket_handle(:ping, state) do | ||
{:reply, {:pong, ""}, state} | ||
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
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
20 changes: 5 additions & 15 deletions
20
apps/game_client/lib/game_client_web/controllers/page_html/home.html.heex
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,15 +1,5 @@ | ||
<ul> | ||
<li> | ||
Mocked Muflus: <a href={"/board/#{Ecto.UUID.generate()}/muflus/player_name"} class="text-yellow-400">link</a> | ||
</li> | ||
<li> | ||
Mocked Uma: <a href={"/board/#{Ecto.UUID.generate()}/uma/player_name"} class="text-yellow-400">link</a> | ||
</li> | ||
<li> | ||
Mocked H4ck: <a href={"/board/#{Ecto.UUID.generate()}/h4ck/player_name"} class="text-yellow-400">link</a> | ||
</li> | ||
<li> | ||
Mocked Valtimer: <a href={"/board/#{Ecto.UUID.generate()}/valtimer/player_name"} class="text-yellow-400">link</a> | ||
</li> | ||
</ul> | ||
|
||
<.form :let={f} for={%{}} action={~p"/"}> | ||
<.input field={f[:character]} name="character" label="Select a Character" type="select" options={["muflus", "h4ck", "uma", "valtimer"]} value=""/> | ||
<.button type="submit" name="game_mode" value="join">Play</.button> | ||
<.button type="submit" name="game_mode" value="quick_game">Quick Game</.button> | ||
</.form> |
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
2 changes: 1 addition & 1 deletion
2
apps/game_client/lib/game_client_web/live/pages/board/game_queue.html.heex
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,3 +1,3 @@ | ||
<div id="board_game" phx-hook="GameQueue" data-player-id={@player_id} data-character={@character} data-player-name={@player_name} class="max-w-full max-h-[40rem] overflow-scroll"></div> | ||
<div id="board_game" phx-hook="GameQueue" data-player-id={@player_id} data-character={@character} data-player-name={@player_name} data-game-mode={@game_mode} class="max-w-full max-h-[40rem] overflow-scroll"></div> | ||
|
||
WAITING FOR A GAME TO START... |
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