MCPcopy Create free account
hub / github.com/OfficialCodeNoodles/2D-Minecraft / loadModels

Function loadModels

2D Minecraft v 1.0/src/entity/Model.cpp:194–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192 }
193
194 void loadModels() {
195 for (int modelIndex = 0; modelIndex < Model::End; modelIndex++) {
196 const std::string filename = render::assetDirectory
197 + "data/entity/model/" + Model::modelStrings[modelIndex]
198 + ".list";
199 const PairVector& pairs = loadPairedFile(
200 filename, '=', "EndProperties");
201
202 Model& model = Model::models[modelIndex];
203 Model::Segment* segment = nullptr;
204 int segmentIndex;
205
206 for (auto& [attribute, value] : pairs) {
207 if (attribute == "NewSegment") {
208 segmentIndex = std::stoi(value);
209 segment = &model.segments[segmentIndex];
210 }
211 else if (segment != nullptr) {
212 if (attribute == "textureIndex")
213 segment->textureIndex = std::stoi(value);
214 else if (attribute == "xpos")
215 segment->position.x = std::stof(value);
216 else if (attribute == "ypos")
217 segment->position.y = std::stof(value);
218 else if (attribute == "xOrigin")
219 segment->origin.x = std::stof(value);
220 else if (attribute == "yOrigin")
221 segment->origin.y = std::stof(value);
222 else if (attribute == "rotation")
223 segment->rotation = std::stof(value);
224 else if (attribute == "redValue")
225 segment->color.r = std::stoi(value);
226 else if (attribute == "greenValue")
227 segment->color.g = std::stoi(value);
228 else if (attribute == "blueValue")
229 segment->color.b = std::stoi(value);
230 }
231 }
232 }
233 }
234}

Callers 1

createFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected