Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
68 changes: 56 additions & 12 deletions src/app/api/common/answer/answerAPI.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,66 @@
import { ICheckAnswerResult } from "@/interfaces/interfaces";
import { ICheckAnswerResult, IGetAnswerResult } from "@/interfaces/interfaces";
import { getDailyKey } from "@/util/time";
import { NextRequest, NextResponse } from "next/server";
import { firestore } from "@/app/api/firebase";

async function getGameAnswerDataFromDatabase(database_collection_name: string, answerKey: string) {
console.log("Getting answer for ", answerKey);
const answerDocRef = firestore
.collection(database_collection_name)
.doc("answers")
.collection("answers")
.doc(answerKey);

const answerDocData = (await answerDocRef.get()).data();

console.log("Answer doc data:", answerDocData);
return answerDocData
}

export async function getGameAnswer(
req: NextRequest,
database_collection_name: string
): Promise<NextResponse<IGetAnswerResult>> {
console.log("Fetching today's answer from the database");
const now = new Date();
console.log("Today is ", now);
const answerKey = getDailyKey(now);
const answerDocData = await getGameAnswerDataFromDatabase(database_collection_name, answerKey)

// if the answer is not in the database, return an error
// runbook: if this happens, the reset did NOT happen correctly
if (!answerDocData || !answerDocData.song || !answerDocData.song.length) {
console.error("Answer not found in the database for date", answerKey);
return NextResponse.json(
{
message: `Answer not found in the database for date ${answerKey}`,
song: "",
correct: false,
startTimeStamp: "",
endTimeStamp: "",
},
{ status: 500 }
);
}

return NextResponse.json(
{
message: `Here is today's answer.`,
correct: true,
song: answerDocData.song,
startTimeStamp: answerDocData.startTimeStamp,
endTimeStamp: answerDocData.endTimeStamp,
},
{ status: 200 }
);
}

