Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859#include "Assets.h"#include <SDL3/SDL.h>#include <SDL3/SDL_filesystem.h>#include <cstdio>#include <filesystem>
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"; } }
// check if exists, else we're probably running inside appimage if (!std::filesystem::exists(basePath)) { const char* appdir = std::getenv("APPDIR"); if (appdir != nullptr) { basePath = std::string(appdir) + "/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;}