23std::string extensionOf(
const std::string &
path) {
24 const auto pos =
path.find_last_of(
'.');
25 if (
pos == std::string::npos)
return {};
26 std::string ext =
path.substr(
pos);
27 for (
char &
c : ext)
c = static_cast<char>(
std::tolower(static_cast<unsigned char>(
c)));
31bool isSoundPath(
const std::string &
path) {
32 const std::string ext = extensionOf(
path);
33 return ext ==
".wav" || ext ==
".ogg" || ext ==
".mp3" || ext ==
".flac" || ext ==
".mod" ||
34 ext ==
".xm" || ext ==
".s3m" || ext ==
".it";
39 const char *reloadKind()
const override {
return "sound"; }
41 bool handlesPath(
const std::string &normPath)
const override {
54 if (!isSoundPath(
path))
return nullptr;
56 auto *fs = filesystem::Filesystem::create();
57 if (!fs)
return nullptr;
58 std::unique_ptr<filesystem::FileData> fd(fs->read(
path));
59 if (!fd || fd->getData() ==
nullptr || fd->getSize() == 0)
62 auto *mod = Sound::create();
64 return mod->newSoundData(fd.get());
70 static SoundLoader loader;
EVENGINE_API_FOUNDATION public API.
static std::string pathOfKey(const std::string &key)
The path part of a cache key (everything before the first '?').
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or gen...
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
EVENGINE_API_FOUNDATION public API.