Cockatrice 2026-01-14-Development-2.11.0-beta.46
A cross-platform 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 <QSet>
26
27namespace GameSpecificColors
28{
29namespace MTG
30{
31inline QColor colorHelper(const QString &name)
32{
33 static const QMap<QString, QColor> colorMap = {
34 {"W", QColor(245, 245, 220)},
35 {"U", QColor(80, 140, 255)},
36 {"B", QColor(60, 60, 60)},
37 {"R", QColor(220, 60, 50)},
38 {"G", QColor(70, 160, 70)},
39 {"Creature", QColor(70, 130, 180)},
40 {"Instant", QColor(138, 43, 226)},
41 {"Sorcery", QColor(199, 21, 133)},
42 {"Enchantment", QColor(218, 165, 32)},
43 {"Artifact", QColor(169, 169, 169)},
44 {"Planeswalker", QColor(210, 105, 30)},
45 {"Land", QColor(110, 80, 50)},
46 };
47
48 if (colorMap.contains(name))
49 return colorMap[name];
50
51 if (name.length() == 1 && colorMap.contains(name.toUpper()))
52 return colorMap[name.toUpper()];
53
54 uint h = qHash(name);
55 int r = 100 + (h % 120);
56 int g = 100 + ((h >> 8) % 120);
57 int b = 100 + ((h >> 16) % 120);
58
59 return QColor(r, g, b);
60}
61
62inline QList<QPair<QString, int>> sortManaMapWUBRGCFirst(const QMap<QString, int> &input)
63{
64 static const QStringList priorityOrder = {"W", "U", "B", "R", "G", "C"};
65
66 QList<QPair<QString, int>> result;
67 QSet<QString> consumed;
68
69 // 1. Add priority colors in fixed order
70 for (const QString &key : priorityOrder) {
71 auto it = input.find(key);
72 if (it != input.end()) {
73 result.append({it.key(), it.value()});
74 consumed.insert(it.key());
75 }
76 }
77
78 // 2. Add remaining keys (QMap iteration is already sorted)
79 for (auto it = input.begin(); it != input.end(); ++it) {
80 if (!consumed.contains(it.key())) {
81 result.append({it.key(), it.value()});
82 }
83 }
84
85 return result;
86}
87} // namespace MTG
88} // namespace GameSpecificColors
89#endif
90
91inline color makeColor(int r, int g, int b)
92{
93 color result;
94 result.set_r(r);
95 result.set_g(g);
96 result.set_b(b);
97 return result;
98}
99
100#endif
color makeColor(int r, int g, int b)
Definition color.h:91
uint qHash(const QRegularExpression &key, uint seed) noexcept
Definition deck_list.cpp:18