/** * @file Story panel component displaying the main questline narrative. * @copyright nhcarrigan * @license Naomi's Public License * @author Naomi Carrigan */ /* eslint-disable max-lines-per-function -- Complex component with many render paths */ /* eslint-disable complexity -- Complex component with many conditional render paths */ import { STORY_CHAPTERS } from "@elysium/types"; import { type JSX, useState } from "react"; import { useGame } from "../../context/gameContext.js"; import { cdnImage } from "../../utils/cdn.js"; /** * Substitutes the character name placeholder in story text. * @param text - The story text with placeholders. * @param characterName - The player's character name. * @returns The text with placeholders replaced. */ const substituteCharacterName = ( text: string, characterName: string, ): string => { const fallback = characterName === "" ? "the guild leader" : characterName; return text.replaceAll("{characterName}", fallback); }; /** * Renders the story panel with chapter navigation and content. * @returns The JSX element. */ const StoryPanel = (): JSX.Element => { const { state, completeChapter } = useGame(); const [ activeChapterIndex, setActiveChapterIndex ] = useState(0); if (state === null) { return (
{"Loading…"}
{paragraph}
; })}{"What do you do?"}
{activeChapter.choices.map((storyChoice) => { const chapterForClosure = activeChapter; function handleChoice(): void { completeChapter(chapterForClosure.id, storyChoice.id); } return ( ); })}{"Your choice:"}{" "} { activeChapter.choices.find((storyChoice) => { return storyChoice.id === completion.choiceId; })?.label }
{substituteCharacterName( activeChapter.choices.find((storyChoice) => { return storyChoice.id === completion.choiceId; })?.outcome ?? "", characterName, )}
{"Chapter "} {activeChapterIndex + 1}
{"đź”’ This chapter has not yet been unlocked."}