-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GameRegistry: GameUIServer spawn/die controls Room rows
- Create a GameUIServer: Room automatically created - GameUIServer dies to timeout: Room deleted, GameServer deleted - API to create rooms directly removed
- Loading branch information
Showing
14 changed files
with
103 additions
and
71 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.swp | ||
*.swo | ||
priv_notes.txt |
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,4 +1,5 @@ | ||
alias Spades.Rooms | ||
alias Spades.Rooms.Room | ||
|
||
alias SpadesGame.{ | ||
Card, | ||
|
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,40 @@ | ||
defmodule SpadesGame.GameRegistry do | ||
@moduledoc """ | ||
Keeps track of games. | ||
""" | ||
require Logger | ||
alias SpadesGame.{GameUI} | ||
alias Spades.Rooms | ||
alias Spades.Rooms.Room | ||
|
||
def add(_game_name, %GameUI{} = gameui) do | ||
gameui | ||
|> to_room_param() | ||
|> Rooms.create_room() | ||
end | ||
|
||
def update(game_name, %GameUI{} = gameui) do | ||
room = Rooms.get_room_by_name(game_name) | ||
|
||
case room do | ||
%Room{} -> Rooms.update_room(room, to_room_param(gameui)) | ||
_ -> nil | ||
end | ||
end | ||
|
||
def remove(game_name) do | ||
room = Rooms.get_room_by_name(game_name) | ||
|
||
case room do | ||
%Room{} -> Rooms.delete_room(room) | ||
_ -> nil | ||
end | ||
end | ||
|
||
defp to_room_param(%GameUI{} = gameui) do | ||
# created_at: DateTime.t() | ||
%{ | ||
name: gameui.game_name | ||
} | ||
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
27 changes: 27 additions & 0 deletions
27
backend/lib/spades_web/controllers/api/v1/game_controller.ex
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,27 @@ | ||
defmodule SpadesWeb.API.V1.GameController do | ||
use SpadesWeb, :controller | ||
|
||
require Logger | ||
|
||
alias Spades.Rooms | ||
alias Spades.Rooms.Room | ||
alias SpadesUtil.{NameGenerator} | ||
alias SpadesGame.{GameOptions, GameUISupervisor} | ||
|
||
def create(conn, _params) do | ||
game_name = NameGenerator.generate() | ||
options = %GameOptions{} | ||
|
||
with {:ok, _pid} <- GameUISupervisor.start_game(game_name, options), | ||
%Room{} = room <- Rooms.get_room_by_name(game_name) do | ||
conn | ||
|> put_status(:created) | ||
|> json(%{success: %{message: "Created game", room: room}}) | ||
else | ||
_ -> | ||
conn | ||
|> put_status(500) | ||
|> json(%{error: %{status: 500, message: "Unable to create game"}}) | ||
end | ||
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
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