Skip to content

Commit 52f82ba

Browse files
committed
builds on v4
1 parent 53615e9 commit 52f82ba

File tree

10 files changed

+62
-65
lines changed

10 files changed

+62
-65
lines changed

include/Keybinds.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <Geode/DefaultInclude.hpp>
4-
#include <Geode/utils/MiniFunction.hpp>
54
#include <Geode/utils/cocos.hpp>
65
#include <Geode/loader/Mod.hpp>
76
#include <Geode/loader/Event.hpp>
@@ -234,7 +233,7 @@ namespace keybinds {
234233
public:
235234
using Callback = geode::ListenerResult(InvokeBindEvent*);
236235

237-
geode::ListenerResult handle(geode::utils::MiniFunction<Callback> fn, InvokeBindEvent* event);
236+
geode::ListenerResult handle(std::function<Callback> fn, InvokeBindEvent* event);
238237
InvokeBindFilter(cocos2d::CCNode* target, ActionID const& id);
239238
};
240239

@@ -253,7 +252,7 @@ namespace keybinds {
253252
public:
254253
using Callback = geode::ListenerResult(PressBindEvent*);
255254

256-
geode::ListenerResult handle(geode::utils::MiniFunction<Callback> fn, PressBindEvent* event);
255+
geode::ListenerResult handle(std::function<Callback> fn, PressBindEvent* event);
257256
PressBindFilter();
258257
};
259258

@@ -276,7 +275,7 @@ namespace keybinds {
276275
public:
277276
using Callback = void(DeviceEvent*);
278277

279-
geode::ListenerResult handle(geode::utils::MiniFunction<Callback> fn, DeviceEvent* event);
278+
geode::ListenerResult handle(std::function<Callback> fn, DeviceEvent* event);
280279
DeviceFilter(std::optional<DeviceID> id = std::nullopt);
281280
};
282281

mod.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"geode": "3.6.0",
2+
"geode": "4.0.0",
33
"gd": {
4-
"win": "2.206",
4+
"win": "2.2073",
55
"android": "2.206"
66
},
77
"version": "v1.9.0",
@@ -29,7 +29,7 @@
2929
"incompatibilities": [],
3030
"settings": {
3131
"open-menu": {
32-
"type": "custom"
32+
"type": "custom:open-menu"
3333
}
3434
}
3535
}

