Skip to content

Commit

Permalink
Refactor naming to signal where the functions are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
sago007 committed Nov 15, 2023
1 parent b3d74fc commit 51c4029
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions source/code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ int main(int argc, char* argv[]) {
std::cout << "Renderer: " << info.name << "\n";
}
globalData.screen = renderer;
globalData.theme = getTheme(0);
globalData.theme = ThemesGet(0);
ResetFullscreen();
SetSDLIcon(sdlWindow);

Expand Down Expand Up @@ -1567,7 +1567,7 @@ int runGame(Gametype gametype, int level) {
if ( event.key.keysym.sym == SDLK_F5 ) {
}
if ( event.key.keysym.sym == SDLK_F11 ) {
globalData.theme = getNextTheme();
globalData.theme = ThemesGetNext();
} //F11
}
if ( event.key.keysym.sym == SDLK_F12 ) {
Expand Down
2 changes: 1 addition & 1 deletion source/code/menudef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static void PlayerConfigMenu() {
}

static void switchTheme() {
globalData.theme = getNextTheme();
globalData.theme = ThemesGetNext();
}


Expand Down
32 changes: 16 additions & 16 deletions source/code/themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ static bool initialized = false;
static size_t current_theme = 0;


static void FillMissingFields(Theme& theme) {
static void ThemesFillMissingFields(Theme& theme) {
if (theme.background.name.empty()) {
//If the theme does not define a background then use the standard.
theme.background.name = "standard";
}
theme.background = background_data[theme.background.name];
}

static void ReadThemeDataFromFile(const std::string& filename) {
static void ThemesReadDataFromFile(const std::string& filename) {
if (globalData.verboseLevel) {
std::cout << "Reading theme data from " << filename << "\n";
}
Expand All @@ -162,12 +162,12 @@ static void ReadThemeDataFromFile(const std::string& filename) {
std::cout << "Adding theme " << theme.theme_name << "\n";
}
themes.push_back(theme);
FillMissingFields(themes.back());
ThemesFillMissingFields(themes.back());
}
}


static void InitBackGroundData() {
static void ThemesInitBackGroundData() {
BackGroundData standard;
standard.name = "standard";
standard.background_sprite = "background";
Expand All @@ -182,7 +182,7 @@ static bool str_startswith(const std::string& s, const char* prefix) {
return (s.rfind(prefix, 0) == 0);
}

void DumpThemeData() {
static void ThemesDumpData() {
ThemeFileData tfd;
tfd.themes = themes;
for (auto& pair : background_data) {
Expand Down Expand Up @@ -219,38 +219,38 @@ static void ThemesAddCustomSlot(std::vector<Theme>& themes, int slot_number) {
Theme new_theme;
new_theme.theme_name = slot_name;
themes.push_back(new_theme);
FillMissingFields(themes.back());
ThemesFillMissingFields(themes.back());
}

void InitThemes() {
void ThemesInit() {
if (initialized) {
return;
}
initialized = true;
InitBackGroundData();
ThemesInitBackGroundData();
themes.resize(1); //Add the default theme
FillMissingFields(themes[0]);
ThemesFillMissingFields(themes[0]);
const std::vector<std::string>& theme_files = sago::GetFileList("themes");
for (const std::string& filename : theme_files) {
if (boost::algorithm::ends_with(filename,".json")) {
ReadThemeDataFromFile("themes/"+filename);
ThemesReadDataFromFile("themes/"+filename);
}
}
ReadThemeDataFromFile("custom_themes.json");
ThemesReadDataFromFile("custom_themes.json");
for (int i=1; i <= 4; ++i) {
ThemesAddCustomSlot(themes, i);
}
DumpThemeData();
ThemesDumpData();
}

Theme getNextTheme() {
InitThemes();
Theme ThemesGetNext() {
ThemesInit();
current_theme++;
current_theme = current_theme % themes.size();
return themes.at(current_theme);
}

Theme getTheme(size_t theme_number) {
InitThemes();
Theme ThemesGet(size_t theme_number) {
ThemesInit();
return themes.at(theme_number % themes.size());
}
4 changes: 2 additions & 2 deletions source/code/themes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ struct ThemeFileData {
* @brief returns a theme from a list
* @return A copy of a theme
*/
Theme getNextTheme();
Theme ThemesGetNext();

/**
* @brief getTheme returns a specific theme
* @param theme_number
* @return
*/
Theme getTheme(size_t theme_number);
Theme ThemesGet(size_t theme_number);

/**
* @brief Saves the themes starting with "custom_slot_" to "custom_themes.json"
Expand Down

0 comments on commit 51c4029

Please sign in to comment.