<commit_before>#include "gamelib/core/res/SpriteResource.hpp"
#include "gamelib/core/res/ResourceManager.hpp"
#include "gamelib/utils/json.hpp"

namespace gamelib
{
    void registerSpriteLoader(ResourceManager& resmgr)
    {
        resmgr.registerFileType("spr", spriteLoader);
    }

    BaseResourceHandle spriteLoader(const std::string& fname, ResourceManager* resmgr)
    {
        Json::Value node;
        if (!loadJsonFromFile(fname, node))
            return nullptr;

        if (!node.isMember("texture"))
        {
            LOG_ERROR("No texture specified for sprite: ", fname);
            return nullptr;
        }

        auto sprite = SpriteResource::create();
        sprite->tex = resmgr->get(node["texture"].asString()).as<TextureResource>();

        math::Vec2f tmp;

        if (loadFromJson(node["framepos"], tmp))
            sprite->rect.pos = tmp;

        if (loadFromJson(node["framesize"], tmp))
            sprite->rect.size = tmp;

        if (loadFromJson(node["origin"], tmp))
            sprite->origin = tmp.asPoint();

        sprite->ani.length = node.get("length", 1).asInt();
        sprite->ani.speed = node.get("speed", 0).asFloat();
        sprite->ani.setIndex(node.get("offset", 0).asInt());

        return sprite.as<BaseResource>();
    }
}<commit_msg>Use texture size as sprite frame size if not given<commit_after>#include "gamelib/core/res/SpriteResource.hpp"
#include "gamelib/core/res/ResourceManager.hpp"
#include "gamelib/utils/json.hpp"
#include "gamelib/utils/conversions.hpp"

namespace gamelib
{
    void registerSpriteLoader(ResourceManager& resmgr)
    {
        resmgr.registerFileType("spr", spriteLoader);
    }

    BaseResourceHandle spriteLoader(const std::string& fname, ResourceManager* resmgr)
    {
        Json::Value node;
        if (!loadJsonFromFile(fname, node))
            return nullptr;

        if (!node.isMember("texture"))
        {
            LOG_ERROR("No texture specified for sprite: ", fname);
            return nullptr;
        }

        auto sprite = SpriteResource::create();
        sprite->tex = resmgr->get(node["texture"].asString()).as<TextureResource>();

        math::Vec2f pos, size = convert(sprite->tex->getSize());
        loadFromJson(node["framepos"], pos);
        loadFromJson(node["framesize"], size);

        sprite->rect.pos = pos;
        sprite->rect.size = size;

        loadFromJson(node["origin"], sprite->origin);

        sprite->ani.length = node.get("length", 1).asInt();
        sprite->ani.speed = node.get("speed", 0).asFloat();
        sprite->ani.setIndex(node.get("offset", 0).asInt());

        return sprite.as<BaseResource>();
    }
}
{'fraction_non_alphanumeric': 0.1497005988023952, 'fraction_numerical': 0.0029940119760479044, 'mean_word_length': 2.829512893982808, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, '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': '5886582', 'n_tokens_mistral': 829, 'n_tokens_neox': 795, 'n_words': 144}