diff --git a/ParsecSoda/MetadataCache.cpp b/ParsecSoda/MetadataCache.cpp index 152df002..92047c7d 100644 --- a/ParsecSoda/MetadataCache.cpp +++ b/ParsecSoda/MetadataCache.cpp @@ -504,7 +504,7 @@ bool MetadataCache::saveThumbnails(vector thumbnails) const string MetadataCache::getSfxPath() { - return getUserDir() + "sfx\\_sfx.json"; + return getUserDir() + "sfx\\"; } const string MetadataCache::getUserDir() diff --git a/ParsecSoda/SFXList.cpp b/ParsecSoda/SFXList.cpp index b3d077cd..4e090c1e 100644 --- a/ParsecSoda/SFXList.cpp +++ b/ParsecSoda/SFXList.cpp @@ -1,18 +1,24 @@ #include "SFXList.h" -void SFXList::init(const char* jsonPath) +void SFXList::init(const char* sfxDirPath) { _lastUseTimestamp = steady_clock::now(); _lastCooldown = 0; stringstream tags; _sfxList.clear(); - - if (MTY_FileExists(jsonPath)) + _sfxDirPath = sfxDirPath; + string jsonPath = string(sfxDirPath) + "_sfx.json"; + + // PlaySound only recognizes paths in format "/" + // but most Windows functions expect format "\\". + Stringer::replacePattern(jsonPath, "\\", "/"); + + if (MTY_FileExists(jsonPath.c_str())) { try { - MTY_JSON* json = MTY_JSONReadFile(jsonPath); + MTY_JSON* json = MTY_JSONReadFile(jsonPath.c_str()); const MTY_JSON* sfxArray = MTY_JSONObjGetItem(json, "sfx"); uint32_t size = MTY_JSONGetLength(sfxArray); @@ -40,7 +46,7 @@ void SFXList::init(const char* jsonPath) } } - sort(_sfxList.begin(), _sfxList.end(), [](const SFX a, const SFX b) { + std::sort(_sfxList.begin(), _sfxList.end(), [](const SFX a, const SFX b) { return a.tag.compare(b.tag) < 0; }); @@ -84,7 +90,7 @@ SFXList::SFXPlayResult SFXList::play(const string tag) return SFXPlayResult::COOLDOWN; } - string path = string("./sfx/custom/") + string((*it).path); + string path = _sfxDirPath + string((*it).path); wstring wide (path.begin(), path.end()); PlaySound(wide.c_str(), NULL, SND_FILENAME | SND_NODEFAULT | SND_ASYNC); _lastCooldown = (*it).cooldown; diff --git a/ParsecSoda/SFXList.h b/ParsecSoda/SFXList.h index 0b985189..a27d3e84 100644 --- a/ParsecSoda/SFXList.h +++ b/ParsecSoda/SFXList.h @@ -33,7 +33,7 @@ class SFXList uint32_t cooldown = 0; }; - void init(const char* jsonPath); + void init(const char* sfxDirPath); int64_t getRemainingCooldown(); SFXPlayResult play(const string tag); const string loadedTags(); @@ -45,4 +45,6 @@ class SFXList vector _sfxList; string _loadedTags; int64_t _lastCooldown; + + string _sfxDirPath{"./"}; }; \ No newline at end of file