mirror of
https://github.com/pupperpowell/bibdle.git
synced 2026-02-04 10:54:44 -05:00
feat: Add Imposter game component and update project assets
This commit is contained in:
@@ -353,6 +353,54 @@ export function getRandomGreekVerses(count: number = 3): {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random set of verses from a specific book
|
||||
* Returns `count` consecutive verses by default
|
||||
*/
|
||||
export function getRandomVersesFromBook(
|
||||
bookNumber: number,
|
||||
count: number = 1
|
||||
): {
|
||||
bookId: string;
|
||||
bookName: string;
|
||||
chapter: number;
|
||||
startVerse: number;
|
||||
endVerse: number;
|
||||
verses: string[];
|
||||
} | null {
|
||||
const book = getBookByNumber(bookNumber);
|
||||
if (!book) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try up to 10 times to find a valid passage
|
||||
for (let attempt = 0; attempt < 10; attempt++) {
|
||||
const chapterNumber = getRandomChapterNumber(bookNumber);
|
||||
const verseCount = getVerseCount(bookNumber, chapterNumber);
|
||||
|
||||
// Skip chapters that don't have enough verses
|
||||
if (verseCount < count) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const startVerse = getRandomStartVerse(bookNumber, chapterNumber, count);
|
||||
const verses = extractVerses(bookNumber, chapterNumber, startVerse, count);
|
||||
|
||||
if (verses.length === count) {
|
||||
return {
|
||||
bookId: book.id,
|
||||
bookName: book.name,
|
||||
chapter: chapterNumber,
|
||||
startVerse,
|
||||
endVerse: startVerse + count - 1,
|
||||
verses
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a reference string from verse data
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user