git repos / blockattack-game

commit 4728de18

Poul Sander · 2024-04-14 20:01
4728de1804b277fe7d93a1a7c9a5308105871936 patch · browse files
parent f45790f5f879c9570cf0e2d6d70a44caeb363f8c

Set standard background if the background has been removed.

Changed files

M source/code/themes.cpp before
M source/code/themes.hpp before
diff --git a/source/code/themes.cpp b/source/code/themes.cpp index 4f7f8a9..64c0ff7 100644 --- a/source/code/themes.cpp +++ b/source/code/themes.cpp
@@ -138,7 +138,7 @@ static size_t current_theme = 0;
void ThemesFillMissingFields(Theme& theme) {
- if (theme.background.name.empty()) {
+ if (theme.background.name.empty() || !ThemesBackgroundExists(theme.background.name) ){
//If the theme does not define a background then use the standard.
theme.background.name = "standard";
}
@@ -156,10 +156,10 @@ static void ThemesReadDataFromFile(const std::string& filename) {
}
json j = json::parse(s);
ThemeFileData tfd = j;
- for (auto& bg : tfd.background_data) {
+ for (const auto& bg : tfd.background_data) {
background_data[bg.name] = bg;
}
- for (auto& dec : tfd.decoration_data) {
+ for (const auto& dec : tfd.decoration_data) {
decoration_data[dec.name] = dec;
}
for (const Theme& theme : tfd.themes) {
@@ -301,6 +301,11 @@ void ThemesAddOrReplace(const Theme& theme) {
themes.push_back(theme);
}
+bool ThemesBackgroundExists(const std::string& name) {
+ ThemesInit();
+ return background_data.find(name) != background_data.end();
+}
+
BackGroundData ThemesGetNextBackground(const std::string& current) {
ThemesInit();
BackGroundData ret = background_data["standard"];
@@ -357,14 +362,6 @@ ThemeBorderData ThemesGetNextBorder(const std::string& current) {
return ret;
}
-void ThemesValidateAndFix(Theme& theme) {
- ThemesInit();
- if (!sago::FileExists(fmt::format("textures/backgrounds/{}.jpg", theme.background.name).c_str()) && !sago::FileExists(fmt::format("textures/backgrounds/{}.png", theme.background.name).c_str())) {
- theme.background.name = "standard";
- }
- ThemesFillMissingFields(theme);
-}
-
void ThemesInitCustomBackgrounds() {
std::vector<std::string> custom_backgrounds = sago::GetFileList("textures/backgrounds");
std::stringstream sprite_stream;
diff --git a/source/code/themes.hpp b/source/code/themes.hpp index da7c6c9..5c9c099 100644 --- a/source/code/themes.hpp +++ b/source/code/themes.hpp
@@ -77,8 +77,6 @@ void ThemesFillMissingFields(Theme& theme);
void ThemesAddOrReplace(const Theme& theme);
-void ThemesValidateAndFix(Theme& theme);
-
/**
* @brief returns a theme from a list
@@ -105,6 +103,8 @@ void ThemesSaveCustomSlots();
*/
size_t ThemesGetNumber(const std::string& name);
+bool ThemesBackgroundExists(const std::string& name);
+
BackGroundData ThemesGetNextBackground(const std::string& current);
std::string ThemesGetNextBoardBackground(const std::string& current);