Skip to content

Commit

Permalink
support for 2.2074
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Nov 15, 2024
1 parent ab429a1 commit e8b7c30
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 102 deletions.
58 changes: 4 additions & 54 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,56 +1,6 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Macos be like
**/.DS_Store

# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# Ignore build folders
**/build
**/build-*

# Workspace files are user-specific
*.sublime-workspace

# ILY vscode
**/.vscode
.idea/

# clangd
.cache/

.vscode/
build/
build-*/
pro/
resources/images/support-popup.png
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ else()
message(STATUS "Including only free features, no Pro")
endif()

if (NOT SKIP_INCLUDING_LARGE_RESOURCES_FOR_SHORTER_BUILD_TIMES)
file(COPY_FILE
resources/support-popup/support-popup.png
resources/images/support-popup.png
)
else()
file(REMOVE resources/images/support-popup.png)
endif()

file(GLOB SOURCES
src/features/*.cpp
src/features/scaling/*.cpp
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# BetterEdit 6

## v6.9.0-alpha.1
* Support for <cy>GD 2.2704</c> and <ca>Geode 4.0.0-beta.1</c>

## v6.8.0
* Add <cd>Modifying Mixed Values</c> in the Group ID Popup (Editor Layers, Z Order, Channel)
* Add inputs for <cb>Scale</c>, <cg>Scale X</c>, and <co>Scale Y</c>
Expand Down
10 changes: 5 additions & 5 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"geode": "3.8.1",
"version": "6.8.0",
"geode": "4.0.0-beta.1",
"version": "6.9.0-alpha.1",
"gd": {
"win": "2.206",
"mac": "2.206",
"android": "2.206"
"win": "2.2074",
"mac": "2.2074",
"android": "2.2074"
},
"id": "hjfod.betteredit",
"name": "BetterEdit",
Expand Down
File renamed without changes
8 changes: 4 additions & 4 deletions src/features/ForceHideTriggerUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class $modify(SetupTriggerPopup) {
if (!Mod::get()->getSettingValue<bool>("hide-trigger-ui")) {
return;
}
getChildOfType<CCScale9Sprite>(m_mainLayer, 0)->runAction(CCFadeTo::create(0.15f, 0));
this->runAction(CCFadeTo::create(0.15f, 0));
m_mainLayer->getChildByType<CCScale9Sprite>(0)->runAction(CCFadeTo::create(.15f, 0));
this->runAction(CCFadeTo::create(.15f, 0));
}
virtual void sliderEnded(Slider* slider) {
SetupTriggerPopup::sliderEnded(slider);
if (!Mod::get()->getSettingValue<bool>("hide-trigger-ui")) {
return;
}
getChildOfType<CCScale9Sprite>(m_mainLayer, 0)->runAction(CCFadeTo::create(0.15f, 255));
this->runAction(CCFadeTo::create(0.15f, 150));
m_mainLayer->getChildByType<CCScale9Sprite>(0)->runAction(CCFadeTo::create(.15f, 255));
this->runAction(CCFadeTo::create(.15f, 150));
}
};
2 changes: 1 addition & 1 deletion src/features/Keybinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct $modify(EditorUI) {
this->editGroup(nullptr);
});
this->defineKeybind("open-edit-special"_spr, [this]() {
this->editObject2(nullptr);
this->editObjectSpecial(0);
});
this->defineKeybind("copy-values"_spr, [this]() {
this->onCopyState(nullptr);
Expand Down
8 changes: 4 additions & 4 deletions src/features/ViewTab/ViewTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using namespace keybinds;
template <class F>
class CCFunction : public CCObject {
protected:
MiniFunction<F> m_func;
std::function<F> m_func;

public:
template <class F2>
Expand Down Expand Up @@ -108,7 +108,7 @@ struct $modify(ViewTabUI, EditorUI) {
toggler->setUserObject("setter", CCFunction<void(bool)>::create(set));
return toggler;
}
CCMenuItemToggler* createViewToggleGV(const char* frame, const char* gv, MiniFunction<void(bool)> postSet = nullptr) {
CCMenuItemToggler* createViewToggleGV(const char* frame, const char* gv, std::function<void(bool)> postSet = nullptr) {
auto off = createViewToggleSpr(frame, false);
auto on = createViewToggleSpr(frame, true);
auto toggler = CCMenuItemToggler::create(off, on, this, menu_selector(ViewTabUI::onViewToggle));
Expand All @@ -121,7 +121,7 @@ struct $modify(ViewTabUI, EditorUI) {
}));
return toggler;
}
CCMenuItemToggler* createViewToggleMSV(const char* frame, const char* modSavedValue, MiniFunction<void(bool)> postSet = nullptr) {
CCMenuItemToggler* createViewToggleMSV(const char* frame, const char* modSavedValue, std::function<void(bool)> postSet = nullptr) {
auto off = createViewToggleSpr(frame, false);
auto on = createViewToggleSpr(frame, true);
auto toggler = CCMenuItemToggler::create(off, on, this, menu_selector(ViewTabUI::onViewToggle));
Expand Down Expand Up @@ -163,7 +163,7 @@ struct $modify(ViewTabUI, EditorUI) {
auto winSize = CCDirector::get()->getWinSize();

// Make a bit space for new style menu since the old one is a tiny bit cramped
if (auto left = getChildOfType<CCSprite>(this, 1), right = getChildOfType<CCSprite>(this, 2); left && right) {
if (auto left = this->getChildByType<CCSprite>(1), right = this->getChildByType<CCSprite>(2); left && right) {
left->setPositionX(winSize.width - right->getPositionX());
}
for (auto& child : CCArrayExt<CCNode*>(m_pChildren)) {
Expand Down
43 changes: 24 additions & 19 deletions src/features/backups/Backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,22 @@ struct BackupMetadata final {

template <>
struct matjson::Serialize<BackupMetadata> {
static matjson::Value to_json(BackupMetadata const& meta) {
return matjson::Object({
static matjson::Value toJson(BackupMetadata const& meta) {
return matjson::makeObject({
{ "create-time", std::chrono::duration_cast<Backup::TimeUnit>(meta.createTime.time_since_epoch()).count() },
{ "automated", meta.automated },
});
}
static BackupMetadata from_json(matjson::Value const& value) {
static Result<BackupMetadata> fromJson(matjson::Value const& value) {
auto meta = BackupMetadata();
auto obj = value.as_object();
auto obj = checkJson(value, "BackupMetadata");

meta.createTime = Backup::TimePoint(Backup::TimeUnit(obj["create-time"].as_int()));
int createTime;
obj.needs("create-time").into(createTime);
meta.createTime = Backup::TimePoint(Backup::TimeUnit(createTime));
obj.has("automated").into(meta.automated);

// Parsing should be as fault-tolerant as possible
if (obj.contains("automated")) {
meta.automated = obj["automated"].as_bool();
}

return meta;
}
static bool is_json(matjson::Value const& value) {
return value.is_object();
return Ok(meta);
}
};

Expand Down Expand Up @@ -85,12 +80,16 @@ Result<> Backup::preserveAutomated() {
.createTime = m_createTime,
.automated = false,
};
GEODE_UNWRAP(file::writeToJson(m_directory / "meta.json", metadata).expect("Unable to save metadata: {error}"));
GEODE_UNWRAP(file::writeToJson(m_directory / "meta.json", metadata).mapErr([](auto error) {
return fmt::format("Unable to save metadata: {}", error);
}));
return Ok();
}

Result<std::shared_ptr<Backup>> Backup::load(std::filesystem::path const& dir, GJGameLevel* forLevel) {
GEODE_UNWRAP_INTO(auto level, gmd::importGmdAsLevel(dir / "level.gmd").expect("Unable to read level file: {error}"));
GEODE_UNWRAP_INTO(auto level, gmd::importGmdAsLevel(dir / "level.gmd").mapErr([](auto error) {
return fmt::format("Unable to read level file: {}", error);
}));
auto meta = file::readFromJson<BackupMetadata>(dir / "meta.json").unwrapOrDefault();

auto backup = std::make_shared<Backup>();
Expand Down Expand Up @@ -133,15 +132,21 @@ Result<> Backup::create(GJGameLevel* level, bool automated) {
return Err("Level was already backed up less than a minute ago");
}

GEODE_UNWRAP(file::createDirectoryAll(dir).expect("Failed to create directory: {error}"));
GEODE_UNWRAP(file::createDirectoryAll(dir).mapErr([](auto error) {
return fmt::format("Failed to create directory: {}", error);
}));

GEODE_UNWRAP(gmd::exportLevelAsGmd(level, dir / "level.gmd").expect("Unable to save level: {error}"));
GEODE_UNWRAP(gmd::exportLevelAsGmd(level, dir / "level.gmd").mapErr([](auto error) {
return fmt::format("Unable to save level: {}", error);
}));

auto metadata = BackupMetadata {
.createTime = time,
.automated = automated,
};
GEODE_UNWRAP(file::writeToJson(dir / "meta.json", metadata).expect("Unable to save metadata: {error}"));
GEODE_UNWRAP(file::writeToJson(dir / "meta.json", metadata).mapErr([](auto error) {
return fmt::format("Unable to save metadata: {}", error);
}));

return Ok();
}
Expand Down
1 change: 0 additions & 1 deletion src/features/backups/Backup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <Geode/binding/GJGameLevel.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/utils/Result.hpp>

using namespace geode::prelude;

Expand Down
14 changes: 7 additions & 7 deletions src/features/scaling/EditorUIScaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class $modify(BetterEditButtonBar, EditButtonBar) {
setPositionX(winSize.width / 2);
m_scrollLayer->setPositionX(-(winSize.width / 2));

if (auto menu = getChildOfType<CCMenu>(this, 0)) {
if (auto menu = this->getChildByType<CCMenu>(0)) {
menu->setVisible(false);

// easier to create a new menu than work with the old one
Expand Down Expand Up @@ -88,7 +88,7 @@ class $modify(BetterEditButtonBar, EditButtonBar) {

// layout the pages and set their widths and heights according to the row and column counts, scale accordingly
for (ButtonPage* page : CCArrayExt<ButtonPage*>(m_scrollLayer->m_pages)) {
if (CCMenu* buttonMenu = getChildOfType<CCMenu>(page, 0)) {
if (CCMenu* buttonMenu = page->getChildByType<CCMenu>(0)) {
RowLayout* layout = RowLayout::create();
layout->setAxisAlignment(AxisAlignment::Start);
layout->setCrossAxisAlignment(AxisAlignment::End);
Expand Down Expand Up @@ -132,7 +132,7 @@ class $modify(ScaledUI, EditorUI) {
float scale = Mod::get()->getSettingValue<double>("scale-factor");
auto size = CCDirector::get()->getWinSize();

if (auto slider = getChildOfType<Slider>(this, 0)) {
if (auto slider = this->getChildByType<Slider>(0)) {
slider->ignoreAnchorPointForPosition(false);
slider->setContentSize(ccp(0, 0));
slider->setScale(scale);
Expand Down Expand Up @@ -189,9 +189,9 @@ class $modify(ScaledUI, EditorUI) {
}

// i am very sorry for using object indexes but no id
// doggo for the love of god at least use getChildOfType
// doggo for the love of god at least use getChildByType

if (auto objBG = getChildOfType<CCSprite>(this, 0)) {
if (auto objBG = this->getChildByType<CCSprite>(0)) {
objBG->setScaleY(scale);
}

Expand Down Expand Up @@ -220,12 +220,12 @@ class $modify(ScaledUI, EditorUI) {
rightTabs->setScale(scale);
}

if (auto leftLine = getChildOfType<CCSprite>(this, 1)) {
if (auto leftLine = this->getChildByType<CCSprite>(1)) {
leftLine->setScale(scale);
leftLine->setPosition(leftLine->getPosition() * scale);
}

if (auto rightLine = getChildOfType<CCSprite>(this, 2)) {
if (auto rightLine = this->getChildByType<CCSprite>(2)) {
rightLine->setScale(scale);
rightLine->setPosition(ccp(size.width - (size.width - rightLine->getPositionX()) * scale, rightLine->getPositionY() * scale));
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class $modify(GameManager) {
//// View-only editor stuff
class ViewOnlyModeData : public CCObject {
protected:
utils::MiniFunction<CCLayer*()> m_returnTo;
std::function<CCLayer*()> m_returnTo;

public:
static ViewOnlyModeData* create(utils::MiniFunction<CCLayer*()> returnTo) {
static ViewOnlyModeData* create(std::function<CCLayer*()> returnTo) {
auto ret = new ViewOnlyModeData();
ret->m_returnTo = returnTo;
ret->autorelease();
Expand All @@ -78,7 +78,7 @@ class ViewOnlyModeData : public CCObject {
}
};

LevelEditorLayer* be::createViewOnlyEditor(GJGameLevel* level, utils::MiniFunction<CCLayer*()> returnTo) {
LevelEditorLayer* be::createViewOnlyEditor(GJGameLevel* level, std::function<CCLayer*()> returnTo) {
auto editor = LevelEditorLayer::create(level, false);
editor->setUserObject("view-only-mode"_spr, ViewOnlyModeData::create(returnTo));

Expand Down Expand Up @@ -227,7 +227,7 @@ class $modify(HideUI, EditorUI) {
UIShowEvent::UIShowEvent(EditorUI* ui, bool show) : ui(ui), show(show) {}

UIShowFilter::UIShowFilter(EditorUI* ui) : m_ui(ui) {}
ListenerResult UIShowFilter::handle(MiniFunction<Callback> fn, UIShowEvent* ev) {
ListenerResult UIShowFilter::handle(std::function<Callback> fn, UIShowEvent* ev) {
if (m_ui == ev->ui) {
fn(ev);
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace be {
* Create a view-only editor, i.e. one where no objects can be placed nor
* edited
*/
LevelEditorLayer* createViewOnlyEditor(GJGameLevel* level, utils::MiniFunction<CCLayer*()> returnTo);
LevelEditorLayer* createViewOnlyEditor(GJGameLevel* level, std::function<CCLayer*()> returnTo);
/**
* Check if the given editor is view-only
*/
Expand Down Expand Up @@ -66,6 +66,6 @@ class UIShowFilter : public EventFilter<UIShowEvent> {
UIShowFilter() = default;
UIShowFilter(EditorUI* ui);

ListenerResult handle(MiniFunction<Callback> fn, UIShowEvent* ev);
ListenerResult handle(std::function<Callback> fn, UIShowEvent* ev);
};
using OnUIHide = EventListener<UIShowFilter>;
2 changes: 1 addition & 1 deletion src/utils/Warn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
#define BE_ALLOW_UNUSED_FUNCTION
#endif

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

0 comments on commit e8b7c30

Please sign in to comment.