Skip to content

Commit

Permalink
Added daily/weekly button notifications & removed the one for daily c…
Browse files Browse the repository at this point in the history
…hests
  • Loading branch information
Jouca committed Jul 15, 2024
1 parent ef1820b commit c26d221
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/Notifications/DailyChest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "DailyChest.h"
#include "EventsPush.h"

static GJRewardItem* time1 = nullptr;
static GJRewardItem* time2 = nullptr;

void DailyChest::getRewards(unsigned int type) {
GameLevelManager* glm = GameLevelManager::sharedState();
glm->m_GJRewardDelegate = this;
Expand All @@ -16,8 +19,8 @@ void DailyChest::rewardsStatusFinished(int p0) {
// Get the rewards
int time1_value = 0x1;
int time2_value = 0x2;
GJRewardItem* time1 = typeinfo_cast<GJRewardItem*>(gsm->m_rewardItems->objectForKey(time1_value));
GJRewardItem* time2 = typeinfo_cast<GJRewardItem*>(gsm->m_rewardItems->objectForKey(time2_value));
time1 = typeinfo_cast<GJRewardItem*>(gsm->m_rewardItems->objectForKey(time1_value));
time2 = typeinfo_cast<GJRewardItem*>(gsm->m_rewardItems->objectForKey(time2_value));

sio::message::ptr msg = sio::object_message::create();
msg->get_map()["sprite"] = sio::string_message::create("GJ_square04.png");
Expand Down
13 changes: 9 additions & 4 deletions src/Notifications/EventsPush.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "EventsPush.h"
#include "../Settings/CustomSettings.hpp"
#include "DailyChest.h"
#include "Geode/utils/general.hpp"
#include <queue>
#include <Geode/utils/web.hpp>
Expand Down Expand Up @@ -295,10 +296,11 @@ void EventsPush::onClickBtn(CCObject* ret) {
if (layer == nullptr) return;
auto events_layer = reinterpret_cast<EventsPush*>(scene->getChildByTag(1932));
if (events_layer == nullptr) return;
if (events_layer->level->m_levelID == 0) return;
std::string layerName = typeid(*layer).name() + 6;
if (layerName != "PlayLayer" && layerName != "PauseLayer" && layerName != "LevelEditorLayer") { // redirect to level
if (eventType == EventType::Rate) {
if (events_layer->level->m_levelID == 0) return;

std::string const& url = "http://www.boomlings.com/database/getGJLevels21.php";
#ifndef GEODE_IS_MACOS
int level_id = events_layer->level->m_levelID.value();
Expand Down Expand Up @@ -351,12 +353,15 @@ void EventsPush::onClickBtn(CCObject* ret) {
)
);
} else if (eventType == EventType::Daily) {
//DailyLevelPage::create(eventType == EventType::Weekly)->show();
DailyLevelPage::create(GJTimedLevelType::Daily)->show();
return;
} else if (eventType == EventType::Weekly) {
DailyLevelPage::create(GJTimedLevelType::Weekly)->show();
return;
} else if (eventType == EventType::smallChest || eventType == EventType::largeChest) {
} /*else if (eventType == EventType::smallChest) {
RewardsPage::create()->show();
return;
}
}*/
} else { // copy to clipboard
#ifndef GEODE_IS_MACOS
clipboard::write(std::to_string(events_layer->level->m_levelID));
Expand Down
19 changes: 11 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ bool setSocket(sio::socket::ptr sock) {
}

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

void start_socket_func() {
while (true) {
Expand All @@ -112,8 +112,8 @@ void start_socket_func() {
sock.set_open_listener(&ConnectionHandler::onSuccess);
sock.set_close_listener(&ConnectionHandler::onClose);
sock.set_fail_listener(&ConnectionHandler::onFail);
sock.connect("http://gdutils.clarifygdps.com:13573");
//sock.connect("http://gdutilstest.clarifygdps.com:46276");
//sock.connect("http://gdutils.clarifygdps.com:13573");
sock.connect("http://gdutilstest.clarifygdps.com:46276");
if (!connect_finish) {
cond.wait(unique_lock);
}
Expand Down Expand Up @@ -169,10 +169,10 @@ 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) {
processChestEvent(scene);
processEvent(scene);
}
}
Expand Down Expand Up @@ -406,11 +406,11 @@ class $modify(MenuLayer) {
bool init() {
if (!MenuLayer::init()) return false;

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

return true;
}
Expand All @@ -419,6 +419,9 @@ class $modify(MenuLayer) {
// When the socket connection is made
$on_mod(Loaded) {
log::info("GDUtils Mod Loaded");

chestQueue.push(1);

bool startSocketServer = Mod::get()->getSettingValue<bool>("socketServer");
if (startSocketServer) {
current_socket = sio::socket::ptr();
Expand Down

0 comments on commit c26d221

Please sign in to comment.