Skip to content

Commit 0215cea

Browse files
committed
feat: daily chests
1 parent f01d9e3 commit 0215cea

File tree

13 files changed

+388
-263
lines changed

13 files changed

+388
-263
lines changed

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,28 @@ EventData data = {
9292
GDUtils::Events::RateEvent::emit(data);
9393
```
9494
95-
### Example Code (Listening for notification events from GDUtils)
95+
### Example Code (Listening for notification events from GDUtils, and checking if the server is online)
9696
```cpp
9797
$execute {
98-
new EventListener<EventFilter<GDUtils::Events::OnRate>>(+[](GDUtils::Events::OnRate* e) {
99-
log::info("A rate event with the title {}", e->getTitle()); // A rate event with the title Small Daily Chest available!
98+
// Listening for *any* rate event.
99+
GDUtils::Events::OnRate().listen([](EventData const& e) {
100+
log::info("A rate event with the title {}", e.getTitle()); // A rate event with the title Small Daily Chest available!
101+
return ListenerResult::Propagate;
102+
});
103+
104+
// Listening for rate events, filtering only by daily
105+
GDUtils::Events::OnRate(EventType::Daily).listen([](EventData const& e) {
106+
log::info("A daily event with the level name {}", e.getLevelName()); // A daily event with the level name Cycles
107+
return ListenerResult::Propagate;
108+
});
109+
110+
// Checking when we connected.
111+
GDUtils::Events::OnServerConnect().listen([](bool const& connected) {
112+
Loader::get()->queueInMainThread([connected]() {
113+
if (connected) {
114+
log::info("I am connected to the notifiaction servers!");
115+
}
116+
});
100117
return ListenerResult::Propagate;
101118
});
102119
}
@@ -105,7 +122,7 @@ View the `test` directory if you want to view an example mod using the API.
105122

106123
## Libraries Used
107124
- [Geode](https://github.com/geode-sdk/geode)
108-
- [socket.io-client-cpp](https://github.com/socketio/socket.io-client-cpp)
125+
- [rabbitmq-c](https://github.com/alanxz/rabbitmq-c)
109126
- [pl_mpeg](https://github.com/phoboslab/pl_mpeg)
110127

111128
## Credits

include/RateEvent.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ namespace GDUtils::Events {
5858
struct OnRate final : geode::GlobalEvent<OnRate, bool(EventData&), bool(EventData&), EventType> {
5959
using GlobalEvent::GlobalEvent;
6060
};
61+
struct OnServerConnect final : geode::ThreadSafeEvent<OnServerConnect, bool(bool)> {
62+
using ThreadSafeEvent::ThreadSafeEvent;
63+
};
6164
}

src/defs/misc.hpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,6 @@
44
#include "geode.hpp"
55

66
namespace misc {
7-
// theres no including Geode Util class funcs so, https://github.com/geode-sdk/DevTools
8-
/*static
9-
static CCObject* findNode(std::string name) {
10-
auto scene = CCDirector::sharedDirector()->getRunningScene();
11-
auto sceneChildren = scene->getChildren();
12-
for (unsigned int i = 0; i < scene->getChildrenCount(); i++) {
13-
auto node = sceneChildren->objectAtIndex(i);
14-
if (node != nullptr) {
15-
std::string layerName = misc::getNodeName(node);
16-
std::cout << layerName << std::endl;
17-
if (layerName == name) {
18-
return node;
19-
}
20-
}
21-
}
22-
return nullptr;
23-
}*/
247
template<typename T>
258
std::vector<std::vector<T>> paginate(const std::vector<T>& arr, size_t size) {
269
std::vector<std::vector<T>> paginated;

src/hooks/MenuLayer.cpp

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/hooks/SecretLayer2.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class $modify(SecretVault, SecretLayer2) {
3434
if (!vault_text) {
3535
vault_text = this->getChildByType<CCLabelBMFont*>(1);
3636
}
37-
log::debug("what are you {}", input);
3837
if (!strcmp(input.c_str(), "bad apple")) {
3938
if (m_fields->m_currentState != States::BadApple) {
4039
m_fields->m_currentState = States::BadApple;

src/main.cpp

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// Ported with help by Firee
33
// Mod made by Jouca & Firee
44

5+
#include "modules/events/DailyChest.hpp"
56
$execute {
6-
// Loader::get()->queueInMainThread([]{
7-
// CCScheduler::get()->scheduleSelector(schedule_selector(EventHandler::check), EventHandler::create(), 1.0F, false);
8-
// //CCScheduler::get()->scheduleUpdateForTarget(EventHandler::create(), Priority::Last, false);
9-
// });
107
// listenForSettingChanges("activate-background", [](bool value) {
118
// log::info("Activate Background changed to {}", value);
129
// toggleSpriteHooks(value);
@@ -24,6 +21,60 @@
2421

2522
bool g_socket_server_ran = false;
2623

24+
$execute {
25+
if (Mod::get()->getSettingValue<bool>("server-notification")) {
26+
GDUtils::Events::OnServerConnect().listen([](bool const& connected) {
27+
Loader::get()->queueInMainThread([connected]() {
28+
if (connected) {
29+
Notification::create("Connected to Rate Server!", NotificationIcon::Success)->show();
30+
}
31+
});
32+
return ListenerResult::Stop;
33+
}).leak();
34+
}
35+
auto [tx, rx] = arc::mpsc::channel<std::string>(1024); // i mean why would robtop ever rate that many levels
36+
auto [etx, erx] = arc::mpsc::channel<EventData>(1024); // ditto
37+
auto [ctx, crx] = arc::mpsc::channel<bool>(64);
38+
AMQT::setTx(std::move(tx));
39+
EventsPush::setTx(std::move(ctx));
40+
//auto interval = arc::interval(Duration::fromMillis(250));
41+
async::runtime().spawn([rx = std::move(rx), crx = std::move(crx), erx = std::move(erx)]() mutable -> arc::Future<> {
42+
bool running = true;
43+
while (running) {
44+
co_await arc::select(
45+
arc::selectee(rx.recv(), [&](auto req) {
46+
if (req) {
47+
std::string msg = std::move(req).unwrap();
48+
Loader::get()->queueInMainThread([m = std::move(msg)]() mutable {
49+
auto director = CCDirector::sharedDirector();
50+
if (!director) return;
51+
auto scene = CCDirector::sharedDirector()->getRunningScene();
52+
if (!scene) return;
53+
if (scene->getChildrenCount() == 0) return;
54+
if (EventsPush::canSendEvent(scene)) {
55+
EventsPush::pushRateLevel(scene, m);
56+
}
57+
});
58+
}
59+
}),
60+
arc::selectee(crx.recv(), [&](auto req) {
61+
if (req) {
62+
bool b = std::move(req).unwrap();
63+
log::debug("Cancelled (Code = {})", b);
64+
} else {
65+
log::debug("Cancelled (Code = Unknown)");
66+
}
67+
Loader::get()->queueInMainThread([]() {
68+
if (auto scene = CCScene::get()) {
69+
EventsPush::eventCompletedCallback(scene);
70+
}
71+
});
72+
})
73+
);
74+
}
75+
});
76+
}
77+
2778
$on_game(Loaded) {
2879
if (g_socket_server_ran) return;
2980
if (geode::Mod::get()->getSettingValue<bool>("socketServer")) {
@@ -61,46 +112,6 @@ bool g_socket_server_ran = false;
61112
Notification::create("Couldn't connect to server, invalid Client ID", NotificationIcon::Error)->show();
62113
return;
63114
}
64-
auto [tx, rx] = arc::mpsc::channel<std::string>(1024); // i mean why would robtop ever rate that many levels
65-
auto [etx, erx] = arc::mpsc::channel<EventData>(1024); // ditto
66-
auto [ctx, crx] = arc::mpsc::channel<bool>(64);
67-
AMQT::setTx(std::move(tx));
68-
EventsPush::setTx(std::move(ctx));
69-
async::runtime().spawn([rx = std::move(rx), crx = std::move(crx), erx = std::move(erx)]() mutable -> arc::Future<> {
70-
bool running = true;
71-
while (running) {
72-
co_await arc::select(
73-
arc::selectee(rx.recv(), [&](auto req) {
74-
if (req) {
75-
std::string msg = std::move(req).unwrap();
76-
Loader::get()->queueInMainThread([m = std::move(msg)]() mutable {
77-
auto director = CCDirector::sharedDirector();
78-
if (!director) return;
79-
auto scene = CCDirector::sharedDirector()->getRunningScene();
80-
if (!scene) return;
81-
if (scene->getChildrenCount() == 0) return;
82-
if (EventsPush::canSendEvent(scene)) {
83-
EventsPush::pushRateLevel(scene, m);
84-
}
85-
});
86-
}
87-
}),
88-
arc::selectee(crx.recv(), [&](auto req) {
89-
if (req) {
90-
bool b = std::move(req).unwrap();
91-
log::debug("Cancelled (Code = {})", b);
92-
} else {
93-
log::debug("Cancelled (Code = Unknown)");
94-
}
95-
Loader::get()->queueInMainThread([]() {
96-
if (auto scene = CCScene::get()) {
97-
EventsPush::eventCompletedCallback(scene);
98-
}
99-
});
100-
})
101-
);
102-
}
103-
});
104115
std::thread hThread([]() mutable {
105116
AMQT handler(Mod::get()->getSavedValue<std::string>("clientId"));
106117
handler.connect();

0 commit comments

Comments
 (0)