Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
609e3fc4
Commit
609e3fc4
authored
Jan 02, 2012
by
Max-Wilhelm Bruker
Browse files
converted SetCardAttr attr_name to enum
parent
4634787b
Changes
12
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/phasestoolbar.cpp
View file @
609e3fc4
...
...
@@ -236,8 +236,7 @@ void PhasesToolbar::actUntapAll()
{
Command_SetCardAttr
cmd
;
cmd
.
set_zone
(
"table"
);
cmd
.
set_card_id
(
-
1
);
cmd
.
set_attr_name
(
"tapped"
);
cmd
.
set_attribute
(
AttrTapped
);
cmd
.
set_attr_value
(
"0"
);
emit
sendGameCommand
(
cmd
,
-
1
);
...
...
cockatrice/src/player.cpp
View file @
609e3fc4
...
...
@@ -723,8 +723,7 @@ void Player::actUntapAll()
{
Command_SetCardAttr
cmd
;
cmd
.
set_zone
(
"table"
);
cmd
.
set_card_id
(
-
1
);
cmd
.
set_attr_name
(
"tapped"
);
cmd
.
set_attribute
(
AttrTapped
);
cmd
.
set_attr_value
(
"0"
);
sendGameCommand
(
cmd
);
...
...
@@ -780,30 +779,38 @@ void Player::actSayMessage()
sendGameCommand
(
cmd
);
}
void
Player
::
setCardAttrHelper
(
const
GameEventContext
&
context
,
CardItem
*
card
,
const
QString
&
anam
e
,
const
QString
&
avalue
,
bool
allCards
)
void
Player
::
setCardAttrHelper
(
const
GameEventContext
&
context
,
CardItem
*
card
,
CardAttribute
attribut
e
,
const
QString
&
avalue
,
bool
allCards
)
{
bool
moveCardContext
=
context
.
HasExtension
(
Context_MoveCard
::
ext
);
if
(
aname
==
"tapped"
)
{
bool
tapped
=
avalue
==
"1"
;
if
(
!
(
!
tapped
&&
card
->
getDoesntUntap
()
&&
allCards
))
{
if
(
!
allCards
)
emit
logSetTapped
(
this
,
card
,
tapped
);
card
->
setTapped
(
tapped
,
!
moveCardContext
);
switch
(
attribute
)
{
case
AttrTapped
:
{
bool
tapped
=
avalue
==
"1"
;
if
(
!
(
!
tapped
&&
card
->
getDoesntUntap
()
&&
allCards
))
{
if
(
!
allCards
)
emit
logSetTapped
(
this
,
card
,
tapped
);
card
->
setTapped
(
tapped
,
!
moveCardContext
);
}
break
;
}
case
AttrAttacking
:
card
->
setAttacking
(
avalue
==
"1"
);
break
;
case
AttrFaceDown
:
card
->
setFaceDown
(
avalue
==
"1"
);
break
;
case
AttrColor
:
card
->
setColor
(
avalue
);
break
;
case
AttrAnnotation
:
{
emit
logSetAnnotation
(
this
,
card
,
avalue
);
card
->
setAnnotation
(
avalue
);
break
;
}
case
AttrDoesntUntap
:
{
bool
value
=
(
avalue
==
"1"
);
emit
logSetDoesntUntap
(
this
,
card
,
value
);
card
->
setDoesntUntap
(
value
);
break
;
}
case
AttrPT
:
{
emit
logSetPT
(
this
,
card
,
avalue
);
card
->
setPT
(
avalue
);
break
;
}
}
else
if
(
aname
==
"attacking"
)
card
->
setAttacking
(
avalue
==
"1"
);
else
if
(
aname
==
"facedown"
)
card
->
setFaceDown
(
avalue
==
"1"
);
else
if
(
aname
==
"annotation"
)
{
emit
logSetAnnotation
(
this
,
card
,
avalue
);
card
->
setAnnotation
(
avalue
);
}
else
if
(
aname
==
"doesnt_untap"
)
{
bool
value
=
(
avalue
==
"1"
);
emit
logSetDoesntUntap
(
this
,
card
,
value
);
card
->
setDoesntUntap
(
value
);
}
else
if
(
aname
==
"pt"
)
{
emit
logSetPT
(
this
,
card
,
avalue
);
card
->
setPT
(
avalue
);
}
}
...
...
@@ -875,8 +882,8 @@ void Player::eventSetCardAttr(const Event_SetCardAttr &event, const GameEventCon
if
(
!
event
.
has_card_id
())
{
const
CardList
&
cards
=
zone
->
getCards
();
for
(
int
i
=
0
;
i
<
cards
.
size
();
i
++
)
setCardAttrHelper
(
context
,
cards
.
at
(
i
),
QString
::
fromStdString
(
event
.
attr
_nam
e
()
)
,
QString
::
fromStdString
(
event
.
attr_value
()),
true
);
if
(
event
.
attr
_nam
e
()
==
"t
apped
"
)
setCardAttrHelper
(
context
,
cards
.
at
(
i
),
event
.
attr
ibut
e
(),
QString
::
fromStdString
(
event
.
attr_value
()),
true
);
if
(
event
.
attr
ibut
e
()
==
AttrT
apped
)
emit
logSetTapped
(
this
,
0
,
event
.
attr_value
()
==
"1"
);
}
else
{
CardItem
*
card
=
zone
->
getCard
(
event
.
card_id
(),
QString
());
...
...
@@ -884,7 +891,7 @@ void Player::eventSetCardAttr(const Event_SetCardAttr &event, const GameEventCon
qDebug
()
<<
"Player::eventSetCardAttr: card id="
<<
event
.
card_id
()
<<
"not found"
;
return
;
}
setCardAttrHelper
(
context
,
card
,
QString
::
fromStdString
(
event
.
attr
_nam
e
()
)
,
QString
::
fromStdString
(
event
.
attr_value
()),
false
);
setCardAttrHelper
(
context
,
card
,
event
.
attr
ibut
e
(),
QString
::
fromStdString
(
event
.
attr_value
()),
false
);
}
}
...
...
@@ -1485,7 +1492,7 @@ void Player::cardMenuAction(QAction *a)
Command_SetCardAttr
*
cmd
=
new
Command_SetCardAttr
;
cmd
->
set_zone
(
card
->
getZone
()
->
getName
().
toStdString
());
cmd
->
set_card_id
(
card
->
getId
());
cmd
->
set_attr
_name
(
"t
apped
"
);
cmd
->
set_attr
ibute
(
AttrT
apped
);
cmd
->
set_attr_value
(
"1"
);
commandList
.
append
(
cmd
);
}
...
...
@@ -1495,7 +1502,7 @@ void Player::cardMenuAction(QAction *a)
Command_SetCardAttr
*
cmd
=
new
Command_SetCardAttr
;
cmd
->
set_zone
(
card
->
getZone
()
->
getName
().
toStdString
());
cmd
->
set_card_id
(
card
->
getId
());
cmd
->
set_attr
_name
(
"t
apped
"
);
cmd
->
set_attr
ibute
(
AttrT
apped
);
cmd
->
set_attr_value
(
"0"
);
commandList
.
append
(
cmd
);
}
...
...
@@ -1504,7 +1511,7 @@ void Player::cardMenuAction(QAction *a)
Command_SetCardAttr
*
cmd
=
new
Command_SetCardAttr
;
cmd
->
set_zone
(
card
->
getZone
()
->
getName
().
toStdString
());
cmd
->
set_card_id
(
card
->
getId
());
cmd
->
set_attr
_name
(
"d
oesnt
_u
ntap
"
);
cmd
->
set_attr
ibute
(
AttrD
oesnt
U
ntap
);
cmd
->
set_attr_value
(
card
->
getDoesntUntap
()
?
"1"
:
"0"
);
commandList
.
append
(
cmd
);
break
;
...
...
@@ -1600,7 +1607,7 @@ void Player::actIncPT(int deltaP, int deltaT)
Command_SetCardAttr
*
cmd
=
new
Command_SetCardAttr
;
cmd
->
set_zone
(
card
->
getZone
()
->
getName
().
toStdString
());
cmd
->
set_card_id
(
card
->
getId
());
cmd
->
set_attr
_name
(
"pt"
);
cmd
->
set_attr
ibute
(
AttrPT
);
cmd
->
set_attr_value
(
ptString
.
toStdString
());
commandList
.
append
(
cmd
);
}
...
...
@@ -1632,7 +1639,7 @@ void Player::actSetPT(QAction * /*a*/)
Command_SetCardAttr
*
cmd
=
new
Command_SetCardAttr
;
cmd
->
set_zone
(
card
->
getZone
()
->
getName
().
toStdString
());
cmd
->
set_card_id
(
card
->
getId
());
cmd
->
set_attr
_name
(
"pt"
);
cmd
->
set_attr
ibute
(
AttrPT
);
cmd
->
set_attr_value
(
pt
.
toStdString
());
commandList
.
append
(
cmd
);
}
...
...
@@ -1665,7 +1672,7 @@ void Player::actSetAnnotation(QAction * /*a*/)
Command_SetCardAttr
*
cmd
=
new
Command_SetCardAttr
;
cmd
->
set_zone
(
card
->
getZone
()
->
getName
().
toStdString
());
cmd
->
set_card_id
(
card
->
getId
());
cmd
->
set_attr
_name
(
"a
nnotation
"
);
cmd
->
set_attr
ibute
(
AttrA
nnotation
);
cmd
->
set_attr_value
(
annotation
.
toStdString
());
commandList
.
append
(
cmd
);
}
...
...
cockatrice/src/player.h
View file @
609e3fc4
...
...
@@ -6,6 +6,7 @@
#include
<QMap>
#include
"abstractgraphicsitem.h"
#include
"pb/game_event.pb.h"
#include
"pb/card_attributes.pb.h"
namespace
google
{
namespace
protobuf
{
class
Message
;
}
}
class
CardDatabase
;
...
...
@@ -174,7 +175,7 @@ private:
HandZone
*
hand
;
PlayerTarget
*
playerTarget
;
void
setCardAttrHelper
(
const
GameEventContext
&
context
,
CardItem
*
card
,
const
QString
&
anam
e
,
const
QString
&
avalue
,
bool
allCards
);
void
setCardAttrHelper
(
const
GameEventContext
&
context
,
CardItem
*
card
,
CardAttribute
attribut
e
,
const
QString
&
avalue
,
bool
allCards
);
QRectF
bRect
;
...
...
cockatrice/src/tablezone.cpp
View file @
609e3fc4
...
...
@@ -201,7 +201,7 @@ void TableZone::toggleTapped()
Command_SetCardAttr
*
cmd
=
new
Command_SetCardAttr
;
cmd
->
set_zone
(
name
.
toStdString
());
cmd
->
set_card_id
(
temp
->
getId
());
cmd
->
set_attr
_name
(
"t
apped
"
);
cmd
->
set_attr
ibute
(
AttrT
apped
);
cmd
->
set_attr_value
(
tapAll
?
"1"
:
"0"
);
cmdList
.
append
(
cmd
);
}
...
...
common/pb/proto/card_attributes.proto
0 → 100644
View file @
609e3fc4
enum
CardAttribute
{
AttrTapped
=
1
;
AttrAttacking
=
2
;
AttrFaceDown
=
3
;
AttrColor
=
4
;
AttrPT
=
5
;
AttrAnnotation
=
6
;
AttrDoesntUntap
=
7
;
}
common/pb/proto/command_set_card_attr.proto
View file @
609e3fc4
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
_nam
e
=
3
;
optional
CardAttribute
attr
ibut
e
=
3
;
optional
string
attr_value
=
4
;
}
common/pb/proto/event_set_card_attr.proto
View file @
609e3fc4
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
_nam
e
=
3
;
optional
CardAttribute
attr
ibut
e
=
3
;
optional
string
attr_value
=
4
;
}
common/server_card.cpp
View file @
609e3fc4
...
...
@@ -45,28 +45,22 @@ void Server_Card::resetState()
setDoesntUntap
(
false
);
}
QString
Server_Card
::
setAttribute
(
const
QString
&
anam
e
,
const
QString
&
avalue
,
bool
allCards
)
QString
Server_Card
::
setAttribute
(
CardAttribute
attribut
e
,
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
;
}
...
...
common/server_card.h
View file @
609e3fc4
...
...
@@ -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
&
anam
e
,
const
QString
&
avalue
,
bool
allCards
);
QString
setAttribute
(
CardAttribute
attribut
e
,
const
QString
&
avalue
,
bool
allCards
);
};
#endif
common/server_player.cpp
View file @
609e3fc4
...
...
@@ -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
(),
"t
apped
"
,
"1"
);
setCardAttrHelper
(
ges
,
targetzone
->
getName
(),
card
->
getId
(),
AttrT
apped
,
"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
&
attrNam
e
,
const
QString
&
attrValue
)
Response
::
ResponseCode
Server_Player
::
setCardAttrHelper
(
GameEventStorage
&
ges
,
const
QString
&
zoneName
,
int
cardId
,
CardAttribute
attribut
e
,
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
(
attr
Nam
e
,
attrValue
,
true
);
result
=
CardIterator
.
next
()
->
setAttribute
(
attr
ibut
e
,
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
(
attr
Nam
e
,
attrValue
,
false
);
result
=
card
->
setAttribute
(
attr
ibut
e
,
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
_nam
e
(
attr
Name
.
toStdString
()
);
event
.
set_attr
ibut
e
(
attr
ibute
);
event
.
set_attr_value
(
result
.
toStdString
());
ges
.
enqueueGameEvent
(
event
,
playerId
);
...
...
common/server_player.h
View file @
609e3fc4
...
...
@@ -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
&
attrNam
e
,
const
QString
&
attrValue
);
Response
::
ResponseCode
setCardAttrHelper
(
GameEventStorage
&
ges
,
const
QString
&
zone
,
int
cardId
,
CardAttribute
attribut
e
,
const
QString
&
attrValue
);
void
sendGameEvent
(
GameEventContainer
*
event
);
};
...
...
common/server_protocolhandler.cpp
View file @
609e3fc4
...
...
@@ -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
_nam
e
()
)
,
QString
::
fromStdString
(
cmd
.
attr_value
()));
return
player
->
setCardAttrHelper
(
ges
,
QString
::
fromStdString
(
cmd
.
zone
()),
cmd
.
card_id
(),
cmd
.
attr
ibut
e
(),
QString
::
fromStdString
(
cmd
.
attr_value
()));
}
Response
::
ResponseCode
Server_ProtocolHandler
::
cmdSetCardCounter
(
const
Command_SetCardCounter
&
cmd
,
Server_Game
*
game
,
Server_Player
*
player
,
ResponseContainer
&
/*rc*/
,
GameEventStorage
&
ges
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment