Skip to content

Commit c5001f3

Browse files
committed
mqtt rewrite
1 parent 9761324 commit c5001f3

File tree

12 files changed

+435
-307
lines changed

12 files changed

+435
-307
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
push:
66
branches:
7-
- main
7+
- '**'
88
jobs:
99
build:
1010
strategy:
@@ -33,6 +33,10 @@ jobs:
3333
- uses: actions/checkout@v4
3434
with:
3535
submodules: 'recursive'
36+
37+
- name: Update Submodule
38+
run: |
39+
git submodule update --init --recursive
3640
3741
- name: Build the mod
3842
uses: geode-sdk/build-geode-mod@main

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "libs/socket.io-client-cpp"]
2-
path = libs/socket.io-client-cpp
3-
url = https://github.com/socketio/socket.io-client-cpp
41
[submodule "libs/pl_mpeg"]
52
path = libs/pl_mpeg
63
url = https://github.com/phoboslab/pl_mpeg

CMakeLists.txt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(CMAKE_CXX_STANDARD 20)
33
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
55
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
6+
include(cmake/CPM.cmake)
67

78
if(NOT DEFINED GEODE_TARGET_PLATFORM)
89
set(GEODE_TARGET_PLATFORM "Win64")
@@ -41,12 +42,25 @@ file(GLOB SOURCES
4142
# Set up the mod binary
4243
add_library(${PROJECT_NAME} SHARED ${SOURCES})
4344

45+
set(PAHO_BUILD_SHARED OFF CACHE INTERNAL "")
46+
set(PAHO_BUILD_STATIC ON CACHE INTERNAL "")
47+
set(PAHO_ENABLE_TESTING OFF CACHE INTERNAL "")
48+
set(PAHO_BUILD_TESTS OFF CACHE INTERNAL "")
49+
set(PAHO_WITH_MQTT_C ON CACHE INTERNAL "")
50+
51+
FetchContent_Declare(
52+
paho-mqttpp3-static
53+
GIT_REPOSITORY https://github.com/eclipse-paho/paho.mqtt.cpp.git
54+
GIT_TAG 71f78aafc3246c05d624098b8438129f5e0a70e5
55+
)
56+
57+
FetchContent_MakeAvailable(paho-mqttpp3-static)
58+
4459
target_include_directories(${PROJECT_NAME} PRIVATE
45-
libs/socket.io-client-cpp
4660
libs/filesystem
4761
libs/pl_mpeg/
4862
libs/glew/
49-
libs/socket.io-client-cpp/src
63+
${paho-mqttpp3-static_SOURCE_DIR}/src
5064
)
5165

5266
if (NOT DEFINED ENV{GEODE_SDK})
@@ -57,12 +71,10 @@ endif()
5771

5872
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
5973

60-
add_subdirectory(libs/socket.io-client-cpp EXCLUDE_FROM_ALL)
61-
add_dependencies(${PROJECT_NAME} sioclient)
6274
if (APPLE) # AND NOT (${GEODE_TARGET_PLATFORM} STREQUAL "iOS" OR IOS)
63-
target_link_libraries(${PROJECT_NAME} sioclient "-framework OpenGL")
75+
target_link_libraries(${PROJECT_NAME} paho-mqttpp3-static "-framework OpenGL")
6476
else()
65-
target_link_libraries(${PROJECT_NAME} sioclient)
77+
target_link_libraries(${PROJECT_NAME} paho-mqttpp3-static)
6678
endif()
6779
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND WIN32)
6880
message("compiling on linux!!")

cmake/CPM.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: MIT
2+
#
3+
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
4+
5+
set(CPM_DOWNLOAD_VERSION 0.38.7)
6+
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5")
7+
8+
if(CPM_SOURCE_CACHE)
9+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
10+
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
11+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
12+
else()
13+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
14+
endif()
15+
16+
# Expand relative path. This is important if the provided path contains a tilde (~)
17+
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
18+
19+
file(DOWNLOAD
20+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
21+
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
22+
)
23+
24+
include(${CPM_DOWNLOAD_LOCATION})