src/ControllerBind.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ ControllerBind* ControllerBind::create(enumKeyCodes button) {
1515

1616
ControllerBind* ControllerBind::parse(matjson::Value const& value) {
1717
return ControllerBind::create(
18-
static_cast<enumKeyCodes>(value["button"].as_double())
18+
static_cast<enumKeyCodes>(value["button"].asInt().unwrapOr(0))
1919
);
2020
}
2121

2222
matjson::Value ControllerBind::save() const {
23-
return matjson::Object {
23+
return matjson::makeObject({
2424
{ "button", static_cast<int>(m_button) },
25-
};
25+
});
2626
}
2727

2828
enumKeyCodes ControllerBind::getButton() const {

src/Keybind.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ Keybind* Keybind::create(enumKeyCodes key, Modifier modifiers) {
1616

1717
Keybind* Keybind::parse(matjson::Value const& value) {
1818
return Keybind::create(
19-
static_cast<enumKeyCodes>(value["key"].as_int()),
20-
static_cast<Modifier>(value["modifiers"].as_int())
19+
static_cast<enumKeyCodes>(value["key"].asInt().unwrapOr(0)),
20+
static_cast<Modifier>(value["modifiers"].asInt().unwrapOr(0))
2121
);
2222
}
2323

2424
matjson::Value Keybind::save() const {
25-
return matjson::Object {
25+
return matjson::makeObject({
2626
{ "key", static_cast<int>(m_key) },
2727
{ "modifiers", static_cast<int>(m_modifiers) }
28-
};
28+
});
2929
}
3030

3131
enumKeyCodes Keybind::getKey() const {

src/Keybinds.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ bool InvokeBindEvent::isDown() const {
189189
return m_down;
190190
}
191191

192-
ListenerResult InvokeBindFilter::handle(utils::MiniFunction<Callback> fn, InvokeBindEvent* event) {
192+
ListenerResult InvokeBindFilter::handle(std::function<Callback> fn, InvokeBindEvent* event) {
193193
if (event->getID() == m_id) {
194194
return fn(event);
195195
}
@@ -211,7 +211,7 @@ bool PressBindEvent::isDown() const {
211211
return m_down;
212212
}
213213

214-
geode::ListenerResult PressBindFilter::handle(MiniFunction<Callback> fn, PressBindEvent* event) {
214+
geode::ListenerResult PressBindFilter::handle(std::function<Callback> fn, PressBindEvent* event) {
215215
return fn(event);
216216
}
217217

@@ -232,7 +232,7 @@ bool DeviceEvent::wasDetached() const {
232232
return !m_attached;
233233
}
234234

235-
ListenerResult DeviceFilter::handle(MiniFunction<Callback> fn, DeviceEvent* event) {
235+
ListenerResult DeviceFilter::handle(std::function<Callback> fn, DeviceEvent* event) {
236236
if (!m_id || m_id == event->getID()) {
237237
fn(event);
238238
}
@@ -309,7 +309,10 @@ matjson::Value BindManager::saveBind(Bind* bind) const {
309309

310310
Bind* BindManager::loadBind(matjson::Value const& json) const {
311311
try {
312-
auto device = json["device"].as_string();
312+
auto res = json["device"].asString();
313+
if (!res)
314+
return nullptr;
315+
auto device = res.unwrap();
313316
if (!m_devices.contains(device)) {
314317
return nullptr;
315318
}
@@ -321,9 +324,9 @@ Bind* BindManager::loadBind(matjson::Value const& json) const {
321324
}
322325

323326
bool BindManager::loadActionBinds(ActionID const& action) {
324-
try {
325-
auto value = Mod::get()->template getSavedValue<matjson::Object>(action);
326-
for (auto bind : value["binds"].as_array()) {
327+
auto inner = [&]() -> Result<> {
328+
auto value = Mod::get()->getSavedValue<matjson::Value>(action);
329+
for (auto bind : value["binds"]) {
327330
// try directly parsing the bind from a string if the device it's for
328331
// is already connected
329332
if (auto b = this->loadBind(bind)) {
@@ -334,9 +337,9 @@ bool BindManager::loadActionBinds(ActionID const& action) {
334337
else {
335338
// if device ID exists, then add this to the list of unbound
336339
// binds
337-
if (bind.contains("device")) {
340+
if (bind.contains("device") && bind["device"].isString()) {
338341
try {
339-
m_devicelessBinds[bind["device"].as_string()][action].insert(bind);
342+
m_devicelessBinds[bind["device"].asString().unwrap()][action].insert(bind);
340343
}
341344
catch(...) {}
342345
}
@@ -345,36 +348,34 @@ bool BindManager::loadActionBinds(ActionID const& action) {
345348
}
346349
// load repeat options
347350
if (value.contains("repeat")) {
348-
auto rep = value["repeat"].as_object();
351+
auto rep = value["repeat"];
349352
auto opts = RepeatOptions();
350-
opts.enabled = rep["enabled"].as_bool();
351-
opts.rate = rep["rate"].as_int();
352-
opts.delay = rep["delay"].as_int();
353+
GEODE_UNWRAP_INTO(opts.enabled, rep["enabled"].asBool());
354+
GEODE_UNWRAP_INTO(opts.rate, rep["rate"].asInt());
355+
GEODE_UNWRAP_INTO(opts.delay, rep["delay"].asInt());
353356
this->setRepeatOptionsFor(action, opts);
354357
}
355-
return true;
356-
}
357-
catch(...) {
358-
return false;
359-
}
358+
return Ok();
359+
};
360+
return inner().isOk();
360361
}
361362

362363
void BindManager::saveActionBinds(ActionID const& action) {
363-
auto obj = matjson::Object();
364-
auto binds = matjson::Array();
364+
auto obj = matjson::Value::object();
365+
auto binds = matjson::Value::array();
365366
for (auto& bind : this->getBindsFor(action)) {
366-
binds.push_back(this->saveBind(bind));
367+
binds.push(this->saveBind(bind));
367368
}
368369
for (auto& [device, actions] : m_devicelessBinds) {
369370
if (actions.contains(action)) {
370371
for (auto& bind : actions.at(action)) {
371-
binds.push_back(bind);
372+
binds.push(bind);
372373
}
373374
}
374375
}
375376
obj["binds"] = binds;
376377
if (auto opts = this->getRepeatOptionsFor(action)) {
377-
auto rep = matjson::Object();
378+
auto rep = matjson::Value::object();
378379
rep["enabled"] = opts.value().enabled;
379380
rep["rate"] = opts.value().rate;
380381
rep["delay"] = opts.value().delay;

src/KeybindsLayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ bool EditRepeatPopup::setup(BindableNode* node) {
257257
rateInput->setString(std::to_string(m_options.rate));
258258
rateInput->setCallback([this](std::string const& text) {
259259
if (auto num = numFromString<int>(text)) {
260-
m_options.rate = *num;
260+
m_options.rate = num.unwrap();
261261
}
262262
});
263263
rateInput->setScale(.75f);
@@ -272,7 +272,7 @@ bool EditRepeatPopup::setup(BindableNode* node) {
272272
delayInput->getInputNode()->setString(std::to_string(m_options.delay));
273273
delayInput->setCallback([this](std::string const& text) {
274274
if (auto num = numFromString<int>(text)) {
275-
m_options.delay = *num;
275+
m_options.delay = num.unwrap();
276276
}
277277
});
278278
delayInput->setScale(.75f);

src/KeybindsLayer.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <Geode/ui/Popup.hpp>
44
#include <Geode/ui/ScrollLayer.hpp>
5-
#include <Geode/ui/InputNode.hpp>
65
#include <Geode/binding/TextInputDelegate.hpp>
76
#include "../include/Keybinds.hpp"
87

src/MouseBind.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ MouseBind* MouseBind::create(MouseButton button, Modifier modifiers) {
1212
}
1313
MouseBind* MouseBind::parse(matjson::Value const& value) {
1414
return MouseBind::create(
15-
static_cast<MouseButton>(value["button"].as_int()),
16-
static_cast<Modifier>(value["modifiers"].as_int())
15+
static_cast<MouseButton>(value["button"].asInt().unwrapOrDefault()),
16+
static_cast<Modifier>(value["modifiers"].asInt().unwrapOrDefault())
1717
);
1818
}
1919

@@ -54,8 +54,8 @@ DeviceID MouseBind::getDeviceID() const {
5454
return "mouse"_spr;
5555
}
5656
matjson::Value MouseBind::save() const {
57-
return matjson::Object {
57+
return matjson::makeObject({
5858
{ "button", static_cast<int>(m_button) },
5959
{ "modifiers", static_cast<int>(m_modifiers) },
60-
};
60+
});
6161
}

src/UILayer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct $modify(PauseLayer) {
4949

5050
// Remove any popups (looking at you, confirm exit)
5151
CCScene* active = CCDirector::sharedDirector()->getRunningScene();
52-
if (auto alert = getChildOfType<FLAlertLayer>(active, 0)) {
52+
if (auto alert = active->getChildByType<FLAlertLayer>(0)) {
5353
return ListenerResult::Propagate;
5454
}
5555
this->onResume(nullptr);
@@ -96,13 +96,13 @@ struct $modify(UILayer) {
9696

9797
bool isPaused() {
9898
return !this->isCurrentPlayLayer()
99-
|| getChildOfType<PauseLayer>(PlayLayer::get()->getParent(), 0) != nullptr
100-
|| getChildOfType<GJDropDownLayer>(PlayLayer::get(), 0) != nullptr;
99+
|| PlayLayer::get()->getParent()->getChildByType<PauseLayer>(0) != nullptr
100+
|| PlayLayer::get()->getChildByType<GJDropDownLayer>(0) != nullptr;
101101
}
102102

103103
bool isCurrentPlayLayer() {
104-
auto playLayer = getChildOfType<PlayLayer>(CCScene::get(), 0);
105-
return playLayer != nullptr && playLayer == PlayLayer::get() && getChildOfType<UILayer>(playLayer, 0) == this;
104+
auto playLayer = CCScene::get()->getChildByType<PlayLayer>(0);
105+
return playLayer != nullptr && playLayer == PlayLayer::get() && playLayer->getChildByType<UILayer>(0) == this;
106106
}
107107

108108
void pressKeyFallthrough(enumKeyCodes key, bool down) {

src/main.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <Geode/binding/ButtonSprite.hpp>
66
#include <Geode/ui/Notification.hpp>
77
#include <Geode/modify/Modify.hpp>
8-
#include <Geode/loader/SettingNode.hpp>
98
#include <Geode/loader/Setting.hpp>
109
#include <Geode/cocos/robtop/keyboard_dispatcher/CCKeyboardDelegate.h>
1110
#include <Geode/cocos/robtop/keyboard_dispatcher/CCKeyboardDispatcher.h>
@@ -279,18 +278,18 @@ class ControllerChecker : public CCObject {
279278
}
280279

281280
// Have to make a SettingValue even if it holds no value
282-
class DummySettingValue : public SettingValue {
281+
class DummySetting : public SettingBaseValue<int> {
283282
public:
284-
DummySettingValue(std::string const& key, std::string const& mod) : SettingValue(key, mod) {}
285-
bool load(matjson::Value const& json) override { return true; }
286-
bool save(matjson::Value&) const override { return true; }
283+
static Result<std::shared_ptr<SettingV3>> parse(std::string const&, std::string const&, matjson::Value const&) {
284+
return Ok(std::make_shared<DummySetting>());
285+
};
287286
SettingNode* createNode(float width) override;
288287
};
289288

290-
class ButtonSettingNode : public SettingNode {
289+
class ButtonSettingNode : public SettingValueNode<DummySetting> {
291290
protected:
292-
bool init(SettingValue* value, float width) {
293-
if (!SettingNode::init(value))
291+
bool init(std::shared_ptr<DummySetting>& setting, float width) {
292+
if (!SettingValueNodeV3::init(setting, width))
294293
return false;
295294

296295
this->setContentSize({ width, 40.f });
@@ -308,12 +307,11 @@ class ButtonSettingNode : public SettingNode {
308307
KeybindsLayer::create()->show();
309308
}
310309
public:
311-
void commit() override { this->dispatchCommitted(); }
312-
bool hasUncommittedChanges() override { return false; }
313-
bool hasNonDefaultValue() override { return false; }
314-
void resetToDefault() override {}
310+
void updateState(CCNode* invoker) override {
311+
SettingValueNodeV3::updateState(invoker);
312+
}
315313

316-
static ButtonSettingNode* create(SettingValue* value, float width) {
314+
static ButtonSettingNode* create(std::shared_ptr<DummySetting> value, float width) {
317315
auto ret = new ButtonSettingNode();
318316
if (ret && ret->init(value, width)) {
319317
ret->autorelease();
@@ -324,10 +322,10 @@ class ButtonSettingNode : public SettingNode {
324322
}
325323
};
326324

327-
SettingNode* DummySettingValue::createNode(float width) {
328-
return ButtonSettingNode::create(this, width);
325+
SettingNode* DummySetting::createNode(float width) {
326+
return ButtonSettingNode::create(std::static_pointer_cast<DummySetting>(shared_from_this()), width);
329327
}
330328

331329
$execute {
332-
Mod::get()->registerCustomSetting("open-menu", std::make_unique<DummySettingValue>(std::string("open-menu"), Mod::get()->getID()));
330+
(void) Mod::get()->registerCustomSettingType("open-menu", &DummySetting::parse);
333331
}

0 commit comments

Comments
 (0)