Skip to content

Commit

Permalink
Load credits file in credits menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkwouter committed Oct 25, 2024
1 parent c767db8 commit d5d9179
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/states/CreditsState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
#include "../utils.hpp"
#include "GameState.hpp"

#include <fstream>
#include <iostream>

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<std::string> 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}));
Expand Down Expand Up @@ -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<std::string> CreditsState::loadCredits()
{
std::vector<std::string> 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;
}
1 change: 1 addition & 0 deletions src/states/CreditsState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CreditsState : public BaseState {
State next_state = State::MENU;

int getTextY(int number);
std::vector<std::string> loadCredits();
public:
CreditsState(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options);
~CreditsState();
Expand Down

0 comments on commit d5d9179

Please sign in to comment.