<commit_before>#include <halley/file_formats/text_file.h>
#include "resources/standard_resources.h"
#include "resources/resources.h"
#include "graphics/sprite/animation.h"
#include "graphics/sprite/sprite_sheet.h"
#include "halley/core/graphics/shader.h"
#include "halley/core/graphics/texture.h"
#include "halley/core/graphics/material/material_definition.h"
#include "graphics/text/font.h"
#include "halley/file_formats/config_file.h"
#include "halley/audio/audio_clip.h"
#include "halley/file_formats/binary_file.h"

using namespace Halley;

void StandardResources::initialize(Resources& resources)
{
	resources.init<Animation>();
	resources.init<SpriteSheet>();
	resources.init<SpriteResource>();
	resources.init<Texture>();
	resources.init<MaterialDefinition>();
	resources.init<ShaderFile>();
	resources.init<BinaryFile>();
	resources.init<TextFile>();
	resources.init<Font>();
	resources.init<ConfigFile>();
	resources.init<AudioClip>();

	resources.of<SpriteResource>().setResourceLoader([&] (const String& name, ResourceLoadPriority) -> std::shared_ptr<Resource>
	{
		String spriteName = ":img:" + name;

		auto& ss = resources.of<SpriteSheet>();
		for (auto& sheetName: ss.enumerate()) {
			auto sheet = ss.get(sheetName);
			if (sheet->hasSprite(spriteName)) {
				return std::make_shared<SpriteResource>(sheet, sheet->getIndex(spriteName));
			}
		}

		// Failed to find it
		return {};
	});
}
<commit_msg>Potentially better way to load sprite resources.<commit_after>#include <halley/file_formats/text_file.h>
#include "resources/standard_resources.h"
#include "resources/resources.h"
#include "graphics/sprite/animation.h"
#include "graphics/sprite/sprite_sheet.h"
#include "halley/core/graphics/shader.h"
#include "halley/core/graphics/texture.h"
#include "halley/core/graphics/material/material_definition.h"
#include "graphics/text/font.h"
#include "halley/file_formats/config_file.h"
#include "halley/audio/audio_clip.h"
#include "halley/file_formats/binary_file.h"

using namespace Halley;

void StandardResources::initialize(Resources& resources)
{
	resources.init<Animation>();
	resources.init<SpriteSheet>();
	resources.init<SpriteResource>();
	resources.init<Texture>();
	resources.init<MaterialDefinition>();
	resources.init<ShaderFile>();
	resources.init<BinaryFile>();
	resources.init<TextFile>();
	resources.init<Font>();
	resources.init<ConfigFile>();
	resources.init<AudioClip>();

	resources.of<SpriteResource>().setResourceLoader([&] (const String& name, ResourceLoadPriority) -> std::shared_ptr<Resource>
	{
		auto& sprites = resources.of<SpriteResource>();

		std::shared_ptr<Resource> result;

		auto& ss = resources.of<SpriteSheet>();
		for (auto& sheetName: ss.enumerate()) {
			auto sheet = ss.get(sheetName);
			for (auto& spriteName: sheet->getSpriteNames()) {
				if (spriteName.startsWith(":img:")) {
					auto res = std::make_shared<SpriteResource>(sheet, sheet->getIndex(spriteName));
					sprites.setResource(0, spriteName, res);

					if (spriteName == ":img:" + name) {
						result = res;
					}
				}
			}
		}

		return result;
	});
}

{'fraction_non_alphanumeric': 0.16023353876094712, 'fraction_numerical': 0.0003243593902043464, 'mean_word_length': 6.073394495412844, 'pattern_counts': {'":': 3, '<': 37, '<?xml version=': 0, '>': 43, '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': '6715232', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1003, 'n_words': 160}