mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Merge pull request #226 from Laupetin/fix/t6-material-json-errors
fix: not properly handling errors when loading json
This commit is contained in:
commit
e2464410b2
@ -18,7 +18,7 @@ namespace nlohmann
|
||||
template<class T> void optional_from_json(const nlohmann::json& j, const char* name, std::optional<T>& value)
|
||||
{
|
||||
const auto it = j.find(name);
|
||||
if (it != j.end())
|
||||
if (it != j.end() && !it->is_null())
|
||||
value = it->get<T>();
|
||||
else
|
||||
value = std::nullopt;
|
||||
|
@ -36,9 +36,18 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
||||
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
||||
}
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse json of leaderboard: {}\n", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool CreateColumnDefFromJson(const JsonColumnDef& jColumn, LbColumnDef& lbColumnDef, LeaderboardDef& leaderboardDef) const
|
||||
|
@ -36,9 +36,18 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
||||
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
||||
}
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse json of leaderboard: {}\n", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
static bool CreateTrackTypeFlagsFromJson(const JsonLeaderboardDef& jLeaderboardDef, int& trackTypeFlags)
|
||||
|
@ -44,9 +44,18 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto jAttachment = jRoot.get<JsonWeaponAttachment>();
|
||||
return CreateWeaponAttachmentFromJson(jAttachment, attachment);
|
||||
}
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse json of attachment: {}\n", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
static void PrintError(const WeaponAttachment& attachment, const std::string& message)
|
||||
|
@ -37,9 +37,18 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
|
||||
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
|
||||
}
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse json of leaderboard: {}\n", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
static bool CreateTrackTypeFlagsFromJson(const JsonLeaderboardDef& jLeaderboardDef, int& trackTypeFlags)
|
||||
|
@ -39,9 +39,18 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto jMaterial = jRoot.get<JsonMaterial>();
|
||||
return CreateMaterialFromJson(jMaterial, material);
|
||||
}
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse json of material: {}\n", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
static void PrintError(const Material& material, const std::string& message)
|
||||
|
@ -39,9 +39,18 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto jWeaponCamo = jRoot.get<JsonWeaponCamo>();
|
||||
return CreateWeaponCamoFromJson(jWeaponCamo, weaponCamo);
|
||||
}
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse json of weapon camo: {}\n", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
static void PrintError(const WeaponCamo& weaponCamo, const std::string& message)
|
||||
|
@ -40,9 +40,18 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto jXModel = jRoot.get<JsonXModel>();
|
||||
return CreateXModelFromJson(jXModel, xmodel);
|
||||
}
|
||||
catch (const json::exception& e)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse json of xmodel: {}\n", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
static void PrintError(const XModel& xmodel, const std::string& message)
|
||||
|
3
thirdparty/json.lua
vendored
3
thirdparty/json.lua
vendored
@ -2,6 +2,9 @@ json = {}
|
||||
|
||||
function json:include(includes)
|
||||
if includes:handle(self:name()) then
|
||||
defines {
|
||||
"JSON_DIAGNOSTICS=1"
|
||||
}
|
||||
includedirs {
|
||||
path.join(ThirdPartyFolder(), "json", "single_include")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user