Skip to content

Commit

Permalink
Backup SFX Hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
FlavioFS committed Feb 26, 2023
1 parent 78fb4a9 commit 121b4ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ParsecSoda/MetadataCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ bool MetadataCache::saveThumbnails(vector<Thumbnail> thumbnails)

const string MetadataCache::getSfxPath()
{
return getUserDir() + "sfx\\_sfx.json";
return getUserDir() + "sfx\\";
}

const string MetadataCache::getUserDir()
Expand Down
18 changes: 12 additions & 6 deletions ParsecSoda/SFXList.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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;
});

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion ParsecSoda/SFXList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -45,4 +45,6 @@ class SFXList
vector<SFX> _sfxList;
string _loadedTags;
int64_t _lastCooldown;

string _sfxDirPath{"./"};
};

0 comments on commit 121b4ae

Please sign in to comment.