Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
game_meta_info.h
Go to the documentation of this file.
1
6
7#ifndef GAME_META_INFO_H
8#define GAME_META_INFO_H
9
10#include <QMap>
11#include <QObject>
12#include <QString>
13#include <libcockatrice/protocol/pb/serverinfo_game.pb.h>
14#include <qtmetamacros.h>
15
16// Translation layer class to expose protobuf safely and hook it up to Qt Signals.
17// This class de-couples the domain object (i.e. the GameMetaInfo) from the network object.
18// If the network object changes, only this class needs to be adjusted.
19
20class AbstractGame;
21
22class GameMetaInfo : public QObject
23{
24 Q_OBJECT
25public:
26 explicit GameMetaInfo(AbstractGame *parent);
27
29
30 // Populate from protobuf (e.g., after network message)
32 {
33 gameInfo_.CopyFrom(gi);
34 }
35
36 const ServerInfo_Game &proto() const
37 {
38 return gameInfo_;
39 }
40
41 // High-level getters that avoid exposing protobuf directly
42 int gameId() const
43 {
44 return gameInfo_.game_id();
45 }
46 int maxPlayers() const
47 {
48 return gameInfo_.max_players();
49 }
50 QString description() const
51 {
52 return QString::fromStdString(gameInfo_.description());
53 }
54 bool started() const
55 {
56 return gameInfo_.started();
57 }
59 {
61 }
62 bool spectatorsCanChat() const
63 {
65 }
66 int gameTypesSize() const
67 {
68 return gameInfo_.game_types_size();
69 }
70 int gameTypeIdAt(int index) const
71 {
72 return gameInfo_.game_types(index);
73 }
74
79
81 {
82 roomGameTypes = _roomGameTypes;
83 }
84
85 QString findRoomGameType(int index)
86 {
87 return roomGameTypes.find(gameInfo_.game_types(index)).value();
88 }
89
90public slots:
91 void setStarted(bool s)
92 {
93 if (gameInfo_.started() == s) {
94 return;
95 }
96 gameInfo_.set_started(s);
97 emit startedChanged(s);
98 }
100 {
101 if (gameInfo_.spectators_omniscient() == v) {
102 return;
103 }
104 gameInfo_.set_spectators_omniscient(v);
106 }
107
108signals:
110 void spectatorsOmniscienceChanged(bool omniscient);
111
112private:
114};
115
116#endif // GAME_META_INFO_H
Definition abstract_game.h:23
int gameId() const
Definition game_meta_info.h:42
bool spectatorsOmniscient() const
Definition game_meta_info.h:58
int gameTypeIdAt(int index) const
Definition game_meta_info.h:70
QMap< int, QString > roomGameTypes
Definition game_meta_info.h:28
void spectatorsOmniscienceChanged(bool omniscient)
void startedChanged(bool started)
QString findRoomGameType(int index)
Definition game_meta_info.h:85
QString description() const
Definition game_meta_info.h:50
void setStarted(bool s)
Definition game_meta_info.h:91
ServerInfo_Game gameInfo_
Definition game_meta_info.h:113
QMap< int, QString > getRoomGameTypes() const
Definition game_meta_info.h:75
void setFromProto(const ServerInfo_Game &gi)
Definition game_meta_info.h:31
bool spectatorsCanChat() const
Definition game_meta_info.h:62
void setSpectatorsOmniscient(bool v)
Definition game_meta_info.h:99
int gameTypesSize() const
Definition game_meta_info.h:66
const ServerInfo_Game & proto() const
Definition game_meta_info.h:36
GameMetaInfo(AbstractGame *parent)
Definition game_meta_info.cpp:5
bool started() const
Definition game_meta_info.h:54
int maxPlayers() const
Definition game_meta_info.h:46
void setRoomGameTypes(QMap< int, QString > _roomGameTypes)
Definition game_meta_info.h:80
Definition game.h:18
Definition serverinfo_game.proto:5
optional sint32 game_id
Definition serverinfo_game.proto:14
optional bool spectators_omniscient
Definition serverinfo_game.proto:47
optional string description
Definition serverinfo_game.proto:17
optional bool started
Definition serverinfo_game.proto:59
optional uint32 max_players
Definition serverinfo_game.proto:23
repeated sint32 game_types
Definition serverinfo_game.proto:26
optional bool spectators_can_chat
Definition serverinfo_game.proto:44