Skip to content

Commit

Permalink
bake pro features into BE on compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Jul 10, 2024
1 parent 3926eac commit 3db14e8
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 20 deletions.
25 changes: 20 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(BetterEdit VERSION 1.0.0)

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/pro/)
message(STATUS "Including Pro features")
set(BE_PRO_FOUND TRUE)
else()
message(STATUS "Including only free features, no Pro")
endif()

file(GLOB SOURCES
src/features/*.cpp
src/features/scaling/*.cpp
Expand All @@ -18,9 +25,21 @@ file(GLOB SOURCES
src/*.cpp
)

add_library(${PROJECT_NAME} SHARED ${SOURCES})
if (${BE_PRO_FOUND})
file(GLOB PRO_SOURCES
pro/*.cpp
pro/features/*.cpp
pro/ui/*.cpp
)
endif()

add_library(${PROJECT_NAME} SHARED ${SOURCES} ${PRO_SOURCES})

target_include_directories(${PROJECT_NAME} PUBLIC "src")
if (${BE_PRO_FOUND})
target_include_directories(${PROJECT_NAME} PUBLIC "")
target_compile_definitions(${PROJECT_NAME} PUBLIC BETTEREDIT_PRO)
endif()

if (NOT DEFINED ENV{GEODE_SDK})
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
Expand All @@ -32,10 +51,6 @@ add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)

setup_geode_mod(${PROJECT_NAME})

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/pro/)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/pro)
endif()

# Bad code will NOT be deployed!
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
Expand Down
20 changes: 20 additions & 0 deletions src/features/Keybinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <Geode/binding/EditButtonBar.hpp>
#include <utils/HolyUB.hpp>

#ifdef BETTEREDIT_PRO
#include <pro/features/GroupSummaryPopup.hpp>
#endif

using namespace geode::prelude;
using namespace keybinds;

Expand Down Expand Up @@ -137,6 +141,12 @@ struct $modify(EditorUI) {
this->defineKeybind("move-obj-big-down"_spr, [this] {
this->moveObjectCall(EditCommand::BigDown);
});

#ifdef BETTEREDIT_PRO
this->defineKeybind("group-summary"_spr, [this] {
GroupSummaryPopup::create()->show();
});
#endif

return true;
}
Expand Down Expand Up @@ -412,6 +422,16 @@ struct $modify(EditorUI) {
{},
Category::EDITOR_MOVE, true
});

#ifdef BETTEREDIT_PRO
BindManager::get()->registerBindable({
"group-summary"_spr,
"Open Group Summary",
"",
{},
Category::EDITOR, false
});
#endif
}

#endif
6 changes: 5 additions & 1 deletion src/features/MoveMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ class CustomEditMenu : public CCNode {
return menu;
}

if (!Mod::get()->template getSettingValue<bool>("new-edit-menu") || isProUIEnabled()) {
if (!Mod::get()->template getSettingValue<bool>("new-edit-menu")) {
return nullptr;
}

if (isProUIEnabled()) {
return nullptr;
}

Expand Down
4 changes: 4 additions & 0 deletions src/features/scaling/EditorUIScaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class $modify(ScaledUI, EditorUI) {
}

void centerBuildTabs() {
if (isProUIEnabled()) {
return;
}

// This centers the build tab
auto winSize = CCDirector::get()->getWinSize();
for (auto c : CCArrayExt<CCNode*>(this->getChildren())) {
Expand Down
10 changes: 0 additions & 10 deletions src/utils/Pro.cpp

This file was deleted.

27 changes: 26 additions & 1 deletion src/utils/Pro.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
#pragma once

bool isProUIEnabled();
#include "Warn.hpp"

#ifdef BETTEREDIT_PRO
#include <pro/Pro.hpp>
#include <pro/ui/UI.hpp>
#endif

BE_ALLOW_START
BE_ALLOW_UNUSED_FUNCTION

static bool isProUIEnabled() {
#ifdef BETTEREDIT_PRO
return pro::isNewUIEnabled();
#else
return false;
#endif
}
static bool isProEnabled() {
#ifdef BETTEREDIT_PRO
return pro::isProEnabled();
#else
return false;
#endif
}

BE_ALLOW_END
9 changes: 6 additions & 3 deletions src/utils/Warn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#define BE_ALLOW_END __pragma(warning( pop ))
#define BE_ALLOW_MSVC(warningNumber) __pragma(warning( disable : warningNumber ))

#define BE_ALLOW_SHADOWING BE_ALLOW_MSVC(4458)
#define BE_ALLOW_FAKE_ENUMS BE_ALLOW_MSVC(4063)
#define BE_ALLOW_UNUSED_PARAMS BE_ALLOW_MSVC(4100)
#define BE_ALLOW_SHADOWING BE_ALLOW_MSVC(4458)
#define BE_ALLOW_FAKE_ENUMS BE_ALLOW_MSVC(4063)
#define BE_ALLOW_UNUSED_PARAMS BE_ALLOW_MSVC(4100)
#define BE_ALLOW_UNUSED_FUNCTION BE_ALLOW_MSVC(4505)
#elif defined(__GNUC__) || defined(__clang__)
#define DO_PRAGMA(X) _Pragma(#X)
#define BE_ALLOW_START DO_PRAGMA(GCC diagnostic push)
Expand All @@ -19,12 +20,14 @@
#define BE_ALLOW_SHADOWING BE_ALLOW_CLANG(-Wshadow)
#define BE_ALLOW_FAKE_ENUMS
#define BE_ALLOW_UNUSED_PARAMS BE_ALLOW_CLANG(-Wunused-parameter)
#define BE_ALLOW_UNUSED_FUNCTION
#else
#define BE_ALLOW_START
#define BE_ALLOW_END
#define BE_ALLOW_SHADOWING
#define BE_ALLOW_FAKE_ENUMS
#define BE_ALLOW_UNUSED_PARAMS
#define BE_ALLOW_UNUSED_FUNCTION
#endif

#define $be_ensure_hookable(...) static_assert(requires { __VA_ARGS__; })

0 comments on commit 3db14e8

Please sign in to comment.