1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Use optional instead of Json for queries

This commit is contained in:
Ivan Savenko
2023-09-19 23:17:25 +03:00
parent 541f7590c5
commit d257fb37f0
18 changed files with 51 additions and 69 deletions

View File

@@ -10,7 +10,6 @@
#pragma once
#include "../../lib/GameConstants.h"
#include "../../lib/JsonNode.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -39,8 +38,7 @@ public:
std::vector<PlayerColor> players; //players that are affected (often "blocked") by query
QueryID queryID;
CQuery(QueriesProcessor * Owner);
CQuery(CGameHandler * gh);
virtual bool blocksPack(const CPack *pack) const; //query can block attempting actions by player. Eg. he can't move hero during the battle.
@@ -53,11 +51,12 @@ public:
virtual void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const;
virtual void setReply(const JsonNode & reply);
virtual void setReply(std::optional<int32_t> reply);
virtual ~CQuery();
protected:
QueriesProcessor * owner;
CGameHandler * gh;
void addPlayer(PlayerColor color);
bool blockAllButReply(const CPack * pack) const;
};
@@ -65,21 +64,13 @@ protected:
std::ostream &operator<<(std::ostream &out, const CQuery &query);
std::ostream &operator<<(std::ostream &out, QueryPtr query);
class CGhQuery : public CQuery
{
public:
CGhQuery(CGameHandler * owner);
protected:
CGameHandler * gh;
};
class CDialogQuery : public CGhQuery
class CDialogQuery : public CQuery
{
public:
CDialogQuery(CGameHandler * owner);
virtual bool endsByPlayerAnswer() const override;
virtual bool blocksPack(const CPack *pack) const override;
void setReply(const JsonNode & reply) override;
void setReply(std::optional<int32_t> reply) override;
protected:
std::optional<ui32> answer;
};
@@ -87,14 +78,14 @@ protected:
class CGenericQuery : public CQuery
{
public:
CGenericQuery(QueriesProcessor * Owner, PlayerColor color, std::function<void(const JsonNode &)> Callback);
CGenericQuery(CGameHandler * gh, PlayerColor color, std::function<void(std::optional<int32_t>)> Callback);
bool blocksPack(const CPack * pack) const override;
bool endsByPlayerAnswer() const override;
void onExposure(QueryPtr topQuery) override;
void setReply(const JsonNode & reply) override;
void setReply(std::optional<int32_t> reply) override;
void onRemoval(PlayerColor color) override;
private:
std::function<void(const JsonNode &)> callback;
JsonNode reply;
std::function<void(std::optional<int32_t>)> callback;
std::optional<int32_t> reply;
};