<commit_before>// Copyright 2014-present [<NAME> <@rcsole, <EMAIL>>]

#include "./TextureManager.h"

TextureManager::TextureManager(SDL_Renderer* ren) {
    g_Renderer = ren;
}

void TextureManager::render() {
    for (unsigned int i = 0; i != texturesVector.size(); i++) {
        printf("%s\n", json_dumps(texturesVector[i].info, JSON_INDENT(2)));
    }
}

void TextureManager::loadTexture(char const *key,
                                 char const *pathJSON,
                                 char const *pathIMG) {
    json_t *tmpJSON = NULL;
    SDL_Texture *tmpTex = NULL;
    Texture t;

    tmpJSON = loadJSON(pathJSON);
    tmpTex = loadImage(pathIMG);

    t.key = key;
    t.info = tmpJSON;
    t.texture = tmpTex;

    texturesVector.push_back(t); // TODO: This just does not feel right, AT ALL.
}

SDL_Texture* TextureManager::loadImage(char const *path) {
    SDL_Texture* tmpTexture = NULL;
    SDL_Surface* tmpSurface = NULL;

    tmpSurface = IMG_Load(path);

    if (tmpSurface == NULL) {
        printf("Error loading image %s: %s\n",
                path, IMG_GetError());

    } else {
        tmpTexture = SDL_CreateTextureFromSurface(g_Renderer, tmpSurface);

        if (tmpTexture == NULL) {
            printf("Error creating texture from %s: %s\n",
                    path, IMG_GetError());
        }

        SDL_FreeSurface(tmpSurface);

        // tmpSurface = NULL;
    }

    return tmpTexture;
}

json_t* TextureManager::loadJSON(char const *path) {
    FILE *p_inputFile = NULL;

    json_t *jsonFile = NULL;
    json_t *root = NULL;
    json_error_t *error = NULL;

    p_inputFile = fopen(path, "r");

    jsonFile = json_loadf(p_inputFile, 0, error);
    root = json_object_get(jsonFile, "frames");

    fclose(p_inputFile);

    return root;
}<commit_msg>error control for the texture manager<commit_after>// Copyright 2014-present [<NAME> <@rcsole, <EMAIL>>]

#include "./TextureManager.h"

TextureManager::TextureManager(SDL_Renderer* ren) {
    g_Renderer = ren;
}

void TextureManager::render() {
    for (unsigned int i = 0; i != texturesVector.size(); i++) {
    // TODO: this loop does not feel right either
        if (!texturesVector[i].info == NULL) {
            printf("%s\n", json_dumps(texturesVector[i].info, JSON_INDENT(2)));
        } else {
            printf("No JSON for texture: %s\n", texturesVector[i].key);
        }
    }
}

void TextureManager::loadTexture(char const *key,
                                 char const *pathJSON,
                                 char const *pathIMG) {
    json_t *tmpJSON = NULL;
    SDL_Texture *tmpTex = NULL;
    Texture t;

    tmpJSON = loadJSON(pathJSON);
    tmpTex = loadImage(pathIMG);

    t.key = key;
    t.info = tmpJSON;
    t.texture = tmpTex;

    texturesVector.push_back(t); // TODO: This just does not feel right, AT ALL.
}

SDL_Texture* TextureManager::loadImage(char const *path) {
    SDL_Texture* tmpTexture = NULL;
    SDL_Surface* tmpSurface = NULL;

    tmpSurface = IMG_Load(path);

    if (tmpSurface == NULL) {
        printf("Error loading image %s: %s\n",
                path, IMG_GetError());

    } else {
        tmpTexture = SDL_CreateTextureFromSurface(g_Renderer, tmpSurface);

        if (tmpTexture == NULL) {
            printf("Error creating texture from %s: %s\n",
                    path, IMG_GetError());
        }

        SDL_FreeSurface(tmpSurface);

        // tmpSurface = NULL;
    }

    return tmpTexture;
}

json_t* TextureManager::loadJSON(char const *path) {
    json_t *root = NULL;

    if (FILE* p_inputFile = fopen(path, "r")) {
        printf("File exists");
        json_t *jsonFile;
        json_error_t *error;

        jsonFile = json_loadf(p_inputFile, 0, error);
        root = json_object_get(jsonFile, "frames");

        fclose(p_inputFile);
    } else {
        printf("Error loading json %s\n", path);

        return NULL;
    }

    return root;
}
{'fraction_non_alphanumeric': 0.12595614482406936, 'fraction_numerical': 0.0035696073431922487, 'mean_word_length': 2.453345070422535, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4099629', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1228, 'n_words': 298}