include/Types.hpp

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
32
#include <Geode/Geode.hpp>
43
enum EventType {
54
Rate,
@@ -13,17 +12,101 @@ enum EventType {
1312
};
1413

1514
struct EventData {
16-
bool demon;
17-
uint8_t starsum;
18-
uint8_t stars;
19-
uint8_t rate;
20-
EventType type;
15+
bool demon = false;
16+
uint16_t starsum = 0;
17+
uint16_t stars = 0;
18+
uint16_t rate = 0;
19+
EventType type = EventType::Rate;
2120
std::string title;
22-
std::string sprite;
21+
std::string sprite = "GJ_square01.png";
2322
std::string level_name;
2423
std::string level_creator;
25-
uint8_t coins;
26-
bool verified_coins;
27-
bool platformer;
24+
uint8_t coins = 0;
25+
bool verified_coins = false;
26+
bool platformer = false;
2827
int level_id = -1;
28+
std::string levels_list;
29+
int maxToCompleteList = 0;
30+
};
31+
32+
template<>
33+
struct matjson::Serialize<EventData> {
34+
static geode::Result<EventData> fromJson(matjson::Value const& value) {
35+
EventData data;
36+
if (value.contains("demon")) {
37+
if (value["demon"].asInt().isErr()) {
38+
GEODE_UNWRAP_INTO(data.demon, value["demon"].asBool());
39+
} else {
40+
GEODE_UNWRAP_INTO(auto demon, value["demon"].asInt());
41+
data.demon = demon == 1;
42+
}
43+
}
44+
GEODE_UNWRAP_INTO(data.starsum, value["starsum"].asUInt());
45+
GEODE_UNWRAP_INTO(data.stars, value["stars"].asUInt());
46+
GEODE_UNWRAP_INTO(data.rate, value["rate"].asUInt());
47+
GEODE_UNWRAP_INTO(auto type, value["type"].asUInt());
48+
// yeahhhh im getting linker errors ok
49+
switch (type) {
50+
default:
51+
data.type = EventType::NA;
52+
break;
53+
case 0: // Rate
54+
data.type = EventType::Rate;
55+
break;
56+
case 1: // Daily
57+
data.type = EventType::Daily;
58+
break;
59+
case 2: // Weekly
60+
data.type = EventType::Weekly;
61+
break;
62+
case 3: // Small chest
63+
data.type = EventType::smallChest;
64+
break;
65+
case 4: // Large chest
66+
data.type = EventType::largeChest;
67+
break;
68+
case 5: // List
69+
data.type = EventType::List;
70+
break;
71+
case 6: // Event
72+
data.type = EventType::Event;
73+
break;
74+
}
75+
GEODE_UNWRAP_INTO(data.title, value["title"].asString());
76+
GEODE_UNWRAP_INTO(data.sprite, value["sprite"].asString());
77+
GEODE_UNWRAP_INTO(data.level_name, value["level_name"].asString());
78+
GEODE_UNWRAP_INTO(data.level_creator, value["level_creator"].asString());
79+
GEODE_UNWRAP_INTO(data.rate, value["rate"].asUInt());
80+
if (value.contains("verified_coins")) {
81+
if (value["verified_coins"].asInt().isErr()) {
82+
GEODE_UNWRAP_INTO(data.verified_coins, value["verified_coins"].asBool());
83+
} else {
84+
GEODE_UNWRAP_INTO(auto verified_coins, value["verified_coins"].asInt());
85+
data.verified_coins = verified_coins == 1;
86+
}
87+
}
88+
if (value.contains("platformer")) {
89+
if (value["platformer"].asInt().isErr()) {
90+
GEODE_UNWRAP_INTO(data.platformer, value["platformer"].asBool());
91+
} else {
92+
GEODE_UNWRAP_INTO(auto platformer, value["platformer"].asInt());
93+
data.platformer = platformer == 1;
94+
}
95+
}
96+
if (value.contains("level_id")) {
97+
if (value["level_id"].asString().isErr()) {
98+
GEODE_UNWRAP_INTO(data.level_id, value["level_id"].asInt());
99+
} else {
100+
GEODE_UNWRAP_INTO(auto level_id, value["level_id"].asString());
101+
data.level_id = geode::utils::numFromString<int>(level_id).unwrapOrDefault();
102+
}
103+
}
104+
if (value.contains("levels_list")) {
105+
GEODE_UNWRAP_INTO(data.levels_list, value["levels_list"].asString());
106+
}
107+
if (value.contains("maxToCompleteList")) {
108+
GEODE_UNWRAP_INTO(data.maxToCompleteList, value["maxToCompleteList"].asInt());
109+
}
110+
return geode::Ok(data);
111+
}
29112
};

libs/socket.io-client-cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Notifications/DailyChest.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,23 @@ void DailyChest::rewardsStatusFinished(int p0) {
2424
time1 = typeinfo_cast<GJRewardItem*>(gsm->m_rewardItems->objectForKey(time1_value));
2525
time2 = typeinfo_cast<GJRewardItem*>(gsm->m_rewardItems->objectForKey(time2_value));
2626

27-
sio::message::ptr msg = sio::object_message::create();
28-
msg->get_map()["sprite"] = sio::string_message::create("GJ_square04.png");
29-
msg->get_map()["level_name"] = sio::string_message::create(" ");
30-
msg->get_map()["level_creator"] = sio::string_message::create(" ");
31-
msg->get_map()["demon"] = sio::int_message::create(0);
32-
msg->get_map()["starsum"] = sio::int_message::create(0);
33-
msg->get_map()["stars"] = sio::int_message::create(0);
34-
msg->get_map()["rate"] = sio::int_message::create(0);
35-
msg->get_map()["coins"] = sio::int_message::create(0);
36-
msg->get_map()["verified_coins"] = sio::int_message::create(0);
37-
msg->get_map()["platformer"] = sio::int_message::create(0);
38-
27+
EventData data;
28+
data.sprite = "GJ_square04.png";
29+
data.level_name = " ";
30+
data.level_creator = " ";
3931
if (time1 != nullptr) {
4032
if (time1->m_timeRemaining == 0) {
41-
msg->get_map()["type"] = sio::int_message::create(3);
42-
msg->get_map()["title"] = sio::string_message::create("Small Daily Chest available!");
43-
EventsPush::pushRateLevel(CCDirector::sharedDirector()->getRunningScene(), msg);
33+
data.type = EventType::smallChest;
34+
data.title = "Small Daily Chest available!";
35+
EventsPush::pushRateLevel(CCDirector::sharedDirector()->getRunningScene(), data);
4436
}
4537
}
4638

4739
if (time2 != nullptr) {
4840
if (time2->m_timeRemaining == 0) {
49-
msg->get_map()["type"] = sio::int_message::create(4);
50-
msg->get_map()["title"] = sio::string_message::create("Big Daily Chest available!");
51-
EventsPush::pushRateLevel(CCDirector::sharedDirector()->getRunningScene(), msg);
41+
data.type = EventType::largeChest;
42+
data.title = "Big Daily Chest available!";
43+
EventsPush::pushRateLevel(CCDirector::sharedDirector()->getRunningScene(), data);
5244
}
5345
}
5446
};

0 commit comments

Comments
 (0)