parent
0272ba8540
commit
48a7f72411
@ -0,0 +1,19 @@ |
||||
{ |
||||
"gui/line": { |
||||
"light": [200,200,200], |
||||
"mid": [100,100,100], |
||||
"dark": [10,10,10] |
||||
}, |
||||
|
||||
"gui/text": { |
||||
"light": [200,200,200], |
||||
"mid": [100,100,100], |
||||
"dark": [10,10,10] |
||||
}, |
||||
|
||||
"gui/accent": { |
||||
"light": [200,200,200], |
||||
"mid": [100,100,100], |
||||
"dark": [10,10,10] |
||||
} |
||||
} |
@ -0,0 +1,40 @@ |
||||
#include <fmt/core.h> |
||||
#include "palette.hpp" |
||||
#include "config.hpp" |
||||
#include "dbc.hpp" |
||||
|
||||
namespace palette { |
||||
using std::string; |
||||
using nlohmann::json; |
||||
|
||||
struct PaletteMgr { |
||||
std::unordered_map<string, sf::Color> palettes; |
||||
}; |
||||
|
||||
static PaletteMgr COLOR; |
||||
|
||||
void init(const string &json_file) { |
||||
Config config(json_file); |
||||
json& colors = config.json(); |
||||
|
||||
for(auto [key, value_specs] : colors.items()) { |
||||
const string& base_key = key; |
||||
|
||||
for(auto [value, rgba] : value_specs.items()) { |
||||
auto color_path = base_key + ":" + value; |
||||
dbc::check(!COLOR.palettes.contains(color_path), |
||||
fmt::format("PALLETES already has a color path {}", color_path)); |
||||
|
||||
uint8_t alpha = rgba.size() == 3 ? 255 : (uint8_t)rgba[3]; |
||||
|
||||
sf::Color color{rgba[0], rgba[1], rgba[2], alpha}; |
||||
|
||||
COLOR.palettes.try_emplace(color_path, color); |
||||
} |
||||
} |
||||
} |
||||
|
||||
sf::Color get(const string& key) { |
||||
return COLOR.palettes.at(key); |
||||
} |
||||
} |
@ -0,0 +1,10 @@ |
||||
#include <string> |
||||
#include <SFML/Graphics/Color.hpp> |
||||
|
||||
namespace palette { |
||||
using std::string; |
||||
|
||||
void init(const std::string &config="assets/palette.json"); |
||||
|
||||
sf::Color get(const string &key); |
||||
} |
@ -0,0 +1,20 @@ |
||||
#include <catch2/catch_test_macros.hpp> |
||||
#include <fmt/core.h> |
||||
#include <string> |
||||
#include "palette.hpp" |
||||
|
||||
using namespace fmt; |
||||
|
||||
TEST_CASE("color palette test", "[color-palette]") { |
||||
palette::init(); |
||||
sf::Color expect{10, 10, 10, 255}; |
||||
|
||||
auto gui_text = palette::get("gui/text:dark"); |
||||
REQUIRE(gui_text == expect); |
||||
|
||||
gui_text = palette::get("gui/text:mid"); |
||||
REQUIRE(gui_text != expect); |
||||
|
||||
expect = {100, 100, 100, 255}; |
||||
REQUIRE(gui_text == expect); |
||||
} |
Loading…
Reference in new issue