converted SetCardAttr attr_name to enum

This commit is contained in:
Max-Wilhelm Bruker 2012-01-02 20:20:31 +01:00
parent 4634787b00
commit 609e3fc41d
12 changed files with 83 additions and 68 deletions

View file

@ -0,0 +1,9 @@
enum CardAttribute {
AttrTapped = 1;
AttrAttacking = 2;
AttrFaceDown = 3;
AttrColor = 4;
AttrPT = 5;
AttrAnnotation = 6;
AttrDoesntUntap = 7;
}

View file

@ -1,10 +1,12 @@
import "game_commands.proto";
import "card_attributes.proto";
message Command_SetCardAttr {
extend GameCommand {
optional Command_SetCardAttr ext = 1013;
}
optional string zone = 1;
optional sint32 card_id = 2 [default = -1];
optional string attr_name = 3;
optional CardAttribute attribute = 3;
optional string attr_value = 4;
}

View file

@ -1,4 +1,5 @@
import "game_event.proto";
import "card_attributes.proto";
message Event_SetCardAttr {
extend GameEvent {
@ -6,6 +7,6 @@ message Event_SetCardAttr {
}
optional string zone_name = 1;
optional sint32 card_id = 2;
optional string attr_name = 3;
optional CardAttribute attribute = 3;
optional string attr_value = 4;
}

View file

@ -45,28 +45,22 @@ void Server_Card::resetState()
setDoesntUntap(false);
}
QString Server_Card::setAttribute(const QString &aname, const QString &avalue, bool allCards)
QString Server_Card::setAttribute(CardAttribute attribute, const QString &avalue, bool allCards)
{
if (aname == "tapped") {
bool value = avalue == "1";
if (!(!value && allCards && doesntUntap))
setTapped(value);
} else if (aname == "attacking") {
setAttacking(avalue == "1");
} else if (aname == "facedown") {
setFaceDown(avalue == "1");
} else if (aname == "color") {
setColor(avalue);
} else if (aname == "pt") {
setPT(avalue);
return getPT();
} else if (aname == "annotation") {
setAnnotation(avalue);
} else if (aname == "doesnt_untap") {
setDoesntUntap(avalue == "1");
} else
return QString();
switch (attribute) {
case AttrTapped: {
bool value = avalue == "1";
if (!(!value && allCards && doesntUntap))
setTapped(value);
break;
}
case AttrAttacking: setAttacking(avalue == "1"); break;
case AttrFaceDown: setFaceDown(avalue == "1"); break;
case AttrColor: setColor(avalue); break;
case AttrPT: setPT(avalue); return getPT();
case AttrAnnotation: setAnnotation(avalue); break;
case AttrDoesntUntap: setDoesntUntap(avalue == "1"); break;
}
return avalue;
}

View file

@ -21,6 +21,7 @@
#define SERVER_CARD_H
#include "server_arrowtarget.h"
#include "pb/card_attributes.pb.h"
#include <QString>
#include <QMap>
@ -86,7 +87,7 @@ public:
void removeAttachedCard(Server_Card *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
void resetState();
QString setAttribute(const QString &aname, const QString &avalue, bool allCards);
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
};
#endif

View file

@ -501,10 +501,10 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, Server_Car
ges.enqueueGameEvent(eventOthers, playerId, GameEventStorageItem::SendToOthers);
if (thisCardProperties->tapped())
setCardAttrHelper(ges, targetzone->getName(), card->getId(), "tapped", "1");
setCardAttrHelper(ges, targetzone->getName(), card->getId(), AttrTapped, "1");
QString ptString = QString::fromStdString(thisCardProperties->pt());
if (!ptString.isEmpty() && !thisCardProperties->face_down())
setCardAttrHelper(ges, targetzone->getName(), card->getId(), "pt", ptString);
setCardAttrHelper(ges, targetzone->getName(), card->getId(), AttrPT, ptString);
}
}
if (startzone->hasCoords() && fixFreeSpaces)
@ -532,7 +532,7 @@ void Server_Player::unattachCard(GameEventStorage &ges, Server_Card *card)
delete cardToMove;
}
Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, const QString &zoneName, int cardId, const QString &attrName, const QString &attrValue)
Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, const QString &zoneName, int cardId, CardAttribute attribute, const QString &attrValue)
{
QMutexLocker locker(&game->gameMutex);
@ -546,7 +546,7 @@ Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, c
if (cardId == -1) {
QListIterator<Server_Card *> CardIterator(zone->cards);
while (CardIterator.hasNext()) {
result = CardIterator.next()->setAttribute(attrName, attrValue, true);
result = CardIterator.next()->setAttribute(attribute, attrValue, true);
if (result.isNull())
return Response::RespInvalidCommand;
}
@ -554,7 +554,7 @@ Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, c
Server_Card *card = zone->getCard(cardId);
if (!card)
return Response::RespNameNotFound;
result = card->setAttribute(attrName, attrValue, false);
result = card->setAttribute(attribute, attrValue, false);
if (result.isNull())
return Response::RespInvalidCommand;
}
@ -563,7 +563,7 @@ Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, c
event.set_zone_name(zone->getName().toStdString());
if (cardId != -1)
event.set_card_id(cardId);
event.set_attr_name(attrName.toStdString());
event.set_attribute(attribute);
event.set_attr_value(result.toStdString());
ges.enqueueGameEvent(event, playerId);

View file

@ -8,6 +8,7 @@
#include <QMutex>
#include "pb/response.pb.h"
#include "pb/card_attributes.pb.h"
class DeckList;
class Server_Game;
@ -86,7 +87,7 @@ public:
Response::ResponseCode moveCard(GameEventStorage &ges, const QString &_startZone, const QList<const CardToMove *> &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y);
Response::ResponseCode moveCard(GameEventStorage &ges, Server_CardZone *startzone, const QList<const CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces = true, bool undoingDraw = false);
void unattachCard(GameEventStorage &ges, Server_Card *card);
Response::ResponseCode setCardAttrHelper(GameEventStorage &ges, const QString &zone, int cardId, const QString &attrName, const QString &attrValue);
Response::ResponseCode setCardAttrHelper(GameEventStorage &ges, const QString &zone, int cardId, CardAttribute attribute, const QString &attrValue);
void sendGameEvent(GameEventContainer *event);
};

View file

@ -1349,7 +1349,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdSetCardAttr(const Command_SetC
if (player->getConceded())
return Response::RespContextError;
return player->setCardAttrHelper(ges, QString::fromStdString(cmd.zone()), cmd.card_id(), QString::fromStdString(cmd.attr_name()), QString::fromStdString(cmd.attr_value()));
return player->setCardAttrHelper(ges, QString::fromStdString(cmd.zone()), cmd.card_id(), cmd.attribute(), QString::fromStdString(cmd.attr_value()));
}
Response::ResponseCode Server_ProtocolHandler::cmdSetCardCounter(const Command_SetCardCounter &cmd, Server_Game *game, Server_Player *player, ResponseContainer & /*rc*/, GameEventStorage &ges)