Blame view

ios/Runner/Wowgame/Classes/game_food/ScenarioObject.h 3.23 KB
cb213901   xiaoyu   添加一个游戏的源码和编译选项
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  //
  //  ScenarioObject.h
  //  SteveMaggieCpp
  //
  //  Created by Katarzyna Kalinowska-Górska on 24.05.2017.
  //
  //
  
  #ifndef ScenarioObject_h
  #define ScenarioObject_h
  
  #include <stdio.h>
  #include "ActionData.h"
  #include "json/document.h"
  #include <map>
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
16
  #include<functional>
cb213901   xiaoyu   添加一个游戏的源码和编译选项
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  class ActionParseDelegate;
  
  // weird, because the whole parser has been translated from JavaScript
  
  class ScenarioObject
  {
      public:
      
          std::string scenarioObjectName;
          std::string scenarioObjectClassName;
      
          ScenarioObject(){
              _customData = NULL;
              _jsonValueStorage = NULL;
              scenarioObjectName = "";
              scenarioObjectClassName = "";
          };
      
          virtual ~ScenarioObject(){
              if(_jsonValueStorage){
                  delete _jsonValueStorage;
              }
              for(auto pair : _animations){
                  delete pair.second;
              }
              
              
              
          };
      
  //        virtual void callFunctionByName(std::string methodName, const rapidjson::Value* arguments, ActionParseDelegate* parseDelegate){
  //            // do nothing
  //        };
      
          virtual void callFunctionByName(std::string methodName, const rapidjson::Value* arguments, ActionParseDelegate* parseDelegate, std::function<void()> callback = [](){}){
              // do nothing
              callback();
          };
      
          virtual void setProperty(std::string propertyName, const rapidjson::Value& newValue, ActionParseDelegate* parseDelegate) {
              // do nothing
          };
  
          virtual std::string getPropertyAsString(std::string propertyName = ""){
              if(propertyName == "objectName"){
                  return scenarioObjectName;
              }
              return "NULL";
          };
      
          virtual ScenarioObject* getScenarioObjectByName(std::string objectName){
              return NULL;
          };
      
          virtual void insertAnimationWithId(std::string animationId, const rapidjson::Value& animationData){
              
              if(_animations.find(animationId) == _animations.end()){
                  rapidjson::Value* animationDataCopy = new rapidjson::Value();
                  animationDataCopy->CopyFrom(animationData, this->getJsonStorage()->GetAllocator());
                  _animations.insert({animationId, animationDataCopy});
              }
          };
      
          virtual const rapidjson::Value* getAnimationById(std::string animationId){
              return _animations[animationId];
          };
      
          virtual void setCustomData(void* data){
              _customData = data;
          };
      
          virtual void* getCustomData(){
              return _customData;
          };
      
          virtual std::string getObjectName(){
              return scenarioObjectName;
          };
      
          virtual std::string getClassName(){
              return scenarioObjectClassName;
          };
      
      protected:
          rapidjson::Document* _jsonValueStorage;
          std::map<std::string, rapidjson::Value*> _animations;
          void* _customData;
      
          rapidjson::Document* getJsonStorage(){
              if(!_jsonValueStorage){
                  _jsonValueStorage = new rapidjson::Document();
              }
              return _jsonValueStorage;
          };
      
  };
  
  #endif /* ScenarioObject_h */