-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: ✨ Catfishes know about other catfishes #264
base: development
Are you sure you want to change the base?
Changes from 9 commits
5757927
6299f0f
187db5a
f212b40
bc3ee58
e9dab4b
ce43550
8d3b19a
349a320
bbad02f
765dc3d
b77ac4a
a56d13d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
export let lobby: Lobby; | ||
export let lobbyCode: string; | ||
export let catfishes: string[]; // empty for cats or spectators | at least one for catfishes | ||
|
||
let errorMessage: string = ""; | ||
|
||
|
@@ -60,7 +61,9 @@ | |
on:click={() => vote(lobby.uids[i])} | ||
> | ||
<AvatarImg {avatar} /> | ||
<span class="mdc-typography--subtitle1">{displayName ?? ""}</span> | ||
<span class="mdc-typography--subtitle1 " class:catfish={catfishes.includes(lobby.uids[i])} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you acedentaly added space in the |
||
>{displayName ?? ""}</span | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. personally I like this <span>
text
</span> more than this <span
>text</span
> |
||
> | ||
<div class="mdc-typography--caption"> | ||
{#if alive} | ||
Answer: {promptAnswer ?? "no answer"} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
import Header from "$components/Header.svelte"; | ||
import LobbySettings from "$components/LobbySettings.svelte"; | ||
|
||
import { onSnapshot, doc, getDoc, type Unsubscribe } from "firebase/firestore"; | ||
import { onSnapshot, doc, getDoc, type Unsubscribe, query, where, CollectionReference } from "firebase/firestore"; | ||
import { onMount, onDestroy } from "svelte"; | ||
import { getPrivatePlayerCollection, lobbyCollection } from "$lib/firebase/firestore-collections"; | ||
import { GAME_STATE_DURATIONS_DEFAULT, type Lobby, type PrivatePlayer } from "$lib/firebase/firestore-types/lobby"; | ||
|
@@ -29,6 +29,11 @@ | |
let privatePlayer: PrivatePlayer | undefined = undefined; | ||
let unsubscribePrivatePlayer: Unsubscribe | undefined = undefined; | ||
|
||
let privatePlayerCollection: CollectionReference<PrivatePlayer>; | ||
|
||
let catfishes: string[] = []; // empty for cats or spectators | at least one for catfishes | ||
let unsubscribeCatfishes: Unsubscribe | undefined = undefined; | ||
|
||
let countdown = GAME_STATE_DURATIONS_DEFAULT.WAIT; | ||
$: countdownVisible = lobby != undefined && DISPLAY_TIMERS[lobby.state] == true; | ||
let timer: ReturnType<typeof setInterval>; | ||
|
@@ -72,7 +77,7 @@ | |
return; | ||
} | ||
|
||
const privatePlayerCollection = getPrivatePlayerCollection(lobbyDocRef); | ||
privatePlayerCollection = getPrivatePlayerCollection(lobbyDocRef); | ||
const privatePlayerDocRef = doc(privatePlayerCollection, $user.uid); | ||
|
||
updateCountdown(); | ||
|
@@ -115,6 +120,8 @@ | |
unsubscribeLobby?.(); | ||
// unsub from privatePlayer | ||
unsubscribePrivatePlayer?.(); | ||
// unsub from catfishes query | ||
unsubscribeCatfishes?.(); | ||
}); | ||
|
||
function errorToJoin(errorMessage: string) { | ||
|
@@ -156,6 +163,31 @@ | |
} | ||
} | ||
} | ||
|
||
$: privatePlayer, getCatfishes(); | ||
function getCatfishes() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we call unsubscribeCatfishes here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I understand but explain why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure the way the code is currently written we resubscribe every time the private player changes (each time there is a new prompt for example) but we never unsubscribe so that will put a lot of unwanted stress on the database. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you saying subscribe for that moment then unsubscribe? And a side note I think the getDocs function might be better since we're not using the newly updated documents to display to the user or anything There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I'm saying unsubscribe before you subscribe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah getDocs makes sense to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// if the current player is a catfish we want them to know all the other catfishes | ||
if (privatePlayer !== undefined && privatePlayer.role == "CATFISH") { | ||
const catfishQuery = query<PrivatePlayer>(privatePlayerCollection, where("role", "==", "CATFISH")); | ||
|
||
// only allow subscribing during ROLE phase | ||
if (lobby?.state == "ROLE") { | ||
unsubscribeCatfishes = onSnapshot( | ||
catfishQuery, | ||
(queryCollection) => { | ||
catfishes = queryCollection.docs.map((doc) => doc.id); | ||
}, | ||
(err) => { | ||
console.error(err); | ||
errorMessage = err instanceof Error ? err.message : String(err); | ||
} | ||
); | ||
} else { | ||
// otherwise unsubscribe | ||
unsubscribeCatfishes?.(); | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<svelte:window on:beforeunload={onbeforeunload} /> | ||
|
@@ -204,7 +236,7 @@ | |
<CircularProgress indeterminate /> | ||
</div> | ||
{:else if lobby.state === "ROLE"} | ||
<Role {privatePlayer} /> | ||
<Role {lobby} {privatePlayer} {catfishes} /> | ||
{:else if lobby.state === "PROMPT"} | ||
{#if lobby.alivePlayers.includes($user.uid)} | ||
<Prompt prompt={privatePlayer.prompt} uid={$user.uid} {lobbyCode} /> | ||
|
@@ -213,11 +245,12 @@ | |
<ChatRoom | ||
{lobby} | ||
{lobbyCode} | ||
{catfishes} | ||
isStalker={privatePlayer.stalker} | ||
isSpectator={!lobby.alivePlayers.includes($user.uid)} | ||
/> | ||
{:else if lobby.state === "VOTE"} | ||
<Vote {lobby} {lobbyCode} /> | ||
<Vote {lobby} {lobbyCode} {catfishes} /> | ||
{:else if lobby.state === "RESULT"} | ||
<Result {lobby} /> | ||
{:else if lobby.state === "END"} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,7 @@ a:visited { | |
.error { | ||
color: theme.$error; | ||
} | ||
|
||
.catfish { | ||
color: #d32f2f; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code is duplicated in |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,7 @@ a:visited { | |
.error { | ||
color: theme.$error; | ||
} | ||
|
||
.catfish { | ||
color: #d32f2f; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,17 @@ service cloud.firestore { | |
} | ||
|
||
match /privatePlayers/{uid} { | ||
|
||
function isCatfish(){ | ||
return get(/databases/$(database)/documents/lobbies/$(code)/privatePlayers/$(request.auth.uid)).data.role == "CATFISH"; | ||
} | ||
|
||
function isCatfishResource(){ | ||
return resource.data.role == "CATFISH" | ||
} | ||
|
||
allow get: if request.auth.uid == uid; | ||
allow list: if isCatfish() && isCatfishResource(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really want catfish to be able to read the entire privatePlayer document? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're only allowed to read other catfish private player docs in which only holds the their role(which we want them to know), stalker(wouldn't matter if they know because they're working together), and prompt in which they would have the same prompt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I guess so but it feels wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have a better idea lmk. We'd be only duplicating a little bit of data if you do have one |
||
} | ||
|
||
match /promptAnswers/{uid} { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this if still needed?