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"
aaba4f1e Poul Sander 2023-07-25 13:34 26
aaba4f1e Poul Sander 2023-07-25 13:34 27
#include <vector>
081d847a Poul Sander 2023-07-29 19:59 28
#include <unordered_map>
aaba4f1e Poul Sander 2023-07-25 13:34 29
aaba4f1e Poul Sander 2023-07-25 13:34 30
static std::vector<Theme> themes(1);
081d847a Poul Sander 2023-07-29 19:59 31
static std::unordered_map<std::string, BackGroundData> background_data;
aaba4f1e Poul Sander 2023-07-25 13:34 32
static bool initialized = false;
aaba4f1e Poul Sander 2023-07-25 13:34 33
static size_t current_theme = 0;
aaba4f1e Poul Sander 2023-07-25 13:34 34
081d847a Poul Sander 2023-07-29 19:59 35
static void InitBackGroundData() {
081d847a Poul Sander 2023-07-29 19:59 36
	BackGroundData standard;
081d847a Poul Sander 2023-07-29 19:59 37
	standard.background_name = "standard";
081d847a Poul Sander 2023-07-29 19:59 38
	standard.background_sprite = "background";
081d847a Poul Sander 2023-07-29 19:59 39
	standard.background_sprite_16x9 = "background_sixteen_nine";
081d847a Poul Sander 2023-07-29 19:59 40
	standard.background_scale = ImgScale::Stretch;
081d847a Poul Sander 2023-07-29 19:59 41
	background_data["standard"] = standard;
081d847a Poul Sander 2023-07-29 19:59 42
	BackGroundData alt_background;
081d847a Poul Sander 2023-07-29 19:59 43
	alt_background.background_name = "alt_background";
081d847a Poul Sander 2023-07-29 19:59 44
	alt_background.background_sprite = "background_sample";
081d847a Poul Sander 2023-07-29 19:59 45
	alt_background.background_sprite_16x9 = "";
081d847a Poul Sander 2023-07-29 19:59 46
	alt_background.background_scale = ImgScale::Tile;
6444412c Poul Sander 2023-07-30 22:07 47
	alt_background.tileMoveSpeedX = 50;
6444412c Poul Sander 2023-07-30 22:07 48
	alt_background.tileMoveSpeedY = 100;
081d847a Poul Sander 2023-07-29 19:59 49
	background_data["alt_background"] = alt_background;
081d847a Poul Sander 2023-07-29 19:59 50
}
081d847a Poul Sander 2023-07-29 19:59 51
081d847a Poul Sander 2023-07-29 19:59 52
static void FillMissingFields(Theme &theme) {
081d847a Poul Sander 2023-07-29 19:59 53
	if (theme.background.background_name.empty()) {
081d847a Poul Sander 2023-07-29 19:59 54
		//If the theme does not define a background then use the standard.
081d847a Poul Sander 2023-07-29 19:59 55
		theme.background = background_data["standard"];
081d847a Poul Sander 2023-07-29 19:59 56
	}
081d847a Poul Sander 2023-07-29 19:59 57
}
081d847a Poul Sander 2023-07-29 19:59 58
aaba4f1e Poul Sander 2023-07-25 13:34 59
void InitThemes() {
aaba4f1e Poul Sander 2023-07-25 13:34 60
	if (initialized) {
aaba4f1e Poul Sander 2023-07-25 13:34 61
		return;
aaba4f1e Poul Sander 2023-07-25 13:34 62
	}
081d847a Poul Sander 2023-07-29 19:59 63
	InitBackGroundData();
aaba4f1e Poul Sander 2023-07-25 13:34 64
	themes.resize(1);  //Add the default theme
081d847a Poul Sander 2023-07-29 19:59 65
	FillMissingFields(themes[0]);
aaba4f1e Poul Sander 2023-07-25 13:34 66
	Theme snow;
aaba4f1e Poul Sander 2023-07-25 13:34 67
	snow.theme_name = "snow";
aaba4f1e Poul Sander 2023-07-25 13:34 68
	snow.back_board = "back_board_sample_snow";
081d847a Poul Sander 2023-07-29 19:59 69
	snow.background = background_data["alt_background"];
081d847a Poul Sander 2023-07-29 19:59 70
	FillMissingFields(snow);
aaba4f1e Poul Sander 2023-07-25 13:34 71
	themes.push_back(snow);
aaba4f1e Poul Sander 2023-07-25 13:34 72
}
aaba4f1e Poul Sander 2023-07-25 13:34 73
aaba4f1e Poul Sander 2023-07-25 13:34 74
Theme getNextTheme() {
aaba4f1e Poul Sander 2023-07-25 13:34 75
	InitThemes();
aaba4f1e Poul Sander 2023-07-25 13:34 76
	current_theme++;
aaba4f1e Poul Sander 2023-07-25 13:34 77
	current_theme = current_theme % themes.size();
aaba4f1e Poul Sander 2023-07-25 13:34 78
	return themes.at(current_theme);
aaba4f1e Poul Sander 2023-07-25 13:34 79
}
081d847a Poul Sander 2023-07-29 19:59 80
081d847a Poul Sander 2023-07-29 19:59 81
Theme getTheme(size_t theme_number) {
081d847a Poul Sander 2023-07-29 19:59 82
	InitThemes();
081d847a Poul Sander 2023-07-29 19:59 83
	return themes.at(theme_number % themes.size());
081d847a Poul Sander 2023-07-29 19:59 84
}
1970-01-01 00:00 85