Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#include "Assets.h"#include <SDL3/SDL.h>#include <SDL3/SDL_filesystem.h>
std::string Assets::basePath;
void Assets::Init() {#ifdef __ANDROID__ basePath = "";#else basePath = SDL_GetBasePath(); if (!basePath.empty()) { // Remove trailing slash if (basePath.back() == '/' || basePath.back() == '\\') { basePath.pop_back(); } // Go up one level and into resources size_t lastSlash = basePath.find_last_of("/\\"); if (lastSlash != std::string::npos) { basePath = basePath.substr(0, lastSlash); basePath += "/resources"; } }#endif}
std::string Assets::Path(const std::string& name) { if (basePath.empty()) { return name; } return basePath + "/" + name;}
SDL_EnumerationResult EnumerateCallback(void* userdata, const char* _dirname, const char* fname) { (void)_dirname; auto* list = static_cast<std::list<std::string>*>(userdata); list->push_back(fname); return SDL_ENUM_CONTINUE;}
std::list<std::string> Assets::Enumerate(const std::string& dir) { std::list<std::string> files;
std::string fullPath = Path(dir); SDL_EnumerateDirectory(fullPath.c_str(), EnumerateCallback, &files);
return files;}