Skip to content

Commit

Permalink
fixed json serializer float check
Browse files Browse the repository at this point in the history
  • Loading branch information
Foifur committed Feb 18, 2025
1 parent 2eda93d commit 4421c29
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/Vanguard/VanguardHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ void FormatJsonData(VanguardSettings& settings, std::ostringstream& json_string)
// iterate through all settings
for (int i = 0; i < settings.array.size(); i++)
{
std::string value(settings.to_string(settings.array[i].second));

// flycast stores bools as "yes" and "no" so we need this hack
if (std::holds_alternative<bool>(settings.array[i].second))
{
Expand All @@ -264,8 +266,12 @@ void FormatJsonData(VanguardSettings& settings, std::ostringstream& json_string)
<< "\": " << settings.to_string(settings.array[i].second);
}

json_string << " \"" << settings.array[i].first
<< "\": " << value;

// if the value is a whole number float, add ".0" so the parser understands
if (std::holds_alternative<float>(settings.array[i].second))
if (std::holds_alternative<float>(settings.array[i].second) &&
value.length() == 1)
{
json_string << ".0";
}
Expand Down

0 comments on commit 4421c29

Please sign in to comment.