Skip to content

Commit

Permalink
Add replay page button on match overview page
Browse files Browse the repository at this point in the history
  • Loading branch information
L-e-x-o-n committed Oct 15, 2024
1 parent 62acf41 commit e46588f
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/teiserver/account/libs/relationship_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ defmodule Teiserver.Account.RelationshipLib do
userid_count = Enum.count(userid_list) |> max(1)

block_count_needed = Config.get_site_config_cache("lobby.Block count to prevent join")
block_percentage_needed = Config.get_site_config_cache("lobby.Block percentage to prevent join")

block_percentage_needed =
Config.get_site_config_cache("lobby.Block percentage to prevent join")

being_blocked_count =
userid
Expand Down Expand Up @@ -334,7 +336,9 @@ defmodule Teiserver.Account.RelationshipLib do
userid_count = Enum.count(userid_list) |> max(1)

avoid_count_needed = Config.get_site_config_cache("lobby.Avoid count to prevent playing")
avoid_percentage_needed = Config.get_site_config_cache("lobby.Avoid percentage to prevent playing")

avoid_percentage_needed =
Config.get_site_config_cache("lobby.Avoid percentage to prevent playing")

being_avoided_count =
userid
Expand Down
5 changes: 3 additions & 2 deletions lib/teiserver/battle/schemas/match.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Teiserver.Battle.Match do
schema "teiserver_battle_matches" do
field :server_uuid, :string
field :uuid, :string
field :game_id, :string
field :map, :string
# The end of match data to be provided by clients
field :data, :map, default: %{}
Expand Down Expand Up @@ -45,7 +46,7 @@ defmodule Teiserver.Battle.Match do
struct
|> cast(
params,
~w(server_uuid uuid map data tags team_count team_size passworded game_type founder_id bots started winning_team finished processed queue_id rating_type_id lobby_policy_id game_duration)a
~w(server_uuid uuid game_id map data tags team_count team_size passworded game_type founder_id bots started winning_team finished processed queue_id rating_type_id lobby_policy_id game_duration)a
)
|> validate_required(
~w(server_uuid uuid map tags team_count team_size passworded game_type founder_id bots started)a
Expand All @@ -57,7 +58,7 @@ defmodule Teiserver.Battle.Match do
struct
|> cast(
params,
~w(server_uuid uuid map data tags team_count team_size passworded game_type founder_id bots started winning_team finished processed queue_id game_duration)a
~w(server_uuid uuid game_id map data tags team_count team_size passworded game_type founder_id bots started winning_team finished processed queue_id game_duration)a
)
|> validate_required(~w(founder_id)a)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/teiserver/battle/tasks/post_match_process_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ defmodule Teiserver.Battle.Tasks.PostMatchProcessTask do
|> hd_or_x({nil, nil})
|> elem(0)

Battle.update_match(match, %{winning_team: winning_team, game_duration: host_game_duration})
Battle.update_match(match, %{
winning_team: winning_team,
game_duration: host_game_duration,
game_id: export_data["gameId"]
})

memberships
|> Enum.map(fn m ->
Expand Down
2 changes: 2 additions & 0 deletions lib/teiserver/helpers/styling_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ defmodule Teiserver.Helper.StylingHelper do
def icon(:quarter, _fa_type), do: ""
def icon(:year, _fa_type), do: ""

def icon(:replay, _fa_type), do: "fa-solid fa-arrow-rotate-left"

# defp split_colour(c) do
# {r, _} = c |> String.slice(1, 2) |> Integer.parse(16)
# {g, _} = c |> String.slice(3, 2) |> Integer.parse(16)
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/controllers/admin/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule TeiserverWeb.Admin.UserController do
ip: params["ip"],
lobby_client: params["lobby_client"],
previous_names: params["previous_names"],
mod_action: params["mod_action"],
mod_action: params["mod_action"]
],
limit: params["limit"] || 50,
order_by: params["order"] || "Name (A-Z)"
Expand Down
9 changes: 5 additions & 4 deletions lib/teiserver_web/live/battles/match/match_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule TeiserverWeb.Battle.MatchComponents do
attr :active, :string, required: true
attr :current_user, :map, required: true
attr :match_id, :integer, default: nil
attr :replay, :string, default: nil

def section_menu(assigns) do
~H"""
Expand Down Expand Up @@ -63,13 +64,13 @@ defmodule TeiserverWeb.Battle.MatchComponents do
<div class="float-end">
<.section_menu_button
:if={@match_id != nil and allow?(@current_user, "Moderator")}
:if={@replay != nil}
bsname={@view_colour}
icon={StylingHelper.icon(:admin)}
icon={StylingHelper.icon(:replay)}
active={false}
url={~p"/battle/#{@match_id}"}
url={@replay}
>
Admin view
Replay
</.section_menu_button>
</div>
"""
Expand Down
15 changes: 15 additions & 0 deletions lib/teiserver_web/live/battles/match/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
end)
|> Enum.sort_by(fn v -> v end, &<=/2)

game_id =
cond do
match.game_id -> match.game_id
match.data -> match.data["export_data"]["gameId"]
true -> nil
end

replay =
if game_id do
Application.get_env(:teiserver, Teiserver)[:main_website] <>
"/replays?gameId=" <> game_id
end

socket
|> assign(:match, match)
|> assign(:match_name, match_name)
Expand All @@ -192,6 +205,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
|> assign(:new_balance, new_balance)
|> assign(:events_by_type, events_by_type)
|> assign(:events_by_team_and_type, events_by_team_and_type)
|> assign(:replay, replay)
else
socket
|> assign(:match, nil)
Expand All @@ -203,6 +217,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do
|> assign(:new_balance, %{})
|> assign(:events_by_type, %{})
|> assign(:events_by_team_and_type, %{})
|> assign(:replay, nil)
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/teiserver_web/live/battles/match/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
view_colour={@view_colour}
current_user={@current_user}
match_id={@match.id}
replay={@replay}
/>
<hr />

Expand Down
9 changes: 9 additions & 0 deletions priv/repo/migrations/20241013105515_add_game_id.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Teiserver.Repo.Migrations.AddGameId do
use Ecto.Migration

def change do
alter table(:teiserver_battle_matches) do
add :game_id, :string
end
end
end

0 comments on commit e46588f

Please sign in to comment.