Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/dreancaste/TriviaPP/llms.txt

Use this file to discover all available pages before exploring further.

Every trivia session in TriviaPP puts the player through 10 Star Wars questions drawn from two sources: a curated bank of classic lore questions and dynamically generated challenges built from live SWAPI data. Questions appear one at a time. The player selects one of four options, receives instant feedback, and then moves to the next question. Once all 10 questions are answered the session ends, the score is saved to both local storage and Firebase Firestore, and a game-over screen is displayed with the final result.
TriviaPP’s UI and all in-game text — questions, feedback messages, and labels — are written in Spanish.

Session Structure

Each game is exactly 10 questions long (totalQuestions = 10). A progress bar driven by progressValue = questionNumber / totalQuestions gives players a visual sense of how far through the session they are. Correct answers are worth 100 points each, so a perfect game yields a maximum score of 1 000 points. After every answer the app displays a feedback message:
  • Correct"¡Correcto, joven padawan!"
  • Incorrect"Incorrecto. La respuesta era: <correct answer>" — the right answer is revealed immediately.

Question Categories

Questions belong to one of four categories depending on how they are generated:
CategorySourceDescription
LoreHardcoded arrayClassic Star Wars knowledge — masters, planets, factions, and key saga events
PersonajesSWAPI /people page 1”¿De qué planeta es [character]?” — homeworld lookup per character
PlanetasSWAPI /planets page 1”¿Cuál es el clima de [planet]?” — climate translated from English to Spanish via MyMemory API
PelículasSWAPI /films”¿Quién dirigió la película ‘[film title]’?” — director drawn from all SWAPI films

Question Generation Logic

TriviaService.generateQuestion() uses a 60 / 40 probability split on every call:
  • 60 % of the time (random < 0.6) it draws from the internal loreQuestions array — 19 hand-crafted questions covering masters, Sith names, planets, orders, and characters.
  • 40 % of the time it picks at random among three live-data generators: generatePeopleQuestion(), generatePlanetQuestion(), and generateFilmQuestion(). Each generator fetches data from SWAPI at runtime and builds a question with four shuffled options using buildUniqueOptions().
Deduplication is handled through the usedQuestionKeys string array. Every question’s question string is stored in this array after it is served. Subsequent calls skip any question whose key is already present. If the entire loreQuestions bank is exhausted within a single session, usedQuestionKeys is automatically reset and the pool is re-used from the start. At the beginning of each new game TriviaService.resetUsedQuestions() clears the array entirely.

Scoring and State

TriviaPage tracks the full session state through the following properties:
PropertyTypePurpose
scorenumberRunning point total (increments by 100 per correct answer)
questionNumbernumber1-based index of the current question
totalQuestionsnumberFixed at 10
correctCountnumberCount of correct answers in the session
answeredbooleanLocks options after the player selects one
selectedAnswerstringThe option the player tapped
feedbackstringMessage shown after an answer is submitted
loadingbooleantrue while a new question is being fetched
gameFinishedbooleantrue after the 10th question is answered
The TriviaQuestion model used throughout the service and page is:
export interface TriviaQuestion {
  question: string;
  options: string[];
  correctAnswer: string;
  category: string;
}

Game End

When the player answers the 10th question, TriviaPage.finishGame() is called. It performs four write operations in sequence:
  1. History — a HistoryItem object (date, score, correct answers, total questions) is prepended to the local history array via StorageService.addHistory().
  2. Local ranking — a RankingItem object (display name, score) is upserted into the local top-20 list via StorageService.addRankingItem().
  3. Cumulative statsStorageService.updateStats(score, correctCount) increments gamesPlayed, accumulates correctAnswers, and updates maxScore if the new score is a personal best.
  4. FirebaseRankingService.addScore(displayName, score) writes the entry to the ranking collection in Firestore with today’s ISO date (YYYY-MM-DD).
The player’s display name comes from StorageService.getProfile().displayName, falling back to "Jugador" if no name has been set.

Haptic Feedback

If the player has enabled the vibration on error setting in their profile (profile.vibrateOnError === true), a heavy haptic impact fires every time a wrong answer is submitted:
await Haptics.impact({ style: ImpactStyle.Heavy });
This is powered by the Capacitor @capacitor/haptics plugin and only produces physical feedback on a real device.

Build docs developers (and LLMs) love