Introduction of color management.

This commit is contained in:
2022-07-14 00:49:01 +02:00
parent d040087c31
commit f3de3648a0
9 changed files with 118 additions and 7 deletions

View File

@@ -53,7 +53,6 @@ public:
const std::string& name() const;
};
// Gives std::hash namespace a new template definition for our type:
template<>
struct std::hash<MHacheArmor>
{

57
include/mhache_color.h Normal file
View File

@@ -0,0 +1,57 @@
#ifndef MHACHE_COLOR_H
#define MHACHE_COLOR_H
#include <array>
class MHacheColor {
private:
std::array<unsigned char, 4> _rgba;
private:
MHacheColor() = delete;
static constexpr unsigned char touccolor(float value)
{
return static_cast<unsigned char>(value * 255.0f);
};
static constexpr float tofcolor(unsigned char value)
{
constexpr const float conversion = 1/255.f;
return static_cast<float>(value) * conversion;
};
public:
MHacheColor(int r, int g, int b, int a = 255);
MHacheColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255u);
MHacheColor(float r, float g, float b, float a = 1.0f);
MHacheColor(const MHacheColor&) = default;
MHacheColor(MHacheColor&&) = default;
MHacheColor& operator = (const MHacheColor&) = default;
MHacheColor& operator = (MHacheColor&&) = default;
~MHacheColor() = default;
template<typename T> T red() const;
template<typename T> T green() const;
template<typename T> T blue() const;
template<typename T> T alpha() const;
template <typename T> std::array<T, 4> channels() const;
static MHacheColor LightBlue();
static MHacheColor Blue();
static MHacheColor DarkBlue();
static MHacheColor LightOrange();
static MHacheColor Orange();
static MHacheColor DarkOrange();
static MHacheColor Purple();
static MHacheColor Grey();
static MHacheColor White();
// static std::unordered_map<std::string, MHacheColor> fixed_colors;
};
#endif

4
include/mhache_factory.h Normal file
View File

@@ -0,0 +1,4 @@
#ifndef MHACHE_FACTORY_H
#define MHACHE_FACTORY_H
#endif

View File

@@ -6,12 +6,15 @@
#include <functional>
#include "mhache_tomltools.h"
#include "mhache_color.h"
class MHacheSkill {
private:
std::string _name;
std::string _description;
MHacheColor* _color;
std::vector<std::string> _levels;
private:

View File

@@ -24,7 +24,7 @@ levels = [
]
[skills."Artillery"]
color = "grey"
color = "gray"
description = "Strengthens explosive attacks like shells, Wyvern's Fire, charge blade phial attacks, and Sticky Ammo."
levels = [
"Increases power of each attack by 10% and reduces Wyvern's Fire cooldown by 15%.",
@@ -105,7 +105,7 @@ levels = [
]
[skills."Bludgeoner"]
color = "grey"
color = "gray"
description = "Increases attack power when your weapon sharpness is low."
levels = [
"+5% attack power when your weapon sharpness gauge is yellow or lower.",

View File

@@ -3,6 +3,7 @@ find_package(OpenGL REQUIRED)
add_executable(
${PROJECT_NAME}
main.cpp
mhache_color.cpp
mhache_skill.cpp
mhache_armor.cpp
mhache_tomltools.cpp

View File

@@ -1,9 +1,15 @@
#include "mhache_armor.h"
bool
MHacheArmor::operator< (const MHacheArmor& other) const
MHacheArmor::operator < (const MHacheArmor& armor) const
{
return _name < other._name;
return _name < armor._name;
}
bool
MHacheArmor::operator == (const MHacheArmor& armor) const
{
return _name == armor._name;
}
const std::string&

41
src/mhache_color.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "mhache_color.h"
MHacheColor::MHacheColor(int r, int g, int b, int a /* = 255 */)
: MHacheColor(
static_cast<unsigned char>(r),
static_cast<unsigned char>(g),
static_cast<unsigned char>(b),
static_cast<unsigned char>(a))
{}
MHacheColor::MHacheColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
: _rgba({ r, g, b, a })
{}
MHacheColor::MHacheColor(float r, float g, float b, float a)
: MHacheColor(touccolor(r), touccolor(g), touccolor(b), touccolor(a))
{}
template<> unsigned char MHacheColor::red<unsigned char>() const { return _rgba[0]; }
template<> unsigned char MHacheColor::green<unsigned char>() const { return _rgba[1]; }
template<> unsigned char MHacheColor::blue<unsigned char>() const { return _rgba[2]; }
template<> unsigned char MHacheColor::alpha<unsigned char>() const { return _rgba[3]; }
template<> std::array<unsigned char, 4> MHacheColor::channels() const
{
return _rgba;
}
template<> float MHacheColor::red<float>() const { return tofcolor(_rgba[0]); }
template<> float MHacheColor::green<float>() const { return tofcolor(_rgba[1]); }
template<> float MHacheColor::blue<float>() const { return tofcolor(_rgba[2]); }
template<> float MHacheColor::alpha<float>() const { return tofcolor(_rgba[3]); }
template<> std::array<float, 4> MHacheColor::channels() const
{
return { red<float>(), green<float>(), blue<float>(), alpha<float>() };
}
MHacheColor MHacheColor::LightBlue() { return MHacheColor(164, 204, 254); }
MHacheColor MHacheColor::Blue() { return MHacheColor(96, 169, 250); }
MHacheColor MHacheColor::DarkBlue() { return MHacheColor(77, 105, 209); }

View File

@@ -7,13 +7,13 @@ MHacheSkill::MHacheSkill(const std::string& name, const std::string& description
{}
bool
MHacheSkill::operator< (const MHacheSkill& other) const
MHacheSkill::operator < (const MHacheSkill& other) const
{
return _name < other._name;
}
bool
MHacheSkill::operator== (const MHacheSkill& other) const
MHacheSkill::operator == (const MHacheSkill& other) const
{
return _name == other._name;
}