ToyRepeatedActionScheduler.h 1.22 KB
//
//  ToyRepeatedActionScheduler.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 27.05.2017.
//
//

#ifndef ToyRepeatedActionScheduler_h
#define ToyRepeatedActionScheduler_h

#include "json/document.h"
#include <stdio.h>
#include <string>
#include "cocos2d.h"


class ActionParseDelegate;

class ToyRepeatedActionScheduler
{
    public:
    
        struct ScheduledActionsData
        {
            std::string callbackKey;
            std::string storedValueKey;
            long long lastTimeRun;
        };
    
        static ToyRepeatedActionScheduler& getInstance()
        {
            static ToyRepeatedActionScheduler instance;
            return instance;
        };
    
        void clearAllScheduledActions(ActionParseDelegate* parseDelegate);
        cocos2d::Action* scheduleActionIfNeeded(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
        bool isActionValidRepeatedAction(const rapidjson::Value& jsonActionObject);
    
    protected:
    
        std::map<std::string, ScheduledActionsData> _scheduledActionsData;
        std::map<std::string, std::function<void(float)>> _waitingFunctions;
};

#endif /* ToyRepeatedActionScheduler_h */