diff --git a/lib/cobblemon_ui_web/live/battles_live.ex b/lib/cobblemon_ui_web/live/battles_live.ex deleted file mode 100644 index 086c2d8..0000000 --- a/lib/cobblemon_ui_web/live/battles_live.ex +++ /dev/null @@ -1,243 +0,0 @@ -defmodule CobblemonUiWeb.BattlesLive do - use CobblemonUiWeb, :live_view - - @impl true - def mount(_params, _session, socket) do - {battles, error} = - case CobblemonUi.BattlesApi.list_battles() do - {:ok, battles} -> {battles, nil} - {:error, reason} -> {[], reason} - end - - {:ok, - assign(socket, - page_title: "Active Battles", - battles: battles, - error: error - )} - end - - @impl true - def handle_event("refresh", _params, socket) do - {battles, error} = - case CobblemonUi.BattlesApi.list_battles() do - {:ok, battles} -> {battles, nil} - {:error, reason} -> {[], reason} - end - - {:noreply, assign(socket, battles: battles, error: error)} - end - - @impl true - def render(assigns) do - ~H""" - -
-
- <%!-- Header --%> -
-
-
- <.icon name="hero-bolt" class="size-6 text-error" /> -
-
-

Active Battles

-

Live battle monitor

-
-
-
- <.link - navigate={~p"/"} - class="btn btn-ghost btn-sm gap-2 hover:bg-base-300/50 transition-colors" - > - <.icon name="hero-arrow-left" class="size-4" /> Players - - -
-
- - <%!-- Error --%> -
-
- <.icon name="hero-exclamation-triangle" class="size-5" /> - {@error} -
-
- - <%!-- Empty state --%> -
- <.icon name="hero-shield-check" class="size-10 mx-auto mb-4 text-base-content/20" /> -

No active battles

-

All is peaceful on the server

-
- - <%!-- Battle cards --%> -
- <%= for battle <- @battles do %> -
- <%!-- Battle header --%> -
-
- - - Live - - {battle.battle_id} -
- - {length(battle.actors)} combatants - -
- - <%!-- Actors --%> -
- <%!-- VS divider on md+ --%> - - - <%= for actor <- battle.actors do %> -
- <%!-- Actor header --%> -
-
- <%= if actor.type == "player" do %> - <.icon name="hero-user" class="size-4 text-primary" /> - <% else %> - <.icon name="hero-cpu-chip" class="size-4 text-warning" /> - <% end %> -
-
-

{actor.name}

-

- {actor.type} -

-
-
- - <%!-- Active Pokémon --%> -
- <%= for poke <- actor.active_pokemon do %> -
-
-
- {poke.species} - - Lv.{poke.level} - -
- - {poke.hp}/{poke.max_hp} - -
- <%!-- HP bar --%> -
-
"bg-base-content/20" - poke.hp / poke.max_hp > 0.5 -> "bg-success" - poke.hp / poke.max_hp > 0.2 -> "bg-warning" - true -> "bg-error" - end - ]} - style={"width: #{if poke.max_hp > 0, do: Float.round(poke.hp / poke.max_hp * 100, 1), else: 0}%"} - > -
-
-
- <% end %> -
- - <%!-- Party moves (player only) --%> - <%= if actor.party != [] do %> -
- - <.icon name="hero-chevron-right" class="size-3 group-open:rotate-90 transition-transform" /> - Party details - -
- <%= for party_poke <- actor.party do %> -
-
-
- - {party_poke.species} - - <%= if party_poke.shiny do %> - ✦ Shiny - <% end %> -
- - Lv.{party_poke.level} - -
-
- - {party_poke.ability} - - - {party_poke.nature |> String.replace("cobblemon:", "")} - -
-
- <%= for move <- party_poke.moves do %> - - {move.name} - {move.pp}/{move.max_pp} - - <% end %> -
-
- <% end %> -
-
- <% end %> -
- <% end %> -
-
- <% end %> -
-
-
-
- """ - end -end diff --git a/lib/cobblemon_ui_web/live/dashboard_live.ex b/lib/cobblemon_ui_web/live/dashboard_live.ex index 964535c..fc062ad 100644 --- a/lib/cobblemon_ui_web/live/dashboard_live.ex +++ b/lib/cobblemon_ui_web/live/dashboard_live.ex @@ -14,6 +14,7 @@ defmodule CobblemonUiWeb.DashboardLive do players: players, selected_player: nil, player_data: nil, + battle: nil, selected_pokemon: nil, view_mode: :party, loading: false, @@ -25,10 +26,13 @@ defmodule CobblemonUiWeb.DashboardLive do def handle_params(%{"uuid" => uuid}, _uri, socket) do case CobblemonUi.CobblemonFS.get_player(uuid) do {:ok, data} -> + battle = find_player_battle(uuid) + {:noreply, assign(socket, selected_player: uuid, player_data: data, + battle: battle, selected_pokemon: nil, error: nil )} @@ -52,7 +56,7 @@ defmodule CobblemonUiWeb.DashboardLive do end def handle_params(_params, _uri, socket) do - {:noreply, assign(socket, selected_player: nil, player_data: nil, selected_pokemon: nil)} + {:noreply, assign(socket, selected_player: nil, player_data: nil, battle: nil, selected_pokemon: nil)} end @impl true @@ -89,9 +93,11 @@ defmodule CobblemonUiWeb.DashboardLive do socket = if uuid = socket.assigns.selected_player do + battle = find_player_battle(uuid) + case CobblemonUi.CobblemonFS.get_player(uuid) do - {:ok, data} -> assign(socket, player_data: data, error: nil) - _ -> socket + {:ok, data} -> assign(socket, player_data: data, battle: battle, error: nil) + _ -> assign(socket, battle: battle) end else socket @@ -118,12 +124,6 @@ defmodule CobblemonUiWeb.DashboardLive do
- <.link - navigate={~p"/battles"} - class="btn btn-ghost btn-sm gap-2 hover:bg-base-300/50 transition-colors" - > - <.icon name="hero-bolt" class="size-4 text-error" /> Battles -
+ <%!-- Active battle --%> + <.battle_panel :if={@battle} battle={@battle} player_id={@selected_player} /> + <%!-- View mode tabs --%>