Blame view

ios/Runner/Wowgame/Classes/game_toy/ToyActionParser.h 5.48 KB
cb213901   xiaoyu   添加一个游戏的源码和编译选项
1
  //
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
2
  //  ToyActionParser.h
cb213901   xiaoyu   添加一个游戏的源码和编译选项
3
4
5
6
7
8
  //  SteveMaggieCpp
  //
  //  Created by Katarzyna Kalinowska-Górska on 26.05.2017.
  //
  //
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
9
10
  #ifndef ToyActionParser_h
  #define ToyActionParser_h
cb213901   xiaoyu   添加一个游戏的源码和编译选项
11
12
13
14
15
  
  #include <stdio.h>
  #include "cocos2d.h"
  #include "json/document.h"
  #include "TouchHandlerTypes.h"
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
16
17
18
  #include "ToyScenarioObject.h"
  #include "ToyRepeatedActionScheduler.h"
  #include "ToySimpleValue.h"
cb213901   xiaoyu   添加一个游戏的源码和编译选项
19
20
21
22
  
  class ActionParseDelegate {
  
      public:
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
23
24
25
26
          virtual ToyScenarioObject* getObjectByName(std::string objectName) = 0;
          virtual ToyScenarioObject* getDefaultObjectForAction(std::string actionType) = 0;
          virtual ToyScenarioObject* getDefaultObjectForConditionCheck() = 0;
          virtual void addNewObject(std::string objectName, ToyScenarioObject* newObject) = 0;
cb213901   xiaoyu   添加一个游戏的源码和编译选项
27
28
          virtual std::string getDefaultSoundsPath() = 0;
          virtual std::string getAlternativeSoundsPath() = 0;
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
29
          virtual std::string getToyValueStorageContainerName() = 0;
cb213901   xiaoyu   添加一个游戏的源码和编译选项
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
          virtual void runAction(cocos2d::Action* action) = 0;
          virtual void actionFinished(const rapidjson::Value& jsonActionObject) = 0;
          virtual void runInstantly(std::function<void()> actionFunction) = 0;
          virtual void runCompletingAction(cocos2d::Action* action) = 0;
          virtual void cancelAllCompletingActions() = 0;
          virtual void schedule(std::function<void(float)> callback, std::string key, float delay) = 0;
          virtual void scheduleOnce(std::function<void(float)> callback, float delay, std::string key) = 0;
          virtual void unschedule(std::string key) = 0;
          virtual void newTouchHandler(std::string key, TouchHandlerFunction touchHandler, TouchHandlerType touchType) = 0;
          virtual void removeTouchHandler(std::string key, TouchHandlerType touchType) = 0;
          virtual long long getLastScreenTouchTime() = 0;
          virtual int getLoopActionCounter(std::string loopId) = 0;
          virtual int addNewLoopActionCounter(std::string loopId, int timesRepeated) = 0;
          virtual int decrementLoopActionCounter(std::string loopId) = 0;
          virtual void deleteLoopActionCounter(std::string loopId) = 0;
          virtual void setLastActionIndex(int index) = 0;
          virtual unsigned int removeStoredSoundId(std::string soundPath) = 0;
          virtual void storeSoundId(std::string soundPath, unsigned int newSoundId) = 0;
  };
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
50
  class ToyActionParser {
cb213901   xiaoyu   添加一个游戏的源码和编译选项
51
52
53
54
  
      public:
  
          //TODO: actually this DEFINITELY should not be a singleton
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
55
          static ToyActionParser& getInstance()
cb213901   xiaoyu   添加一个游戏的源码和编译选项
56
          {
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
57
              static ToyActionParser instance;
cb213901   xiaoyu   添加一个游戏的源码和编译选项
58
59
60
              return instance;
          };
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
61
          ToyActionParser(){
cb213901   xiaoyu   添加一个游戏的源码和编译选项
62
63
64
              _valueStorage = new (std::nothrow) rapidjson::Document();
          };
      
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
65
          ~ToyActionParser(){
cb213901   xiaoyu   添加一个游戏的源码和编译选项
66
67
68
69
70
71
72
73
              if(_valueStorage){
                  delete _valueStorage;
              }
          }
  
          cocos2d::Action* parseJSONAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished = true);
          void cleanUp(ActionParseDelegate* delegate);
      
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
74
75
          static std::vector<cocos2d::Node*> convertToNodeArray(std::vector<ToyScenarioObject*> objects);
          static cocos2d::Node* convertToNode(ToyScenarioObject* object);
cb213901   xiaoyu   添加一个游戏的源码和编译选项
76
      
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
77
78
79
          ToyScenarioObject* parseObject(std::string objectName, ActionParseDelegate* parseDelegate);
          std::vector<ToyScenarioObject*> parseObjects(const rapidjson::Value& objectJsonArray, ActionParseDelegate* parseDelegate);
          std::vector<ToyScenarioObject*> parseObjectOrObjects(const rapidjson::Value& jsonObject, std::string objectKey, std::string objectsKey, ActionParseDelegate* parseDelegate);
cb213901   xiaoyu   添加一个游戏的源码和编译选项
80
      
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
81
82
          friend class ToySimpleActionParser;
          friend class ToyBlockingActionParser;
cb213901   xiaoyu   添加一个游戏的源码和编译选项
83
          friend class DynamicObjectMapper;
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
84
          friend class ToyRepeatedActionScheduler;
cb213901   xiaoyu   添加一个游戏的源码和编译选项
85
86
87
88
89
90
91
92
93
94
95
96
97
98
          
      protected:
      
          rapidjson::Document* _valueStorage;
  
      
          cocos2d::Action* parseConditionalAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
          cocos2d::Action* parseRandomAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
          cocos2d::Action* parseSequenceAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
          cocos2d::Action* parseSpawnAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
          cocos2d::Action* parseLoopAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
          cocos2d::Action* embedFunctionInAction(std::function<void()> actionFunction, const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
          bool checkCondition(std::string condition, ActionParseDelegate* parseDelegate);
          bool checkExpression(std::string leftValue, std::string rightValue, std::string operatorString);
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
99
          std::vector<ToyScenarioObject*> prepareObjectsForAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate);
cb213901   xiaoyu   添加一个游戏的源码和编译选项
100
101
102
103
104
          void parseAndRunActions(const rapidjson::Value& actionsArray, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
          void parseAndRunAction(const rapidjson::Value& action, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished);
          bool checkLateCondition(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate);
  };
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
105
  #endif /* ToyActionParser_h */
cb213901   xiaoyu   添加一个游戏的源码和编译选项