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 {
47 if (!isSoundPath(path))
return nullptr;
49 auto *fs = filesystem::Filesystem::create();
50 if (!fs)
return nullptr;
51 std::unique_ptr<filesystem::FileData> fd(fs->read(path));
52 if (!fd || fd->getData() ==
nullptr || fd->getSize() == 0)
53 throw eve::Exception(
"Could not read sound file: %s", path.c_str());
55 auto *mod = Sound::create();
57 return mod->newSoundData(fd.get());
63 static SoundLoader loader;
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...