Cockatrice/libcockatrice_game/libcockatrice/game/game_meta_info.h
Lukas Brübach dfa0edfcdb [Client] Drop dead player event handler extension points
The second PlayerLogic constructor taking a custom PlayerEventHandler was UB
(converting this to PlayerLogic* in the base initializer, and connecting a
freshly-built handler against a not-yet-constructed object), and its abstract
extension surface — virtual initializeZones, virtual getPlayerEventHandler,
virtual processGameEvent, protected player member — has no subclass consumer in
the stack. Revert to the single primary constructor.

Also:
- Drop the unused GameMetaInfo::setIsTournament setter. Tournament status is
  authoritative from Event_GameJoined's ServerInfo_Game; the redundant
  is_tournament field on Event_GameStateChanged is removed in [Protocol].
- Gate the parent-game routing on has_parent_game_id() instead of comparing the
  proto default, so a future drop of the default keeps working.
2026-11-03 00:25:34 +01:00

132 lines
2.8 KiB
C++

/**
* @file game_meta_info.h
* @ingroup GameLogic
*/
//! \todo Document this file.
#ifndef GAME_META_INFO_H
#define GAME_META_INFO_H
#include <QMap>
#include <QObject>
#include <QString>
#include <libcockatrice/protocol/pb/serverinfo_game.pb.h>
#include <qtmetamacros.h>
// Translation layer class to expose protobuf safely and hook it up to Qt Signals.
// This class de-couples the domain object (i.e. the GameMetaInfo) from the network object.
// If the network object changes, only this class needs to be adjusted.
class AbstractGame;
class GameMetaInfo : public QObject
{
Q_OBJECT
public:
explicit GameMetaInfo(AbstractGame *parent);
QMap<int, QString> roomGameTypes;
// Populate from protobuf (e.g., after network message)
void setFromProto(const ServerInfo_Game &gi)
{
gameInfo_.CopyFrom(gi);
}
const ServerInfo_Game &proto() const
{
return gameInfo_;
}
// High-level getters that avoid exposing protobuf directly
int gameId() const
{
return gameInfo_.game_id();
}
int maxPlayers() const
{
return gameInfo_.max_players();
}
QString description() const
{
return QString::fromStdString(gameInfo_.description());
}
bool started() const
{
return gameInfo_.started();
}
bool spectatorsOmniscient() const
{
return gameInfo_.spectators_omniscient();
}
bool spectatorsCanChat() const
{
return gameInfo_.spectators_can_chat();
}
int gameTypesSize() const
{
return gameInfo_.game_types_size();
}
int gameTypeIdAt(int index) const
{
return gameInfo_.game_types(index);
}
QMap<int, QString> getRoomGameTypes() const
{
return roomGameTypes;
}
void setRoomGameTypes(QMap<int, QString> _roomGameTypes)
{
roomGameTypes = _roomGameTypes;
}
QString findRoomGameType(int index)
{
return roomGameTypes.find(gameInfo_.game_types(index)).value();
}
bool isTournament() const
{
return gameInfo_.is_tournament();
}
int parentGameId() const
{
return parentGameId_;
}
void setParentGameId(int id)
{
parentGameId_ = id;
}
public slots:
void setStarted(bool s)
{
if (gameInfo_.started() == s) {
return;
}
gameInfo_.set_started(s);
emit startedChanged(s);
}
void setSpectatorsOmniscient(bool v)
{
if (gameInfo_.spectators_omniscient() == v) {
return;
}
gameInfo_.set_spectators_omniscient(v);
emit spectatorsOmniscienceChanged(v);
}
signals:
void startedChanged(bool started);
void spectatorsOmniscienceChanged(bool omniscient);
private:
ServerInfo_Game gameInfo_;
int parentGameId_ = -1;
};
#endif // GAME_META_INFO_H