GameServer.Leaderboards.Leaderboard (GameServer v1.0.637)

Copy Markdown

Ecto schema for the leaderboards table.

A leaderboard is a self-contained scoreboard that can be permanent or time-limited. Each leaderboard has its own settings for sort order and score operator.

Slug

The slug is a human-readable identifier (e.g., "weekly_kills") that can be reused across multiple leaderboard instances (seasons). Use the slug to always target the currently active leaderboard, or use the integer id for a specific instance.

Sort Order

  • :desc — Higher scores rank first (default)
  • :asc — Lower scores rank first (e.g., fastest time)

Operators

  • :set — Always replace with new score
  • :best — Only update if new score is better (default)
  • :incr — Add to existing score
  • :decr — Subtract from existing score

Summary

Functions

Returns true if the leaderboard is currently active (not ended).

Changeset for creating a new leaderboard.

Returns true if the leaderboard has ended.

Returns the localized description for the given locale.

Returns the localized title for the given locale.

Changeset for updating an existing leaderboard. Does not allow changing slug, sort_order, or operator after creation.

Types

operator()

@type operator() :: :set | :best | :incr | :decr

sort_order()

@type sort_order() :: :desc | :asc

t()

@type t() :: %GameServer.Leaderboards.Leaderboard{
  __meta__: term(),
  description: term(),
  ends_at: term(),
  id: term(),
  inserted_at: term(),
  metadata: term(),
  operator: term(),
  records: term(),
  slug: term(),
  sort_order: term(),
  starts_at: term(),
  title: term(),
  updated_at: term()
}

Functions

active?(leaderboard)

Returns true if the leaderboard is currently active (not ended).

changeset(leaderboard, attrs)

Changeset for creating a new leaderboard.

ended?(lb)

Returns true if the leaderboard has ended.

localized_description(map, locale)

Returns the localized description for the given locale.

Looks up metadata["descriptions"][locale], falling back to description. Works with both %Leaderboard{} structs and plain maps (e.g. group info).

localized_title(map, locale)

Returns the localized title for the given locale.

Looks up metadata["titles"][locale], falling back to title. Works with both %Leaderboard{} structs and plain maps (e.g. group info).

Examples

iex> lb = %Leaderboard{title: "Weekly Kills", metadata: %{"titles" => %{"es" => "Muertes Semanales"}}}
iex> Leaderboard.localized_title(lb, "es")
"Muertes Semanales"
iex> Leaderboard.localized_title(lb, "en")
"Weekly Kills"

update_changeset(leaderboard, attrs)

Changeset for updating an existing leaderboard. Does not allow changing slug, sort_order, or operator after creation.