Skip to content

Commit

Permalink
hopefully fix chest issues
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMario211 committed Jun 9, 2024
1 parent d23e702 commit b1bf09e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
1 change: 0 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# v1.3.0
- Port to Geometry Dash 2.206

- Increased leaderboards top to INFINITE
- Daily chest notifications
- Epic Gauntlets redesign
Expand Down
28 changes: 0 additions & 28 deletions src/Notifications/DailyChest.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include "../includes.h"
#include "DailyChest.h"
#include "EventsPush.h"
#include <Geode/modify/MenuLayer.hpp>


bool is_dailychest_ready = false;

void DailyChest::getRewards(unsigned int type) {
GameLevelManager* glm = GameLevelManager::sharedState();
Expand Down Expand Up @@ -56,26 +51,3 @@ void DailyChest::rewardsStatusFinished(int p0) {
void DailyChest::rewardsStatusFailed() {
log::error("Failed to get rewards");
};

// Daily chests notifications
void dailyChestThread() {
while (true) {
auto dailyChest = new DailyChest();
dailyChest->getRewards(0);

std::this_thread::sleep_for(std::chrono::minutes(20));
}
}
class $modify(MenuLayer) {
bool init() {
if (!MenuLayer::init()) return false;

if (!is_dailychest_ready) {
std::thread hThread(dailyChestThread);
hThread.detach();
is_dailychest_ready = true;
}

return true;
}
};
1 change: 1 addition & 0 deletions src/Notifications/DailyChest.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <Geode/Geode.hpp>
using namespace geode::prelude;

class DailyChest : public CCNode, public GJRewardDelegate {
public:
Expand Down
2 changes: 2 additions & 0 deletions src/Settings/CustomSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "CustomSettings.hpp"
#include <Geode/loader/Dirs.hpp>
#include <filesystem>
#include "../Notifications/EventsPush.h"
#include "../includes.h"
int cycleTypes = -1;

SettingNode* SettingSectionValue::createNode(float width) {
Expand Down
5 changes: 2 additions & 3 deletions src/Settings/CustomSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include <Geode/loader/SettingNode.hpp>
#include "CreditsBetaMenu.h"
#include "CreditsMenu.h"
#include "../Notifications/EventsPush.h"
#include "../includes.h"
#include <Geode/ui/TextInput.hpp>
using namespace geode::prelude;

/*
Expand Down Expand Up @@ -518,7 +517,7 @@ class SettingAppNode : public SettingNode {
)->show();
}
public:
InputNode* defaultApp_input = InputNode::create(180.0F, "Application", "bigFont.fnt", "", 1);
TextInput* defaultApp_input = TextInput::create(180.0F, "Application", "bigFont.fnt");
void commit() override {
static_cast<SettingAppValue*>(m_value)->setApp(m_currentApp);
this->dispatchCommitted();
Expand Down
40 changes: 38 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Geode/modify/CreatorLayer.hpp>
#include <Geode/modify/CCSprite.hpp>
#include <Geode/modify/CCScale9Sprite.hpp>
#include <Geode/modify/MenuLayer.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/utils/web.hpp>
#include "includes.h"
Expand All @@ -18,9 +19,9 @@
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <random>
#include <string>
#include <sstream>
#include "Notifications/DailyChest.h"
#include <codecvt>

static std::unordered_map<std::string, web::WebTask> RUNNING_REQUESTS {};
Expand All @@ -36,6 +37,7 @@ bool event_fired = false;


std::queue<sio::message::ptr> dataQueue;
std::queue<int> chestQueue;

sio::message::ptr event_data = nullptr;
std::mutex lock;
Expand Down Expand Up @@ -78,7 +80,7 @@ namespace ConnectionHandler {
bool setSocket(sio::socket::ptr sock) {
current_socket = sock;
log::info("listening for events");
current_socket->emit("geode-" + Mod::get()->getVersion().toString());
current_socket->emit(fmt::format("geode-{}", Mod::get()->getVersion()));
current_socket->on("rate", sio::socket::event_listener_aux([&](std::string const& user, sio::message::ptr const& data, bool isAck, sio::message::list &ack_resp) {
log::info("call rate event");
event_fired = true;
Expand All @@ -91,6 +93,14 @@ bool setSocket(sio::socket::ptr sock) {
return true;
}

// Daily chests notifications
void dailyChestThread() {
while (true) {
chestQueue.push(1);
std::this_thread::sleep_for(std::chrono::minutes(20));
}
}

void start_socket_func() {
while (true) {
log::info("Starting socket...");
Expand Down Expand Up @@ -130,6 +140,15 @@ void processEvent(CCScene* self) {
}
}

void processChestEvent(CCScene* self) {
if (!chestQueue.empty()) {
auto data = chestQueue.front();
chestQueue.pop();
auto dailyChest = new DailyChest();
dailyChest->getRewards(0);
}
}

class $modify(CCScheduler) { // used to be GameManager
void update(float dt) {
CCScheduler::update(dt);
Expand All @@ -148,6 +167,7 @@ class $modify(CCScheduler) { // used to be GameManager
if (currentLayer != layerName) {
currentLayer = layerName;
EventsPush::stopNow(scene);
processChestEvent(scene);
bool everywhereElse = Mod::get()->getSettingValue<bool>("everywhereElse");
if ((layerName != "LevelEditorLayer" && layerName != "PlayLayer") && !everywhereElse) return;
if ((layerName != "LevelEditorLayer" && layerName != "PlayLayer") && everywhereElse) {
Expand Down Expand Up @@ -377,6 +397,22 @@ class $modify(CCScale9Sprite) {
}
};

bool is_dailychest_ready = false;

class $modify(MenuLayer) {
bool init() {
if (!MenuLayer::init()) return false;

if (!is_dailychest_ready) {
std::thread hThread(dailyChestThread);
hThread.detach();
is_dailychest_ready = true;
}

return true;
}
};

// When the socket connection is made
$on_mod(Loaded) {
log::info("GDUtils Mod Loaded");
Expand Down

0 comments on commit b1bf09e

Please sign in to comment.