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