mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-11 13:41:50 +00:00
Merge pull request #471 from Laupetin/fix/show-json-errors
fix: show asset that failed when not being able to parse jsons
This commit is contained in:
@ -23,21 +23,21 @@ namespace
|
|||||||
|
|
||||||
bool Load(LeaderboardDef& leaderboardDef) const
|
bool Load(LeaderboardDef& leaderboardDef) const
|
||||||
{
|
{
|
||||||
const auto jRoot = json::parse(m_stream);
|
|
||||||
std::string type;
|
|
||||||
unsigned version;
|
|
||||||
|
|
||||||
jRoot.at("_type").get_to(type);
|
|
||||||
jRoot.at("_version").get_to(version);
|
|
||||||
|
|
||||||
if (type != "leaderboard" || version != 1u)
|
|
||||||
{
|
|
||||||
std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const auto jRoot = json::parse(m_stream);
|
||||||
|
std::string type;
|
||||||
|
unsigned version;
|
||||||
|
|
||||||
|
jRoot.at("_type").get_to(type);
|
||||||
|
jRoot.at("_version").get_to(version);
|
||||||
|
|
||||||
|
if (type != "leaderboard" || version != 1u)
|
||||||
|
{
|
||||||
|
std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
||||||
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
||||||
}
|
}
|
||||||
|
@ -23,21 +23,21 @@ namespace
|
|||||||
|
|
||||||
bool Load(LeaderboardDef& leaderboardDef) const
|
bool Load(LeaderboardDef& leaderboardDef) const
|
||||||
{
|
{
|
||||||
const auto jRoot = json::parse(m_stream);
|
|
||||||
std::string type;
|
|
||||||
unsigned version;
|
|
||||||
|
|
||||||
jRoot.at("_type").get_to(type);
|
|
||||||
jRoot.at("_version").get_to(version);
|
|
||||||
|
|
||||||
if (type != "leaderboard" || version != 1u)
|
|
||||||
{
|
|
||||||
std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const auto jRoot = json::parse(m_stream);
|
||||||
|
std::string type;
|
||||||
|
unsigned version;
|
||||||
|
|
||||||
|
jRoot.at("_type").get_to(type);
|
||||||
|
jRoot.at("_version").get_to(version);
|
||||||
|
|
||||||
|
if (type != "leaderboard" || version != 1u)
|
||||||
|
{
|
||||||
|
std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
||||||
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
||||||
}
|
}
|
||||||
|
@ -26,21 +26,21 @@ namespace
|
|||||||
|
|
||||||
bool Load(WeaponAttachment& attachment) const
|
bool Load(WeaponAttachment& attachment) const
|
||||||
{
|
{
|
||||||
const auto jRoot = json::parse(m_stream);
|
|
||||||
std::string type;
|
|
||||||
unsigned version;
|
|
||||||
|
|
||||||
jRoot.at("_type").get_to(type);
|
|
||||||
jRoot.at("_version").get_to(version);
|
|
||||||
|
|
||||||
if (type != "attachment" || version != 1u)
|
|
||||||
{
|
|
||||||
std::cerr << "Tried to load attachment \"" << attachment.szInternalName << "\" but did not find expected type attachment of version 1\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const auto jRoot = json::parse(m_stream);
|
||||||
|
std::string type;
|
||||||
|
unsigned version;
|
||||||
|
|
||||||
|
jRoot.at("_type").get_to(type);
|
||||||
|
jRoot.at("_version").get_to(version);
|
||||||
|
|
||||||
|
if (type != "attachment" || version != 1u)
|
||||||
|
{
|
||||||
|
std::cerr << "Tried to load attachment \"" << attachment.szInternalName << "\" but did not find expected type attachment of version 1\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto jAttachment = jRoot.get<JsonWeaponAttachment>();
|
const auto jAttachment = jRoot.get<JsonWeaponAttachment>();
|
||||||
return CreateWeaponAttachmentFromJson(jAttachment, attachment);
|
return CreateWeaponAttachmentFromJson(jAttachment, attachment);
|
||||||
}
|
}
|
||||||
|
@ -23,21 +23,21 @@ namespace
|
|||||||
|
|
||||||
bool Load(LeaderboardDef& leaderboardDef) const
|
bool Load(LeaderboardDef& leaderboardDef) const
|
||||||
{
|
{
|
||||||
const auto jRoot = json::parse(m_stream);
|
|
||||||
std::string type;
|
|
||||||
unsigned version;
|
|
||||||
|
|
||||||
jRoot.at("_type").get_to(type);
|
|
||||||
jRoot.at("_version").get_to(version);
|
|
||||||
|
|
||||||
if (type != "leaderboard" || version != 1u)
|
|
||||||
{
|
|
||||||
std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const auto jRoot = json::parse(m_stream);
|
||||||
|
std::string type;
|
||||||
|
unsigned version;
|
||||||
|
|
||||||
|
jRoot.at("_type").get_to(type);
|
||||||
|
jRoot.at("_version").get_to(version);
|
||||||
|
|
||||||
|
if (type != "leaderboard" || version != 1u)
|
||||||
|
{
|
||||||
|
std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
||||||
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
||||||
}
|
}
|
||||||
|
@ -26,21 +26,21 @@ namespace
|
|||||||
|
|
||||||
bool Load(WeaponCamo& weaponCamo) const
|
bool Load(WeaponCamo& weaponCamo) const
|
||||||
{
|
{
|
||||||
const auto jRoot = json::parse(m_stream);
|
|
||||||
std::string type;
|
|
||||||
unsigned version;
|
|
||||||
|
|
||||||
jRoot.at("_type").get_to(type);
|
|
||||||
jRoot.at("_version").get_to(version);
|
|
||||||
|
|
||||||
if (type != "weaponCamo" || version != 1u)
|
|
||||||
{
|
|
||||||
std::cerr << std::format("Tried to load weapon camo \"{}\" but did not find expected type weaponCamo of version {}\n", weaponCamo.name, 1u);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const auto jRoot = json::parse(m_stream);
|
||||||
|
std::string type;
|
||||||
|
unsigned version;
|
||||||
|
|
||||||
|
jRoot.at("_type").get_to(type);
|
||||||
|
jRoot.at("_version").get_to(version);
|
||||||
|
|
||||||
|
if (type != "weaponCamo" || version != 1u)
|
||||||
|
{
|
||||||
|
std::cerr << std::format("Tried to load weapon camo \"{}\" but did not find expected type weaponCamo of version {}\n", weaponCamo.name, 1u);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto jWeaponCamo = jRoot.get<JsonWeaponCamo>();
|
const auto jWeaponCamo = jRoot.get<JsonWeaponCamo>();
|
||||||
return CreateWeaponCamoFromJson(jWeaponCamo, weaponCamo);
|
return CreateWeaponCamoFromJson(jWeaponCamo, weaponCamo);
|
||||||
}
|
}
|
||||||
|
@ -61,31 +61,31 @@ namespace
|
|||||||
|
|
||||||
bool Load(Material& material) const
|
bool Load(Material& material) const
|
||||||
{
|
{
|
||||||
const auto jRoot = json::parse(m_stream);
|
|
||||||
std::string type;
|
|
||||||
unsigned version;
|
|
||||||
|
|
||||||
jRoot.at("_type").get_to(type);
|
|
||||||
jRoot.at("_version").get_to(version);
|
|
||||||
|
|
||||||
if (type != "material" || version != 1u)
|
|
||||||
{
|
|
||||||
std::cerr << std::format("Tried to load material \"{}\" but did not find expected type material of version 1\n", material.info.name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef FEATURE_T6 // T6 did not have this check in version 1, so to stay backwards compatible, let it stay that way
|
|
||||||
std::string game;
|
|
||||||
jRoot.at("_game").get_to(game);
|
|
||||||
if (game != GAME_LOWER)
|
|
||||||
{
|
|
||||||
std::cerr << std::format("Tried to load material \"{}\" but \"_game\" did not find expected type value {}\n", material.info.name, GAME_LOWER);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const auto jRoot = json::parse(m_stream);
|
||||||
|
std::string type;
|
||||||
|
unsigned version;
|
||||||
|
|
||||||
|
jRoot.at("_type").get_to(type);
|
||||||
|
jRoot.at("_version").get_to(version);
|
||||||
|
|
||||||
|
if (type != "material" || version != 1u)
|
||||||
|
{
|
||||||
|
std::cerr << std::format("Tried to load material \"{}\" but did not find expected type material of version 1\n", material.info.name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef FEATURE_T6 // T6 did not have this check in version 1, so to stay backwards compatible, let it stay that way
|
||||||
|
std::string game;
|
||||||
|
jRoot.at("_game").get_to(game);
|
||||||
|
if (game != GAME_LOWER)
|
||||||
|
{
|
||||||
|
std::cerr << std::format("Tried to load material \"{}\" but \"_game\" did not find expected type value {}\n", material.info.name, GAME_LOWER);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const auto jMaterial = jRoot.get<JsonMaterial>();
|
const auto jMaterial = jRoot.get<JsonMaterial>();
|
||||||
return CreateMaterialFromJson(jMaterial, material);
|
return CreateMaterialFromJson(jMaterial, material);
|
||||||
}
|
}
|
||||||
|
@ -81,21 +81,21 @@ namespace
|
|||||||
private:
|
private:
|
||||||
bool LoadFromFile(std::istream& jsonStream, XModel& xmodel, AssetCreationContext& context, AssetRegistration<AssetXModel>& registration)
|
bool LoadFromFile(std::istream& jsonStream, XModel& xmodel, AssetCreationContext& context, AssetRegistration<AssetXModel>& registration)
|
||||||
{
|
{
|
||||||
const auto jRoot = nlohmann::json::parse(jsonStream);
|
|
||||||
std::string type;
|
|
||||||
unsigned version;
|
|
||||||
|
|
||||||
jRoot.at("_type").get_to(type);
|
|
||||||
jRoot.at("_version").get_to(version);
|
|
||||||
|
|
||||||
if (type != "xmodel" || version != 1u)
|
|
||||||
{
|
|
||||||
std::cerr << std::format("Tried to load xmodel \"{}\" but did not find expected type material of version 1\n", xmodel.name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const auto jRoot = nlohmann::json::parse(jsonStream);
|
||||||
|
std::string type;
|
||||||
|
unsigned version;
|
||||||
|
|
||||||
|
jRoot.at("_type").get_to(type);
|
||||||
|
jRoot.at("_version").get_to(version);
|
||||||
|
|
||||||
|
if (type != "xmodel" || version != 1u)
|
||||||
|
{
|
||||||
|
std::cerr << std::format("Tried to load xmodel \"{}\" but did not find expected type material of version 1\n", xmodel.name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto jXModel = jRoot.get<JsonXModel>();
|
const auto jXModel = jRoot.get<JsonXModel>();
|
||||||
return CreateXModelFromJson(jXModel, xmodel, context, registration);
|
return CreateXModelFromJson(jXModel, xmodel, context, registration);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user