MCPcopy Create free account
hub / github.com/AbyssEngine/AbyssEngineOld / loadTile

Method loadTile

src/OD2/Scenes/MapTest/MapTest.cpp:130–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void MapTest::loadTile(const std::string &altName) {
131 Abyss::Common::Log::debug("Loading level alt: {}", altName);
132 const auto &levelPrest = getLevelPrest(_selectedLevelName);
133 const auto levelId = std::stoi(levelPrest.at("LevelId"));
134 const auto &levelDetails = getLevelDetails(levelId);
135 const auto &levelTypeId = std::stoi(levelDetails.at("LevelType"));
136 //const auto act = std::stoi(levelDetails.at("Act")) + 1;
137 const auto act = std::stoi(_selectedLevelName.substr(4, 1));
138 const auto &levelType = getLevelType(levelTypeId);
139 const auto &palette = Common::PaletteManager::getInstance().getPalette("Act" + std::to_string(act));
140
141 std::vector<std::string> dt1sToLoad{};
142
143 for (int i = 1; i <= 31; ++i) {
144 const auto &file = "File " + std::to_string(i);
145 auto dt1 = levelType.at(file);
146 std::ranges::transform(dt1, dt1.begin(), [](const auto c) { return std::tolower(c); });
147 if (dt1 != "None" && dt1 != "Expansion" && dt1 != "0" && std::ranges::find(dt1sToLoad, dt1) == dt1sToLoad.end()) {
148 auto filePath = "/data/global/tiles/" + dt1;
149 std::ranges::transform(filePath, filePath.begin(), [](const auto c) { return std::tolower(c); });
150 dt1sToLoad.push_back("/data/global/tiles/" + dt1);
151 }
152 }
153
154 Abyss::DataTypes::DS1 ds1("/data/global/tiles/" + altName);
155
156 // Add all the DS1 files to the DT1s
157 for (auto &file : ds1.files) {
158 std::ranges::replace(file, '\\', '/');
159 if (file.starts_with("/d2/")) // Because why not?
160 file = file.substr(3);
161 std::ranges::transform(file, file.begin(), [](const auto c) { return std::tolower(c); });
162 if (std::ranges::find(dt1sToLoad, file) == dt1sToLoad.end()) {
163 absl::StrReplaceAll({{".tg1", ".dt1"}}, &file); // Replace tg1 with dt1 because blizzard
164 absl::StrReplaceAll({{".ds1", ".dt1"}}, &file); // Why yes, this is also a thing....
165 // remove /d2 if it starts with it
166 if (file.starts_with("/d2/"))
167 file = file.substr(3);
168
169 dt1sToLoad.push_back(file);
170 }
171 }
172
173 const auto dsSubIndex = std::ranges::find(_mapAltSelections, altName) - _mapAltSelections.begin();
174 // Load all dt1s into a vector
175 std::vector<Abyss::DataTypes::DT1> dt1s{};
176 dt1s.reserve(dt1sToLoad.size());
177 for (const auto &dt1 : dt1sToLoad)
178 dt1s.emplace_back(dt1, palette);
179
180 const auto mapWidth = ds1.width;
181 const auto mapHeight = ds1.height;
182
183 _mapEngine = std::make_unique<Abyss::MapEngine::MapEngine>(mapWidth, mapHeight, std::move(dt1s), std::vector{std::move(ds1)});
184 _mapEngine->stampDs1(0, 0, 0);
185
186 // Center the map
187 const auto mapCenterX = mapWidth / 2;

Callers

nothing calls this directly

Calls 4

debugFunction · 0.85
stampDs1Method · 0.80
setCameraPositionMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected