diff --git a/include/Keybinds.hpp b/include/Keybinds.hpp index b1ed5c2..878abba 100644 --- a/include/Keybinds.hpp +++ b/include/Keybinds.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -234,7 +233,7 @@ namespace keybinds { public: using Callback = geode::ListenerResult(InvokeBindEvent*); - geode::ListenerResult handle(geode::utils::MiniFunction fn, InvokeBindEvent* event); + geode::ListenerResult handle(std::function fn, InvokeBindEvent* event); InvokeBindFilter(cocos2d::CCNode* target, ActionID const& id); }; @@ -253,7 +252,7 @@ namespace keybinds { public: using Callback = geode::ListenerResult(PressBindEvent*); - geode::ListenerResult handle(geode::utils::MiniFunction fn, PressBindEvent* event); + geode::ListenerResult handle(std::function fn, PressBindEvent* event); PressBindFilter(); }; @@ -276,7 +275,7 @@ namespace keybinds { public: using Callback = void(DeviceEvent*); - geode::ListenerResult handle(geode::utils::MiniFunction fn, DeviceEvent* event); + geode::ListenerResult handle(std::function fn, DeviceEvent* event); DeviceFilter(std::optional id = std::nullopt); }; diff --git a/mod.json b/mod.json index 60e5d8b..f5dd4e4 100644 --- a/mod.json +++ b/mod.json @@ -1,7 +1,7 @@ { - "geode": "3.6.0", + "geode": "4.0.0", "gd": { - "win": "2.206", + "win": "2.2073", "android": "2.206" }, "version": "v1.9.0", @@ -29,7 +29,7 @@ "incompatibilities": [], "settings": { "open-menu": { - "type": "custom" + "type": "custom:open-menu" } } } diff --git a/src/ControllerBind.cpp b/src/ControllerBind.cpp index 77236fe..26f5b97 100644 --- a/src/ControllerBind.cpp +++ b/src/ControllerBind.cpp @@ -15,14 +15,14 @@ ControllerBind* ControllerBind::create(enumKeyCodes button) { ControllerBind* ControllerBind::parse(matjson::Value const& value) { return ControllerBind::create( - static_cast(value["button"].as_double()) + static_cast(value["button"].asInt().unwrapOr(0)) ); } matjson::Value ControllerBind::save() const { - return matjson::Object { + return matjson::makeObject({ { "button", static_cast(m_button) }, - }; + }); } enumKeyCodes ControllerBind::getButton() const { diff --git a/src/Keybind.cpp b/src/Keybind.cpp index 8b49a18..9b635ed 100644 --- a/src/Keybind.cpp +++ b/src/Keybind.cpp @@ -16,16 +16,16 @@ Keybind* Keybind::create(enumKeyCodes key, Modifier modifiers) { Keybind* Keybind::parse(matjson::Value const& value) { return Keybind::create( - static_cast(value["key"].as_int()), - static_cast(value["modifiers"].as_int()) + static_cast(value["key"].asInt().unwrapOr(0)), + static_cast(value["modifiers"].asInt().unwrapOr(0)) ); } matjson::Value Keybind::save() const { - return matjson::Object { + return matjson::makeObject({ { "key", static_cast(m_key) }, { "modifiers", static_cast(m_modifiers) } - }; + }); } enumKeyCodes Keybind::getKey() const { diff --git a/src/Keybinds.cpp b/src/Keybinds.cpp index f4accce..7a20be4 100644 --- a/src/Keybinds.cpp +++ b/src/Keybinds.cpp @@ -189,7 +189,7 @@ bool InvokeBindEvent::isDown() const { return m_down; } -ListenerResult InvokeBindFilter::handle(utils::MiniFunction fn, InvokeBindEvent* event) { +ListenerResult InvokeBindFilter::handle(std::function fn, InvokeBindEvent* event) { if (event->getID() == m_id) { return fn(event); } @@ -211,7 +211,7 @@ bool PressBindEvent::isDown() const { return m_down; } -geode::ListenerResult PressBindFilter::handle(MiniFunction fn, PressBindEvent* event) { +geode::ListenerResult PressBindFilter::handle(std::function fn, PressBindEvent* event) { return fn(event); } @@ -232,7 +232,7 @@ bool DeviceEvent::wasDetached() const { return !m_attached; } -ListenerResult DeviceFilter::handle(MiniFunction fn, DeviceEvent* event) { +ListenerResult DeviceFilter::handle(std::function fn, DeviceEvent* event) { if (!m_id || m_id == event->getID()) { fn(event); } @@ -309,7 +309,10 @@ matjson::Value BindManager::saveBind(Bind* bind) const { Bind* BindManager::loadBind(matjson::Value const& json) const { try { - auto device = json["device"].as_string(); + auto res = json["device"].asString(); + if (!res) + return nullptr; + auto device = res.unwrap(); if (!m_devices.contains(device)) { return nullptr; } @@ -321,9 +324,9 @@ Bind* BindManager::loadBind(matjson::Value const& json) const { } bool BindManager::loadActionBinds(ActionID const& action) { - try { - auto value = Mod::get()->template getSavedValue(action); - for (auto bind : value["binds"].as_array()) { + auto inner = [&]() -> Result<> { + auto value = Mod::get()->getSavedValue(action); + for (auto bind : value["binds"]) { // try directly parsing the bind from a string if the device it's for // is already connected if (auto b = this->loadBind(bind)) { @@ -334,9 +337,9 @@ bool BindManager::loadActionBinds(ActionID const& action) { else { // if device ID exists, then add this to the list of unbound // binds - if (bind.contains("device")) { + if (bind.contains("device") && bind["device"].isString()) { try { - m_devicelessBinds[bind["device"].as_string()][action].insert(bind); + m_devicelessBinds[bind["device"].asString().unwrap()][action].insert(bind); } catch(...) {} } @@ -345,36 +348,34 @@ bool BindManager::loadActionBinds(ActionID const& action) { } // load repeat options if (value.contains("repeat")) { - auto rep = value["repeat"].as_object(); + auto rep = value["repeat"]; auto opts = RepeatOptions(); - opts.enabled = rep["enabled"].as_bool(); - opts.rate = rep["rate"].as_int(); - opts.delay = rep["delay"].as_int(); + GEODE_UNWRAP_INTO(opts.enabled, rep["enabled"].asBool()); + GEODE_UNWRAP_INTO(opts.rate, rep["rate"].asInt()); + GEODE_UNWRAP_INTO(opts.delay, rep["delay"].asInt()); this->setRepeatOptionsFor(action, opts); } - return true; - } - catch(...) { - return false; - } + return Ok(); + }; + return inner().isOk(); } void BindManager::saveActionBinds(ActionID const& action) { - auto obj = matjson::Object(); - auto binds = matjson::Array(); + auto obj = matjson::Value::object(); + auto binds = matjson::Value::array(); for (auto& bind : this->getBindsFor(action)) { - binds.push_back(this->saveBind(bind)); + binds.push(this->saveBind(bind)); } for (auto& [device, actions] : m_devicelessBinds) { if (actions.contains(action)) { for (auto& bind : actions.at(action)) { - binds.push_back(bind); + binds.push(bind); } } } obj["binds"] = binds; if (auto opts = this->getRepeatOptionsFor(action)) { - auto rep = matjson::Object(); + auto rep = matjson::Value::object(); rep["enabled"] = opts.value().enabled; rep["rate"] = opts.value().rate; rep["delay"] = opts.value().delay; diff --git a/src/KeybindsLayer.cpp b/src/KeybindsLayer.cpp index 688da28..14cb388 100644 --- a/src/KeybindsLayer.cpp +++ b/src/KeybindsLayer.cpp @@ -257,7 +257,7 @@ bool EditRepeatPopup::setup(BindableNode* node) { rateInput->setString(std::to_string(m_options.rate)); rateInput->setCallback([this](std::string const& text) { if (auto num = numFromString(text)) { - m_options.rate = *num; + m_options.rate = num.unwrap(); } }); rateInput->setScale(.75f); @@ -272,7 +272,7 @@ bool EditRepeatPopup::setup(BindableNode* node) { delayInput->getInputNode()->setString(std::to_string(m_options.delay)); delayInput->setCallback([this](std::string const& text) { if (auto num = numFromString(text)) { - m_options.delay = *num; + m_options.delay = num.unwrap(); } }); delayInput->setScale(.75f); diff --git a/src/KeybindsLayer.hpp b/src/KeybindsLayer.hpp index cbbbb1a..c1008f5 100644 --- a/src/KeybindsLayer.hpp +++ b/src/KeybindsLayer.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include "../include/Keybinds.hpp" diff --git a/src/MouseBind.cpp b/src/MouseBind.cpp index fdf363c..d253a99 100644 --- a/src/MouseBind.cpp +++ b/src/MouseBind.cpp @@ -12,8 +12,8 @@ MouseBind* MouseBind::create(MouseButton button, Modifier modifiers) { } MouseBind* MouseBind::parse(matjson::Value const& value) { return MouseBind::create( - static_cast(value["button"].as_int()), - static_cast(value["modifiers"].as_int()) + static_cast(value["button"].asInt().unwrapOrDefault()), + static_cast(value["modifiers"].asInt().unwrapOrDefault()) ); } @@ -54,8 +54,8 @@ DeviceID MouseBind::getDeviceID() const { return "mouse"_spr; } matjson::Value MouseBind::save() const { - return matjson::Object { + return matjson::makeObject({ { "button", static_cast(m_button) }, { "modifiers", static_cast(m_modifiers) }, - }; + }); } diff --git a/src/UILayer.cpp b/src/UILayer.cpp index 3581e80..d43f059 100644 --- a/src/UILayer.cpp +++ b/src/UILayer.cpp @@ -49,7 +49,7 @@ struct $modify(PauseLayer) { // Remove any popups (looking at you, confirm exit) CCScene* active = CCDirector::sharedDirector()->getRunningScene(); - if (auto alert = getChildOfType(active, 0)) { + if (auto alert = active->getChildByType(0)) { return ListenerResult::Propagate; } this->onResume(nullptr); @@ -96,13 +96,13 @@ struct $modify(UILayer) { bool isPaused() { return !this->isCurrentPlayLayer() - || getChildOfType(PlayLayer::get()->getParent(), 0) != nullptr - || getChildOfType(PlayLayer::get(), 0) != nullptr; + || PlayLayer::get()->getParent()->getChildByType(0) != nullptr + || PlayLayer::get()->getChildByType(0) != nullptr; } bool isCurrentPlayLayer() { - auto playLayer = getChildOfType(CCScene::get(), 0); - return playLayer != nullptr && playLayer == PlayLayer::get() && getChildOfType(playLayer, 0) == this; + auto playLayer = CCScene::get()->getChildByType(0); + return playLayer != nullptr && playLayer == PlayLayer::get() && playLayer->getChildByType(0) == this; } void pressKeyFallthrough(enumKeyCodes key, bool down) { diff --git a/src/main.cpp b/src/main.cpp index 6fb8a1f..bdd660b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -279,18 +278,18 @@ class ControllerChecker : public CCObject { } // Have to make a SettingValue even if it holds no value -class DummySettingValue : public SettingValue { +class DummySetting : public SettingBaseValue { public: - DummySettingValue(std::string const& key, std::string const& mod) : SettingValue(key, mod) {} - bool load(matjson::Value const& json) override { return true; } - bool save(matjson::Value&) const override { return true; } + static Result> parse(std::string const&, std::string const&, matjson::Value const&) { + return Ok(std::make_shared()); + }; SettingNode* createNode(float width) override; }; -class ButtonSettingNode : public SettingNode { +class ButtonSettingNode : public SettingValueNode { protected: - bool init(SettingValue* value, float width) { - if (!SettingNode::init(value)) + bool init(std::shared_ptr& setting, float width) { + if (!SettingValueNodeV3::init(setting, width)) return false; this->setContentSize({ width, 40.f }); @@ -308,12 +307,11 @@ class ButtonSettingNode : public SettingNode { KeybindsLayer::create()->show(); } public: - void commit() override { this->dispatchCommitted(); } - bool hasUncommittedChanges() override { return false; } - bool hasNonDefaultValue() override { return false; } - void resetToDefault() override {} + void updateState(CCNode* invoker) override { + SettingValueNodeV3::updateState(invoker); + } - static ButtonSettingNode* create(SettingValue* value, float width) { + static ButtonSettingNode* create(std::shared_ptr value, float width) { auto ret = new ButtonSettingNode(); if (ret && ret->init(value, width)) { ret->autorelease(); @@ -324,10 +322,10 @@ class ButtonSettingNode : public SettingNode { } }; -SettingNode* DummySettingValue::createNode(float width) { - return ButtonSettingNode::create(this, width); +SettingNode* DummySetting::createNode(float width) { + return ButtonSettingNode::create(std::static_pointer_cast(shared_from_this()), width); } $execute { - Mod::get()->registerCustomSetting("open-menu", std::make_unique(std::string("open-menu"), Mod::get()->getID())); + (void) Mod::get()->registerCustomSettingType("open-menu", &DummySetting::parse); }