Blame view

ios/Runner/Wowgame/Classes/game_animal/AniGameStaticCreator.h 2.8 KB
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
  //
  //  AniGameStaticCreator.h
  //  SteveAndMaggieGame
  //
  //  Created by Katarzyna Kalinowska-Górska on 07/05/2019.
  //
  
  #ifndef AniGameStaticCreator_h
  #define AniGameStaticCreator_h
  
  #include "AniMiscUtils.h"
  #include "AniGameConfigParser.h"
  #include "AniResourceUtilities.h"
  
  class AniGameStaticCreator {
      
  public:
  
      void preloadGameResources(std::function<void(std::vector<std::string>)> callback){
          if(m_counter >= 0){
              return; //do nothing
          } else {
              m_counter = 0;
              
              onResourcesLoadedCallback = callback;
              auto layoutFile = getLayoutFile();
              auto AniResourceUtilities = AniResourceUtilities::getInstance();
              auto subCallback = [&](std::vector<std::string> res){
                  ++m_counter;
                  if(m_counter == CounterTarget){
                      onResourcesLoadedCallback(res);
                      m_counter = -1;
                  }
              };
              std::vector<std::string> settingsResources = {"graphics/levels/level_1.png", "graphics/levels/level_2.png", "graphics/levels/level_3.png", "settings_buttons/steve_maggie.png", "settings_buttons/play_preview_again.png", "graphics/level_halo.png" };
  //            std::vector<std::string> tutorialResources = {/*"graphics/tutorials/graphics/fingers_two.png",*/ "graphics/tutorials/graphics/finger_one.png"};
              // don't load two fingers.it will only be used rarely after the first time.
              std::vector<std::string> otherGameResources = {"graphics/star.png", "graphics/tutorials/graphics/finger_one.png"}; /*"buttons/graphics/button_repeat.png",*/
  //            std::vector<std::stirng> mapTilesets = {"baby_level/tileset.png", }; //maybe we don't need them. mind the path!!
              
              AniResourceUtilities.preloadResourcesForFile(layoutFile, subCallback);
              AniResourceUtilities.preloadFiles(settingsResources, subCallback);
  //            AniResourceUtilities.preloadFiles(tutorialResources, subCallback);
              AniResourceUtilities.preloadFiles(otherGameResources, subCallback);
          }
      }
      
      cocos2d::Scene* createGameScene(){
          AniGameConfigParser parser("common/games/game_map/gconfig.gcf");
          //TODO use adv scene mmethod somehow? duplicated in AniAdventureScene.
          std::string layoutFile = getLayoutFile();
          return parser.createGameScene(1, layoutFile);
      }
      
  private:
      
      const int CounterTarget = 3;
      int m_counter { -1 };
      std::function<void(std::vector<std::string>)> onResourcesLoadedCallback {[](std::vector<std::string>){}};
      
      static std::string getLayoutFile(){
          return AniMiscUtils::lastLevel() == AniMiscUtils::Level::CHILD ? "graphics/game_map/baby_level/scene_layout_baby.scl" : "graphics/game_map/scene_layout.scl";
      }
  };
  
  #endif /* AniGameStaticCreator_h */