IMapController.h 5.3 KB
//
//  AniMapLayer.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
//
//

#ifndef IMapController_h
#define IMapController_h

#include "cocos2d.h"
#include "IMapImageObject.h"
#include "IMapAdventureObject.h"
#include "IMapAdventureObjectMapper.h"
#include "AniMapUtils.h"
#include "IMapControlInterface.h"

class IMapController : public IMapControlInterface {
    
public:
    IMapController(cocos2d::TMXTiledMap* p_map, IMapAdventureObjectMapper* p_adventureObjectMapper){
        m_map = p_map;
        m_adventureObjectMapper = p_adventureObjectMapper;
    }
    
    inline cocos2d::TMXTiledMap* getMap(){ return m_map; }
    virtual cocos2d::TMXLayer* getTileLayer() = 0;
    virtual cocos2d::TMXLayer* getTileObjectLayer() = 0;
//    virtual void addBlockedTile(AniMapUtils::TileData p_tile) = 0;
    virtual void addBlockedTiles(std::vector<AniMapUtils::TileData> p_tiles, bool recalculateGraph) = 0;
//    virtual void removeBlockedTile(AniMapUtils::TileData p_tile) = 0;
    virtual void removeBlockedTiles(std::vector<AniMapUtils::TileData> p_tiles, bool recalculateGraph) = 0;
    inline AniMapUtils::TileData getTileForTouchPoint(cocos2d::Point p_screenTouchPoint){
        auto mapPoint = AniMapUtils::getInstance().translateScreenPositionToMapPosition(p_screenTouchPoint, getCameraPosition());
        return AniMapUtils::getInstance().translateXYPointToColRow(mapPoint, m_map->getTileSize().width, m_map->getTileSize().height, m_map->getMapSize().width, m_map->getMapSize().height);
    }

    virtual void revealTile(cocos2d::Vec2 tileCoord) = 0;
    virtual void revealTilesInRadius(cocos2d::Point p_center, float p_radiusX, float p_radiusY) = 0;
    
    // map image objects
    virtual int getBackgroundDepth() = 0;
    virtual int getMaxObjectDepth() = 0;
    virtual IMapImageObject* getMapImageObject(std::string p_objectName) = 0;
    virtual std::vector<IMapImageObject*> getMapImageObjects() = 0;
    virtual std::vector<IMapImageObject*> getMapImageObjectsBoundByRect(cocos2d::Rect p_rect) = 0;
    
    // map adventure objects
    virtual void parseAdventureObjects(const std::string& p_mapAdventureObjectsFile, IMapAdventureObjectDelegate* p_objectsDelegate) = 0;
    virtual std::vector<IMapAdventureObject*> getAdventureObjectsAtTile(const AniMapUtils::TileData& p_tileData, bool activeObjectsOnly = true) = 0;
    std::vector<IMapAdventureObject*> getAdventureObjectsAtMapPoint(cocos2d::Point p_mapPoint, bool activeObjectsOnly = true){
        auto rowCol = AniMapUtils::getInstance().translateXYPointToColRow(p_mapPoint, m_map->getTileSize().width, m_map->getTileSize().height, m_map->getMapSize().width, m_map->getMapSize().height);
        return getAdventureObjectsAtTile(rowCol);
    }
    std::vector<IMapAdventureObject*> getAdventureObjectsAtTouchPoint(cocos2d::Point p_screenTouchPoint, bool activeObjectsOnly = true){
            return getAdventureObjectsAtMapPoint(AniMapUtils::getInstance().translateScreenPositionToMapPosition(p_screenTouchPoint, getCameraPosition()), activeObjectsOnly);
    }
    virtual void clearAdventureObjects(bool clearAssociatedImageObjects = true) = 0;
    virtual void clearAdventureObject(IMapAdventureObject* p_adventureObject, bool clearAssociatedImageObjects = true) = 0;
    virtual void remapAdventureObject(IMapAdventureObject* p_adventureObject) = 0;
    
    // TODO TIHS IS TEMP> PARSING SHOULD E SOMEWHERE IN A MAP PARSER EVERYTHING SHOULD BE ARRANGED IN A SMART WAY
    //TODO ADVENTURE OBJECTS HSOULD BE HERE AS WELL
    virtual void insertMapImageObject(std::string objectName, IMapImageObject* object) = 0;
    
    // camera
    constexpr static float DefaultCameraVelocity {800};
    inline void setCameraVelocity(float p_cameraVelocity){ m_cameraVelocity = p_cameraVelocity;}
    inline cocos2d::Point getCameraPosition(){ return m_map->getParent()->getPosition(); };
    virtual cocos2d::Vec2 moveCamera(float deltaX, float deltaY, bool animated = false) = 0;
    virtual bool setCameraCenter(cocos2d::Point position, bool instantEffect = false) = 0;
    virtual bool centerCameraOnNode(cocos2d::Node* p_node, bool instantEffect = false) = 0;
    virtual bool isInZoomMode() = 0;
    virtual void cancelZoomMode() = 0;
    inline void setCameraDestination(cocos2d::Point p_cameraDestination){
        m_cameraDestination = p_cameraDestination;
    }
    inline void moveCameraDestination(cocos2d::Point p_delta){
        m_cameraDestination += p_delta;
    }
    virtual void setCameraCut(cocos2d::Rect cameraCut){
        m_cameraCut = cameraCut;
    };
    virtual void cancelCameraCut(){
        m_cameraCut = cocos2d::Rect::ZERO;
    }
    
    
    // update
    virtual void update(float dt) = 0;
    
    virtual void reset() = 0;
    
    virtual ~IMapController(){};
//
//// IMapControlInterface
//    
//    virtual void handleCommandSingleXYPress(const IMapControlSingleXYEventData& eventData) = 0;
//    virtual void handleCommandSingleXYMove(const IMapControlSingleXYEventData& eventData) = 0;
//    virtual void handleCommandSingleXYRelease(const IMapControlSingleXYEventData& eventData) = 0;
    
protected:
    cocos2d::TMXTiledMap* m_map;
    cocos2d::Rect m_cameraCut { cocos2d::Rect::ZERO };
    IMapAdventureObjectMapper* m_adventureObjectMapper;
    cocos2d::Point m_cameraDestination;
    float m_cameraVelocity {DefaultCameraVelocity};
};

#endif /* IMapController_h */