Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

168 improve UI regarding minimum and maximum players in a room #201

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/jsLinters/eslint.xml

This file was deleted.

1 change: 1 addition & 0 deletions client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function onLogoClick() {
<div class="mb-2">
<portal-target name="banner" />
</div>
<portal-target name="modal" class="m-0" />
jengu288 marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/endRound/EndRound.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ watch(selectedId, async (val: string) => {
});
onMounted(() => {
selectedId.value = roomStore.self!.id;
selectedId.value = roomStore.self.id;
});
function sendVote() {
Expand Down
47 changes: 45 additions & 2 deletions client/src/components/lobby/Lobby.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<script setup lang="ts">
import PlayerList from '@/components/lobby/PlayerList.vue';
import Options from '@/components/lobby/Options.vue';
import { computed } from 'vue';
import { computed, onUnmounted } from 'vue';
import socket from '@/socket/socket.js';
import { AudioWrap } from '@/mixins/audiowrap.js';
import ClickMp3 from '@/assets/audio/click2.mp3';
import { useRoomStore } from '@/stores/room.js';
import { useI18n } from 'vue-i18n';
import { Portal } from 'portal-vue';
import { Modal } from 'bootstrap';
import { useGameStore } from '@/stores/game';
const click = new AudioWrap(ClickMp3);
const roomStore = useRoomStore();
const gameStore = useGameStore();

onUnmounted(() => {
Modal.getInstance(document.getElementById('recPlayersModal') as HTMLElement)?.dispose();
});

const leader = computed<boolean>(() => {
return !!roomStore.self && roomStore.self.leader;
Expand All @@ -17,7 +25,18 @@ const canStart = computed<boolean>(() => {
return leader.value && roomStore.players.length >= 3;
});

function startGameRequest() {
if (roomStore.players.length <= gameStore.options.recPlayers) {
//canStart is already checked so min players has been reached
startGame();
} else {
//we have more than the recommended amount of players per room
Modal.getOrCreateInstance(document.getElementById('recPlayersModal') as HTMLElement).show();
}
}

function startGame() {
Modal.getInstance(document.getElementById('recPlayersModal') as HTMLElement)?.hide();
click.play();
socket.emit('startGame');
}
Expand All @@ -28,6 +47,30 @@ const { t } = useI18n();
<div class="w-100 d-flex flex-column justify-content-between align-items-center gap-3 pt-1 pb-4">
<h1 v-t="'players'" class="font-fancy text-dark display-3" />
<player-list />
<portal to="modal">
<div
id="recPlayersModal"
class="modal fade"
tabindex="-1"
aria-labelledby="recPlayersModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 id="recPlayersModalLabel" class="modal-title mx-auto font-fancy display-6">Warning!</h5>
</div>
<div class="modal-body">
This lobby is a bit crowded for the best game experience. Splitting into two groups could make things more
enjoyable!
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-blue" @click="startGame">Start Game</button>
</div>
</div>
</div>
</div>
</portal>

<div class="w-100 d-flex flex-column justify-content-start align-items-center gap-3">
<options :disabled="!leader" />
Expand All @@ -37,7 +80,7 @@ const { t } = useI18n();
class="btn btn-blue fs-4 w-100"
:class="{ 'd-none': !leader, disabled: !canStart }"
:disabled="!canStart"
@click="startGame" />
@click="startGameRequest" />
</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/responseMatching/MatchingSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const gameStore = useGameStore();
const roomStore = useRoomStore();
const matchers = computed<Player[]>(() => {
return roomStore.players.filter((player: Player) => player.active && player.id !== gameStore.selector!.id);
return roomStore.players.filter((player: Player) => player.active && player.id !== gameStore.selector.id);
});
function endRound(): void {
Expand Down
28 changes: 14 additions & 14 deletions client/src/stores/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@
getters: {
isSelector(): boolean {
const room = useRoomStore();
return this.selector?.id === room.self!.id;
return this.selector?.id === room.self.id;

Check failure on line 89 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 89 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
jengu288 marked this conversation as resolved.
Show resolved Hide resolved
},
playerResponses() {
const room = useRoomStore();
return (id: string) => {
// default to self if not provided
if (!id) id = room.self!.id;
if (!id) id = room.self.id;

Check failure on line 95 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 95 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
return this.responses[id];
};
},
Expand All @@ -117,7 +117,7 @@
},
canEndRound() {
const room = useRoomStore();
const self = room.self!.id;
const self = room.self.id;

Check failure on line 120 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 120 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
if (this.selector?.id !== self) return false;

let finishedMatching = true;
Expand Down Expand Up @@ -145,7 +145,7 @@
},
resetResponses() {
const room = useRoomStore();
const selfId = room.self!.id;
const selfId = room.self.id;

Check failure on line 148 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 148 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
this.responses = {};
this.responses[selfId] = {
id: selfId,
Expand All @@ -157,20 +157,20 @@
},
useResponse(response: string) {
const room = useRoomStore();
this.responses[room.self!.id].used.push(response);
this.responses[room.self.id].used.push(response);

Check failure on line 160 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 160 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
},
useSelectorResponse(response: string) {
const room = useRoomStore();
this.responses[room.self!.id].used.push(response);
this.responses[room.self.id].used.push(response);

Check failure on line 164 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 164 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
if (this.selectionType === 'strike') {
this.responses[room.self!.id].selectedStrike = response;
this.responses[room.self.id].selectedStrike = response;

Check failure on line 166 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 166 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
} else {
this.responses[room.self!.id].selectedSike = response;
this.responses[room.self.id].selectedSike = response;

Check failure on line 168 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 168 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
}
},
unuseResponse(response: string) {
const room = useRoomStore();
this.responses[room.self!.id].used = this.responses[room.self!.id].used.filter((r) => r !== response);
this.responses[room.self.id].used = this.responses[room.self.id].used.filter((r) => r !== response);

Check failure on line 173 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 173 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'room.self' is possibly 'undefined'.

Check failure on line 173 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.

Check failure on line 173 in client/src/stores/game.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'room.self' is possibly 'undefined'.
},
async startTimer() {
if (this.timeoutId) {
Expand Down Expand Up @@ -205,15 +205,15 @@
exact: match.exact
});
}
if (match.player === room.self!.id) {
if (match.player === room.self.id) {
this.useResponse(match.response);
this.scene = 'MatchingSummary';
}
}
},
unmatch() {
const room = useRoomStore();
const selfId = room.self!.id;
const selfId = room.self.id;
const usedResponse = this.matches.find((match: Match) => match.player.id === selfId)!.response;
this.unuseResponse(usedResponse);
this.unmatched = true;
Expand Down Expand Up @@ -264,15 +264,15 @@

socket.on('promptResponse', (response: string) => {
const room = useRoomStore();
this.responses[room.self!.id].all.push(response);
this.responses[room.self.id].all.push(response);
});

socket.on('nextSelection', (data: { selector: string; selectionType: string }) => {
const room = useRoomStore();
const selector = room.players.find((player: Player) => player.id === data.selector);
// before we clear matches, make sure we used our match, this can happen if a next selection happens between
// unmatch and match
const selfId = room.self!.id;
const selfId = room.self.id;
const selfMatch = this.matches.find((match: Match) => match.player.id === selfId);
if (selfMatch && !this.responses[selfId].used.includes(selfMatch.response))
this.useResponse(selfMatch.response);
Expand Down Expand Up @@ -337,7 +337,7 @@
if (data.timer) {
void this.startTimer();
}
const isSelector = this.selector?.id === room.self!.id;
const isSelector = this.selector?.id === room.self.id;
let scene: Scene = 'Lobby';
//'lobby', 'response', 'selection', 'matching'
switch (data.stage) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/styles/_min-bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@import '~bootstrap/scss/list-group';
//@import "~bootstrap/scss/close";
//@import "~bootstrap/scss/toasts";
//@import "~bootstrap/scss/modal";
@import '~bootstrap/scss/modal';
@import '~bootstrap/scss/tooltip';
//@import "~bootstrap/scss/popover";
//@import "~bootstrap/scss/carousel";
Expand Down
2 changes: 2 additions & 0 deletions common/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { z } from 'zod';
// good for hiding beta features, can be moved to exposed options schema if we want clients to be able to control it
type ConfigFlags = {
maxPlayers: number;
recPlayers: number;
minPlayers: number;
promptSkipping: boolean;
};
Expand Down Expand Up @@ -65,6 +66,7 @@ export const defaultOptions: Options = {
sikeRetries: 0,
promptSkipping: true,
minPlayers: 3,
recPlayers: 5,
jengu288 marked this conversation as resolved.
Show resolved Hide resolved
maxPlayers: 12,
jengu288 marked this conversation as resolved.
Show resolved Hide resolved
packs: {},
customPrompts: []
Expand Down
Loading