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.

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

Link to this function

change_match(match, attrs \\ %{})

View Source
@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{}}
Link to this function

end_match(match_id, outcome)

View Source

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{}
Link to this function

get_match(match_id, query_args \\ [])

View Source

Gets a single match.

Returns nil if the Match does not exist.

Examples

iex> get_match(123)
%Match{}

iex> get_match(456)
nil
Link to this function

get_match!(match_id, query_args \\ [])

View Source

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)
Link to this function

list_matches(query_args)

View Source
@spec list_matches(Teiserver.query_args()) :: [Teiserver.Game.Match.t()]

Returns the list of matches.

Examples

iex> list_matches()
[%Match{}, ...]

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.

Link to this function

update_match(match, attrs)

View Source
@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{}}