MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / loadLevel

Method loadLevel

Source/BaseGameLayer.cpp:72–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72void BaseGameLayer::loadLevel()
73{
74 // TODO: find a modern gzip decompress library or write own gzip decompress
75
76 std::string levelStr = _level->_levelString;
77 if (levelStr.empty())
78 {
79 nlohmann::json file =
80 nlohmann::json::parse(FileUtils::getInstance()->getStringFromFile("Custom/mainLevels.json"));
81 std::string levelID = std::to_string(_level->_levelID);
82
83 if (!file.contains(levelID))
84 return; // check if our level actually exists in mainlevels list before doing anything
85
86 levelStr = fmt::format("H4sIAAAAAAAAA{}", file.at(levelID).get<std::string>());
87 }
88 levelStr = GJGameLevel::decompressLvlStr(levelStr);
89 {
90 auto s = BenchmarkTimer("load level");
91 setupLevel(levelStr);
92 createObjectsFromSetup(levelStr);
93 }
94
95 if (_allObjects.size() != 0)
96 {
97 _lastObjXPos = 570.0f;
98
99 for (GameObject* object : _allObjects)
100 {
101 if (_lastObjXPos < object->getPositionX())
102 _lastObjXPos = object->getPositionX();
103 }
104
105 GameToolbox::log("last x: {}", _lastObjXPos);
106
107 for (size_t i = 0; i < sectionForPos(_lastObjXPos); i++)
108 {
109 std::vector<GameObject*> vec;
110 _sectionObjects.push_back(vec);
111 }
112
113 for (GameObject* object : _allObjects)
114 {
115 int section = sectionForPos(object->getPositionX());
116 object->_section = section - 1 < 0 ? 0 : section - 1;
117 _sectionObjects[section - 1 < 0 ? 0 : section - 1].push_back(object);
118
119 object->setCascadeOpacityEnabled(false);
120 object->update();
121 }
122 }
123}
124
125void BaseGameLayer::initBatchNodes()
126{

Callers

nothing calls this directly

Calls 7

parseFunction · 0.85
BenchmarkTimerClass · 0.85
logFunction · 0.85
emptyMethod · 0.80
sizeMethod · 0.80
to_stringFunction · 0.50
updateMethod · 0.45

Tested by

no test coverage detected