#include "client/AssetsManager.h"

#include "blitz/misc/Format.h"
#include "blitz/misc/Log.h"
#include <SDL2/SDL_rwops.h>

namespace blitz {
namespace utils {
namespace AssetsManager {

DataBuffer GetAsset(const std::string& fileName) {
	utils::LOGD(utils::Format("Opening file %s...", fileName.c_str()));

	SDL_RWops* io = SDL_RWFromFile(fileName.c_str(), "rb");

	assert(io != nullptr);

	std::int64_t bufferSize = SDL_RWsize(io);

	assert(bufferSize != -1);

	DataBuffer result;
	result.Resize(bufferSize);

	SDL_RWread(io, result.data(), bufferSize, 1);
	SDL_RWclose(io);
	return result;
}

}  // namespace AssetsManager
}  // namespace utils
}  // namespace blitz
