rBD IS WORKING!!!! at least for now!

This commit is contained in:
RezHackXYZ 2025-05-18 12:42:44 +05:30
parent 3ad30b476a
commit 8e1cfbcb6f
No known key found for this signature in database
31 changed files with 374 additions and 81 deletions

View file

@ -2,4 +2,4 @@ export function load({ params }) {
return {
gamePin: params.gamePin
};
}
}

View file

@ -1,11 +1,12 @@
<script>
import PlayingDisplay from "./components/DuringGame/display.svelte";
import AwnserQuetion from "./components/awnseringQuetions/display.svelte";
import LobbyDisplay from "./components/lobby/display.svelte";
import { Status } from "./logic/HostsData.svelte.js";
import { AutoUpdatePlayersList } from "./logic/UpdatePlayersList.js";
import { GetCurrentPlayers } from "./logic/GetCurrentPlayers.js";
import { IntializeGameStart } from "./logic/IntializeGameStart.js";
import { onMount } from "svelte";
import { name,playerid } from "./logic/HostsData.svelte.js";
export let data;
const gamePin = data.gamePin;
@ -13,6 +14,10 @@
onMount(() => {
GetCurrentPlayers(gamePin);
AutoUpdatePlayersList(gamePin);
IntializeGameStart(gamePin);
name.v = new URLSearchParams(new URL(window.location.href).search).get("name");
playerid.v = new URLSearchParams(new URL(window.location.href).search).get("playerid");
});
</script>
@ -23,7 +28,7 @@
{#if Status.v == "lobby"}
<LobbyDisplay {gamePin} />
{:else if Status.v == "started"}
<PlayingDisplay />
<AwnserQuetion />
{/if}
</div>
</div>

View file

@ -1,13 +0,0 @@
<script>
import { PeopleAwnseredQ, Totalplayers } from "./../../logic/HostsData.svelte.js";
</script>
<div class="mt-1 mb-3 flex w-full flex-col rounded-2xl border-2 border-green-400 p-2">
<h3>{PeopleAwnseredQ.v} out of {Totalplayers.v} have awnsered the quetion</h3>
<div class="flex-1 rounded-full border-2 border-gray-600">
<div
class="h-4 rounded-full bg-green-600 transition-all duration-500"
style="width: {(PeopleAwnseredQ.v / Totalplayers.v) * 100}%;"
></div>
</div>
</div>

View file

@ -1,13 +0,0 @@
<script>
import { currentQuestion, totalQuetions } from "./../../logic/HostsData.svelte.js";
</script>
<div class="mt-1 mb-3 flex w-full flex-col rounded-2xl border-2 border-green-400 p-2">
<h3>Question {currentQuestion.v + 1} of {totalQuetions.v} is beeing awnsered</h3>
<div class="flex-1 rounded-full border-2 border-gray-600">
<div
class="h-4 rounded-full bg-green-600 transition-all duration-500"
style="width: {(currentQuestion.v + 1 / totalQuetions.v) * 100}%;"
></div>
</div>
</div>

View file

@ -1,9 +0,0 @@
<script>
import PeopleAwnsered from "./PeopleAwnsered.svelte";
import QuetionsAwnsred from "./QuetionsAwnsred.svelte";
</script>
<h1 class="m-[0] text-7xl">HOSTING</h1>
<QuetionsAwnsred />
<PeopleAwnsered />

View file

@ -0,0 +1,22 @@
<script>
import { questions, Selected } from "../../logic/HostsData.svelte.js";
</script>
<div class="mt-5 grid grid-cols-2 gap-5 gap-x-3">
{#each questions.v.answers as answer, index}
<div class="flex">
<input
type="radio"
id="O{index}"
name="question"
class="peer sr-only"
value={index}
bind:group={Selected.v}
/>
<label
class="w-full cursor-pointer rounded-lg border-3 border-gray-600 bg-gray-600 pt-1 pr-2 pb-1 pl-2 text-center text-3xl transition-all peer-checked:border-blue-600 peer-checked:bg-blue-600 hover:border-blue-600"
for="O{index}">{answer}</label
>
</div>
{/each}
</div>

View file

@ -0,0 +1,13 @@
<script>
import { CurrentQuestion, TotalQuestions } from "../../logic/HostsData.svelte.js";
</script>
<div class="mb-5 flex w-full items-center justify-center gap-3">
<h3>Question {CurrentQuestion.v + 1} of {TotalQuestions.v}</h3>
<div class="flex-1 rounded-full border-2 border-gray-600">
<div
class="h-4 rounded-full bg-green-600 transition-all duration-700"
style="width: {(CurrentQuestion.v / TotalQuestions.v) * 100}%;"
></div>
</div>
</div>

View file

@ -0,0 +1,4 @@
<button
class="mt-4 cursor-pointer gap-0 rounded-lg bg-gray-700 p-2 text-3xl transition-all hover:scale-110"
>select a answer
</button>

View file

@ -0,0 +1,9 @@
<script>
import { SubmitAnswer } from "../../../logic/SubmitAnswer.js";
</script>
<button
class="mt-4 cursor-pointer gap-0 rounded-lg bg-green-700 p-2 text-3xl transition-all hover:scale-110 hover:-rotate-10"
onclick={SubmitAnswer}
>submit answer
</button>

View file

@ -0,0 +1,28 @@
<script>
import Question from "./text/Quetion.svelte";
import Awnsers from "./Awnsers.svelte";
import ProgressBar from "./ProgressBar.svelte";
import SelectFirst from "./buttons/SelectFirst.svelte";
import Wait from "./text/wait.svelte";
import SubmitAwnser from "./buttons/submitAwnser.svelte";
import { CurrentQuestion, Selected } from "../../logic/HostsData.svelte.js";
</script>
<div class="bg-grey-900 flex h-full items-center justify-center">
<div
class="flex max-w-[700px] flex-col items-center justify-center gap-1 rounded-lg bg-gray-900 p-8 shadow-lg"
>
<ProgressBar />
{#if CurrentQuestion.v != null}
<Question />
<Awnsers />
{#if Selected.v != null}
<SubmitAwnser />
{:else}
<SelectFirst />
{/if}
{:else}
<Wait />
{/if}
</div>
</div>

View file

@ -0,0 +1,7 @@
<script>
import { CurrentQuestion, questions } from "../../../logic/HostsData.svelte.js";
</script>
<h1 class="m-[0] text-center text-5xl">
Q{CurrentQuestion.v + 1}. {questions.v.question}
</h1>

View file

@ -0,0 +1 @@
<h1 class="m-[0] text-center text-5xl">Please wait for everyone else to answer the question.</h1>

View file

@ -1,9 +1,9 @@
export let players = $state({ v: [] });
export let players = $state({ v: {} });
export let Status = $state({ v: "lobby" });
export let questions = $state({ v: [] });
export let CurrentQuestion = $state({ v: -1 });
export let currentQuestion = $state({ v: 0 });
export let totalQuetions = $state({ v: 3 });
export let PeopleAwnseredQ = $state({ v: 0 });
export let Totalplayers = $state({ v: 3 });
export let questions = $state({ v: {} });
export let CurrentQuestion = $state({ v: null });
export let TotalQuestions = $state({ v: 0 });
export let Selected = $state({ v: null });
export let isWait = $state({ v: true });
export let name = $state({ v: "" });
export let playerid = $state({ v: null });

View file

@ -0,0 +1,22 @@
import { supabase } from "$lib/supabase.js";
import { NewStatus } from "./NewStatus.js";
export async function IntializeGameStart(gamepin) {
supabase
.channel(`game_status_${gamepin}`)
.on(
"postgres_changes",
{
event: "UPDATE",
schema: "public",
table: "games",
filter: `gamepin=eq.${gamepin}`,
},
(payload) => {
if (payload.new.status) {
NewStatus(payload.new.status, gamepin);
}
},
)
.subscribe();
}

View file

@ -0,0 +1,41 @@
import {
CurrentQuestion,
Status,
questions,
isWait,
Selected,
playerid,
} from "./HostsData.svelte.js";
import { supabase } from "$lib/supabase.js";
export async function NewStatus(NewStatus, gamePin) {
if (NewStatus == "completed") {
window.location.replace("/results/" + gamePin + "?playerID=" + playerid.v);
return;
}
Status.v = "started";
CurrentQuestion.v = Number(NewStatus.replace("question-", ""));
const { data: questionsData } = await supabase
.from("questions")
.select("id,questionstext,correctanswer")
.eq("gameid", Number(gamePin))
.order("id", { ascending: true });
const { data: answers } = await supabase
.from("answers")
.select("content")
.eq("questionid", Number(questionsData[CurrentQuestion.v].id))
.order("id", { ascending: true });
questions.v = {
question: questionsData[CurrentQuestion.v].questionstext,
correctAnswer: questionsData[CurrentQuestion.v].correctanswer,
answers: answers.map((answer) => answer.content),
questionid: questionsData[CurrentQuestion.v].id,
};
isWait.v = false;
Selected.v = null;
}

View file

@ -0,0 +1,31 @@
import { CurrentQuestion, Selected, questions, playerid } from "./HostsData.svelte.js";
import { supabase } from "$lib/supabase.js";
export async function SubmitAnswer() {
CurrentQuestion.v = null;
if (Selected.v == questions.v.correctAnswer) {
await supabase
.from("answeredby")
.insert([
{ questionid: questions.v.questionid, nameofanswerer: playerid.v, correct: true },
])
.select();
let { data: score } = await supabase.from("players").select("score").eq("id", playerid.v);
await supabase
.from("players")
.update({ score: score[0].score + 1 })
.eq("id", playerid.v)
.select();
} else {
await supabase
.from("answeredby")
.insert([
{ questionid: questions.v.questionid, nameofanswerer: playerid.v, correct: false },
])
.select();
}
}

View file

@ -1,6 +1,6 @@
import { supabase } from "$lib/supabase.js";
import { LobbyConnection } from "./UpdatePlayersList.js";
import { questions, Status, CurrentQuestion, currentQuestion } from "./HostsData.svelte.js";
import { questions, Status, CurrentQuestion } from "./HostsData.svelte.js";
export async function startGame(gamePin) {
await supabase.removeChannel(LobbyConnection);
@ -18,7 +18,7 @@ export async function startGame(gamePin) {
await supabase
.from("games")
.update({ status: `question-${currentQuestion.v}` })
.update({ status: `question-${CurrentQuestion.v}` })
.eq("gamepin", gamePin);