Cockatrice 2026-06-01-Development-3.1.0-beta.3
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
color.h
Go to the documentation of this file.
1#ifndef COLOR_H
2#define COLOR_H
3
4#ifdef QT_GUI_LIB
5#include <QColor>
6#endif
7
8#include <libcockatrice/protocol/pb/color.pb.h>
9
10#ifdef QT_GUI_LIB
11inline QColor convertColorToQColor(const color &c)
12{
13 return QColor(c.r(), c.g(), c.b());
14}
15
16inline color convertQColorToColor(const QColor &c)
17{
18 color result;
19 result.set_r(c.red());
20 result.set_g(c.green());
21 result.set_b(c.blue());
22 return result;
23}
24
25#include <QMap>
26#include <QSet>
27
28namespace GameSpecificColors
29{
30namespace MTG
31{
32inline QColor colorHelper(const QString &name)
33{
34 static const QMap<QString, QColor> colorMap = {
35 {"W", QColor(245, 245, 220)},
36 {"U", QColor(80, 140, 255)},
37 {"B", QColor(60, 60, 60)},
38 {"R", QColor(220, 60, 50)},
39 {"G", QColor(70, 160, 70)},
40 {"Creature", QColor(70, 130, 180)},
41 {"Instant", QColor(138, 43, 226)},
42 {"Sorcery", QColor(199, 21, 133)},
43 {"Enchantment", QColor(218, 165, 32)},
44 {"Artifact", QColor(169, 169, 169)},
45 {"Planeswalker", QColor(210, 105, 30)},
46 {"Land", QColor(110, 80, 50)},
47 };
48
49 if (colorMap.contains(name)) {
50 return colorMap[name];
51 }
52
53 if (name.length() == 1 && colorMap.contains(name.toUpper())) {
54 return colorMap[name.toUpper()];
55 }
56
57 uint h = qHash(name);
58 int r = 100 + (h % 120);
59 int g = 100 + ((h >> 8) % 120);
60 int b = 100 + ((h >> 16) % 120);
61
62 return QColor(r, g, b);
63}
64
65inline QList<QPair<QString, int>> sortManaMapWUBRGCFirst(const QMap<QString, int> &input)
66{
67 static const QStringList priorityOrder = {"W", "U", "B", "R", "G", "C"};
68
69 QList<QPair<QString, int>> result;
70 QSet<QString> consumed;
71
72 // 1. Add priority colors in fixed order
73 for (const QString &key : priorityOrder) {
74 auto it = input.find(key);
75 if (it != input.end()) {
76 result.append({it.key(), it.value()});
77 consumed.insert(it.key());
78 }
79 }
80
81 // 2. Add remaining keys (QMap iteration is already sorted)
82 for (auto it = input.begin(); it != input.end(); ++it) {
83 if (!consumed.contains(it.key())) {
84 result.append({it.key(), it.value()});
85 }
86 }
87
88 return result;
89}
90} // namespace MTG
91} // namespace GameSpecificColors
92#endif
93
94inline color makeColor(int r, int g, int b)
95{
96 color result;
97 result.set_r(r);
98 result.set_g(g);
99 result.set_b(b);
100 return result;
101}
102
103#endif
color makeColor(int r, int g, int b)
Definition color.h:94
uint qHash(const QRegularExpression &key, uint seed) noexcept
Definition deck_list.cpp:18