Skip to content

Commit

Permalink
Merge pull request #61 from MuhXd/main
Browse files Browse the repository at this point in the history
Fix double sounds with xdbot and stuff
  • Loading branch information
BeatACVR authored Dec 28, 2024
2 parents 944738f + 5e50be8 commit d6799bb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
},
"links": {
"community": "https://discord.gg/tu98bsGA32",
"source": "https://github.com/BeatACVR/geode-clicksound"
"source": "https://github.com/BeatACVR/geode-clicksound",
"homepage": "https://clicksounds.github.io/clicks/"
},
"tags": [
"universal",
Expand Down
5 changes: 4 additions & 1 deletion src/jsonReader/Json.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <Geode/Geode.hpp>
#include <filesystem>
#include "Getsettingsinfo.hpp"
#include <fstream>
#include <sstream>
#include <vector>
Expand All @@ -24,7 +25,7 @@ class JsonReader {
std::map<std::string, CategoryData> usefulData;
bool hassomedata = false;

void loadData() {
void loadData( std::function<void()> h) {
std::thread([=] {
auto configDir = Mod::get()->getConfigDir();
auto clicksPath = configDir / "Clicks" / "clicks-main";
Expand All @@ -33,9 +34,11 @@ class JsonReader {
loadCategoryData(clicksPath / "Useful", usefulData);
hassomedata = true;
log::debug("Loaded Category!");
if (h) { h(); };
} else {
//log::error("Unable to load Categories");
}

}).detach();
}

Expand Down
33 changes: 18 additions & 15 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ bool integrityCheck(PlayerObject* object, PlayerButton Pressed) {
}
Level = Pl->m_level;
};
if (object->m_isSecondPlayer && Level->m_twoPlayerMode || !object->m_isSecondPlayer) {
GJBaseGameLayer* LayerCheck = GJBaseGameLayer::get();
if (!LayerCheck) {
return false;
}
if (Level->m_twoPlayerMode && LayerCheck->m_player2 == object || LayerCheck->m_player1 == object) {
return true;
} else {
return false;
Expand Down Expand Up @@ -170,45 +174,44 @@ class $modify(PlayerObject) {

class $modify(MenuLayer) {
void SendRequestAPI() {
std::thread([=] {
web::WebRequest().get("https://github.com/clicksounds/clicks/archive/refs/heads/main.zip").listen([=](auto res) {
if (res->string().unwrapOr("failed") == "failed") {
indexzip.Failed = true;
indexzip.Finished = true;
return;
}
auto indexzipPtr = std::make_shared<decltype(indexzip)>(indexzip);
std::thread([=] {
if (res->into(Mod::get()->getConfigDir() / "Clicks.zip")) {
auto unzip = file::Unzip::create(Mod::get()->getConfigDir() / "Clicks.zip");
if (!unzip) {
indexzip.Failed = true;
indexzip.Finished = true;
indexzipPtr->Failed = true;
indexzipPtr->Finished = true;
return;
}
std::filesystem::remove_all(Mod::get()->getConfigDir() / "Clicks");
(void) unzip.unwrap().extractAllTo(Mod::get()->getConfigDir() / "Clicks");
indexzip.Finished = true;
ClickJson->loadData();
onsettingsUpdate();
indexzipPtr->Finished = true;
ClickJson->loadData([=](){
onsettingsUpdate();
});
}
}).detach();
},
[](auto prog){},
[=]() {
indexzip.Failed = true;
indexzip.Finished = true;
});
}).detach();
}
bool init() {
if (!indexzip.StartedDownloading) {
indexzip.StartedDownloading = true;
geode::Loader::get()->queueInMainThread([=] {
std::thread([=] {
// on boot set Sound Caches
ClickJson->loadData();
// on boot set Sound Caches
ClickJson->loadData([=](){
onsettingsUpdate();
this->SendRequestAPI();
}).detach();
});
});
this->SendRequestAPI();
}
return MenuLayer::init();
}
Expand Down

0 comments on commit d6799bb

Please sign in to comment.