View Source Teiserver.Game.MatchLib (Teiserver v0.0.4)
TODO: Library of match related functions.
Summary
Functions
Returns an %Ecto.Changeset{}
for tracking match changes.
Creates a match.
Deletes a match.
Ends an ongoing match and updates memberships accordingly.
Gets a single match.
Gets a single match.
Returns the list of matches.
Given a lobby_id, will update the match, memberships and settings for that lobby and then update the Lobby itself to show the lobby is now in progress.
Updates a match.
Functions
@spec change_match(Teiserver.Game.Match.t(), map()) :: Ecto.Changeset.t()
Returns an %Ecto.Changeset{}
for tracking match changes.
Examples
iex> change_match(match)
%Ecto.Changeset{data: %Match{}}
@spec create_match(map()) :: {:ok, Teiserver.Game.Match.t()} | {:error, Ecto.Changeset.t()}
Creates a match.
Examples
iex> create_match(%{field: value})
{:ok, %Match{}}
iex> create_match(%{field: bad_value})
{:error, %Ecto.Changeset{}}
@spec delete_match(Teiserver.Game.Match.t()) :: {:ok, Teiserver.Game.Match.t()} | {:error, Ecto.Changeset.t()}
Deletes a match.
Examples
iex> delete_match(match)
{:ok, %Match{}}
iex> delete_match(match)
{:error, %Ecto.Changeset{}}
@spec end_match(Teiserver.Game.Match.id(), map()) :: Teiserver.Game.Match.t()
Ends an ongoing match and updates memberships accordingly.
Second argument is a map of the outcomes for the match with the following keys:
:winning_team
- The team_number of the winning team:ended_normally?
- A boolean indicating if the match ended normally:players
- A map of player data with the keys being the user_id of the player and the value being a map of their specific outcome
Player outcomes are expected to map like so: Required:
Optional:
:left_after_seconds
- The number of seconds after the start the player left if early. If not included it is assumed the player remained until the end.
Examples
iex> end_match(123, %{winning_team: 1, ended_normally?: true, player_data: %{123: }})
%Match{}
@spec get_match(Teiserver.Game.Match.id(), Teiserver.query_args()) :: Teiserver.Game.Match.t() | nil
Gets a single match.
Returns nil if the Match does not exist.
Examples
iex> get_match(123)
%Match{}
iex> get_match(456)
nil
@spec get_match!(Teiserver.Game.Match.id(), Teiserver.query_args()) :: Teiserver.Game.Match.t()
Gets a single match.
Raises Ecto.NoResultsError
if the Match does not exist.
Examples
iex> get_match!(123)
%Match{}
iex> get_match!(456)
** (Ecto.NoResultsError)
@spec list_matches(Teiserver.query_args()) :: [Teiserver.Game.Match.t()]
Returns the list of matches.
Examples
iex> list_matches()
[%Match{}, ...]
@spec start_match(Teiserver.Game.Lobby.id()) :: Teiserver.Game.Match.t()
Given a lobby_id, will update the match, memberships and settings for that lobby and then update the Lobby itself to show the lobby is now in progress.
@spec update_match(Teiserver.Game.Match.t(), map()) :: {:ok, Teiserver.Game.Match.t()} | {:error, Ecto.Changeset.t()}
Updates a match.
Examples
iex> update_match(match, %{field: new_value})
{:ok, %Match{}}
iex> update_match(match, %{field: bad_value})
{:error, %Ecto.Changeset{}}