<commit_before>#include "Block_Data.h"

#include "../../Util/json.h"

#include <string>
#include <fstream>
#include <sstream>
#include <iostream>

namespace
{
    std::string getFileContents(const std::string& filePath)
    {
        std::ifstream inFile(filePath);
        std::stringstream stream;

        stream << inFile.rdbuf();   //Gets the file contents into a string stream
        return stream.str();        //Return the string from the string stream
    }
}

namespace Block
{
    Data::Data(const std::string& fileName)
    {
        auto source = getFileContents("Data/Blocks/" + fileName + ".json");
        nlohmann::json jsonFile = nlohmann::json::parse(source.c_str());

        m_holder.name       = jsonFile["Name"]      .get<std::string>();
        m_holder.isOpaque   = jsonFile["Opaque"]    .get<bool>();
        m_holder.isObstacle = jsonFile["Obstacle"]  .get<bool>();

        m_holder.blockID    = (Block::ID) jsonFile["ID"]    .get<int32_t>();
        m_holder.meshType   = (Mesh_Type) jsonFile["Mesh"]  .get<int32_t>();

        {
            auto uv = jsonFile["Texture Top"].get<std::vector<float>>();
            m_holder.topTextureCoords.x = uv[0];
            m_holder.topTextureCoords.y = uv[1];
        }

        {
            auto uv = jsonFile["Texture Side"].get<std::vector<float>>();
            m_holder.sideTextureCoords.x = uv[0];
            m_holder.sideTextureCoords.y = uv[1];
        }

        {
            auto uv = jsonFile["Texture Bottom"].get<std::vector<float>>();
            m_holder.bottomTextureCoords.x = uv[0];
            m_holder.bottomTextureCoords.y = uv[1];
        }
    }
}
<commit_msg>Improve JSON loading a bit<commit_after>#include "Block_Data.h"

#include "../../Util/json.h"

#include <string>
#include <fstream>
#include <sstream>
#include <iostream>

namespace
{
    std::string getFileContents(const std::string& filePath)
    {
        std::ifstream inFile(filePath);
        std::stringstream stream;

        stream << inFile.rdbuf();   //Gets the file contents into a string stream
        return stream.str();        //Return the string from the string stream
    }
}

namespace Block
{
    Data::Data(const std::string& fileName)
    {
        auto source = getFileContents("Data/Blocks/" + fileName + ".json");
        nlohmann::json jsonFile = nlohmann::json::parse(source.c_str());

        m_holder.name       = jsonFile["Name"]      .get<std::string>();
        m_holder.isOpaque   = jsonFile["Opaque"]    .get<bool>();
        m_holder.isObstacle = jsonFile["Obstacle"]  .get<bool>();

        m_holder.blockID    = (Block::ID) jsonFile["ID"]    .get<int32_t>();
        m_holder.meshType   = (Mesh_Type) jsonFile["Mesh"]  .get<int32_t>();

        auto getTexCoords = [&](const std::string& loc, Vector2& vect)
        {
            auto uv = jsonFile["Texture " + loc].get<std::vector<float>>();
            vect.x = uv[0];
            vect.y = uv[1];
        };

        getTexCoords("Top",     m_holder.topTextureCoords);
        getTexCoords("Side",    m_holder.sideTextureCoords);
        getTexCoords("Bottom",  m_holder.bottomTextureCoords);
    }
}

{'fraction_non_alphanumeric': 0.15369958717053034, 'fraction_numerical': 0.005398539218799619, 'mean_word_length': 2.543307086614173, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5648680', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1012, 'n_words': 189}