ToyLayoutObject.h 2.22 KB
//
//  ToyLayoutObject.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 16.05.2017.
//
//

#ifndef ToyLayoutObject_h
#define ToyLayoutObject_h

#include "json/document.h"
#include "ui/CocosGUI.h"
#include "ToyScenarioObject.h"
#include "ToyJSONParseUtils.h"

class ToyLayoutViewInterface;

class ToyLayoutObject : public ToyScenarioObject
{
    public:
    
        std::string className;
        std::string objectName;
        cocos2d::Point originalPosition;
    
        virtual ~ToyLayoutObject();
    
        virtual void loadPropertiesFromJSON(const rapidjson::Value& jsonValue, ToyLayoutViewInterface* scene = NULL, const std::string resFolder = "", const std::string altResFolder = "") = 0;
    
        virtual void loadCommonPropertiesFromJSON(const rapidjson::Value& jsonValue, ToyLayoutViewInterface* scene = NULL, const std::string resFolder = "", const std::string altResFolder = "");
    
        virtual void prepareSize(const rapidjson::Value& jsonValue, float& width, float& height);
    
        virtual bool isWidget()
        {
            return false;
        };
    
        // for widgets
    
        virtual void setOnTouchBeganCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback){};
        virtual void setOnTouchEndedCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback){};
        virtual void setOnTouchCancelledCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback){};

        // ToyScenarioObject
        virtual std::string getObjectName(){
            return objectName;
        };
    
        virtual std::string getClassName(){
            return className;
        };
    
        virtual std::string getPropertyAsString(std::string propertyName = ""){
            if(propertyName == "objectName"){
                return objectName;
            }
            return "NULL";
        };
    
        virtual void animate(){
            if(_activationAnimation != nullptr){
                animate(_activationAnimation);
            }
        }
    
protected:
    rapidjson::Value* _activationAnimation;
    
    virtual float animate(rapidjson::Value* animationData);
};

#endif /* ToyLayoutObject_h */