From d5d9179872dc4b12530d4c11655f303a2c6c992b Mon Sep 17 00:00:00 2001 From: Wouter Wijsman Date: Sat, 26 Oct 2024 00:47:21 +0200 Subject: [PATCH] Load credits file in credits menu --- src/states/CreditsState.cpp | 31 +++++++++++++++++++++++++++++++ src/states/CreditsState.hpp | 1 + 2 files changed, 32 insertions(+) diff --git a/src/states/CreditsState.cpp b/src/states/CreditsState.cpp index b68fded..eb2e32e 100644 --- a/src/states/CreditsState.cpp +++ b/src/states/CreditsState.cpp @@ -6,12 +6,18 @@ #include "../utils.hpp" #include "GameState.hpp" +#include +#include + CreditsState::CreditsState(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options) : renderer(renderer), fonts(fonts), sounds(sounds), options(options), theme(renderer, options, Theme::MENU) { this->text_title = fonts->getTexture(renderer, _("Credits"), FontType::TITLE, {COLOR_MENU_TITLE.r, COLOR_MENU_TITLE.g, COLOR_MENU_TITLE.b, COLOR_MENU_TITLE.a}); this->text_bottom = fonts->getTexture(renderer, _("press confirm for next, cancel to go back"), FontType::NORMAL, {255, 255, 255, 255}); + std::vector credits = this->loadCredits(); + + std::string standard_mode_completed = options->getStandardModeCompleted() ? _("yes") : _("no"); texts.push_back(fonts->getTexture(renderer, _("standard mode completed: ") + standard_mode_completed, FontType::SMALL, {255, 255, 255, 255})); texts.push_back(fonts->getTexture(renderer, _("highest level reached in challenge mode: ") + std::to_string(options->getChallengeModeHighscore()), FontType::SMALL, {255, 255, 255, 255})); @@ -83,6 +89,31 @@ int CreditsState::getTextY(int number) { return this->options->getScreenHeight()/(((int) texts.size())+this->text_offset*2)*(number+this->text_offset); } +std::vector CreditsState::loadCredits() +{ + std::vector credits; + std::string credits_path = getResourcePath("CREDITS.md"); + + std::ifstream credits_file(credits_path); + + std::string line; + if (credits_file.is_open()) { + while(std::getline(credits_file, line)) { + credits.push_back(line); + } + } else { + SDL_Log("Error: Could not open CREDITS.md at %s", credits_path.c_str()); + } + + for (std::string credits_line : credits) + { + /* code */ + SDL_Log("%s", credits_line.c_str()); + } + + return credits; +} + State CreditsState::getNextState() { return this->next_state; } \ No newline at end of file diff --git a/src/states/CreditsState.hpp b/src/states/CreditsState.hpp index 2429691..277b95f 100644 --- a/src/states/CreditsState.hpp +++ b/src/states/CreditsState.hpp @@ -30,6 +30,7 @@ class CreditsState : public BaseState { State next_state = State::MENU; int getTextY(int number); + std::vector loadCredits(); public: CreditsState(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options); ~CreditsState();