Skip to content

Commit

Permalink
6.6.1 bugfixes & improvements
Browse files Browse the repository at this point in the history
 * Auto-saved changes are now discarded if you exit without saving (for Colon)
 * Fix Auto-Save countdown being permanently stuck on screen (fix #323, fix #348, fix #350)
 * Fix Layer Controls being clipped a little off-screen (fix #332, fix #322)
 * Fix Group Offset not working (fix #366)
 * Expand Changelog to include historical versions of BetterEdit too for the sake of fun
  • Loading branch information
HJfod committed Jul 7, 2024
1 parent 9e3e008 commit d718e84
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 31 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# BetterEdit 6

## v6.6.1
* <cj>Auto-saved changes</c> are now <co>discarded if you exit without saving</c>
* Fix <cj>Auto-Save countdown</c> being permanently stuck on screen
* Fix <cy>Layer Controls</c> being clipped a little off-screen
* Fix <cg>Group Offset</c> not working
* Expand <cp>Changelog</c> to include historical versions of BetterEdit too for the sake of fun

## v6.6.0
* Add keybinds for <cj>Save Level</c>, <co>Build Helper</c>, <cp>Align X</c>, <ca>Align Y</c>, <cb>Edit Object</c>, <co>Edit Group</c>, <cj>Edit Special</c>, <cr>Copy Values</c>, <cg>Paste State</c>, <cy>Paste Color</c>, and <cl>Toggle Link Controls</c>

Expand Down
4 changes: 2 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "3.1.1",
"version": "6.6.0",
"geode": "3.2.0",
"version": "6.6.1",
"gd": {
"win": "2.206",
"mac": "2.206",
Expand Down
17 changes: 0 additions & 17 deletions src/features/CrashRecovery.cpp

This file was deleted.

1 change: 1 addition & 0 deletions src/features/NextFreeOffset.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include <Geode/modify/SetGroupIDLayer.hpp>
#include <utils/NextFreeOffsetInput.hpp>
#include <utils/Warn.hpp>
#include <Geode/binding/GameObject.hpp>

using namespace geode::prelude;
Expand Down
3 changes: 3 additions & 0 deletions src/features/TypeInZLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class $modify(TypeInUI, EditorUI) {
auto layerMenu = this->getChildByID("layer-menu");
layerMenu->setContentSize({ 130, layerMenu->getContentSize().height });

// Otherwise it clippety clips off the screen
layerMenu->setPositionX(layerMenu->getPositionX() - 10);

auto layerLockSpr = CCSprite::createWithSpriteFrameName("GJ_lockGray_001.png");
layerLockSpr->setScale(.75f);
auto layerLockBtn = CCMenuItemSpriteExtra::create(
Expand Down
2 changes: 2 additions & 0 deletions src/features/ViewTab/PortalLineColors.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// geode-begin-ignore-all

// #include <Geode/utils/cocos.hpp>
// #include <Geode/binding/GameObject.hpp>
// #include <Geode/modify/DrawGridLayer.hpp>
Expand Down
9 changes: 4 additions & 5 deletions src/features/backups/AutoSave.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Geode/modify/EditorUI.hpp>
#include "Backup.hpp"
#include "QuickSave.hpp"

using namespace geode::prelude;

Expand Down Expand Up @@ -46,7 +47,7 @@ class $modify(AutoSaveUI, EditorUI) {
// Make sure the autosave notification exists
if (!m_fields->autoSaveCountdownNotification) {
m_fields->autoSaveCountdownNotification = Notification::create(
"", CCSprite::createWithSpriteFrameName("GJ_timeIcon_001.png"), 0
"", CCSprite::createWithSpriteFrameName("GJ_timeIcon_001.png"), COUNTDOWN.count()
);
m_fields->autoSaveCountdownNotification->show();
}
Expand All @@ -64,10 +65,8 @@ class $modify(AutoSaveUI, EditorUI) {
this->onStopPlaytest(nullptr);
}

// Save level (using QuickSave if enabled)
auto layer = EditorPauseLayer::create(m_editorLayer);
layer->saveLevel();
layer->release();
// Save level
createAutoSave(m_editorLayer);

// Create backup
auto res = Backup::create(m_editorLayer->m_level, true);
Expand Down
63 changes: 56 additions & 7 deletions src/features/QuickSave.cpp → src/features/backups/QuickSave.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
#include "QuickSave.hpp"
#include <Geode/modify/EditorPauseLayer.hpp>
#include <Geode/modify/GManager.hpp>
#include <Geode/modify/MenuLayer.hpp>
#include <cvolton.level-id-api/include/EditorIDs.hpp>
#include <hjfod.gmd-api/include/GMD.hpp>
#include <utils/HolyUB.hpp>

using namespace geode::prelude;

static std::filesystem::path getQuickSaveDir() {
return Mod::get()->getSaveDir() / "quicksave";
}
static std::filesystem::path getQuickSaveFile(GJGameLevel* level) {
return getQuickSaveDir() / fmt::format("{}.gmd", EditorIDs::getID(level));

// Autosave is stored separately, as if you press Exit without saving in the
// editor then that should discard autosaves too, but not quicksaves
static std::filesystem::path getAutoSaveDir() {
return Mod::get()->getSaveDir() / "autosave";
}

static bool CREATING_AUTO_SAVE = false;
void ::createAutoSave(LevelEditorLayer* lel) {
CREATING_AUTO_SAVE = true;
fakeEditorPauseLayer(lel)->saveLevel();
CREATING_AUTO_SAVE = false;
}

static bool SKIP_NEXT_LLM_SAVE = false;
Expand All @@ -27,6 +39,7 @@ class $modify(GManager) {
if (isLLM) {
std::error_code ec;
std::filesystem::remove_all(getQuickSaveDir(), ec);
std::filesystem::remove_all(getAutoSaveDir(), ec);
}
}
};
Expand All @@ -37,15 +50,49 @@ class $modify(EditorPauseLayer) {
// In any case we need to still run the rest of `saveLevel` to have GD
// update the level state but for quicksave we just skip the function
// saving CCLocalLevels
SKIP_NEXT_LLM_SAVE = Mod::get()->template getSettingValue<bool>("quick-save");
SKIP_NEXT_LLM_SAVE = Mod::get()->template getSettingValue<bool>("quick-save") || CREATING_AUTO_SAVE;
EditorPauseLayer::saveLevel();

auto dir = CREATING_AUTO_SAVE ? getAutoSaveDir() : getQuickSaveDir();
CREATING_AUTO_SAVE = false;

// Save to individual file regardless as a backup if saving crashes
(void)file::createDirectoryAll(getQuickSaveDir());
auto res = gmd::exportLevelAsGmd(m_editorLayer->m_level, getQuickSaveFile(m_editorLayer->m_level));
(void)file::createDirectoryAll(dir);
auto res = gmd::exportLevelAsGmd(
m_editorLayer->m_level,
dir / fmt::format("{}.gmd", EditorIDs::getID(m_editorLayer->m_level))
);
if (!res) {
log::error("Unable to quicksave level '{}': {}", m_editorLayer->m_level->m_levelName, res.unwrapErr());
log::error("Unable to save level '{}': {}", m_editorLayer->m_level->m_levelName, res.unwrapErr());
}
}

$override
void FLAlert_Clicked(FLAlertLayer* fl, bool btn2) {
// Discard autosaves on exit without save
if (fl->getTag() == 1 && btn2) {
log::warn("Discarding autosaved changes");
std::error_code ec;
std::filesystem::remove_all(
getAutoSaveDir() / fmt::format("{}.gmd", EditorIDs::getID(m_editorLayer->m_level)),
ec
);
}
EditorPauseLayer::FLAlert_Clicked(fl, btn2);
}

$override
void onExitNoSave(CCObject*) {
auto fl = FLAlertLayer::create(
this,
"Exit",
"<cy>Exit</c> without saving? All unsaved changes will be <cr>lost</c>!\n"
"<co>All auto-saved changes will also be discarded!</c>",
"Cancel", "Exit",
300
);
fl->setTag(1);
fl->show();
}
};
class $modify(MenuLayer) {
Expand All @@ -54,7 +101,9 @@ class $modify(MenuLayer) {
return false;

// Check if there's quicksaved crash data
for (auto file : file::readDirectory(getQuickSaveDir()).unwrapOrDefault()) {
auto files = file::readDirectory(getQuickSaveDir()).unwrapOrDefault();
ranges::push(files, file::readDirectory(getAutoSaveDir()).unwrapOrDefault());
for (auto file : files) {
auto data = gmd::importGmdAsLevel(file);
if (!data) continue;
auto imported = *data;
Expand Down
7 changes: 7 additions & 0 deletions src/features/backups/QuickSave.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <Geode/binding/GJGameLevel.hpp>

using namespace geode::prelude;

void createAutoSave(LevelEditorLayer* lel);
1 change: 1 addition & 0 deletions src/utils/NextFreeOffsetInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class NextFreeOffsetInput : public CCNode {
m_input->setString(numToString(s_value));
}
m_input->setCallback([](auto str) {
log::info("hi: {}", str);
if (auto value = numFromString<ValueType>(str)) {
s_value = clamp(value.unwrap(), Source::MIN_VALUE, Source::MAX_VALUE);
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/Pro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ using namespace geode::prelude;

bool isProUIEnabled() {
auto pro = Loader::get()->getLoadedMod("hjfod.betteredit-pro");
// geode-ignore-unknown-setting
return pro && pro->template getSettingValue<bool>("pro-ui");
}
2 changes: 2 additions & 0 deletions src/utils/Warn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
#define BE_ALLOW_FAKE_ENUMS
#define BE_ALLOW_UNUSED_PARAMS
#endif

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

0 comments on commit d718e84

Please sign in to comment.