mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 02:53:56 -07:00
Made QColor wrapper class so that Servatrice will compile without QtGui
This commit is contained in:
parent
ee0a010add
commit
b1d8c7bda0
19 changed files with 226 additions and 184 deletions
27
common/color.h
Normal file
27
common/color.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef COLOR_H
|
||||
#define COLOR_H
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
#include <QColor>
|
||||
#endif
|
||||
|
||||
class Color {
|
||||
private:
|
||||
int value;
|
||||
public:
|
||||
Color(int _value = 0) : value(_value) { }
|
||||
Color(int r, int g, int b) : value(r * 65536 + g * 256 + b) { }
|
||||
int getValue() const { return value; }
|
||||
#ifdef QT_GUI_LIB
|
||||
Color(const QColor &_color)
|
||||
{
|
||||
value = _color.red() * 65536 + _color.green() * 256 + _color.blue();
|
||||
}
|
||||
QColor getQColor() const
|
||||
{
|
||||
return QColor(value / 65536, (value % 65536) / 256, value % 256);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QTextStream>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <QVector>
|
||||
#include <QPair>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include "serializable_item.h"
|
||||
|
||||
class CardDatabase;
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ QList<ServerInfo_Card *> ServerInfo_Zone::getCardList() const
|
|||
return result;
|
||||
}
|
||||
|
||||
ServerInfo_Counter::ServerInfo_Counter(int _id, const QString &_name, const QColor &_color, int _radius, int _count)
|
||||
ServerInfo_Counter::ServerInfo_Counter(int _id, const QString &_name, const Color &_color, int _radius, int _count)
|
||||
: SerializableItem_Map("counter")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("id", _id));
|
||||
|
|
@ -123,7 +123,7 @@ ServerInfo_Counter::ServerInfo_Counter(int _id, const QString &_name, const QCol
|
|||
insertItem(new SerializableItem_Int("count", _count));
|
||||
}
|
||||
|
||||
ServerInfo_Arrow::ServerInfo_Arrow(int _id, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color)
|
||||
ServerInfo_Arrow::ServerInfo_Arrow(int _id, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const Color &_color)
|
||||
: SerializableItem_Map("arrow")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("id", _id));
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
#define PROTOCOL_DATASTRUCTURES_H
|
||||
|
||||
#include <QString>
|
||||
#include <QColor>
|
||||
#include <QDateTime>
|
||||
#include "serializable_item.h"
|
||||
#include "color.h"
|
||||
|
||||
class DeckList;
|
||||
|
||||
|
|
@ -107,18 +107,18 @@ public:
|
|||
|
||||
class ServerInfo_Counter : public SerializableItem_Map {
|
||||
public:
|
||||
ServerInfo_Counter(int _id = -1, const QString &_name = QString(), const QColor &_color = QColor(), int _radius = -1, int _count = -1);
|
||||
ServerInfo_Counter(int _id = -1, const QString &_name = QString(), const Color &_color = Color(), int _radius = -1, int _count = -1);
|
||||
static SerializableItem *newItem() { return new ServerInfo_Counter; }
|
||||
int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
|
||||
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
|
||||
QColor getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); }
|
||||
Color getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); }
|
||||
int getRadius() const { return static_cast<SerializableItem_Int *>(itemMap.value("radius"))->getData(); }
|
||||
int getCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("count"))->getData(); }
|
||||
};
|
||||
|
||||
class ServerInfo_Arrow : public SerializableItem_Map {
|
||||
public:
|
||||
ServerInfo_Arrow(int _id = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor());
|
||||
ServerInfo_Arrow(int _id = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const Color &_color = Color());
|
||||
static SerializableItem *newItem() { return new ServerInfo_Arrow; }
|
||||
int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
|
||||
int getStartPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_player_id"))->getData(); }
|
||||
|
|
@ -127,7 +127,7 @@ public:
|
|||
int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); }
|
||||
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); }
|
||||
int getTargetCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_card_id"))->getData(); }
|
||||
QColor getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); }
|
||||
Color getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); }
|
||||
};
|
||||
|
||||
class ServerInfo_PlayerProperties : public SerializableItem_Map {
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ Command_CreateToken::Command_CreateToken(int _gameId, const QString &_zone, cons
|
|||
insertItem(new SerializableItem_Int("x", _x));
|
||||
insertItem(new SerializableItem_Int("y", _y));
|
||||
}
|
||||
Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color)
|
||||
Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const Color &_color)
|
||||
: GameCommand("create_arrow", _gameId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("start_player_id", _startPlayerId));
|
||||
|
|
@ -207,7 +207,7 @@ Command_IncCounter::Command_IncCounter(int _gameId, int _counterId, int _delta)
|
|||
insertItem(new SerializableItem_Int("counter_id", _counterId));
|
||||
insertItem(new SerializableItem_Int("delta", _delta));
|
||||
}
|
||||
Command_CreateCounter::Command_CreateCounter(int _gameId, const QString &_counterName, const QColor &_color, int _radius, int _value)
|
||||
Command_CreateCounter::Command_CreateCounter(int _gameId, const QString &_counterName, const Color &_color, int _radius, int _value)
|
||||
: GameCommand("create_counter", _gameId)
|
||||
{
|
||||
insertItem(new SerializableItem_String("counter_name", _counterName));
|
||||
|
|
|
|||
|
|
@ -235,14 +235,14 @@ public:
|
|||
class Command_CreateArrow : public GameCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor());
|
||||
Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const Color &_color = Color());
|
||||
int getStartPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_player_id"))->getData(); };
|
||||
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
|
||||
int getStartCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_card_id"))->getData(); };
|
||||
int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); };
|
||||
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
|
||||
int getTargetCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_card_id"))->getData(); };
|
||||
QColor getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); };
|
||||
Color getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Command_CreateArrow; }
|
||||
int getItemId() const { return ItemId_Command_CreateArrow; }
|
||||
};
|
||||
|
|
@ -314,9 +314,9 @@ public:
|
|||
class Command_CreateCounter : public GameCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_CreateCounter(int _gameId = -1, const QString &_counterName = QString(), const QColor &_color = QColor(), int _radius = -1, int _value = -1);
|
||||
Command_CreateCounter(int _gameId = -1, const QString &_counterName = QString(), const Color &_color = Color(), int _radius = -1, int _value = -1);
|
||||
QString getCounterName() const { return static_cast<SerializableItem_String *>(itemMap.value("counter_name"))->getData(); };
|
||||
QColor getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); };
|
||||
Color getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); };
|
||||
int getRadius() const { return static_cast<SerializableItem_Int *>(itemMap.value("radius"))->getData(); };
|
||||
int getValue() const { return static_cast<SerializableItem_Int *>(itemMap.value("value"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Command_CreateCounter; }
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@ while (<file>) {
|
|||
$constructorCode .= "\tinsertItem(new SerializableItem_Int(\"$value\", _$prettyVarName));\n";
|
||||
$getFunctionCode .= "\t$dataType get$prettyVarName2() const { return static_cast<SerializableItem_Int *>(itemMap.value(\"$value\"))->getData(); };\n";
|
||||
} elsif ($key eq 'c') {
|
||||
$dataType = 'QColor';
|
||||
$constructorParamsH .= "const QColor &_$prettyVarName = QColor()";
|
||||
$constructorParamsCpp .= "const QColor &_$prettyVarName";
|
||||
$dataType = 'Color';
|
||||
$constructorParamsH .= "const Color &_$prettyVarName = Color()";
|
||||
$constructorParamsCpp .= "const Color &_$prettyVarName";
|
||||
$constructorCode .= "\tinsertItem(new SerializableItem_Color(\"$value\", _$prettyVarName));\n";
|
||||
$getFunctionCode .= "\t$dataType get$prettyVarName2() const { return static_cast<SerializableItem_Color *>(itemMap.value(\"$value\"))->getData(); };\n";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,29 +116,19 @@ void SerializableItem_Bool::writeElement(QXmlStreamWriter *xml)
|
|||
xml->writeCharacters(data ? "1" : "0");
|
||||
}
|
||||
|
||||
int SerializableItem_Color::colorToInt(const QColor &color) const
|
||||
{
|
||||
return color.red() * 65536 + color.green() * 256 + color.blue();
|
||||
}
|
||||
|
||||
QColor SerializableItem_Color::colorFromInt(int colorValue) const
|
||||
{
|
||||
return QColor(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256);
|
||||
}
|
||||
|
||||
bool SerializableItem_Color::readElement(QXmlStreamReader *xml)
|
||||
{
|
||||
if (xml->isCharacters() && !xml->isWhitespace()) {
|
||||
bool ok;
|
||||
int colorValue = xml->text().toString().toInt(&ok);
|
||||
data = ok ? colorFromInt(colorValue) : Qt::black;
|
||||
data = ok ? Color(colorValue) : Color();
|
||||
}
|
||||
return SerializableItem::readElement(xml);
|
||||
}
|
||||
|
||||
void SerializableItem_Color::writeElement(QXmlStreamWriter *xml)
|
||||
{
|
||||
xml->writeCharacters(QString::number(colorToInt(data)));
|
||||
xml->writeCharacters(QString::number(data.getValue()));
|
||||
}
|
||||
|
||||
bool SerializableItem_DateTime::readElement(QXmlStreamReader *xml)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#include <QMap>
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
#include <QColor>
|
||||
#include <QDateTime>
|
||||
#include "color.h"
|
||||
|
||||
class QXmlStreamReader;
|
||||
class QXmlStreamWriter;
|
||||
|
|
@ -111,17 +111,15 @@ public:
|
|||
|
||||
class SerializableItem_Color : public SerializableItem {
|
||||
private:
|
||||
QColor data;
|
||||
int colorToInt(const QColor &color) const;
|
||||
QColor colorFromInt(int colorValue) const;
|
||||
Color data;
|
||||
protected:
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void writeElement(QXmlStreamWriter *xml);
|
||||
public:
|
||||
SerializableItem_Color(const QString &_itemType, const QColor &_data)
|
||||
SerializableItem_Color(const QString &_itemType, const Color &_data)
|
||||
: SerializableItem(_itemType), data(_data) { }
|
||||
const QColor &getData() { return data; }
|
||||
void setData(const QColor &_data) { data = _data; }
|
||||
const Color &getData() { return data; }
|
||||
void setData(const Color &_data) { data = _data; }
|
||||
};
|
||||
|
||||
class SerializableItem_DateTime : public SerializableItem {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef SERVER_ARROW_H
|
||||
#define SERVER_ARROW_H
|
||||
|
||||
#include <QColor>
|
||||
#include "color.h"
|
||||
|
||||
class Server_Card;
|
||||
class Server_ArrowTarget;
|
||||
|
|
@ -11,14 +11,14 @@ private:
|
|||
int id;
|
||||
Server_Card *startCard;
|
||||
Server_ArrowTarget *targetItem;
|
||||
QColor color;
|
||||
Color color;
|
||||
public:
|
||||
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const QColor &_color)
|
||||
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const Color &_color)
|
||||
: id(_id), startCard(_startCard), targetItem(_targetItem), color(_color) { }
|
||||
int getId() const { return id; }
|
||||
Server_Card *getStartCard() const { return startCard; }
|
||||
Server_ArrowTarget *getTargetItem() const { return targetItem; }
|
||||
QColor getColor() const { return color; }
|
||||
const Color &getColor() const { return color; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -21,21 +21,21 @@
|
|||
#define SERVER_COUNTER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QColor>
|
||||
#include "color.h"
|
||||
|
||||
class Server_Counter {
|
||||
protected:
|
||||
int id;
|
||||
QString name;
|
||||
QColor color;
|
||||
Color color;
|
||||
int radius;
|
||||
int count;
|
||||
public:
|
||||
Server_Counter(int _id, const QString &_name, const QColor &_color, int _radius, int _count = 0) : id(_id), name(_name), color(_color), radius(_radius), count(_count) { }
|
||||
Server_Counter(int _id, const QString &_name, const Color &_color, int _radius, int _count = 0) : id(_id), name(_name), color(_color), radius(_radius), count(_count) { }
|
||||
~Server_Counter() { }
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
QColor getColor() const { return color; }
|
||||
Color getColor() const { return color; }
|
||||
int getRadius() const { return radius; }
|
||||
int getCount() const { return count; }
|
||||
void setCount(int _count) { count = _count; }
|
||||
|
|
|
|||
|
|
@ -67,14 +67,14 @@ void Server_Player::setupZones()
|
|||
addZone(new Server_CardZone(this, "grave", false, PublicZone));
|
||||
addZone(new Server_CardZone(this, "rfg", false, PublicZone));
|
||||
|
||||
addCounter(new Server_Counter(0, "life", Qt::white, 25, 20));
|
||||
addCounter(new Server_Counter(1, "w", QColor(255, 255, 150), 20, 0));
|
||||
addCounter(new Server_Counter(2, "u", QColor(150, 150, 255), 20, 0));
|
||||
addCounter(new Server_Counter(3, "b", QColor(150, 150, 150), 20, 0));
|
||||
addCounter(new Server_Counter(4, "r", QColor(250, 150, 150), 20, 0));
|
||||
addCounter(new Server_Counter(5, "g", QColor(150, 255, 150), 20, 0));
|
||||
addCounter(new Server_Counter(6, "x", QColor(255, 255, 255), 20, 0));
|
||||
addCounter(new Server_Counter(7, "storm", QColor(255, 255, 255), 20, 0));
|
||||
addCounter(new Server_Counter(0, "life", Color(255, 255, 255), 25, 20));
|
||||
addCounter(new Server_Counter(1, "w", Color(255, 255, 150), 20, 0));
|
||||
addCounter(new Server_Counter(2, "u", Color(150, 150, 255), 20, 0));
|
||||
addCounter(new Server_Counter(3, "b", Color(150, 150, 150), 20, 0));
|
||||
addCounter(new Server_Counter(4, "r", Color(250, 150, 150), 20, 0));
|
||||
addCounter(new Server_Counter(5, "g", Color(150, 255, 150), 20, 0));
|
||||
addCounter(new Server_Counter(6, "x", Color(255, 255, 255), 20, 0));
|
||||
addCounter(new Server_Counter(7, "storm", Color(255, 255, 255), 20, 0));
|
||||
|
||||
initialCards = 7;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue