Game Config: make tc/color_info take a string_view and allow heterogeneous lookup

This commit is contained in:
Charles Dang 2024-01-29 21:14:07 -05:00
parent f71e0b3b17
commit 8619e403a8
2 changed files with 10 additions and 10 deletions

View File

@ -140,11 +140,11 @@ std::vector<color_t> red_green_scale_text;
static std::vector<color_t> blue_white_scale;
static std::vector<color_t> blue_white_scale_text;
std::map<std::string, color_range> team_rgb_range;
std::map<std::string, color_range, std::less<>> team_rgb_range;
// Map [color_range]id to [color_range]name, or "" if no name
std::map<std::string, t_string> team_rgb_name;
std::map<std::string, t_string, std::less<>> team_rgb_name;
std::map<std::string, std::vector<color_t>> team_rgb_colors;
std::map<std::string, std::vector<color_t>, std::less<>> team_rgb_colors;
std::vector<std::string> default_colors;
@ -501,7 +501,7 @@ void reset_color_info()
team_rgb_range.clear();
}
const color_range& color_info(const std::string& name)
const color_range& color_info(std::string_view name)
{
auto i = team_rgb_range.find(name);
if(i != team_rgb_range.end()) {
@ -521,7 +521,7 @@ const color_range& color_info(const std::string& name)
return color_info(name);
}
const std::vector<color_t>& tc_info(const std::string& name)
const std::vector<color_t>& tc_info(std::string_view name)
{
auto i = team_rgb_colors.find(name);
if(i != team_rgb_colors.end()) {

View File

@ -157,9 +157,9 @@ namespace game_config
* Colors defined by WML [color_range] tags. In addition to team colors such as "red" and
* "blue", this also contains the colors used on the minimap for "cave", "fungus" etc.
*/
extern std::map<std::string, color_range> team_rgb_range;
extern std::map<std::string, t_string> team_rgb_name;
extern std::map<std::string, std::vector<color_t>> team_rgb_colors;
extern std::map<std::string, color_range, std::less<>> team_rgb_range;
extern std::map<std::string, t_string, std::less<>> team_rgb_name;
extern std::map<std::string, std::vector<color_t>, std::less<>> team_rgb_colors;
extern std::vector<std::string> default_colors;
@ -187,8 +187,8 @@ namespace game_config
void add_color_info(const game_config_view& v);
void reset_color_info();
const std::vector<color_t>& tc_info(const std::string& name);
const color_range& color_info(const std::string& name);
const std::vector<color_t>& tc_info(std::string_view name);
const color_range& color_info(std::string_view name);
/**
* Return a color corresponding to the value val