git repos / blockattack-game

blame: source/code/themes.cpp

normal view · raw

aaba4f1e Poul Sander 2023-07-25 13:34 1
/*
aaba4f1e Poul Sander 2023-07-25 13:34 2
===========================================================================
aaba4f1e Poul Sander 2023-07-25 13:34 3
blockattack - Block Attack - Rise of the Blocks
aaba4f1e Poul Sander 2023-07-25 13:34 4
Copyright (C) 2005-2023 Poul Sander
aaba4f1e Poul Sander 2023-07-25 13:34 5
aaba4f1e Poul Sander 2023-07-25 13:34 6
This program is free software: you can redistribute it and/or modify
aaba4f1e Poul Sander 2023-07-25 13:34 7
it under the terms of the GNU General Public License as published by
aaba4f1e Poul Sander 2023-07-25 13:34 8
the Free Software Foundation, either version 2 of the License, or
aaba4f1e Poul Sander 2023-07-25 13:34 9
(at your option) any later version.
aaba4f1e Poul Sander 2023-07-25 13:34 10
aaba4f1e Poul Sander 2023-07-25 13:34 11
This program is distributed in the hope that it will be useful,
aaba4f1e Poul Sander 2023-07-25 13:34 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
aaba4f1e Poul Sander 2023-07-25 13:34 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
aaba4f1e Poul Sander 2023-07-25 13:34 14
GNU General Public License for more details.
aaba4f1e Poul Sander 2023-07-25 13:34 15
aaba4f1e Poul Sander 2023-07-25 13:34 16
You should have received a copy of the GNU General Public License
aaba4f1e Poul Sander 2023-07-25 13:34 17
along with this program.  If not, see http://www.gnu.org/licenses/
aaba4f1e Poul Sander 2023-07-25 13:34 18
aaba4f1e Poul Sander 2023-07-25 13:34 19
Source information and contacts persons can be found at
aaba4f1e Poul Sander 2023-07-25 13:34 20
https://www.blockattack.net
aaba4f1e Poul Sander 2023-07-25 13:34 21
===========================================================================
aaba4f1e Poul Sander 2023-07-25 13:34 22
*/
aaba4f1e Poul Sander 2023-07-25 13:34 23
aaba4f1e Poul Sander 2023-07-25 13:34 24
aaba4f1e Poul Sander 2023-07-25 13:34 25
#include "themes.hpp"
2660ccea Poul Sander 2023-09-22 19:25 26
#include "sago/SagoMisc.hpp"
aaba4f1e Poul Sander 2023-07-25 13:34 27
#include <vector>
00759e5a Poul Sander 2023-09-24 20:01 28
#include <map>
2660ccea Poul Sander 2023-09-22 19:25 29
#include "nlohmann/json.hpp"
b9eda2d4 Poul Sander 2023-10-04 20:16 30
#include <iostream>
b9eda2d4 Poul Sander 2023-10-04 20:16 31
#include "global.hpp"
7d88cb38 Poul Sander 2023-10-05 20:48 32
#include <boost/algorithm/string/predicate.hpp>
68c75938 Poul Sander 2023-11-13 23:03 33
#include <fmt/core.h>
2660ccea Poul Sander 2023-09-22 19:25 34
2660ccea Poul Sander 2023-09-22 19:25 35
using json = nlohmann::json;
2660ccea Poul Sander 2023-09-22 19:25 36
2660ccea Poul Sander 2023-09-22 19:25 37
7602f86d Poul Sander 2024-01-10 21:39 38
const int NUMBER_OF_CUSTOM_SLOTS = 2;
7602f86d Poul Sander 2024-01-10 21:39 39
7602f86d Poul Sander 2024-01-10 21:39 40
b9eda2d4 Poul Sander 2023-10-04 20:16 41
void to_json(json& j, const ImgScale& p) {
b9eda2d4 Poul Sander 2023-10-04 20:16 42
	switch (p) {
b9eda2d4 Poul Sander 2023-10-04 20:16 43
	case ImgScale::Stretch:
b9eda2d4 Poul Sander 2023-10-04 20:16 44
		j = "stretch";
b9eda2d4 Poul Sander 2023-10-04 20:16 45
		break;
b9eda2d4 Poul Sander 2023-10-04 20:16 46
	case ImgScale::Tile:
b9eda2d4 Poul Sander 2023-10-04 20:16 47
		j = "tile";
b9eda2d4 Poul Sander 2023-10-04 20:16 48
		break;
b9eda2d4 Poul Sander 2023-10-04 20:16 49
	case ImgScale::Resize:
b9eda2d4 Poul Sander 2023-10-04 20:16 50
		j = "resize";
b9eda2d4 Poul Sander 2023-10-04 20:16 51
		break;
b9eda2d4 Poul Sander 2023-10-04 20:16 52
	case ImgScale::Cut:
b9eda2d4 Poul Sander 2023-10-04 20:16 53
		j = "cut";
b9eda2d4 Poul Sander 2023-10-04 20:16 54
		break;
b9eda2d4 Poul Sander 2023-10-04 20:16 55
	default:
b9eda2d4 Poul Sander 2023-10-04 20:16 56
		j = "stretch";
b9eda2d4 Poul Sander 2023-10-04 20:16 57
		break;
b9eda2d4 Poul Sander 2023-10-04 20:16 58
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 59
}
b9eda2d4 Poul Sander 2023-10-04 20:16 60
b9eda2d4 Poul Sander 2023-10-04 20:16 61
void from_json(const json& j, ImgScale& p) {
b9eda2d4 Poul Sander 2023-10-04 20:16 62
	std::string s = j;
b9eda2d4 Poul Sander 2023-10-04 20:16 63
	if (s == "stretch") {
b9eda2d4 Poul Sander 2023-10-04 20:16 64
		p = ImgScale::Stretch;
b9eda2d4 Poul Sander 2023-10-04 20:16 65
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 66
	else if (s == "tile") {
b9eda2d4 Poul Sander 2023-10-04 20:16 67
		p = ImgScale::Tile;
b9eda2d4 Poul Sander 2023-10-04 20:16 68
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 69
	else if (s == "resize") {
b9eda2d4 Poul Sander 2023-10-04 20:16 70
		p = ImgScale::Resize;
b9eda2d4 Poul Sander 2023-10-04 20:16 71
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 72
	else if (s == "cut") {
b9eda2d4 Poul Sander 2023-10-04 20:16 73
		p = ImgScale::Cut;
b9eda2d4 Poul Sander 2023-10-04 20:16 74
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 75
	else {
b9eda2d4 Poul Sander 2023-10-04 20:16 76
		p = ImgScale::Stretch;
b9eda2d4 Poul Sander 2023-10-04 20:16 77
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 78
}
b9eda2d4 Poul Sander 2023-10-04 20:16 79
2660ccea Poul Sander 2023-09-22 19:25 80
void to_json(json& j, const BackGroundData& p) {
b9eda2d4 Poul Sander 2023-10-04 20:16 81
	j = json{ {"background_name", p.name}, {"background_sprite", p.background_sprite}, {"background_sprite_16x9", p.background_sprite_16x9}, {"background_scale", p.background_scale}, {"tileMoveSpeedX", p.tileMoveSpeedX}, {"tileMoveSpeedY", p.tileMoveSpeedY} };
2660ccea Poul Sander 2023-09-22 19:25 82
}
2660ccea Poul Sander 2023-09-22 19:25 83
2660ccea Poul Sander 2023-09-22 19:25 84
void to_json(json& j, const Theme& p) {
173b1d55 Poul Sander 2023-09-23 21:29 85
	j = json{ {"theme_name", p.theme_name}, {"back_board", p.back_board}, {"background_name", p.background.name}, {"decoration_name", p.decoration.name} };
2660ccea Poul Sander 2023-09-22 19:25 86
}
2660ccea Poul Sander 2023-09-22 19:25 87
00759e5a Poul Sander 2023-09-24 20:01 88
void to_json(json& j, const DecorationData& p) {
00759e5a Poul Sander 2023-09-24 20:01 89
	j = json{ {"name", p.name}, {"decoration_sprites", p.decoration_sprites} };
00759e5a Poul Sander 2023-09-24 20:01 90
}
00759e5a Poul Sander 2023-09-24 20:01 91
2660ccea Poul Sander 2023-09-22 19:25 92
void to_json(json& j, const ThemeFileData& p) {
00759e5a Poul Sander 2023-09-24 20:01 93
	j = json{ {"background_data", p.background_data}, {"decoration_data", p.decoration_data}, {"themes", p.themes} };
2660ccea Poul Sander 2023-09-22 19:25 94
}
2660ccea Poul Sander 2023-09-22 19:25 95
b9eda2d4 Poul Sander 2023-10-04 20:16 96
void from_json(const json& j, BackGroundData& p) {
b9eda2d4 Poul Sander 2023-10-04 20:16 97
	j.at("background_name").get_to(p.name);
b9eda2d4 Poul Sander 2023-10-04 20:16 98
	j.at("background_sprite").get_to(p.background_sprite);
b9eda2d4 Poul Sander 2023-10-04 20:16 99
	j.at("background_sprite_16x9").get_to(p.background_sprite_16x9);
b9eda2d4 Poul Sander 2023-10-04 20:16 100
	j.at("background_scale").get_to(p.background_scale);
b9eda2d4 Poul Sander 2023-10-04 20:16 101
	j.at("tileMoveSpeedX").get_to(p.tileMoveSpeedX);
b9eda2d4 Poul Sander 2023-10-04 20:16 102
	j.at("tileMoveSpeedY").get_to(p.tileMoveSpeedY);
b9eda2d4 Poul Sander 2023-10-04 20:16 103
}
b9eda2d4 Poul Sander 2023-10-04 20:16 104
b9eda2d4 Poul Sander 2023-10-04 20:16 105
void from_json(const json& j, Theme& p) {
b9eda2d4 Poul Sander 2023-10-04 20:16 106
	j.at("theme_name").get_to(p.theme_name);
b9eda2d4 Poul Sander 2023-10-04 20:16 107
	j.at("back_board").get_to(p.back_board);
b9eda2d4 Poul Sander 2023-10-04 20:16 108
	j.at("background_name").get_to(p.background.name);
b9eda2d4 Poul Sander 2023-10-04 20:16 109
	j.at("decoration_name").get_to(p.decoration.name);
b9eda2d4 Poul Sander 2023-10-04 20:16 110
}
b9eda2d4 Poul Sander 2023-10-04 20:16 111
b9eda2d4 Poul Sander 2023-10-04 20:16 112
void from_json(const json& j, DecorationData& p) {
b9eda2d4 Poul Sander 2023-10-04 20:16 113
	j.at("name").get_to(p.name);
b9eda2d4 Poul Sander 2023-10-04 20:16 114
	j.at("decoration_sprites").get_to(p.decoration_sprites);
b9eda2d4 Poul Sander 2023-10-04 20:16 115
}
b9eda2d4 Poul Sander 2023-10-04 20:16 116
b9eda2d4 Poul Sander 2023-10-04 20:16 117
void from_json(const json& j, ThemeFileData& p) {
b9eda2d4 Poul Sander 2023-10-04 20:16 118
	if (j.contains("background_data")) {
b9eda2d4 Poul Sander 2023-10-04 20:16 119
		j.at("background_data").get_to(p.background_data);
b9eda2d4 Poul Sander 2023-10-04 20:16 120
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 121
	if (j.contains("decoration_data")) {
b9eda2d4 Poul Sander 2023-10-04 20:16 122
		j.at("decoration_data").get_to(p.decoration_data);
b9eda2d4 Poul Sander 2023-10-04 20:16 123
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 124
	if (j.contains("themes")) {
b9eda2d4 Poul Sander 2023-10-04 20:16 125
		j.at("themes").get_to(p.themes);
b9eda2d4 Poul Sander 2023-10-04 20:16 126
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 127
}
2660ccea Poul Sander 2023-09-22 19:25 128
2660ccea Poul Sander 2023-09-22 19:25 129
aaba4f1e Poul Sander 2023-07-25 13:34 130
aaba4f1e Poul Sander 2023-07-25 13:34 131
static std::vector<Theme> themes(1);
00759e5a Poul Sander 2023-09-24 20:01 132
static std::map<std::string, BackGroundData> background_data;
00759e5a Poul Sander 2023-09-24 20:01 133
static std::map<std::string, DecorationData> decoration_data;
aaba4f1e Poul Sander 2023-07-25 13:34 134
static bool initialized = false;
aaba4f1e Poul Sander 2023-07-25 13:34 135
static size_t current_theme = 0;
aaba4f1e Poul Sander 2023-07-25 13:34 136
2660ccea Poul Sander 2023-09-22 19:25 137
66d6174b Poul Sander 2024-01-13 22:45 138
void ThemesFillMissingFields(Theme& theme) {
b9eda2d4 Poul Sander 2023-10-04 20:16 139
	if (theme.background.name.empty()) {
b9eda2d4 Poul Sander 2023-10-04 20:16 140
		//If the theme does not define a background then use the standard.
b9eda2d4 Poul Sander 2023-10-04 20:16 141
		theme.background.name = "standard";
b9eda2d4 Poul Sander 2023-10-04 20:16 142
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 143
	theme.background = background_data[theme.background.name];
b9eda2d4 Poul Sander 2023-10-04 20:16 144
}
b9eda2d4 Poul Sander 2023-10-04 20:16 145
51c4029b Poul Sander 2023-11-15 16:11 146
static void ThemesReadDataFromFile(const std::string& filename) {
b9eda2d4 Poul Sander 2023-10-04 20:16 147
	if (globalData.verboseLevel) {
b9eda2d4 Poul Sander 2023-10-04 20:16 148
		std::cout << "Reading theme data from " << filename << "\n";
b9eda2d4 Poul Sander 2023-10-04 20:16 149
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 150
	std::string s = sago::GetFileContent(filename);
68c75938 Poul Sander 2023-11-13 23:03 151
	if (s.empty()) {
68c75938 Poul Sander 2023-11-13 23:03 152
		std::cout << "File \"" << filename << "\" does not exit!\n";
68c75938 Poul Sander 2023-11-13 23:03 153
		return;
68c75938 Poul Sander 2023-11-13 23:03 154
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 155
	json j = json::parse(s);
b9eda2d4 Poul Sander 2023-10-04 20:16 156
	ThemeFileData tfd = j;
b9eda2d4 Poul Sander 2023-10-04 20:16 157
	for (auto& bg : tfd.background_data) {
b9eda2d4 Poul Sander 2023-10-04 20:16 158
		background_data[bg.name] = bg;
b9eda2d4 Poul Sander 2023-10-04 20:16 159
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 160
	for (auto& dec : tfd.decoration_data) {
b9eda2d4 Poul Sander 2023-10-04 20:16 161
		decoration_data[dec.name] = dec;
b9eda2d4 Poul Sander 2023-10-04 20:16 162
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 163
	for (const Theme& theme : tfd.themes) {
b9eda2d4 Poul Sander 2023-10-04 20:16 164
		if (globalData.verboseLevel) {
b9eda2d4 Poul Sander 2023-10-04 20:16 165
			std::cout << "Adding theme " << theme.theme_name << "\n";
b9eda2d4 Poul Sander 2023-10-04 20:16 166
		}
b9eda2d4 Poul Sander 2023-10-04 20:16 167
		themes.push_back(theme);
51c4029b Poul Sander 2023-11-15 16:11 168
		ThemesFillMissingFields(themes.back());
b9eda2d4 Poul Sander 2023-10-04 20:16 169
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 170
}
b9eda2d4 Poul Sander 2023-10-04 20:16 171
b9eda2d4 Poul Sander 2023-10-04 20:16 172
51c4029b Poul Sander 2023-11-15 16:11 173
static void ThemesInitBackGroundData() {
081d847a Poul Sander 2023-07-29 19:59 174
	BackGroundData standard;
173b1d55 Poul Sander 2023-09-23 21:29 175
	standard.name = "standard";
081d847a Poul Sander 2023-07-29 19:59 176
	standard.background_sprite = "background";
081d847a Poul Sander 2023-07-29 19:59 177
	standard.background_sprite_16x9 = "background_sixteen_nine";
081d847a Poul Sander 2023-07-29 19:59 178
	standard.background_scale = ImgScale::Stretch;
00759e5a Poul Sander 2023-09-24 20:01 179
	background_data[standard.name] = standard;
00759e5a Poul Sander 2023-09-24 20:01 180
	DecorationData smileys;
00759e5a Poul Sander 2023-09-24 20:01 181
	decoration_data[smileys.name] = smileys;
081d847a Poul Sander 2023-07-29 19:59 182
}
081d847a Poul Sander 2023-07-29 19:59 183
68c75938 Poul Sander 2023-11-13 23:03 184
static bool str_startswith(const std::string& s, const char* prefix) {
68c75938 Poul Sander 2023-11-13 23:03 185
	return (s.rfind(prefix, 0) == 0);
68c75938 Poul Sander 2023-11-13 23:03 186
}
2660ccea Poul Sander 2023-09-22 19:25 187
51c4029b Poul Sander 2023-11-15 16:11 188
static void ThemesDumpData() {
2660ccea Poul Sander 2023-09-22 19:25 189
	ThemeFileData tfd;
2660ccea Poul Sander 2023-09-22 19:25 190
	tfd.themes = themes;
6d46a5a3 Poul Sander 2023-09-23 14:42 191
	for (auto& pair : background_data) {
2660ccea Poul Sander 2023-09-22 19:25 192
		tfd.background_data.push_back(pair.second);
081d847a Poul Sander 2023-07-29 19:59 193
	}
00759e5a Poul Sander 2023-09-24 20:01 194
	for (auto& pair : decoration_data) {
00759e5a Poul Sander 2023-09-24 20:01 195
		tfd.decoration_data.push_back(pair.second);
00759e5a Poul Sander 2023-09-24 20:01 196
	}
2660ccea Poul Sander 2023-09-22 19:25 197
	json j = tfd;
2660ccea Poul Sander 2023-09-22 19:25 198
	std::string s = j.dump(4);
2660ccea Poul Sander 2023-09-22 19:25 199
	sago::WriteFileContent("themes_dump.json", s);
081d847a Poul Sander 2023-07-29 19:59 200
}
081d847a Poul Sander 2023-07-29 19:59 201
68c75938 Poul Sander 2023-11-13 23:03 202
void ThemesSaveCustomSlots() {
68c75938 Poul Sander 2023-11-13 23:03 203
	ThemeFileData tfd;
68c75938 Poul Sander 2023-11-13 23:03 204
	for (const Theme& theme : themes) {
68c75938 Poul Sander 2023-11-13 23:03 205
		if ( str_startswith(theme.theme_name,"custom_slot_")) {
68c75938 Poul Sander 2023-11-13 23:03 206
			tfd.themes.push_back(theme);
68c75938 Poul Sander 2023-11-13 23:03 207
		}
68c75938 Poul Sander 2023-11-13 23:03 208
	}
68c75938 Poul Sander 2023-11-13 23:03 209
	json j = tfd;
68c75938 Poul Sander 2023-11-13 23:03 210
	std::string s = j.dump(4);
68c75938 Poul Sander 2023-11-13 23:03 211
	sago::WriteFileContent("custom_themes.json", s);
68c75938 Poul Sander 2023-11-13 23:03 212
}
68c75938 Poul Sander 2023-11-13 23:03 213
68c75938 Poul Sander 2023-11-13 23:03 214
static void ThemesAddCustomSlot(std::vector<Theme>& themes, int slot_number) {
68c75938 Poul Sander 2023-11-13 23:03 215
	std::string slot_name = fmt::format("custom_slot_{}", slot_number);
68c75938 Poul Sander 2023-11-13 23:03 216
	for (const Theme& theme : themes) {
68c75938 Poul Sander 2023-11-13 23:03 217
		if (theme.theme_name == slot_name) {
68c75938 Poul Sander 2023-11-13 23:03 218
			//Custom slot already exists
68c75938 Poul Sander 2023-11-13 23:03 219
			return;
68c75938 Poul Sander 2023-11-13 23:03 220
		}
68c75938 Poul Sander 2023-11-13 23:03 221
	}
68c75938 Poul Sander 2023-11-13 23:03 222
	Theme new_theme;
68c75938 Poul Sander 2023-11-13 23:03 223
	new_theme.theme_name = slot_name;
68c75938 Poul Sander 2023-11-13 23:03 224
	themes.push_back(new_theme);
51c4029b Poul Sander 2023-11-15 16:11 225
	ThemesFillMissingFields(themes.back());
68c75938 Poul Sander 2023-11-13 23:03 226
}
68c75938 Poul Sander 2023-11-13 23:03 227
51c4029b Poul Sander 2023-11-15 16:11 228
void ThemesInit() {
aaba4f1e Poul Sander 2023-07-25 13:34 229
	if (initialized) {
aaba4f1e Poul Sander 2023-07-25 13:34 230
		return;
aaba4f1e Poul Sander 2023-07-25 13:34 231
	}
b9eda2d4 Poul Sander 2023-10-04 20:16 232
	initialized = true;
51c4029b Poul Sander 2023-11-15 16:11 233
	ThemesInitBackGroundData();
aaba4f1e Poul Sander 2023-07-25 13:34 234
	themes.resize(1);  //Add the default theme
51c4029b Poul Sander 2023-11-15 16:11 235
	ThemesFillMissingFields(themes[0]);
7d88cb38 Poul Sander 2023-10-05 20:48 236
	const std::vector<std::string>& theme_files = sago::GetFileList("themes");
7d88cb38 Poul Sander 2023-10-05 20:48 237
	for (const std::string& filename : theme_files) {
7d88cb38 Poul Sander 2023-10-05 20:48 238
		if (boost::algorithm::ends_with(filename,".json")) {
51c4029b Poul Sander 2023-11-15 16:11 239
			ThemesReadDataFromFile("themes/"+filename);
7d88cb38 Poul Sander 2023-10-05 20:48 240
		}
7d88cb38 Poul Sander 2023-10-05 20:48 241
	}
51c4029b Poul Sander 2023-11-15 16:11 242
	ThemesReadDataFromFile("custom_themes.json");
7602f86d Poul Sander 2024-01-10 21:39 243
	for (int i=1; i <= NUMBER_OF_CUSTOM_SLOTS; ++i) {
68c75938 Poul Sander 2023-11-13 23:03 244
		ThemesAddCustomSlot(themes, i);
68c75938 Poul Sander 2023-11-13 23:03 245
	}
51c4029b Poul Sander 2023-11-15 16:11 246
	ThemesDumpData();
aaba4f1e Poul Sander 2023-07-25 13:34 247
}
aaba4f1e Poul Sander 2023-07-25 13:34 248
51c4029b Poul Sander 2023-11-15 16:11 249
Theme ThemesGetNext() {
51c4029b Poul Sander 2023-11-15 16:11 250
	ThemesInit();
aaba4f1e Poul Sander 2023-07-25 13:34 251
	current_theme++;
aaba4f1e Poul Sander 2023-07-25 13:34 252
	current_theme = current_theme % themes.size();
aaba4f1e Poul Sander 2023-07-25 13:34 253
	return themes.at(current_theme);
aaba4f1e Poul Sander 2023-07-25 13:34 254
}
081d847a Poul Sander 2023-07-29 19:59 255
7602f86d Poul Sander 2024-01-10 21:39 256
Theme& ThemesGet(size_t theme_number) {
51c4029b Poul Sander 2023-11-15 16:11 257
	ThemesInit();
081d847a Poul Sander 2023-07-29 19:59 258
	return themes.at(theme_number % themes.size());
081d847a Poul Sander 2023-07-29 19:59 259
}
7602f86d Poul Sander 2024-01-10 21:39 260
7602f86d Poul Sander 2024-01-10 21:39 261
size_t ThemeGetNumber(const std::string& name) {
7602f86d Poul Sander 2024-01-10 21:39 262
	size_t ret = 0;  // Default to 0
7602f86d Poul Sander 2024-01-10 21:39 263
	ThemesInit();
7602f86d Poul Sander 2024-01-10 21:39 264
	for (size_t i = 0; i < themes.size(); ++i) {
7602f86d Poul Sander 2024-01-10 21:39 265
		if (themes[i].theme_name == name) {
7602f86d Poul Sander 2024-01-10 21:39 266
			ret = i;
7602f86d Poul Sander 2024-01-10 21:39 267
		}
7602f86d Poul Sander 2024-01-10 21:39 268
	}
7602f86d Poul Sander 2024-01-10 21:39 269
	return ret;
7602f86d Poul Sander 2024-01-10 21:39 270
}
66d6174b Poul Sander 2024-01-13 22:45 271
66d6174b Poul Sander 2024-01-13 22:45 272
void ThemesAddOrReplace(const Theme& theme) {
66d6174b Poul Sander 2024-01-13 22:45 273
	ThemesInit();
66d6174b Poul Sander 2024-01-13 22:45 274
	for (size_t i = 0; i < themes.size(); ++i) {
66d6174b Poul Sander 2024-01-13 22:45 275
		if (themes[i].theme_name == theme.theme_name) {
66d6174b Poul Sander 2024-01-13 22:45 276
			themes[i] = theme;
66d6174b Poul Sander 2024-01-13 22:45 277
			return;
66d6174b Poul Sander 2024-01-13 22:45 278
		}
66d6174b Poul Sander 2024-01-13 22:45 279
	}
66d6174b Poul Sander 2024-01-13 22:45 280
	themes.push_back(theme);
66d6174b Poul Sander 2024-01-13 22:45 281
}
66d6174b Poul Sander 2024-01-13 22:45 282
66d6174b Poul Sander 2024-01-13 22:45 283
BackGroundData ThemesGetNextBackground(const std::string& current) {
66d6174b Poul Sander 2024-01-13 22:45 284
	ThemesInit();
66d6174b Poul Sander 2024-01-13 22:45 285
	BackGroundData ret = background_data["standard"];
66d6174b Poul Sander 2024-01-13 22:45 286
	for (auto& pair : background_data) {
66d6174b Poul Sander 2024-01-13 22:45 287
		if (pair.first == current) {
66d6174b Poul Sander 2024-01-13 22:45 288
			auto it = background_data.find(current);
66d6174b Poul Sander 2024-01-13 22:45 289
			++it;
66d6174b Poul Sander 2024-01-13 22:45 290
			if (it == background_data.end()) {
66d6174b Poul Sander 2024-01-13 22:45 291
				it = background_data.begin();
66d6174b Poul Sander 2024-01-13 22:45 292
			}
66d6174b Poul Sander 2024-01-13 22:45 293
			ret = it->second;
66d6174b Poul Sander 2024-01-13 22:45 294
			break;
66d6174b Poul Sander 2024-01-13 22:45 295
		}
66d6174b Poul Sander 2024-01-13 22:45 296
	}
66d6174b Poul Sander 2024-01-13 22:45 297
	return ret;
66d6174b Poul Sander 2024-01-13 22:45 298
}
de41f458 Poul Sander 2024-01-29 20:53 299
de41f458 Poul Sander 2024-01-29 20:53 300
std::string ThemesGetNextBoardBackground(const std::string& current) {
de41f458 Poul Sander 2024-01-29 20:53 301
	ThemesInit();
de41f458 Poul Sander 2024-01-29 20:53 302
	std::vector<std::string> back_boards = {"back_board", "back_board_sample_snow", "trans_cover"};
de41f458 Poul Sander 2024-01-29 20:53 303
	std::string ret = "back_board";
de41f458 Poul Sander 2024-01-29 20:53 304
	for (size_t i = 0; i < back_boards.size(); ++i) {
de41f458 Poul Sander 2024-01-29 20:53 305
		if (back_boards[i] == current) {
de41f458 Poul Sander 2024-01-29 20:53 306
			ret = back_boards[(i + 1) % back_boards.size()];
de41f458 Poul Sander 2024-01-29 20:53 307
			break;
de41f458 Poul Sander 2024-01-29 20:53 308
		}
de41f458 Poul Sander 2024-01-29 20:53 309
	}
de41f458 Poul Sander 2024-01-29 20:53 310
	return ret;
de41f458 Poul Sander 2024-01-29 20:53 311
}
1970-01-01 00:00 312