MCPcopy Create free account
hub / github.com/ddnet/ddnet / LoadSkin

Method LoadSkin

src/game/client/components/skins7.cpp:189–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187}
188
189bool CSkins7::LoadSkin(const char *pName, int DirType)
190{
191 char aFilename[IO_MAX_PATH_LENGTH];
192 str_format(aFilename, sizeof(aFilename), SKINS_DIR "/%s", pName);
193 void *pFileData;
194 unsigned JsonFileSize;
195 if(!Storage()->ReadFile(aFilename, DirType, &pFileData, &JsonFileSize))
196 {
197 log_error("skins7", "Failed to read skin json file '%s'", aFilename);
198 return false;
199 }
200
201 CSkin Skin;
202 str_copy(Skin.m_aName, pName, 1 + str_length(pName) - str_length(".json"));
203 const bool SpecialSkin = IsSpecialSkin(Skin.m_aName);
204 Skin.m_Flags = 0;
205 if(SpecialSkin)
206 {
207 Skin.m_Flags |= SKINFLAG_SPECIAL;
208 }
209 if(DirType != IStorage::TYPE_SAVE)
210 {
211 Skin.m_Flags |= SKINFLAG_STANDARD;
212 }
213
214 json_settings JsonSettings{};
215 char aError[256];
216 json_value *pJsonData = json_parse_ex(&JsonSettings, static_cast<const json_char *>(pFileData), JsonFileSize, aError);
217 free(pFileData);
218 if(pJsonData == nullptr)
219 {
220 log_error("skins7", "Failed to parse skin json file '%s': %s", aFilename, aError);
221 return false;
222 }
223
224 const json_value &Start = (*pJsonData)["skin"];
225 if(Start.type != json_object)
226 {
227 log_error("skins7", "Failed to parse skin json file '%s': root must be an object", aFilename);
228 json_value_free(pJsonData);
229 return false;
230 }
231
232 for(int PartIndex = 0; PartIndex < protocol7::NUM_SKINPARTS; ++PartIndex)
233 {
234 Skin.m_aUseCustomColors[PartIndex] = 0;
235 Skin.m_aPartColors[PartIndex] = (PartIndex == protocol7::SKINPART_MARKING ? 0xFF000000u : 0u) + 0x00FF80u;
236
237 const json_value &Part = Start[(const char *)ms_apSkinPartNames[PartIndex]];
238 if(Part.type == json_none)
239 {
240 Skin.m_apParts[PartIndex] = FindDefaultSkinPart(PartIndex);
241 continue;
242 }
243 if(Part.type != json_object)
244 {
245 log_error("skins7", "Failed to parse skin json file '%s': attribute '%s' must specify an object", aFilename, ms_apSkinPartNames[PartIndex]);
246 json_value_free(pJsonData);

Callers 1

SkinScanMethod · 0.80

Calls 11

str_formatFunction · 0.85
StorageFunction · 0.85
str_lengthFunction · 0.85
json_parse_exFunction · 0.85
json_value_freeFunction · 0.85
str_compFunction · 0.85
ReadFileMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
str_copyFunction · 0.50
ConfigFunction · 0.50

Tested by

no test coverage detected