/**
* Check if the answer is correct.
* Checks the answer in the database in the "today" document.
* @param req
*/
export async function getGameAnswer(
export async function checkGameAnswer(
req: NextRequest,
database_collection_name: string
): Promise<NextResponse<ICheckAnswerResult>> {
Expand All @@ -25,20 +77,12 @@ export async function getGameAnswer(
{ status: 400 }
);
}

console.log("Fetching today's answer from the database");
const now = new Date();
console.log("Today is ", now);
const answerKey = getDailyKey(now);
console.log("Getting answer for ", answerKey);
const answerDocRef = firestore
.collection(database_collection_name)
.doc("answers")
.collection("answers")
.doc(answerKey);

const answerDocData = (await answerDocRef.get()).data();

console.log("Answer doc data:", answerDocData);
const answerDocData = await getGameAnswerDataFromDatabase(database_collection_name, answerKey)

// if the answer is not in the database, return an error
// runbook: if this happens, the reset did NOT happen correctly
Expand Down
15 changes: 12 additions & 3 deletions src/app/api/game/answer/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
import { FIREBASE_DATABASE_COLLECTION_NAME } from "@/constants";
import { ICheckAnswerResult } from "@/interfaces/interfaces";
import { getGameAnswer } from "@/app/api/common/answer/answerAPI";
import { ICheckAnswerResult, IGetAnswerResult } from "@/interfaces/interfaces";
import { checkGameAnswer, getGameAnswer } from "@/app/api/common/answer/answerAPI";

export async function PATCH(
req: NextRequest
): Promise<NextResponse<ICheckAnswerResult>> {
return await getGameAnswer(req, FIREBASE_DATABASE_COLLECTION_NAME);
return await checkGameAnswer(req, FIREBASE_DATABASE_COLLECTION_NAME);
}

export async function GET(
req: NextRequest
): Promise<NextResponse<IGetAnswerResult>> {
return await getGameAnswer(
req,
FIREBASE_DATABASE_COLLECTION_NAME
);
}
15 changes: 12 additions & 3 deletions src/app/api/instrumental/answer/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { NextRequest, NextResponse } from "next/server";
import { FIREBASE_DATABASE_COLLECTION_NAME_INSTRUMENTAL_MODE } from "@/constants";
import { ICheckAnswerResult } from "@/interfaces/interfaces";
import { getGameAnswer } from "@/app/api/common/answer/answerAPI";
import { ICheckAnswerResult, IGetAnswerResult } from "@/interfaces/interfaces";
import { checkGameAnswer, getGameAnswer} from "@/app/api/common/answer/answerAPI";

export async function PATCH(
req: NextRequest
): Promise<NextResponse<ICheckAnswerResult>> {
return await getGameAnswer(
return await checkGameAnswer(
req,
FIREBASE_DATABASE_COLLECTION_NAME_INSTRUMENTAL_MODE
);
}

export async function GET(
req: NextRequest
): Promise<NextResponse<IGetAnswerResult>> {
return await getGameAnswer(
req,
FIREBASE_DATABASE_COLLECTION_NAME_INSTRUMENTAL_MODE
);
}
File renamed without changes.
30 changes: 29 additions & 1 deletion src/app/services/gameService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import { ValidAPIBaseEndpoint } from "@/constants";
import { HttpError, ICheckAnswerResult } from "@/interfaces/interfaces";
import { HttpError, ICheckAnswerResult, IGetAnswerResult } from "@/interfaces/interfaces";
import { getNextResetTime } from "@/util/time";

export async function getAnswer(
base_endpoint: ValidAPIBaseEndpoint
): Promise<IGetAnswerResult> {
const response = await fetch(`${base_endpoint}/answer`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});

if (!response.ok) {
let errorMessage = await response.text();
if (response.status === 429) {
errorMessage = "Try again in a minute.";
}
throw new HttpError(errorMessage, response.status);
}

const data: IGetAnswerResult = await response.json();

return {
message: data.message,
song: data.song,
startTimeStamp: data.startTimeStamp,
endTimeStamp: data.endTimeStamp,
};
}

export async function checkAnswer(
guess: string,
base_endpoint: ValidAPIBaseEndpoint
Expand Down
8 changes: 1 addition & 7 deletions src/components/Game/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ export default function Game({
useEffect(() => {
logEvent("page_view");

if (getYearMonthDay(new Date()) === "2025-11-14") {
createSystemNotification(
"Something broke earlier today! The song did not update properly. If you are having problems guessing the song, try running the game in Incognito mode!"
);
}

// if we are in legend mode, add a gradient to the background
const root = document.documentElement;
const body = document.body;
Expand All @@ -130,7 +124,7 @@ export default function Game({
// optional cleanup of CSS vars
root.style.removeProperty("--overlay-gradient");
// advertise legend mode
// createInformationalNotification("Legend mode is out! Go to the main menu and check it out!", "Great news!")
createInformationalNotification("Legend mode is out! Go to the main menu and check it out!", "Great news!")
}

// load volume from localStorage
Expand Down
3 changes: 1 addition & 2 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ export default function Menu() {
</Button>
<Button
onClick={() => {
// playButtonSoundLegend();
playButtonSoundLegend();
}}
size="lg"
w={buttonWidth}
variant="filled"
component="a"
color={PRIMARY_COLOR}
leftSection={<IconSword />}
disabled={true}
>
Legend (Instrumentals)
</Button>
Expand Down
35 changes: 31 additions & 4 deletions src/components/modals/DisclaimerModal/DisclaimerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PRIMARY_COLOR } from "@/config/theme";
import { useButtonSound } from "@/hooks/audio/useButtonSound";
import ModalTitle from "../ModalTitle";
import { SUPPORT_EMAIL } from "@/constants";
import SongLyrics from "../SongLyrics";

export default function DisclaimerModal({
openState,
Expand Down Expand Up @@ -41,8 +42,11 @@ export default function DisclaimerModal({
<Title order={4}>Attribution / Credits</Title>
<Title order={5}>Game/Coding</Title>
<Text>Yours Truly: Dylan</Text>
<SongLyrics mtOverride={null}>
<Text>I'm super honored that you're playing and enjoying Epicdle! If you enjoyed the game, the best way to support me is to share it with your friends and let me know how much you enjoy the game! </Text>
</SongLyrics>
<Text>
Got any problems or questions? Shoot me an email:{" "}
Got any problems, questions, or suggestions? Please shoot me an email:{" "}
<Anchor
href={`mailto:${SUPPORT_EMAIL}`}
target="_blank"
Expand All @@ -54,6 +58,29 @@ export default function DisclaimerModal({

<Title order={5}>Music</Title>
<Text>Jorge Rivera-Herrans, Winion Entertainment LLC</Text>
<List>
<List.Item>
<Anchor
href="https://www.youtube.com/@JayHerrans"
target="_blank"
rel="noreferrer"
>
YouTube
</Anchor>
</List.Item>
</List>
<Text>SIM Instrumentals</Text>
<List>
<List.Item>
<Anchor
href="https://www.youtube.com/watch?v=3lagxsoGf8I&list=PLtzLG85ydSlh-Fx231WzUUR5mHWqDNdfg"
target="_blank"
rel="noreferrer"
>
YouTube Playlist
</Anchor>
</List.Item>
</List>
<Title order={5}>Album Art</Title>
<Text>
<Anchor
Expand Down Expand Up @@ -173,12 +200,12 @@ export default function DisclaimerModal({
{/* --- Footer Content --- */}
<Title order={4}>Disclaimer</Title>
<Text>
I'm just a humble developer who codes for fun. This is a completely
I'm just a humble developer who codes fun things. I will never paywall any features, add ads, or otherwise seek to actively monetize Epicdle. Epicdle is a completely
free, fan-made project created out of love for the musical.
</Text>
<Text>
If you enjoy the game and would like to support me to help cover the
game server maintenance and other costs coming out of my own pocket,
Still, if you enjoy the game and would like to support me to help cover the
game server maintenance and other related costs coming out of my own pocket,
you can do so{" "}
<Anchor
href="https://buymeacoffee.com/dylanvu"
Expand Down
4 changes: 4 additions & 0 deletions src/components/modals/LoseModal/LoseModal.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.game {
color: black;
}

.revealButton {
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
Loading