From 39f5a518c3c75f39b6bf43bb49cbdd5a2020aa0c Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Mon, 5 Apr 2021 16:23:45 +0200 Subject: [PATCH] added methods to simplify some common actions --- client/src/network/board.cpp | 4 ++-- client/src/network/object.cpp | 16 ++++++++++++++++ client/src/network/object.hpp | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/client/src/network/board.cpp b/client/src/network/board.cpp index 43dd83f8..b169edc3 100644 --- a/client/src/network/board.cpp +++ b/client/src/network/board.cpp @@ -44,12 +44,12 @@ void Board::getTileData() int Board::addTile(int16_t x, int16_t y, TileRotate rotate, const QString& id, bool replace, std::function callback) { - return callMethod(*m_connection, *getMethod("add_tile"), std::move(callback), x, y, rotate, id, replace); + return ::callMethod(*m_connection, *getMethod("add_tile"), std::move(callback), x, y, rotate, id, replace); } int Board::deleteTile(int16_t x, int16_t y, std::function callback) { - return callMethod(*m_connection, *getMethod("delete_tile"), std::move(callback), x, y); + return ::callMethod(*m_connection, *getMethod("delete_tile"), std::move(callback), x, y); } void Board::getTileDataResponse(const Message& response) diff --git a/client/src/network/object.cpp b/client/src/network/object.cpp index 228223c4..5533a2b5 100644 --- a/client/src/network/object.cpp +++ b/client/src/network/object.cpp @@ -59,6 +59,14 @@ AbstractProperty* Object::getProperty(const QString& name) return dynamic_cast(m_interfaceItems.find(name)); } +void Object::setPropertyValue(const QString& name, bool value) +{ + if(AbstractProperty* property = getProperty(name)) + property->setValueBool(value); + else + Q_ASSERT(false); +} + const Method* Object::getMethod(const QString& name) const { return dynamic_cast(m_interfaceItems.find(name)); @@ -68,3 +76,11 @@ Method* Object::getMethod(const QString& name) { return dynamic_cast(m_interfaceItems.find(name)); } + +void Object::callMethod(const QString& name) +{ + if(Method* method = getMethod(name)) + method->call(); + else + Q_ASSERT(false); +} diff --git a/client/src/network/object.hpp b/client/src/network/object.hpp index 0d70fc7c..4bb8dedd 100644 --- a/client/src/network/object.hpp +++ b/client/src/network/object.hpp @@ -63,8 +63,12 @@ class Object : public QObject const AbstractProperty* getProperty(const QString& name) const; AbstractProperty* getProperty(const QString& name); + void setPropertyValue(const QString& name, bool value); + const Method* getMethod(const QString& name) const; Method* getMethod(const QString& name); + + void callMethod(const QString& name); }; #endif