Skip to content

Commit

Permalink
Minor swiss fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vtm9 committed Nov 1, 2023
1 parent 2cef237 commit 033ff71
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export const activeGameReady = machine => dispatch => {
dispatch(actions.setTournamentsInfo(data));
machine.send('tournament:game:created', { payload });
if (!Gon.getAsset('cancel_redirect_to_new_game')) {
setTimeout(() => { window.location.replace(makeGameUrl(payload.gameId)); }, 500);
setTimeout(() => { window.location.replace(makeGameUrl(payload.gameId)); }, 10);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ export const connectToTournamentPlayer = () => dispatch => {
const handleRoundFinished = response => {
const data = camelizeKeys(response);

dispatch(actions.updateTournamentData({ state: data.state, breakState: 'on' }));
dispatch(actions.updateTournamentData({ state: data.state, breakState: data.breakState }));
dispatch(actions.updateTournamentMatches(data.matches));
dispatch(actions.updateTournamentGameResults(data.gameResults));
};

const handleTournamentRoundCreated = response => {
Expand All @@ -72,7 +71,7 @@ export const connectToTournamentPlayer = () => dispatch => {

setTimeout(params => {
dispatch(actions.setActiveGameId(params));
}, 1000, data);
}, 10, data);
};

const refs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const RoundStatus = ({ playerId, matches }) => {
}

if (
(player.score > opponent.score)
(player.score > opponent.score)
|| (
(player.score === opponent.score)
&& (player.winMatches.length > opponent.winMatches.length)
Expand Down Expand Up @@ -312,7 +312,7 @@ function TournamentPlayer({
<div className="container-fluid d-flex flex-column min-vh-100">
<div className={spectatorDisplayClassName} style={{ flex: '1 1 auto' }}>
<div className="d-flex flex-column col-12 col-xl-4 col-lg-6 p-1">
{GameStateCodes.playing === gameState ? <GamePanel /> : <MatchesPannel />}
{(tournament.breakState === 'off' && tournament.state === TournamentStates.active) ? <GamePanel /> : <MatchesPannel />}
</div>
<SpectatorEditor
switchedWidgetsStatus={switchedWidgetsStatus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function useRoundStatistics(
playerId,
matches,
) {
if (matches.length === 0) {
if (matches.length === 0 && playerId) {
return [emptyStats, emptyStats];
}

Expand All @@ -37,7 +37,7 @@ function useRoundStatistics(
const opponentWinMatches = matches.filter(match => opponentId === match.winnerId);

const playerScore = sum(finishedMatches.map(match => match.playerResults[playerId].score || 0));
const opponentScore = sum(finishedMatches.map(match => match.playerResults[opponentId].score || 0));
const opponentScore = sum(finishedMatches.map(match => match.playerResults[opponentId]?.score || 0));

const playerAvgTests = matchesCount !== 0
? sum(finishedMatches.map(match => match.playerResults[playerId]?.resultPercent || 0)) / matchesCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ defmodule Codebattle.Tournament.Base do
end

defp maybe_start_rematch(tournament, params) do
if round_ends_by_time?(tournament) and seconds_to_end_round(tournament) > 10 do
if round_ends_by_time?(tournament) and seconds_to_end_round(tournament) > 15 do
finished_match = get_match(tournament, params.ref)

match_id = Enum.count(tournament.matches)
Expand All @@ -237,6 +237,8 @@ defmodule Codebattle.Tournament.Base do
|> Enum.map(&get_player(tournament, &1))
|> Enum.map(&Tournament.Player.new!/1)

# TODO: add timeout without blocking server for rematches
:timer.sleep(5000)
game_id = create_game(tournament, match_id, players)

match = %Tournament.Match{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule CodebattleWeb.TournamentPlayerChannel do
def handle_info(%{event: "tournament:round_created", payload: payload}, socket) do
push(socket, "tournament:round_created", %{
state: payload.state,
break_state: payload.break_state
break_state: "off"
})

{:noreply, socket}
Expand All @@ -55,7 +55,7 @@ defmodule CodebattleWeb.TournamentPlayerChannel do

push(socket, "tournament:round_finished", %{
state: payload.state,
break_state: payload.break_state,
break_state: "on",
matches: matches
})

Expand Down

0 comments on commit 033ff71

Please sign in to comment.