From 621aab73d479c78156816d488255317226df8331 Mon Sep 17 00:00:00 2001
From: EndrII <EndrIIMail@gmail.com>
Date: Wed, 4 Aug 2021 16:47:55 +0300
Subject: [PATCH] ref #98 rename the IPlayer to the PlayableObject

---
 src/Core/Crawl/iworld.cpp                     |  7 +-
 src/Core/Crawl/iworld.h                       |  9 +--
 .../Crawl/{iplayer.cpp => playableobject.cpp} | 32 ++-------
 .../Crawl/{iplayer.h => playableobject.h}     | 71 ++++++++-----------
 src/Core/Crawl/snake.cpp                      |  4 +-
 src/Core/Crawl/snake.h                        |  4 +-
 src/Core/CrawlModule/qmldir                   |  4 --
 src/CrawlAbstractLvl/private/abslvlworld.cpp  |  2 +-
 src/CrawlAbstractLvl/private/abslvlworld.h    |  2 +-
 src/CrawlTestLvl/private/world.cpp            |  2 +-
 src/CrawlTestLvl/private/world.h              |  2 +-
 src/JungleLvl/private/world.cpp               |  2 +-
 src/JungleLvl/private/world.h                 |  2 +-
 tests/units/clasterstest.cpp                  |  2 +-
 14 files changed, 52 insertions(+), 93 deletions(-)
 rename src/Core/Crawl/{iplayer.cpp => playableobject.cpp} (59%)
 rename src/Core/Crawl/{iplayer.h => playableobject.h} (52%)

