Skip to content

Commit d47a413

Browse files
button to start new match; confirm match result
1 parent b792561 commit d47a413

File tree

4 files changed

+118
-49
lines changed

4 files changed

+118
-49
lines changed

Readme.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
😁
2-
![Imagem do projeto](https://raw.githubusercontent.com/YuriAlessandro/peladaManager/main/assets/image.png)
1+
# Gerenciador de Peladas
2+
3+
Com esse APP fica muito mais fácil você gerenciar sua pelada, de qualquer esporte que seja.
4+
5+
É possível adicionar os jogadores, definir os placares e montar os times de forma extremamente rápida.
6+
7+
![Imagem do projeto](https://raw.githubusercontent.com/YuriAlessandro/peladaManager/main/assets/image.png)
8+
9+
## Para desenvolver
10+
11+
Você precisa rodar o backend, que está no seguinte repositório: [https://github.com/isaacbatst/pelada-manager-backend](https://github.com/isaacbatst/pelada-manager-backend)
12+
13+
Após isso, só colocar o `index.html` para rodar em qualquer live service.

assets/image.png

108 KB
Loading

index.html

+27-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@
4848
display: flex !important;
4949
padding: 11px 17px !important;
5050
}
51+
52+
.select2-container--default .select2-selection--multiple {
53+
background-color: hsl(171deg, 100%,calc(9% + 0%));
54+
border-color: hsl(171deg, 100%,calc(41% + 0%));
55+
border-radius: var(--bulma-input-radius);
56+
color: hsl(var(--bulma-input-h), var(--bulma-input-s), var(--bulma-input-color-l));
57+
}
58+
59+
.select2-dropdown {
60+
background-color: hsl(171deg, 100%,calc(9% + 0%));
61+
border-color: hsl(171deg, 100%,calc(41% + 0%));
62+
color: hsl(var(--bulma-input-h), var(--bulma-input-s), var(--bulma-input-color-l));
63+
}
64+
65+
.select2-container--default .select2-results__option[aria-selected=true],
66+
.select2-container--default .select2-selection--multiple .select2-selection__choice {
67+
background-color: hsl(171deg, 100%,calc(41% + 0%));
68+
border-color: black;
69+
color: black;
70+
}
71+
72+
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
73+
color: hsl(171deg, 100%,calc(9% + 0%));
74+
}
5175
</style>
5276

5377
<link rel="apple-touch-icon" sizes="180x180" href="assets/apple-touch-icon.png">
@@ -144,6 +168,7 @@ <h1 id="team-1-captain" class="title">TEAM 1 CAPTAIN</h1>
144168
</div>
145169
<div class="cell is-row-span-2 has-text-centered">
146170
<h1 class="title">X</h1>
171+
<button id="start-next-match" class="button is-danger is-large" style="margin-top: 160px; display: none">Iniciar próxima partida</button>
147172
</div>
148173
<div class="cell has-text-centered">
149174
<h1 id="team-2-captain" class="title">TEAM 2 CAPTAIN</h1>
@@ -162,7 +187,6 @@ <h1 id="team-2-captain" class="title">TEAM 2 CAPTAIN</h1>
162187
<div class="grid">
163188
<div class="cell">
164189
<button id="swap-current-match" class="button is-warning is-large"><i class="fa-solid fa-right-left"></i></button>
165-
<button id="end-current-match" class="button is-warning is-large"><i class="fa-solid fa-stop"></i></button>
166190
</div>
167191
<div class="cell is-col-from-end-1">
168192
<button id="change-match-day" class="button is-info is-large"><i class="fa-solid fa-gear"></i></button>
@@ -196,7 +220,7 @@ <h1 id="team-2-captain" class="title">TEAM 2 CAPTAIN</h1>
196220
<button id="end-court" class="button is-danger is-large" style="display: none;">FINALIZAR QUADRA</button>
197221
<label class="checkbox">
198222
<input type="checkbox" id="dev-mode" />
199-
v5.Modo desenvolvedor
223+
v6.Modo desenvolvedor
200224
</label>
201225
</div>
202226
</div>
@@ -211,7 +235,7 @@ <h1>Histórico de Partidas</h1>
211235
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
212236
crossorigin="anonymous"></script>
213237
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
214-
<script type="module" src="./index.js?v=6"></script>
238+
<script type="module" src="./index.js?v=7"></script>
215239
<script>
216240
const options = window.location.hostname.includes('localhost') || window.location.hostname.includes('ngrok-free.app')
217241
? undefined : { scope: '/peladaManager/' };

index.js

+78-44
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ let currentId = 0;
1616
let autoSwitchTeamsPoints = 0;
1717
let joinCode = '';
1818
let lastGameDayMatch = 0;
19-
let courtId = null
19+
let courtId = null;
2020
const localStorage = window.localStorage;
21+
let playersToNextGame = [];
2122

2223
const createSpinner = (id) => {
2324
const wrapper = document.createElement('span');
@@ -77,15 +78,10 @@ socket.on('game-day:updated', async () => {
7778
lastGameDayMatch = activeGame.lastMatch;
7879
currentId = activeGame.id;
7980
joinCode = activeGame.joinCode;
80-
courtId = activeGame.courtId || null
81-
82-
if(playingTeams.length === 0) {
83-
const playersToTeam = findNextMatchPlayers()
84-
if(playersToTeam.length > 0) {
85-
playingTeams = await generateTeams(playersToTeam);
86-
await upsertGameDay();
87-
}
88-
}
81+
courtId = activeGame.courtId || null;
82+
playersToNextGame = activeGame.playersToNextGame || [];
83+
84+
// await upsertGameDay();
8985

9086
$('#add-new-player-select').empty();
9187
getPlayers()
@@ -96,7 +92,7 @@ socket.on('game-day:updated', async () => {
9692

9793

9894
currentMatchMaxPoints = maxPoints;
99-
updateCurrentMatch(playingTeams);
95+
updatePlayerList();
10096
$("#new-match-day").hide();
10197
$("#new-match-day-form").hide();
10298
$("#new-match-day-button").hide();
@@ -208,9 +204,10 @@ async function updateGameDay(isLive = true) {
208204
matches,
209205
isLive,
210206
autoSwitchTeamsPoints,
211-
playedOn: new Date()
207+
playedOn: new Date(),
208+
playersToNextGame,
212209
})
213-
})
210+
});
214211

215212
if(response.ok){
216213
socket.emit("game-day:updated", currentId);
@@ -337,14 +334,26 @@ function updatePlayerList() {
337334
const rows = playersToList.map(player => {
338335
const isPlayingHere = playingTeams.flat().some(p => p.name === player.name);
339336
const isPlayingSomewhereElse = otherPlayingTeams.flat().some(p => p.name === player.name);
340-
const rowClass = isPlayingHere ? 'is-selected' : isPlayingSomewhereElse ? 'is-selected is-warning' : '';
337+
const shouldBeOnNextMatch = playersToNextGame.some(p => p.name === player.name);
341338
const formatter = new Intl.NumberFormat('pt-BR', { maximumFractionDigits: 2, minimumFractionDigits: 2 });
342339
const elo = devMode ? `${formatter.format(player.mu)}/${formatter.format(player.sigma)}` : '';
343340
const playingClass = isPlayingSomewhereElse
344341
? ''
345342
: player.playing
346343
? 'remove-player is-clickable'
347344
: 'is-danger remove-player is-clickable';
345+
346+
let rowClass = '';
347+
if (isPlayingHere) {
348+
rowClass = 'is-selected';
349+
} else if (isPlayingSomewhereElse) {
350+
rowClass = 'is-selected is-warning';
351+
} else if (shouldBeOnNextMatch) {
352+
rowClass = 'is-info';
353+
} else {
354+
rowClass = player.playing ? 'remove-player is-clickable' : 'is-danger remove-player is-clickable';
355+
}
356+
348357
return `
349358
<tr class="${rowClass}">
350359
<th>${player.name}</th>
@@ -413,6 +422,9 @@ $("#all-player-list").on("click", ".remove-player", async function() {
413422

414423
const playerIndex = players.findIndex(player => player.name === playerName);
415424
players[playerIndex].playing = !players[playerIndex].playing;
425+
426+
// Remove this player from next match
427+
playersToNextGame = playersToNextGame.filter(player => player.name !== playerName);
416428

417429
await upsertGameDay();
418430
updatePlayerList();
@@ -529,7 +541,7 @@ async function updateCurrentMatch(teams) {
529541
}
530542

531543
$("#start-match-day").click(async function() {
532-
const startMatchDaySpinner = createSpinner('start-match-day-spinner');
544+
const startMatchDaySpinner = createSpinner('start-match-day-spinner');
533545
const button = document.getElementById('start-match-day');
534546
button.insertAdjacentElement('afterend', startMatchDaySpinner);
535547
button.setAttribute('disabled', 'disabled');
@@ -552,8 +564,6 @@ $("#start-match-day").click(async function() {
552564
maxPoints = parseInt($("#max-points").val());
553565
currentMatchMaxPoints = maxPoints;
554566
playersPerTeam = $("#players-per-team").val();
555-
556-
console.log('players', players)
557567

558568
if (playersPerTeam * 2 > players.length) {
559569
alert("Sem jogadores suficientes para começar a partida.");
@@ -566,7 +576,8 @@ $("#start-match-day").click(async function() {
566576
.filter(p => p.playing)
567577
.slice(0, playersPerTeam * 2);
568578
if(firstPlayers.length < playersPerTeam * 2) {
569-
alert("Não há jogadores suficientes para começar a partida.");
579+
alert("Não há jogadores suficientes para começar a partida nesta quadra agora.");
580+
570581
return;
571582
}
572583
playingTeams = await generateTeams(firstPlayers);
@@ -645,8 +656,18 @@ async function endMatch(victoryTeam) {
645656
players[playerIndex].sigma = player.sigma;
646657
});
647658

659+
// Match is ended, no one is playing
660+
playingTeams = [];
648661

649-
$("#match").hide();
662+
$("#team-1-captain").text("");
663+
$("#team-2-captain").text("");
664+
$("#team-1-players").empty();
665+
$("#team-2-players").empty();
666+
$("#score-team-1").text("00");
667+
$("#score-team-2").text("00");
668+
669+
updatePlayerList();
670+
650671
}
651672

652673
function findPlayerByName(players, name) {
@@ -691,6 +712,7 @@ function findNextMatchPlayers(winners = []) {
691712

692713

693714
async function startNewMatch(winningPlayers) {
715+
$("#start-next-match").hide();
694716
$("#match").show();
695717
$("#score-team-1").text("00");
696718
$("#score-team-2").text("00");
@@ -702,9 +724,14 @@ async function startNewMatch(winningPlayers) {
702724

703725
const nextMatchPlayers = findNextMatchPlayers(winningPlayers);
704726
currentMatchMaxPoints = maxPoints;
727+
728+
// Remove players from this match from players next game
729+
playersToNextGame = playersToNextGame.filter(player => !findPlayerByName(nextMatchPlayers, player.name));
730+
705731
randomServe();
706732
await updateCurrentMatch(await generateTeams(nextMatchPlayers));
707733
await upsertGameDay();
734+
updatePlayerList();
708735
}
709736

710737
function randomServe() {
@@ -746,19 +773,35 @@ $(".score-point").click(async function() {
746773
}
747774

748775
if (team1Score >= currentMatchMaxPoints && diff >= 2) {
749-
await endMatch(0);
750-
await startNewMatch(playingTeams[0]);
776+
let confirmEndGame = window.confirm(`Time ${playingTeams[0][0].name} venceu a partida? Confirmar para encerrar.`);
777+
778+
if (confirmEndGame) {
779+
$("#start-next-match").show();
780+
playersToNextGame = playersToNextGame.concat(playingTeams[0]);
781+
await endMatch(0);
782+
await upsertGameDay();
783+
}
751784
} else if (team2Score >= currentMatchMaxPoints && diff >= 2) {
752-
await endMatch(1);
753-
await startNewMatch(playingTeams[1]);
785+
let confirmEndGame = window.confirm(`Time ${playingTeams[1][0].name} venceu a partida? Confirmar para encerrar.`);
786+
787+
if (confirmEndGame) {
788+
$("#start-next-match").show();
789+
playersToNextGame = playersToNextGame.concat(playingTeams[1]);
790+
await endMatch(1);
791+
await upsertGameDay();
792+
}
754793
}
755-
794+
756795
if (autoSwitchTeamsPoints > 0) {
757796
const totalPoints = team1Score + team2Score;
758797
if (totalPoints % autoSwitchTeamsPoints === 0) swapTeams();
759798
}
760799
});
761800

801+
$("#start-next-match").click(async function() {
802+
await startNewMatch(playersToNextGame);
803+
});
804+
762805
$(".undo-point").click(function() {
763806
const teamIndex = $(this).attr("id");
764807

@@ -767,10 +810,12 @@ $(".undo-point").click(function() {
767810

768811
if (teamIndex === "undo-1") {
769812
team1Score -= 1;
770-
$("#score-team-1").text(team1Score >= 0 ? team1Score : 0);
813+
const value = team1Score >= 0 ? team1Score : 0;
814+
$("#score-team-1").text(value.toString().padStart(2, 0));
771815
} else if (teamIndex === "undo-2") {
772816
team2Score -= 1;
773-
$("#score-team-2").text(team2Score >= 0 ? team2Score : 0);
817+
const value = team2Score >= 0 ? team2Score : 0;
818+
$("#score-team-2").text(value.toString().padStart(2, 0));
774819
}
775820

776821
upsertGameDay();
@@ -869,24 +914,6 @@ $("#change-match-day").click(function() {
869914
$("#max-points").val(maxPoints);
870915
});
871916

872-
$("#end-current-match").click(async function() {
873-
let team1Score = parseInt($("#score-team-1").text());
874-
let team2Score = parseInt($("#score-team-2").text());
875-
876-
if (team1Score === team2Score) {
877-
alert("Partida empatada, não é possível encerrar. Decida um vencedor.");
878-
return;
879-
}
880-
881-
const winningTeam = team1Score > team2Score ? 0 : 1;
882-
const losingTeam = 1 - winningTeam;
883-
884-
const confirm = window.confirm("Deseja realmente encerrar a partida?");
885-
if (confirm) {
886-
await startNewMatch(playingTeams[winningTeam], playingTeams[losingTeam]);
887-
}
888-
});
889-
890917
async function swapTeams() {
891918
const temp = playingTeams[0];
892919
playingTeams[0] = playingTeams[1];
@@ -1060,3 +1087,10 @@ $(document).ready(async function (){
10601087
socket.emit('join', currentId);
10611088
}
10621089
});
1090+
1091+
history.pushState(null, null, window.top.location.pathname + window.top.location.search);
1092+
window.addEventListener('popstate', (e) => {
1093+
e.preventDefault();
1094+
// Insert Your Logic Here, You Can Do Whatever You Want
1095+
history.pushState(null, null, window.top.location.pathname + window.top.location.search);
1096+
});

0 commit comments

Comments
 (0)