diff --git a/src/Core/Crawl/iworld.cpp b/src/Core/Crawl/iworld.cpp
index 995c55d..61df549 100644
--- a/src/Core/Crawl/iworld.cpp
+++ b/src/Core/Crawl/iworld.cpp
@@ -58,11 +58,6 @@ void IWorld::render(unsigned int tbfMsec) {
 
     _ItemsMutex.unlock();
 
-
-    if (_player->isDead()) {
-        emit sigGameFinished(_player->getCurrentStatus());
-    }
-
     updateWorld();
 
     int waitTime = 1000 / _targetFps - tbfMsec;
@@ -101,7 +96,7 @@ void IWorld::setPlayer(QObject *newPlayer) {
     if (_player == newPlayer)
         return;
 
-    auto newPlayerObject = dynamic_cast<IPlayer*>(newPlayer);
+    auto newPlayerObject = dynamic_cast<PlayableObject*>(newPlayer);
     if (!newPlayerObject) {
         QuasarAppUtils::Params::log("Failed to set player object. The input object is not player.",
                                     QuasarAppUtils::Error);
diff --git a/src/Core/Crawl/iworld.h b/src/Core/Crawl/iworld.h
index 54c2e5e..6f8a433 100644
--- a/src/Core/Crawl/iworld.h
+++ b/src/Core/Crawl/iworld.h
@@ -8,7 +8,8 @@
 #ifndef CRAWL_IWORLD_H
 #define CRAWL_IWORLD_H
 
-#include "iplayer.h"
+#include "gameresult.h"
+#include "playableobject.h"
 
 #include <QHash>
 #include <QMap>
@@ -26,7 +27,7 @@ class ClastersTest;
 namespace CRAWL {
 
 class IWorldItem;
-class IPlayer;
+class PlayableObject;
 class GroundClaster;
 class IControl;
 class IAI;
@@ -67,7 +68,7 @@ public:
      * @note The Palyer object will be deleted when wold distroed.
      *  So do not delete your created player pbject yuorself.
      */
-    virtual IPlayer* initPlayer() const = 0;
+    virtual PlayableObject* initPlayer() const = 0;
 
     /**
      * @brief initWorldRules The implementation of this interface must be retun initialized list of the world rules.
@@ -494,7 +495,7 @@ private:
     WorldRule *_worldRules = nullptr;
     WorldRule::const_iterator _currendWorldLevel;
 
-    IPlayer *_player = nullptr;
+    PlayableObject *_player = nullptr;
     IControl *_userInterface = nullptr;
     IAI *_backgroundAI = nullptr;
     int _worldStatus = 0;
diff --git a/src/Core/Crawl/iplayer.cpp b/src/Core/Crawl/playableobject.cpp
similarity index 59%
rename from src/Core/Crawl/iplayer.cpp
rename to src/Core/Crawl/playableobject.cpp
index ed9f5ff..f34831f 100644
--- a/src/Core/Crawl/iplayer.cpp
+++ b/src/Core/Crawl/playableobject.cpp
@@ -6,55 +6,35 @@
 //#
 
 #include "defaultcontrol.h"
-#include "iplayer.h"
+#include "playableobject.h"
 
 namespace CRAWL {
 
 
-IPlayer::IPlayer(const QString &name,
+PlayableObject::PlayableObject(const QString &name,
                  const QString &viewTempalte,
                  QObject *ptr):
     IWorldItem(name, viewTempalte, ptr) {
 
 }
 
-GameResult IPlayer::getCurrentStatus() const {
-    return {_currentPoints, static_cast<int>(position().distanceToPoint({0,0,0}))};
-}
-
-bool IPlayer::isDead() const {
-    return _fDead;
-}
-
-void IPlayer::reward(int value) {
-    _currentPoints += value;
-}
-
-void IPlayer::fine(int value) {
-    _currentPoints -= value;
-}
-
-void IPlayer::render(unsigned int tbfMsec) {
+void PlayableObject::render(unsigned int tbfMsec) {
     MovableObject::render(tbfMsec);
 }
 
-void IPlayer::setControl(const IControl *control) {
+void PlayableObject::setControl(const IControl *control) {
 
 
     if (auto oldControl = dynamic_cast<const DefaultControl*>(_currentControl)) {
-        disconnect(oldControl, &DefaultControl::userTap, this, &IPlayer::onTap);
+        disconnect(oldControl, &DefaultControl::userTap, this, &PlayableObject::onTap);
     }
 
     auto defaultControl = dynamic_cast<const DefaultControl*>(control);
     _currentControl = defaultControl;
 
     if (_currentControl) {
-        connect(defaultControl, &DefaultControl::userTap, this, &IPlayer::onTap);
+        connect(defaultControl, &DefaultControl::userTap, this, &PlayableObject::onTap);
     }
 }
 
-void IPlayer::kill() {
-    _fDead = true;
-}
-
 }
diff --git a/src/Core/Crawl/iplayer.h b/src/Core/Crawl/playableobject.h
similarity index 52%
rename from src/Core/Crawl/iplayer.h
rename to src/Core/Crawl/playableobject.h
index 76f7a97..5b150cc 100644
--- a/src/Core/Crawl/iplayer.h
+++ b/src/Core/Crawl/playableobject.h
@@ -5,10 +5,9 @@
 //# of this license document, but changing it is not allowed.
 //#
 
-#ifndef IPLAYER_H
-#define IPLAYER_H
+#ifndef PLAYABLEOBJECT_H
+#define PLAYABLEOBJECT_H
 
-#include "gameresult.h"
 #include "global.h"
 #include "iworlditem.h"
 #include "Extensions/movableobject.h"
@@ -19,56 +18,46 @@ namespace CRAWL {
 class IControl;
 
 /**
- * @brief The IPlayer class This is base class of the player functions.
+ * @brief The PlayableObject class support works withe the IControl child classes.
+ * **How to is works**? You need to override the  PlayableObject::setControl method for adding your own cpntroll classes. By Default This class use The DefaultControl class.
  */
-class CRAWL_EXPORT IPlayer: public IWorldItem, public MovableObject {
+class CRAWL_EXPORT PlayableObject: public IWorldItem, public MovableObject {
     Q_OBJECT
 public:
-    IPlayer(const QString& name,
+    PlayableObject(const QString& name,
             const QString& viewTempalte = DEFAULT_VIEW_TEMPLATE,
             QObject *ptr = nullptr);
 
-    /**
-     * @brief getCurrentStatus This method return current game state of the player.
-     * @return current gameState.
-     */
-    GameResult getCurrentStatus() const;
-
-    /**
-     * @brief isDead This method return true if your player are dead.
-     * @return true if a player are dead.
-     */
-    bool isDead() const;
-
     /**
      * @brief setControl This method should be connect player object with control object.
      * @param control This is control object.
      * @note This method can invoked two or more times, for example connect with AI control object and player control object. So your implementation should be contains disconnect methods.
+     *
+     * ### Example of use
+     *
+     * @code{cpp}
+        void MyPlayableObject::setControl(const IControl *control) {
+
+
+            if (auto oldControl = dynamic_cast<const DefaultControl*>(_currentControl)) {
+                disconnect(oldControl, &DefaultControl::userTap, this, &PlayableObject::onTap);
+                // some disconnect methodots
+            }
+
+            auto defaultControl = dynamic_cast<const DefaultControl*>(control);
+            _currentControl = defaultControl;
+
+            if (_currentControl) {
+                connect(defaultControl, &DefaultControl::userTap, this, &PlayableObject::onTap);
+                // some connect methodots
+
+            }
+        }
+     * @endcode
      */
     virtual void setControl(const IControl* control);
 
 protected:
-
-    /**
-     * @brief kill This method kill your player.
-     *  Invoke this method when you want to kell your player.
-     */
-    void kill();
-
-    /**
-     * @brief reward This method add reward for player.
-     * @param value This is new value;
-     * @note This method increment current value.
-     */
-    void reward(int value);
-
-    /**
-     * @brief fine This method remove reward for player.
-     * @param value This is fine amount;
-     * @note This method decriment current points value.
-     */
-    void fine(int value);
-
     void render(unsigned int tbfMsec) override;
 
 protected slots:
@@ -80,12 +69,10 @@ protected slots:
 
 
 private:
-    bool _fDead = false;
-    int _currentPoints = 0;
     const IControl * _currentControl = nullptr;
 
 };
 
 }
 
-#endif // IPLAYER_H
+#endif // PLAYABLEOBJECT_H
diff --git a/src/Core/Crawl/snake.cpp b/src/Core/Crawl/snake.cpp
index 1142c05..9c14643 100644
--- a/src/Core/Crawl/snake.cpp
+++ b/src/Core/Crawl/snake.cpp
@@ -15,7 +15,7 @@ namespace CRAWL {
 
 
 Snake::Snake(const QString &name, const QString &viewTempalte, QObject *ptr):
-    IPlayer (name, viewTempalte, ptr) {
+    PlayableObject (name, viewTempalte, ptr) {
 
     _vectors = new QVector3D[2];
     setAngularVelocity(100);
@@ -39,7 +39,7 @@ Snake::~Snake( ){
 }
 
 void Snake::render(unsigned int tbfMsec) {
-    IPlayer::render(tbfMsec);
+    PlayableObject::render(tbfMsec);
 }
 
 void Snake::add(ClasterItem *object) {
diff --git a/src/Core/Crawl/snake.h b/src/Core/Crawl/snake.h
index 7a32877..497e4d3 100644
--- a/src/Core/Crawl/snake.h
+++ b/src/Core/Crawl/snake.h
@@ -8,7 +8,7 @@
 #ifndef CRAWL_SNAKE_H
 #define CRAWL_SNAKE_H
 
-#include "iplayer.h"
+#include "playableobject.h"
 #include "Extensions/autogenerateclaster.h"
 
 namespace CRAWL {
@@ -18,7 +18,7 @@ class SnakeItem;
 /**
  * @brief The Snake class This class implement render mehod for snake object.
  */
-class CRAWL_EXPORT Snake : public IPlayer, public AutoGenerateClaster
+class CRAWL_EXPORT Snake : public PlayableObject, public AutoGenerateClaster
 {
     Q_OBJECT
 public:
diff --git a/src/Core/CrawlModule/qmldir b/src/Core/CrawlModule/qmldir
index d6f71f8..925eebe 100644
--- a/src/Core/CrawlModule/qmldir
+++ b/src/Core/CrawlModule/qmldir
@@ -4,7 +4,3 @@ DefaultMenu 1.0 DefaultMenu.qml
 GraphicItem 1.0 GraphicItem.qml
 ParticleEffect 1.0 ParticleEffect.qml
 Light 1.0 Light.qml
-GraphicItem 1.0 GraphicItem.qml
-GraphicItem 1.0 GraphicItem.qml
-GraphicItem 1.0 GraphicItem.qml
-GraphicItem 1.0 GraphicItem.qml
diff --git a/src/CrawlAbstractLvl/private/abslvlworld.cpp b/src/CrawlAbstractLvl/private/abslvlworld.cpp
index 0e286c9..5b3aeee 100644
--- a/src/CrawlAbstractLvl/private/abslvlworld.cpp
+++ b/src/CrawlAbstractLvl/private/abslvlworld.cpp
@@ -23,7 +23,7 @@ AbsLvlWorld::AbsLvlWorld() {
     setCameraRotation(QQuaternion::fromEulerAngles({0,0,0}));
 }
 
-CRAWL::IPlayer *AbsLvlWorld::initPlayer() const {
+CRAWL::PlayableObject *AbsLvlWorld::initPlayer() const {
     return new AbsLvlSnake();
 }
 
diff --git a/src/CrawlAbstractLvl/private/abslvlworld.h b/src/CrawlAbstractLvl/private/abslvlworld.h
index 773336b..2f075cf 100644
--- a/src/CrawlAbstractLvl/private/abslvlworld.h
+++ b/src/CrawlAbstractLvl/private/abslvlworld.h
@@ -20,7 +20,7 @@ public:
     AbsLvlWorld();
 
 
-    CRAWL::IPlayer *initPlayer() const override;
+    CRAWL::PlayableObject *initPlayer() const override;
     CRAWL::WorldRule *initWorldRules() override;
     QString initHdrBackGround() const override;
     QString description() const override;
diff --git a/src/CrawlTestLvl/private/world.cpp b/src/CrawlTestLvl/private/world.cpp
index bdfa823..281bb39 100644
--- a/src/CrawlTestLvl/private/world.cpp
+++ b/src/CrawlTestLvl/private/world.cpp
@@ -73,7 +73,7 @@ void World::initPlayerControl(CRAWL::IControl *control) {
     return IWorld::initPlayerControl(control);
 }
 
-CRAWL::IPlayer *World::initPlayer() const {
+CRAWL::PlayableObject *World::initPlayer() const {
     return new TestSnake();
 }
 
diff --git a/src/CrawlTestLvl/private/world.h b/src/CrawlTestLvl/private/world.h
index 7c45e9d..f8038f7 100644
--- a/src/CrawlTestLvl/private/world.h
+++ b/src/CrawlTestLvl/private/world.h
@@ -28,7 +28,7 @@ public:
     int costToUnlock() const override;
     CRAWL::IControl *initUserInterface() const override;
     void initPlayerControl(CRAWL::IControl *control) override;
-    CRAWL::IPlayer *initPlayer() const override;
+    CRAWL::PlayableObject *initPlayer() const override;
     CRAWL::IAI *initBackGroundAI() const override;
 
 private slots:
diff --git a/src/JungleLvl/private/world.cpp b/src/JungleLvl/private/world.cpp
index 62db223..b036387 100644
--- a/src/JungleLvl/private/world.cpp
+++ b/src/JungleLvl/private/world.cpp
@@ -108,7 +108,7 @@ void World::initPlayerControl(CRAWL::IControl *control) {
     return IWorld::initPlayerControl(control);
 }
 
-CRAWL::IPlayer *World::initPlayer() const {
+CRAWL::PlayableObject *World::initPlayer() const {
     return new Snake();
 }
 
diff --git a/src/JungleLvl/private/world.h b/src/JungleLvl/private/world.h
index 5862250..98bf398 100644
--- a/src/JungleLvl/private/world.h
+++ b/src/JungleLvl/private/world.h
@@ -27,7 +27,7 @@ public:
     int costToUnlock() const override;
     CRAWL::IControl *initUserInterface() const override;
     void initPlayerControl(CRAWL::IControl *control) override;
-    CRAWL::IPlayer *initPlayer() const override;
+    CRAWL::PlayableObject *initPlayer() const override;
     CRAWL::IAI *initBackGroundAI() const override;
 
 private slots:
diff --git a/tests/units/clasterstest.cpp b/tests/units/clasterstest.cpp
index f48f62a..219c0e6 100644
--- a/tests/units/clasterstest.cpp
+++ b/tests/units/clasterstest.cpp
@@ -45,7 +45,7 @@ public:
 
     // IWorld interface
 public:
-    CRAWL::IPlayer *initPlayer() const {return nullptr;};
+    CRAWL::PlayableObject *initPlayer() const {return nullptr;};
     CRAWL::WorldRule *initWorldRules() {return nullptr;};
     QString initHdrBackGround() const {return "";};
     QString description() const {return "";};