mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 15:37:53 -05:00
remove minifunction
This commit is contained in:
parent
985b3aedb5
commit
bed622243b
49 changed files with 126 additions and 283 deletions
|
@ -12,5 +12,4 @@
|
||||||
#include "utils/permission.hpp"
|
#include "utils/permission.hpp"
|
||||||
#include "utils/general.hpp"
|
#include "utils/general.hpp"
|
||||||
#include "utils/timer.hpp"
|
#include "utils/timer.hpp"
|
||||||
#include "utils/MiniFunction.hpp"
|
|
||||||
#include "utils/ObjcHook.hpp"
|
#include "utils/ObjcHook.hpp"
|
||||||
|
|
|
@ -1095,7 +1095,7 @@ public:
|
||||||
template <class Filter, class... Args>
|
template <class Filter, class... Args>
|
||||||
geode::EventListenerProtocol* addEventListener(
|
geode::EventListenerProtocol* addEventListener(
|
||||||
std::string const& id,
|
std::string const& id,
|
||||||
geode::utils::MiniFunction<typename Filter::Callback> callback,
|
std::function<typename Filter::Callback> callback,
|
||||||
Args&&... args
|
Args&&... args
|
||||||
) {
|
) {
|
||||||
auto listener = new geode::EventListener<Filter>(
|
auto listener = new geode::EventListener<Filter>(
|
||||||
|
@ -1106,7 +1106,7 @@ public:
|
||||||
}
|
}
|
||||||
template <class Filter, class... Args>
|
template <class Filter, class... Args>
|
||||||
geode::EventListenerProtocol* addEventListener(
|
geode::EventListenerProtocol* addEventListener(
|
||||||
geode::utils::MiniFunction<typename Filter::Callback> callback,
|
std::function<typename Filter::Callback> callback,
|
||||||
Args&&... args
|
Args&&... args
|
||||||
) {
|
) {
|
||||||
return this->addEventListener<Filter, Args...>(
|
return this->addEventListener<Filter, Args...>(
|
||||||
|
@ -1916,7 +1916,7 @@ namespace geode {
|
||||||
std::string m_targetID;
|
std::string m_targetID;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, UserObjectSetEvent* event);
|
ListenerResult handle(std::function<Callback> fn, UserObjectSetEvent* event);
|
||||||
|
|
||||||
AttributeSetFilter(std::string const& id);
|
AttributeSetFilter(std::string const& id);
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace geode {
|
||||||
return dispatchPools()[m_id];
|
return dispatchPools()[m_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, Ev* event) {
|
ListenerResult handle(std::function<Callback> fn, Ev* event) {
|
||||||
if (event->getID() == m_id) {
|
if (event->getID() == m_id) {
|
||||||
return std::apply(fn, event->getArgs());
|
return std::apply(fn, event->getArgs());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../utils/casts.hpp"
|
#include "../utils/casts.hpp"
|
||||||
#include "../utils/MiniFunction.hpp"
|
|
||||||
|
|
||||||
#include <Geode/DefaultInclude.hpp>
|
#include <Geode/DefaultInclude.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -103,7 +102,7 @@ namespace geode {
|
||||||
using Callback = ListenerResult(T*);
|
using Callback = ListenerResult(T*);
|
||||||
using Event = T;
|
using Event = T;
|
||||||
|
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, T* e) {
|
ListenerResult handle(std::function<Callback> fn, T* e) {
|
||||||
return fn(e);
|
return fn(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +155,7 @@ namespace geode {
|
||||||
this->enable();
|
this->enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
EventListener(utils::MiniFunction<Callback> fn, T filter = T())
|
EventListener(std::function<Callback> fn, T filter = T())
|
||||||
: m_callback(fn), m_filter(filter)
|
: m_callback(fn), m_filter(filter)
|
||||||
{
|
{
|
||||||
m_filter.setListener(this);
|
m_filter.setListener(this);
|
||||||
|
@ -193,10 +192,7 @@ namespace geode {
|
||||||
this->enable();
|
this->enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bind(utils::MiniFunction<Callback> const& fn) {
|
void bind(std::function<Callback> fn) {
|
||||||
m_callback = fn;
|
|
||||||
}
|
|
||||||
void bind(utils::MiniFunction<Callback>&& fn) {
|
|
||||||
m_callback = fn;
|
m_callback = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,12 +214,12 @@ namespace geode {
|
||||||
return m_filter;
|
return m_filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::MiniFunction<Callback>& getCallback() {
|
std::function<Callback>& getCallback() {
|
||||||
return m_callback;
|
return m_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
utils::MiniFunction<Callback> m_callback = nullptr;
|
std::function<Callback> m_callback = nullptr;
|
||||||
T m_filter;
|
T m_filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace geode::ipc {
|
||||||
std::string m_messageID;
|
std::string m_messageID;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, IPCEvent* event);
|
ListenerResult handle(std::function<Callback> fn, IPCEvent* event);
|
||||||
IPCFilter(
|
IPCFilter(
|
||||||
std::string const& modID,
|
std::string const& modID,
|
||||||
std::string const& messageID
|
std::string const& messageID
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "../utils/Result.hpp"
|
#include "../utils/Result.hpp"
|
||||||
#include "../utils/MiniFunction.hpp"
|
|
||||||
#include "Log.hpp"
|
#include "Log.hpp"
|
||||||
#include "ModEvent.hpp"
|
#include "ModEvent.hpp"
|
||||||
#include "ModMetadata.hpp"
|
#include "ModMetadata.hpp"
|
||||||
|
@ -15,7 +14,7 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace geode {
|
namespace geode {
|
||||||
using ScheduledFunction = utils::MiniFunction<void()>;
|
using ScheduledFunction = std::function<void()>;
|
||||||
|
|
||||||
struct InvalidGeodeFile {
|
struct InvalidGeodeFile {
|
||||||
std::filesystem::path path;
|
std::filesystem::path path;
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace geode {
|
||||||
Mod* m_mod;
|
Mod* m_mod;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, ModStateEvent* event);
|
ListenerResult handle(std::function<Callback> fn, ModStateEvent* event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a mod state listener
|
* Create a mod state listener
|
||||||
|
|
|
@ -658,7 +658,7 @@ namespace geode {
|
||||||
public:
|
public:
|
||||||
using Callback = void(std::shared_ptr<SettingV3>);
|
using Callback = void(std::shared_ptr<SettingV3>);
|
||||||
|
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, SettingChangedEventV3* event);
|
ListenerResult handle(std::function<Callback> fn, SettingChangedEventV3* event);
|
||||||
/**
|
/**
|
||||||
* Listen to changes on a setting, or all settings
|
* Listen to changes on a setting, or all settings
|
||||||
* @param modID Mod whose settings to listen to
|
* @param modID Mod whose settings to listen to
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../utils/MiniFunction.hpp"
|
|
||||||
#include "Traits.hpp"
|
#include "Traits.hpp"
|
||||||
|
|
||||||
#include <Geode/loader/Loader.hpp>
|
#include <Geode/loader/Loader.hpp>
|
||||||
|
@ -20,7 +19,7 @@ namespace geode::modifier {
|
||||||
class FieldContainer {
|
class FieldContainer {
|
||||||
private:
|
private:
|
||||||
std::vector<void*> m_containedFields;
|
std::vector<void*> m_containedFields;
|
||||||
std::vector<utils::MiniFunction<void(void*)>> m_destructorFunctions;
|
std::vector<std::function<void(void*)>> m_destructorFunctions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~FieldContainer() {
|
~FieldContainer() {
|
||||||
|
@ -40,9 +39,9 @@ namespace geode::modifier {
|
||||||
return m_containedFields.at(index);
|
return m_containedFields.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* setField(size_t index, size_t size, utils::MiniFunction<void(void*)> destructor) {
|
void* setField(size_t index, size_t size, std::function<void(void*)> destructor) {
|
||||||
m_containedFields.at(index) = operator new(size);
|
m_containedFields.at(index) = operator new(size);
|
||||||
m_destructorFunctions.at(index) = destructor;
|
m_destructorFunctions.at(index) = std::move(destructor);
|
||||||
return m_containedFields.at(index);
|
return m_containedFields.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace geode {
|
||||||
std::optional<std::string> m_targetID;
|
std::optional<std::string> m_targetID;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, AEnterLayerEvent* event);
|
ListenerResult handle(std::function<Callback> fn, AEnterLayerEvent* event);
|
||||||
|
|
||||||
AEnterLayerFilter(
|
AEnterLayerFilter(
|
||||||
std::optional<std::string> const& id
|
std::optional<std::string> const& id
|
||||||
|
@ -63,7 +63,7 @@ namespace geode {
|
||||||
std::optional<std::string> m_targetID;
|
std::optional<std::string> m_targetID;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, EnterLayerEvent<N>* event) {
|
ListenerResult handle(std::function<Callback> fn, EnterLayerEvent<N>* event) {
|
||||||
if (m_targetID == event->getID()) {
|
if (m_targetID == event->getID()) {
|
||||||
fn(static_cast<T*>(event));
|
fn(static_cast<T*>(event));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,13 @@ namespace geode {
|
||||||
class GEODE_DLL MDPopup :
|
class GEODE_DLL MDPopup :
|
||||||
public Popup<
|
public Popup<
|
||||||
std::string const&, std::string const&, char const*, char const*,
|
std::string const&, std::string const&, char const*, char const*,
|
||||||
utils::MiniFunction<void(bool)>> {
|
std::function<void(bool)>> {
|
||||||
protected:
|
protected:
|
||||||
utils::MiniFunction<void(bool)> m_onClick = nullptr;
|
std::function<void(bool)> m_onClick = nullptr;
|
||||||
|
|
||||||
bool setup(
|
bool setup(
|
||||||
std::string const& title, std::string const& info, char const* btn1, char const* btn2,
|
std::string const& title, std::string const& info, char const* btn1, char const* btn2,
|
||||||
utils::MiniFunction<void(bool)> onClick
|
std::function<void(bool)> onClick
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
void onBtn(CCObject*);
|
void onBtn(CCObject*);
|
||||||
|
@ -27,7 +27,7 @@ namespace geode {
|
||||||
public:
|
public:
|
||||||
static MDPopup* create(
|
static MDPopup* create(
|
||||||
std::string const& title, std::string const& content, char const* btn1,
|
std::string const& title, std::string const& content, char const* btn1,
|
||||||
char const* btn2 = nullptr, utils::MiniFunction<void(bool)> onClick = nullptr
|
char const* btn2 = nullptr, std::function<void(bool)> onClick = nullptr
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
|
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
|
||||||
#include <Geode/binding/FLAlertLayer.hpp>
|
#include <Geode/binding/FLAlertLayer.hpp>
|
||||||
#include <Geode/utils/MiniFunction.hpp>
|
|
||||||
#include <Geode/utils/cocos.hpp>
|
#include <Geode/utils/cocos.hpp>
|
||||||
#include <Geode/ui/Layout.hpp>
|
#include <Geode/ui/Layout.hpp>
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ namespace geode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, CloseEvent* event) {
|
ListenerResult handle(std::function<Callback> fn, CloseEvent* event) {
|
||||||
if (event->getPopup() == m_impl->popup) {
|
if (event->getPopup() == m_impl->popup) {
|
||||||
fn(event);
|
fn(event);
|
||||||
}
|
}
|
||||||
|
@ -214,21 +213,21 @@ namespace geode {
|
||||||
|
|
||||||
GEODE_DLL FLAlertLayer* createQuickPopup(
|
GEODE_DLL FLAlertLayer* createQuickPopup(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||||
utils::MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow = true
|
std::function<void(FLAlertLayer*, bool)> selected, bool doShow = true
|
||||||
);
|
);
|
||||||
|
|
||||||
GEODE_DLL FLAlertLayer* createQuickPopup(
|
GEODE_DLL FLAlertLayer* createQuickPopup(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||||
float width, utils::MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow = true
|
float width, std::function<void(FLAlertLayer*, bool)> selected, bool doShow = true
|
||||||
);
|
);
|
||||||
|
|
||||||
GEODE_DLL FLAlertLayer* createQuickPopup(
|
GEODE_DLL FLAlertLayer* createQuickPopup(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||||
utils::MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow, bool cancelledByEscape
|
std::function<void(FLAlertLayer*, bool)> selected, bool doShow, bool cancelledByEscape
|
||||||
);
|
);
|
||||||
|
|
||||||
GEODE_DLL FLAlertLayer* createQuickPopup(
|
GEODE_DLL FLAlertLayer* createQuickPopup(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||||
float width, utils::MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow, bool cancelledByEscape
|
float width, std::function<void(FLAlertLayer*, bool)> selected, bool doShow, bool cancelledByEscape
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,13 @@ namespace geode {
|
||||||
protected:
|
protected:
|
||||||
std::vector<T> m_list;
|
std::vector<T> m_list;
|
||||||
size_t m_index = 0;
|
size_t m_index = 0;
|
||||||
utils::MiniFunction<void(T const&, size_t)> m_onChange;
|
std::function<void(T const&, size_t)> m_onChange;
|
||||||
cocos2d::CCLabelBMFont* m_label;
|
cocos2d::CCLabelBMFont* m_label;
|
||||||
CCMenuItemSpriteExtra* m_prevBtn;
|
CCMenuItemSpriteExtra* m_prevBtn;
|
||||||
CCMenuItemSpriteExtra* m_nextBtn;
|
CCMenuItemSpriteExtra* m_nextBtn;
|
||||||
|
|
||||||
bool init(
|
bool init(
|
||||||
float width, std::vector<T> const& list, utils::MiniFunction<void(T const&, size_t)> onChange
|
float width, std::vector<T> const& list, std::function<void(T const&, size_t)> onChange
|
||||||
) {
|
) {
|
||||||
if (!cocos2d::CCMenu::init()) return false;
|
if (!cocos2d::CCMenu::init()) return false;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ namespace geode {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static SelectList* create(
|
static SelectList* create(
|
||||||
float width, std::vector<T> const& list, utils::MiniFunction<void(T const&, size_t)> onChange
|
float width, std::vector<T> const& list, std::function<void(T const&, size_t)> onChange
|
||||||
) {
|
) {
|
||||||
auto ret = new SelectList();
|
auto ret = new SelectList();
|
||||||
if (ret->init(width, list, onChange)) {
|
if (ret->init(width, list, onChange)) {
|
||||||
|
|
|
@ -122,7 +122,7 @@ namespace geode {
|
||||||
* to distinguish between bold, italic and
|
* to distinguish between bold, italic and
|
||||||
* regular text.
|
* regular text.
|
||||||
*/
|
*/
|
||||||
using Font = utils::MiniFunction<Label(int)>;
|
using Font = std::function<Label(int)>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
cocos2d::CCPoint m_origin = cocos2d::CCPointZero;
|
cocos2d::CCPoint m_origin = cocos2d::CCPointZero;
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace geode {
|
||||||
std::string m_id;
|
std::string m_id;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, ColorProvidedEvent* event);
|
ListenerResult handle(std::function<Callback> fn, ColorProvidedEvent* event);
|
||||||
|
|
||||||
ColorProvidedFilter(std::string const& id);
|
ColorProvidedFilter(std::string const& id);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "../loader/Log.hpp"
|
#include "../loader/Log.hpp"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <Geode/utils/MiniFunction.hpp>
|
|
||||||
#include <Geode/utils/Result.hpp>
|
#include <Geode/utils/Result.hpp>
|
||||||
|
|
||||||
namespace geode {
|
namespace geode {
|
||||||
|
@ -73,7 +72,7 @@ namespace geode {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
using JsonValueValidator = utils::MiniFunction<bool(T const&)>;
|
using JsonValueValidator = std::function<bool(T const&)>;
|
||||||
|
|
||||||
struct JsonMaybeObject;
|
struct JsonMaybeObject;
|
||||||
struct JsonMaybeValue;
|
struct JsonMaybeValue;
|
||||||
|
|
|
@ -1,141 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Geode/DefaultInclude.hpp>
|
|
||||||
#include <memory>
|
|
||||||
#include <concepts>
|
|
||||||
#include "terminate.hpp"
|
|
||||||
|
|
||||||
namespace geode::utils {
|
|
||||||
|
|
||||||
template <class FunctionType>
|
|
||||||
class MiniFunction;
|
|
||||||
|
|
||||||
template <class Ret, class... Args>
|
|
||||||
class MiniFunctionStateBase {
|
|
||||||
public:
|
|
||||||
virtual ~MiniFunctionStateBase() = default;
|
|
||||||
virtual Ret call(Args... args) const = 0;
|
|
||||||
virtual MiniFunctionStateBase* clone() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Type, class Ret, class... Args>
|
|
||||||
class MiniFunctionState final : public MiniFunctionStateBase<Ret, Args...> {
|
|
||||||
public:
|
|
||||||
Type m_func;
|
|
||||||
|
|
||||||
explicit MiniFunctionState(Type func) : m_func(func) {}
|
|
||||||
|
|
||||||
Ret call(Args... args) const override {
|
|
||||||
return const_cast<Type&>(m_func)(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
MiniFunctionStateBase<Ret, Args...>* clone() const override {
|
|
||||||
return new MiniFunctionState(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Type, class Ret, class... Args>
|
|
||||||
class MiniFunctionStatePointer final : public MiniFunctionStateBase<Ret, Args...> {
|
|
||||||
public:
|
|
||||||
Type m_func;
|
|
||||||
|
|
||||||
explicit MiniFunctionStatePointer(Type func) : m_func(func) {}
|
|
||||||
|
|
||||||
Ret call(Args... args) const override {
|
|
||||||
return const_cast<Type&>(*m_func)(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
MiniFunctionStateBase<Ret, Args...>* clone() const override {
|
|
||||||
return new MiniFunctionStatePointer(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Type, class Ret, class Class, class... Args>
|
|
||||||
class MiniFunctionStateMemberPointer final : public MiniFunctionStateBase<Ret, Class, Args...> {
|
|
||||||
public:
|
|
||||||
Type m_func;
|
|
||||||
|
|
||||||
explicit MiniFunctionStateMemberPointer(Type func) : m_func(func) {}
|
|
||||||
|
|
||||||
Ret call(Class self, Args... args) const override {
|
|
||||||
return const_cast<Type&>(self->*m_func)(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
MiniFunctionStateBase<Ret, Class, Args...>* clone() const override {
|
|
||||||
return new MiniFunctionStateMemberPointer(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Callable, class Ret, class... Args>
|
|
||||||
concept MiniFunctionCallable = requires(Callable&& func, Args... args) {
|
|
||||||
{ func(std::forward<Args>(args)...) } -> std::same_as<Ret>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Ret, class... Args>
|
|
||||||
class MiniFunction<Ret(Args...)> {
|
|
||||||
public:
|
|
||||||
using FunctionType = Ret(Args...);
|
|
||||||
using StateType = MiniFunctionStateBase<Ret, Args...>;
|
|
||||||
|
|
||||||
private:
|
|
||||||
StateType* m_state;
|
|
||||||
|
|
||||||
public:
|
|
||||||
MiniFunction() : m_state(nullptr) {}
|
|
||||||
|
|
||||||
MiniFunction(std::nullptr_t) : MiniFunction() {}
|
|
||||||
|
|
||||||
MiniFunction(MiniFunction const& other) :
|
|
||||||
m_state(other.m_state ? other.m_state->clone() : nullptr) {}
|
|
||||||
|
|
||||||
MiniFunction(MiniFunction&& other) : m_state(other.m_state) {
|
|
||||||
other.m_state = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
~MiniFunction() {
|
|
||||||
if (m_state) delete m_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Callable>
|
|
||||||
requires(MiniFunctionCallable<Callable, Ret, Args...> && !std::is_same_v<std::decay_t<Callable>, MiniFunction<FunctionType>>)
|
|
||||||
MiniFunction(Callable&& func) :
|
|
||||||
m_state(new MiniFunctionState<std::decay_t<Callable>, Ret, Args...>(std::forward<Callable>(func))) {}
|
|
||||||
|
|
||||||
template <class FunctionPointer>
|
|
||||||
requires(!MiniFunctionCallable<FunctionPointer, Ret, Args...> && std::is_pointer_v<FunctionPointer> && std::is_function_v<std::remove_pointer_t<FunctionPointer>>)
|
|
||||||
MiniFunction(FunctionPointer func) :
|
|
||||||
m_state(new MiniFunctionStatePointer<FunctionPointer, Ret, Args...>(func)) {}
|
|
||||||
|
|
||||||
template <class MemberFunctionPointer>
|
|
||||||
requires(std::is_member_function_pointer_v<MemberFunctionPointer>)
|
|
||||||
MiniFunction(MemberFunctionPointer func) :
|
|
||||||
m_state(new MiniFunctionStateMemberPointer<MemberFunctionPointer, Ret, Args...>(func)) {}
|
|
||||||
|
|
||||||
MiniFunction& operator=(MiniFunction const& other) {
|
|
||||||
if (m_state) delete m_state;
|
|
||||||
m_state = other.m_state ? other.m_state->clone() : nullptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
MiniFunction& operator=(MiniFunction&& other) {
|
|
||||||
if (m_state) delete m_state;
|
|
||||||
m_state = other.m_state;
|
|
||||||
other.m_state = nullptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ret operator()(Args... args) const {
|
|
||||||
if (!m_state) {
|
|
||||||
utils::terminate(
|
|
||||||
"Attempted to call a MiniFunction that was never assigned "
|
|
||||||
"any function, or one that has been moved"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return m_state->call(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit operator bool() const {
|
|
||||||
return m_state;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "general.hpp"
|
#include "general.hpp"
|
||||||
#include "MiniFunction.hpp"
|
|
||||||
#include "../loader/Event.hpp"
|
#include "../loader/Event.hpp"
|
||||||
#include "../loader/Loader.hpp"
|
#include "../loader/Loader.hpp"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -249,11 +248,11 @@ namespace geode {
|
||||||
|
|
||||||
using Value = T;
|
using Value = T;
|
||||||
using Progress = P;
|
using Progress = P;
|
||||||
using PostResult = utils::MiniFunction<void(Result)>;
|
using PostResult = std::function<void(Result)>;
|
||||||
using PostProgress = utils::MiniFunction<void(P)>;
|
using PostProgress = std::function<void(P)>;
|
||||||
using HasBeenCancelled = utils::MiniFunction<bool()>;
|
using HasBeenCancelled = std::function<bool()>;
|
||||||
using Run = utils::MiniFunction<Result(PostProgress, HasBeenCancelled)>;
|
using Run = std::function<Result(PostProgress, HasBeenCancelled)>;
|
||||||
using RunWithCallback = utils::MiniFunction<void(PostResult, PostProgress, HasBeenCancelled)>;
|
using RunWithCallback = std::function<void(PostResult, PostProgress, HasBeenCancelled)>;
|
||||||
|
|
||||||
using Callback = void(Event*);
|
using Callback = void(Event*);
|
||||||
|
|
||||||
|
@ -752,7 +751,7 @@ namespace geode {
|
||||||
this->listen(std::move(onResult), [](auto const&) {}, [] {});
|
this->listen(std::move(onResult), [](auto const&) {}, [] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, Event* e) {
|
ListenerResult handle(std::function<Callback> fn, Event* e) {
|
||||||
if (e->m_handle == m_handle && (!e->m_for || e->m_for == m_listener)) {
|
if (e->m_handle == m_handle && (!e->m_for || e->m_for == m_listener)) {
|
||||||
fn(e);
|
fn(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include "../loader/Event.hpp"
|
#include "../loader/Event.hpp"
|
||||||
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
|
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
|
||||||
#include <Geode/binding/CCMenuItemToggler.hpp>
|
#include <Geode/binding/CCMenuItemToggler.hpp>
|
||||||
#include "MiniFunction.hpp"
|
|
||||||
|
|
||||||
// support converting ccColor3B / ccColor4B to / from json
|
// support converting ccColor3B / ccColor4B to / from json
|
||||||
|
|
||||||
|
@ -658,7 +657,7 @@ namespace geode::cocos {
|
||||||
*/
|
*/
|
||||||
GEODE_DLL cocos2d::CCScene* switchToScene(cocos2d::CCLayer* layer);
|
GEODE_DLL cocos2d::CCScene* switchToScene(cocos2d::CCLayer* layer);
|
||||||
|
|
||||||
using CreateLayerFunc = utils::MiniFunction<cocos2d::CCLayer*()>;
|
using CreateLayerFunc = std::function<cocos2d::CCLayer*()>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reload textures, overwriting the scene to return to after the loading
|
* Reload textures, overwriting the scene to return to after the loading
|
||||||
|
@ -726,7 +725,7 @@ namespace geode::cocos {
|
||||||
* there is none
|
* there is none
|
||||||
*/
|
*/
|
||||||
template <class Type = cocos2d::CCNode>
|
template <class Type = cocos2d::CCNode>
|
||||||
Type* findFirstChildRecursive(cocos2d::CCNode* node, utils::MiniFunction<bool(Type*)> predicate) {
|
Type* findFirstChildRecursive(cocos2d::CCNode* node, std::function<bool(Type*)> predicate) {
|
||||||
if (cast::typeinfo_cast<Type*>(node) && predicate(static_cast<Type*>(node)))
|
if (cast::typeinfo_cast<Type*>(node) && predicate(static_cast<Type*>(node)))
|
||||||
return static_cast<Type*>(node);
|
return static_cast<Type*>(node);
|
||||||
|
|
||||||
|
@ -880,7 +879,7 @@ namespace geode::cocos {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename C, typename = std::enable_if_t<std::is_pointer_v<C>>>
|
template <typename T, typename C, typename = std::enable_if_t<std::is_pointer_v<C>>>
|
||||||
static cocos2d::CCArray* vectorToCCArray(std::vector<T> const& vec, utils::MiniFunction<C(T)> convFunc) {
|
static cocos2d::CCArray* vectorToCCArray(std::vector<T> const& vec, std::function<C(T)> convFunc) {
|
||||||
auto res = cocos2d::CCArray::createWithCapacity(vec.size());
|
auto res = cocos2d::CCArray::createWithCapacity(vec.size());
|
||||||
for (auto const& item : vec)
|
for (auto const& item : vec)
|
||||||
res->addObject(convFunc(item));
|
res->addObject(convFunc(item));
|
||||||
|
@ -907,7 +906,7 @@ namespace geode::cocos {
|
||||||
template <
|
template <
|
||||||
typename K, typename V, typename C,
|
typename K, typename V, typename C,
|
||||||
typename = std::enable_if_t<std::is_same_v<C, std::string> || std::is_same_v<C, intptr_t>>>
|
typename = std::enable_if_t<std::is_same_v<C, std::string> || std::is_same_v<C, intptr_t>>>
|
||||||
static cocos2d::CCDictionary* mapToCCDict(std::map<K, V> const& map, utils::MiniFunction<C(K)> convFunc) {
|
static cocos2d::CCDictionary* mapToCCDict(std::map<K, V> const& map, std::function<C(K)> convFunc) {
|
||||||
auto res = cocos2d::CCDictionary::create();
|
auto res = cocos2d::CCDictionary::create();
|
||||||
for (auto const& [key, value] : map)
|
for (auto const& [key, value] : map)
|
||||||
res->setObject(value, convFunc(key));
|
res->setObject(value, convFunc(key));
|
||||||
|
@ -1180,11 +1179,11 @@ namespace geode::cocos {
|
||||||
template <class Node>
|
template <class Node>
|
||||||
class LambdaCallback : public cocos2d::CCObject {
|
class LambdaCallback : public cocos2d::CCObject {
|
||||||
public:
|
public:
|
||||||
utils::MiniFunction<void(Node*)> m_callback;
|
std::function<void(Node*)> m_callback;
|
||||||
|
|
||||||
static LambdaCallback* create(utils::MiniFunction<void(Node*)>&& callback) {
|
static LambdaCallback* create(std::function<void(Node*)> callback) {
|
||||||
auto ret = new (std::nothrow) LambdaCallback();
|
auto ret = new (std::nothrow) LambdaCallback();
|
||||||
if (ret->init(std::forward<std::remove_reference_t<decltype(callback)>>(callback))) {
|
if (ret->init(std::move(callback))) {
|
||||||
ret->autorelease();
|
ret->autorelease();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1192,8 +1191,8 @@ namespace geode::cocos {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init(utils::MiniFunction<void(Node*)>&& callback) {
|
bool init(std::function<void(Node*)> callback) {
|
||||||
m_callback = std::forward<std::remove_reference_t<decltype(callback)>>(callback);
|
m_callback = std::move(callback);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1204,20 +1203,20 @@ namespace geode::cocos {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static cocos2d::CCMenuItem* create(
|
static cocos2d::CCMenuItem* create(
|
||||||
utils::MiniFunction<void(cocos2d::CCMenuItem*)>&& callback
|
std::function<void(cocos2d::CCMenuItem*)> callback
|
||||||
) {
|
) {
|
||||||
auto item = cocos2d::CCMenuItem::create();
|
auto item = cocos2d::CCMenuItem::create();
|
||||||
assignCallback(item, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
assignCallback(item, std::move(callback));
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cocos2d::CCMenuItemSprite* createSprite(
|
static cocos2d::CCMenuItemSprite* createSprite(
|
||||||
cocos2d::CCNode* normalSprite,
|
cocos2d::CCNode* normalSprite,
|
||||||
cocos2d::CCNode* selectedSprite,
|
cocos2d::CCNode* selectedSprite,
|
||||||
utils::MiniFunction<void(cocos2d::CCMenuItemSprite*)>&& callback
|
std::function<void(cocos2d::CCMenuItemSprite*)> callback
|
||||||
) {
|
) {
|
||||||
auto item = cocos2d::CCMenuItemSprite::create(normalSprite, selectedSprite);
|
auto item = cocos2d::CCMenuItemSprite::create(normalSprite, selectedSprite);
|
||||||
assignCallback(item, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
assignCallback(item, std::move(callback));
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1225,57 +1224,57 @@ namespace geode::cocos {
|
||||||
cocos2d::CCNode* normalSprite,
|
cocos2d::CCNode* normalSprite,
|
||||||
cocos2d::CCNode* selectedSprite,
|
cocos2d::CCNode* selectedSprite,
|
||||||
cocos2d::CCNode* disabledSprite,
|
cocos2d::CCNode* disabledSprite,
|
||||||
utils::MiniFunction<void(cocos2d::CCMenuItemSprite*)>&& callback
|
std::function<void(cocos2d::CCMenuItemSprite*)> callback
|
||||||
) {
|
) {
|
||||||
auto item = cocos2d::CCMenuItemSprite::create(normalSprite, selectedSprite, disabledSprite);
|
auto item = cocos2d::CCMenuItemSprite::create(normalSprite, selectedSprite, disabledSprite);
|
||||||
assignCallback(item, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
assignCallback(item, std::move(callback));
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CCMenuItemSpriteExtra* createSpriteExtra(
|
static CCMenuItemSpriteExtra* createSpriteExtra(
|
||||||
cocos2d::CCNode* normalSprite,
|
cocos2d::CCNode* normalSprite,
|
||||||
utils::MiniFunction<void(CCMenuItemSpriteExtra*)>&& callback
|
std::function<void(CCMenuItemSpriteExtra*)> callback
|
||||||
) {
|
) {
|
||||||
auto item = CCMenuItemSpriteExtra::create(normalSprite, nullptr, nullptr);
|
auto item = CCMenuItemSpriteExtra::create(normalSprite, nullptr, nullptr);
|
||||||
assignCallback(item, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
assignCallback(item, std::move(callback));
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CCMenuItemSpriteExtra* createSpriteExtraWithFilename(
|
static CCMenuItemSpriteExtra* createSpriteExtraWithFilename(
|
||||||
std::string_view normalSpriteName,
|
std::string_view normalSpriteName,
|
||||||
float scale,
|
float scale,
|
||||||
utils::MiniFunction<void(CCMenuItemSpriteExtra*)>&& callback
|
std::function<void(CCMenuItemSpriteExtra*)> callback
|
||||||
) {
|
) {
|
||||||
auto sprite = cocos2d::CCSprite::create(normalSpriteName.data());
|
auto sprite = cocos2d::CCSprite::create(normalSpriteName.data());
|
||||||
sprite->setScale(scale);
|
sprite->setScale(scale);
|
||||||
|
|
||||||
return createSpriteExtra(sprite, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
return createSpriteExtra(sprite, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
static CCMenuItemSpriteExtra* createSpriteExtraWithFrameName(
|
static CCMenuItemSpriteExtra* createSpriteExtraWithFrameName(
|
||||||
std::string_view normalSpriteName,
|
std::string_view normalSpriteName,
|
||||||
float scale,
|
float scale,
|
||||||
utils::MiniFunction<void(CCMenuItemSpriteExtra*)>&& callback
|
std::function<void(CCMenuItemSpriteExtra*)> callback
|
||||||
) {
|
) {
|
||||||
auto sprite = cocos2d::CCSprite::createWithSpriteFrameName(normalSpriteName.data());
|
auto sprite = cocos2d::CCSprite::createWithSpriteFrameName(normalSpriteName.data());
|
||||||
sprite->setScale(scale);
|
sprite->setScale(scale);
|
||||||
|
|
||||||
return createSpriteExtra(sprite, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
return createSpriteExtra(sprite, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
static CCMenuItemToggler* createToggler(
|
static CCMenuItemToggler* createToggler(
|
||||||
cocos2d::CCNode* onSprite,
|
cocos2d::CCNode* onSprite,
|
||||||
cocos2d::CCNode* offSprite,
|
cocos2d::CCNode* offSprite,
|
||||||
utils::MiniFunction<void(CCMenuItemToggler*)>&& callback
|
std::function<void(CCMenuItemToggler*)> callback
|
||||||
) {
|
) {
|
||||||
auto item = CCMenuItemToggler::create(offSprite, onSprite, nullptr, nullptr);
|
auto item = CCMenuItemToggler::create(offSprite, onSprite, nullptr, nullptr);
|
||||||
assignCallback(item, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
assignCallback(item, std::move(callback));
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CCMenuItemToggler* createTogglerWithStandardSprites(
|
static CCMenuItemToggler* createTogglerWithStandardSprites(
|
||||||
float scale,
|
float scale,
|
||||||
utils::MiniFunction<void(CCMenuItemToggler*)>&& callback
|
std::function<void(CCMenuItemToggler*)> callback
|
||||||
) {
|
) {
|
||||||
auto offSprite = cocos2d::CCSprite::createWithSpriteFrameName("GJ_checkOff_001.png");
|
auto offSprite = cocos2d::CCSprite::createWithSpriteFrameName("GJ_checkOff_001.png");
|
||||||
auto onSprite = cocos2d::CCSprite::createWithSpriteFrameName("GJ_checkOn_001.png");
|
auto onSprite = cocos2d::CCSprite::createWithSpriteFrameName("GJ_checkOn_001.png");
|
||||||
|
@ -1283,14 +1282,14 @@ namespace geode::cocos {
|
||||||
offSprite->setScale(scale);
|
offSprite->setScale(scale);
|
||||||
onSprite->setScale(scale);
|
onSprite->setScale(scale);
|
||||||
|
|
||||||
return createToggler(onSprite, offSprite, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
return createToggler(onSprite, offSprite, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
static CCMenuItemToggler* createTogglerWithFilename(
|
static CCMenuItemToggler* createTogglerWithFilename(
|
||||||
std::string_view onSpriteName,
|
std::string_view onSpriteName,
|
||||||
std::string_view offSpriteName,
|
std::string_view offSpriteName,
|
||||||
float scale,
|
float scale,
|
||||||
utils::MiniFunction<void(CCMenuItemToggler*)>&& callback
|
std::function<void(CCMenuItemToggler*)> callback
|
||||||
) {
|
) {
|
||||||
auto offSprite = cocos2d::CCSprite::create(offSpriteName.data());
|
auto offSprite = cocos2d::CCSprite::create(offSpriteName.data());
|
||||||
auto onSprite = cocos2d::CCSprite::create(onSpriteName.data());
|
auto onSprite = cocos2d::CCSprite::create(onSpriteName.data());
|
||||||
|
@ -1298,14 +1297,14 @@ namespace geode::cocos {
|
||||||
offSprite->setScale(scale);
|
offSprite->setScale(scale);
|
||||||
onSprite->setScale(scale);
|
onSprite->setScale(scale);
|
||||||
|
|
||||||
return createToggler(onSprite, offSprite, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
return createToggler(onSprite, offSprite, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
static CCMenuItemToggler* createTogglerWithFrameName(
|
static CCMenuItemToggler* createTogglerWithFrameName(
|
||||||
std::string_view onSpriteName,
|
std::string_view onSpriteName,
|
||||||
std::string_view offSpriteName,
|
std::string_view offSpriteName,
|
||||||
float scale,
|
float scale,
|
||||||
utils::MiniFunction<void(CCMenuItemToggler*)>&& callback
|
std::function<void(CCMenuItemToggler*)> callback
|
||||||
) {
|
) {
|
||||||
auto offSprite = cocos2d::CCSprite::createWithSpriteFrameName(offSpriteName.data());
|
auto offSprite = cocos2d::CCSprite::createWithSpriteFrameName(offSpriteName.data());
|
||||||
auto onSprite = cocos2d::CCSprite::createWithSpriteFrameName(onSpriteName.data());
|
auto onSprite = cocos2d::CCSprite::createWithSpriteFrameName(onSpriteName.data());
|
||||||
|
@ -1313,15 +1312,15 @@ namespace geode::cocos {
|
||||||
offSprite->setScale(scale);
|
offSprite->setScale(scale);
|
||||||
onSprite->setScale(scale);
|
onSprite->setScale(scale);
|
||||||
|
|
||||||
return createToggler(onSprite, offSprite, std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
return createToggler(onSprite, offSprite, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Node>
|
template <class Node>
|
||||||
static void assignCallback(
|
static void assignCallback(
|
||||||
cocos2d::CCMenuItem* item,
|
cocos2d::CCMenuItem* item,
|
||||||
utils::MiniFunction<void(Node*)>&& callback
|
std::function<void(Node*)> callback
|
||||||
) {
|
) {
|
||||||
auto lambda = LambdaCallback<Node>::create(std::forward<std::remove_reference_t<decltype(callback)>>(callback));
|
auto lambda = LambdaCallback<Node>::create(std::move(callback));
|
||||||
item->setTarget(lambda, menu_selector(LambdaCallback<Node>::execute));
|
item->setTarget(lambda, menu_selector(LambdaCallback<Node>::execute));
|
||||||
item->setUserObject("lambda-callback", lambda);
|
item->setUserObject("lambda-callback", lambda);
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ namespace geode::utils::file {
|
||||||
* @param callback Callback to call with the progress of the unzip operation
|
* @param callback Callback to call with the progress of the unzip operation
|
||||||
*/
|
*/
|
||||||
void setProgressCallback(
|
void setProgressCallback(
|
||||||
utils::MiniFunction<void(uint32_t, uint32_t)> callback
|
std::function<void(uint32_t, uint32_t)> callback
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -213,7 +213,7 @@ namespace geode::utils::file {
|
||||||
);
|
);
|
||||||
|
|
||||||
static Result<> intoDir(
|
static Result<> intoDir(
|
||||||
utils::MiniFunction<void(uint32_t, uint32_t)> progressCallback,
|
std::function<void(uint32_t, uint32_t)> progressCallback,
|
||||||
Path const& from,
|
Path const& from,
|
||||||
Path const& to,
|
Path const& to,
|
||||||
bool deleteZipAfter = false
|
bool deleteZipAfter = false
|
||||||
|
@ -281,7 +281,7 @@ namespace geode::utils::file {
|
||||||
public:
|
public:
|
||||||
using Callback = void(FileWatchEvent*);
|
using Callback = void(FileWatchEvent*);
|
||||||
|
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> callback, FileWatchEvent* event);
|
ListenerResult handle(std::function<Callback> callback, FileWatchEvent* event);
|
||||||
FileWatchFilter(std::filesystem::path const& path);
|
FileWatchFilter(std::filesystem::path const& path);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace geode::utils::map {
|
||||||
* false if not.
|
* false if not.
|
||||||
*/
|
*/
|
||||||
template <typename T, typename R, typename H>
|
template <typename T, typename R, typename H>
|
||||||
bool contains(std::unordered_map<T, R, H> const& map, utils::MiniFunction<bool(R)> containFunc) {
|
bool contains(std::unordered_map<T, R, H> const& map, std::function<bool(R)> containFunc) {
|
||||||
for (auto const& [_, r] : map) {
|
for (auto const& [_, r] : map) {
|
||||||
if (containFunc(r)) return true;
|
if (containFunc(r)) return true;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ namespace geode::utils::map {
|
||||||
* a pointer.
|
* a pointer.
|
||||||
*/
|
*/
|
||||||
template <class T, class R, class H>
|
template <class T, class R, class H>
|
||||||
R select(std::unordered_map<T, R, H> const& map, utils::MiniFunction<bool(R)> selectFunc) {
|
R select(std::unordered_map<T, R, H> const& map, std::function<bool(R)> selectFunc) {
|
||||||
for (auto const& [_, r] : map) {
|
for (auto const& [_, r] : map) {
|
||||||
if (selectFunc(r)) return r;
|
if (selectFunc(r)) return r;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ namespace geode::utils::map {
|
||||||
*/
|
*/
|
||||||
template <class T, class R, class H>
|
template <class T, class R, class H>
|
||||||
std::vector<R> selectAll(
|
std::vector<R> selectAll(
|
||||||
std::unordered_map<T, R, H> const& map, utils::MiniFunction<bool(R)> selectFunc
|
std::unordered_map<T, R, H> const& map, std::function<bool(R)> selectFunc
|
||||||
) {
|
) {
|
||||||
std::vector<R> res;
|
std::vector<R> res;
|
||||||
for (auto const& [_, r] : map) {
|
for (auto const& [_, r] : map) {
|
||||||
|
@ -111,7 +111,7 @@ namespace geode::utils::map {
|
||||||
template <class T1, class V1, class H1, class T2, class V2, class H2>
|
template <class T1, class V1, class H1, class T2, class V2, class H2>
|
||||||
std::unordered_map<T2, V2, H2> remap(
|
std::unordered_map<T2, V2, H2> remap(
|
||||||
std::unordered_map<T1, V1, H1> const& map,
|
std::unordered_map<T1, V1, H1> const& map,
|
||||||
utils::MiniFunction<std::pair<T2, V2>(std::pair<T1, V1>)> remapFunc
|
std::function<std::pair<T2, V2>(std::pair<T1, V1>)> remapFunc
|
||||||
) {
|
) {
|
||||||
std::unordered_map<T2, V2, H2> res;
|
std::unordered_map<T2, V2, H2> res;
|
||||||
for (auto const& [t, v] : map) {
|
for (auto const& [t, v] : map) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Geode/DefaultInclude.hpp>
|
#include <Geode/DefaultInclude.hpp>
|
||||||
#include "MiniFunction.hpp"
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace geode::utils::permission {
|
namespace geode::utils::permission {
|
||||||
|
@ -21,5 +20,5 @@ namespace geode::utils::permission {
|
||||||
* @param permission The permission
|
* @param permission The permission
|
||||||
* @param callback The callback, passed value is 'true' if permission was granted and 'false' otherwise.
|
* @param callback The callback, passed value is 'true' if permission was granted and 'false' otherwise.
|
||||||
*/
|
*/
|
||||||
void GEODE_DLL requestPermission(Permission permission, utils::MiniFunction<void(bool)> callback);
|
void GEODE_DLL requestPermission(Permission permission, std::function<void(bool)> callback);
|
||||||
}
|
}
|
|
@ -335,7 +335,7 @@ void CCNode::updateLayout(bool updateChildOrder) {
|
||||||
UserObjectSetEvent::UserObjectSetEvent(CCNode* node, std::string const& id, CCObject* value)
|
UserObjectSetEvent::UserObjectSetEvent(CCNode* node, std::string const& id, CCObject* value)
|
||||||
: node(node), id(id), value(value) {}
|
: node(node), id(id), value(value) {}
|
||||||
|
|
||||||
ListenerResult AttributeSetFilter::handle(MiniFunction<Callback> fn, UserObjectSetEvent* event) {
|
ListenerResult AttributeSetFilter::handle(std::function<Callback> fn, UserObjectSetEvent* event) {
|
||||||
if (event->id == m_targetID) {
|
if (event->id == m_targetID) {
|
||||||
fn(event);
|
fn(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,14 @@
|
||||||
|
|
||||||
#include <Geode/DefaultInclude.hpp>
|
#include <Geode/DefaultInclude.hpp>
|
||||||
//#include <Geode/utils/general.hpp>
|
//#include <Geode/utils/general.hpp>
|
||||||
#include <Geode/utils/MiniFunction.hpp>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class FileWatcher {
|
class FileWatcher {
|
||||||
public:
|
public:
|
||||||
using FileWatchCallback = geode::utils::MiniFunction<void(std::filesystem::path)>;
|
using FileWatchCallback = std::function<void(std::filesystem::path)>;
|
||||||
using ErrorCallback = geode::utils::MiniFunction<void(std::string)>;
|
using ErrorCallback = std::function<void(std::string)>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::filesystem::path m_file;
|
std::filesystem::path m_file;
|
||||||
|
|
|
@ -20,7 +20,7 @@ protected:
|
||||||
std::string content;
|
std::string content;
|
||||||
std::string optionA;
|
std::string optionA;
|
||||||
std::string optionB;
|
std::string optionB;
|
||||||
MiniFunction<void(bool)> after;
|
std::function<void(bool)> after;
|
||||||
};
|
};
|
||||||
|
|
||||||
EventListener<server::ModDownloadFilter> m_download;
|
EventListener<server::ModDownloadFilter> m_download;
|
||||||
|
|
|
@ -19,7 +19,7 @@ ipc::IPCEvent::IPCEvent(
|
||||||
|
|
||||||
ipc::IPCEvent::~IPCEvent() {}
|
ipc::IPCEvent::~IPCEvent() {}
|
||||||
|
|
||||||
ListenerResult ipc::IPCFilter::handle(utils::MiniFunction<Callback> fn, IPCEvent* event) {
|
ListenerResult ipc::IPCFilter::handle(std::function<Callback> fn, IPCEvent* event) {
|
||||||
if (event->targetModID == m_modID && event->messageID == m_messageID) {
|
if (event->targetModID == m_modID && event->messageID == m_messageID) {
|
||||||
event->replyData = fn(event);
|
event->replyData = fn(event);
|
||||||
return ListenerResult::Stop;
|
return ListenerResult::Stop;
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <Geode/utils/Result.hpp>
|
#include <Geode/utils/Result.hpp>
|
||||||
#include <Geode/utils/map.hpp>
|
#include <Geode/utils/map.hpp>
|
||||||
#include <Geode/utils/ranges.hpp>
|
#include <Geode/utils/ranges.hpp>
|
||||||
#include <Geode/utils/MiniFunction.hpp>
|
|
||||||
#include "ModImpl.hpp"
|
#include "ModImpl.hpp"
|
||||||
#include <crashlog.hpp>
|
#include <crashlog.hpp>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -41,7 +40,7 @@ namespace geode {
|
||||||
|
|
||||||
LoadingState m_loadingState = LoadingState::None;
|
LoadingState m_loadingState = LoadingState::None;
|
||||||
|
|
||||||
std::vector<utils::MiniFunction<void(void)>> m_mainThreadQueue;
|
std::vector<std::function<void(void)>> m_mainThreadQueue;
|
||||||
mutable std::mutex m_mainThreadMutex;
|
mutable std::mutex m_mainThreadMutex;
|
||||||
std::vector<std::pair<Hook*, Mod*>> m_uninitializedHooks;
|
std::vector<std::pair<Hook*, Mod*>> m_uninitializedHooks;
|
||||||
bool m_readyToHook = false;
|
bool m_readyToHook = false;
|
||||||
|
|
|
@ -12,7 +12,7 @@ Mod* ModStateEvent::getMod() const {
|
||||||
return m_mod;
|
return m_mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListenerResult ModStateFilter::handle(utils::MiniFunction<Callback> fn, ModStateEvent* event) {
|
ListenerResult ModStateFilter::handle(std::function<Callback> fn, ModStateEvent* event) {
|
||||||
// log::debug("Event mod filter: {}, {}, {}, {}", m_mod, static_cast<int>(m_type), event->getMod(), static_cast<int>(event->getType()));
|
// log::debug("Event mod filter: {}, {}, {}, {}", m_mod, static_cast<int>(m_type), event->getMod(), static_cast<int>(event->getType()));
|
||||||
if ((!m_mod || event->getMod() == m_mod) && event->getType() == m_type) {
|
if ((!m_mod || event->getMod() == m_mod) && event->getType() == m_type) {
|
||||||
fn(event);
|
fn(event);
|
||||||
|
|
|
@ -422,7 +422,7 @@ public:
|
||||||
std::optional<std::string> settingKey;
|
std::optional<std::string> settingKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
ListenerResult SettingChangedFilterV3::handle(utils::MiniFunction<Callback> fn, SettingChangedEventV3* event) {
|
ListenerResult SettingChangedFilterV3::handle(std::function<Callback> fn, SettingChangedEventV3* event) {
|
||||||
if (
|
if (
|
||||||
event->getSetting()->getModID() == m_impl->modID &&
|
event->getSetting()->getModID() == m_impl->modID &&
|
||||||
!m_impl->settingKey || event->getSetting()->getKey() == m_impl->settingKey
|
!m_impl->settingKey || event->getSetting()->getKey() == m_impl->settingKey
|
||||||
|
|
|
@ -16,7 +16,7 @@ updater::ResourceDownloadEvent::ResourceDownloadEvent(
|
||||||
) : status(std::move(status)) {}
|
) : status(std::move(status)) {}
|
||||||
|
|
||||||
ListenerResult updater::ResourceDownloadFilter::handle(
|
ListenerResult updater::ResourceDownloadFilter::handle(
|
||||||
const utils::MiniFunction<Callback>& fn,
|
const std::function<Callback>& fn,
|
||||||
ResourceDownloadEvent* event
|
ResourceDownloadEvent* event
|
||||||
) {
|
) {
|
||||||
fn(event);
|
fn(event);
|
||||||
|
@ -30,7 +30,7 @@ updater::LoaderUpdateEvent::LoaderUpdateEvent(
|
||||||
) : status(std::move(status)) {}
|
) : status(std::move(status)) {}
|
||||||
|
|
||||||
ListenerResult updater::LoaderUpdateFilter::handle(
|
ListenerResult updater::LoaderUpdateFilter::handle(
|
||||||
const utils::MiniFunction<Callback>& fn,
|
const std::function<Callback>& fn,
|
||||||
LoaderUpdateEvent* event
|
LoaderUpdateEvent* event
|
||||||
) {
|
) {
|
||||||
fn(event);
|
fn(event);
|
||||||
|
@ -45,8 +45,8 @@ std::optional<matjson::Value> s_latestGithubRelease;
|
||||||
bool s_isNewUpdateDownloaded = false;
|
bool s_isNewUpdateDownloaded = false;
|
||||||
|
|
||||||
void updater::fetchLatestGithubRelease(
|
void updater::fetchLatestGithubRelease(
|
||||||
const utils::MiniFunction<void(matjson::Value const&)>& then,
|
const std::function<void(matjson::Value const&)>& then,
|
||||||
utils::MiniFunction<void(std::string const&)> expect, bool force
|
std::function<void(std::string const&)> expect, bool force
|
||||||
) {
|
) {
|
||||||
if (s_latestGithubRelease) {
|
if (s_latestGithubRelease) {
|
||||||
return then(s_latestGithubRelease.value());
|
return then(s_latestGithubRelease.value());
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <matjson.hpp>
|
#include <matjson.hpp>
|
||||||
#include <Geode/utils/MiniFunction.hpp>
|
|
||||||
#include <Geode/loader/Event.hpp>
|
#include <Geode/loader/Event.hpp>
|
||||||
|
|
||||||
namespace geode::updater {
|
namespace geode::updater {
|
||||||
|
@ -20,7 +19,7 @@ namespace geode::updater {
|
||||||
public:
|
public:
|
||||||
using Callback = void(ResourceDownloadEvent*);
|
using Callback = void(ResourceDownloadEvent*);
|
||||||
|
|
||||||
static ListenerResult handle(const utils::MiniFunction<Callback>& fn, ResourceDownloadEvent* event);
|
static ListenerResult handle(const std::function<Callback>& fn, ResourceDownloadEvent* event);
|
||||||
ResourceDownloadFilter();
|
ResourceDownloadFilter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ namespace geode::updater {
|
||||||
public:
|
public:
|
||||||
using Callback = void(LoaderUpdateEvent*);
|
using Callback = void(LoaderUpdateEvent*);
|
||||||
|
|
||||||
static ListenerResult handle(const utils::MiniFunction<Callback>& fn, LoaderUpdateEvent* event);
|
static ListenerResult handle(const std::function<Callback>& fn, LoaderUpdateEvent* event);
|
||||||
LoaderUpdateFilter();
|
LoaderUpdateFilter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,8 +42,8 @@ namespace geode::updater {
|
||||||
void downloadLatestLoaderResources();
|
void downloadLatestLoaderResources();
|
||||||
void downloadLoaderUpdate(std::string const& url);
|
void downloadLoaderUpdate(std::string const& url);
|
||||||
void fetchLatestGithubRelease(
|
void fetchLatestGithubRelease(
|
||||||
const utils::MiniFunction<void(matjson::Value const&)>& then,
|
const std::function<void(matjson::Value const&)>& then,
|
||||||
utils::MiniFunction<void(std::string const&)> expect,
|
std::function<void(std::string const&)> expect,
|
||||||
bool force = false
|
bool force = false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ using namespace geode::prelude;
|
||||||
#include <Geode/utils/web.hpp>
|
#include <Geode/utils/web.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <Geode/utils/general.hpp>
|
#include <Geode/utils/general.hpp>
|
||||||
#include <Geode/utils/MiniFunction.hpp>
|
|
||||||
#include <Geode/utils/permission.hpp>
|
#include <Geode/utils/permission.hpp>
|
||||||
#include <Geode/utils/Task.hpp>
|
#include <Geode/utils/Task.hpp>
|
||||||
#include <Geode/loader/Loader.hpp>
|
#include <Geode/loader/Loader.hpp>
|
||||||
|
@ -139,9 +138,9 @@ bool utils::file::openFolder(std::filesystem::path const& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex s_callbackMutex;
|
std::mutex s_callbackMutex;
|
||||||
static utils::MiniFunction<void(Result<std::filesystem::path>)> s_fileCallback {};
|
static std::function<void(Result<std::filesystem::path>)> s_fileCallback {};
|
||||||
static utils::MiniFunction<void(Result<std::vector<std::filesystem::path>>)> s_filesCallback {};
|
static std::function<void(Result<std::vector<std::filesystem::path>>)> s_filesCallback {};
|
||||||
static utils::MiniFunction<bool()> s_taskCancelled {};
|
static std::function<bool()> s_taskCancelled {};
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_selectFileCallback(
|
JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_selectFileCallback(
|
||||||
|
@ -356,7 +355,7 @@ bool geode::utils::permission::getPermissionStatus(Permission permission) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MiniFunction<void(bool)> s_permissionCallback;
|
static std::function<void(bool)> s_permissionCallback;
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_permissionCallback(
|
JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_permissionCallback(
|
||||||
|
@ -371,7 +370,7 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_permissionCallba
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void geode::utils::permission::requestPermission(Permission permission, utils::MiniFunction<void(bool)> callback) {
|
void geode::utils::permission::requestPermission(Permission permission, std::function<void(bool)> callback) {
|
||||||
s_permissionCallback = callback;
|
s_permissionCallback = callback;
|
||||||
JniMethodInfo info;
|
JniMethodInfo info;
|
||||||
if (JniHelper::getStaticMethodInfo(info, "com/geode/launcher/utils/GeodeUtils", "requestPermission", "(Ljava/lang/String;)V")) {
|
if (JniHelper::getStaticMethodInfo(info, "com/geode/launcher/utils/GeodeUtils", "requestPermission", "(Ljava/lang/String;)V")) {
|
||||||
|
|
|
@ -39,6 +39,6 @@ bool geode::utils::permission::getPermissionStatus(Permission permission) {
|
||||||
return true; // unimplemented
|
return true; // unimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
void geode::utils::permission::requestPermission(Permission permission, utils::MiniFunction<void(bool)> callback) {
|
void geode::utils::permission::requestPermission(Permission permission, std::function<void(bool)> callback) {
|
||||||
callback(true); // unimplemented
|
callback(true); // unimplemented
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,7 +309,7 @@ bool geode::utils::permission::getPermissionStatus(Permission permission) {
|
||||||
return true; // unimplemented
|
return true; // unimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
void geode::utils::permission::requestPermission(Permission permission, utils::MiniFunction<void(bool)> callback) {
|
void geode::utils::permission::requestPermission(Permission permission, std::function<void(bool)> callback) {
|
||||||
callback(true); // unimplemented
|
callback(true); // unimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ bool geode::utils::permission::getPermissionStatus(Permission permission) {
|
||||||
return true; // unimplemented
|
return true; // unimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
void geode::utils::permission::requestPermission(Permission permission, utils::MiniFunction<void(bool)> callback) {
|
void geode::utils::permission::requestPermission(Permission permission, std::function<void(bool)> callback) {
|
||||||
callback(true); // unimplemented
|
callback(true); // unimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ using namespace server;
|
||||||
|
|
||||||
ModDownloadEvent::ModDownloadEvent(std::string const& id) : id(id) {}
|
ModDownloadEvent::ModDownloadEvent(std::string const& id) : id(id) {}
|
||||||
|
|
||||||
ListenerResult ModDownloadFilter::handle(MiniFunction<Callback> fn, ModDownloadEvent* event) {
|
ListenerResult ModDownloadFilter::handle(std::function<Callback> fn, ModDownloadEvent* event) {
|
||||||
if (m_id.empty() || m_id == event->id) {
|
if (m_id.empty() || m_id == event->id) {
|
||||||
fn(event);
|
fn(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace server {
|
||||||
std::string m_id;
|
std::string m_id;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(MiniFunction<Callback> fn, ModDownloadEvent* event);
|
ListenerResult handle(std::function<Callback> fn, ModDownloadEvent* event);
|
||||||
|
|
||||||
ModDownloadFilter();
|
ModDownloadFilter();
|
||||||
ModDownloadFilter(std::string const& id);
|
ModDownloadFilter(std::string const& id);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
UpdateModListStateEvent::UpdateModListStateEvent(UpdateState&& target) : target(target) {}
|
UpdateModListStateEvent::UpdateModListStateEvent(UpdateState&& target) : target(target) {}
|
||||||
|
|
||||||
ListenerResult UpdateModListStateFilter::handle(MiniFunction<Callback> fn, UpdateModListStateEvent* event) {
|
ListenerResult UpdateModListStateFilter::handle(std::function<Callback> fn, UpdateModListStateEvent* event) {
|
||||||
if (
|
if (
|
||||||
// If the listener wants to hear all state updates then let it
|
// If the listener wants to hear all state updates then let it
|
||||||
std::holds_alternative<UpdateWholeState>(m_target) ||
|
std::holds_alternative<UpdateWholeState>(m_target) ||
|
||||||
|
|
|
@ -35,7 +35,7 @@ protected:
|
||||||
UpdateState m_target;
|
UpdateState m_target;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(MiniFunction<Callback> fn, UpdateModListStateEvent* event);
|
ListenerResult handle(std::function<Callback> fn, UpdateModListStateEvent* event);
|
||||||
|
|
||||||
UpdateModListStateFilter();
|
UpdateModListStateFilter();
|
||||||
UpdateModListStateFilter(UpdateState&& target);
|
UpdateModListStateFilter(UpdateState&& target);
|
||||||
|
|
|
@ -15,7 +15,7 @@ static size_t ceildiv(size_t a, size_t b) {
|
||||||
|
|
||||||
InvalidateCacheEvent::InvalidateCacheEvent(ModListSource* src) : source(src) {}
|
InvalidateCacheEvent::InvalidateCacheEvent(ModListSource* src) : source(src) {}
|
||||||
|
|
||||||
ListenerResult InvalidateCacheFilter::handle(MiniFunction<Callback> fn, InvalidateCacheEvent* event) {
|
ListenerResult InvalidateCacheFilter::handle(std::function<Callback> fn, InvalidateCacheEvent* event) {
|
||||||
if (event->source == m_source) {
|
if (event->source == m_source) {
|
||||||
fn(event);
|
fn(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
using Callback = void(InvalidateCacheEvent*);
|
using Callback = void(InvalidateCacheEvent*);
|
||||||
|
|
||||||
ListenerResult handle(MiniFunction<Callback> fn, InvalidateCacheEvent* event);
|
ListenerResult handle(std::function<Callback> fn, InvalidateCacheEvent* event);
|
||||||
|
|
||||||
InvalidateCacheFilter() = default;
|
InvalidateCacheFilter() = default;
|
||||||
InvalidateCacheFilter(ModListSource* src);
|
InvalidateCacheFilter(ModListSource* src);
|
||||||
|
|
|
@ -40,7 +40,7 @@ using namespace geode::prelude;
|
||||||
// ColorPickPopup* popup;
|
// ColorPickPopup* popup;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// ListenerResult ColorPickPopupEventFilter::handle(utils::MiniFunction<Callback> fn, ColorPickPopupEvent* event) {
|
// ListenerResult ColorPickPopupEventFilter::handle(std::function<Callback> fn, ColorPickPopupEvent* event) {
|
||||||
// if (event->getPopup() == m_impl->popup) {
|
// if (event->getPopup() == m_impl->popup) {
|
||||||
// if (event->isPopupClosed()) {
|
// if (event->isPopupClosed()) {
|
||||||
// m_impl->popup = nullptr;
|
// m_impl->popup = nullptr;
|
||||||
|
|
|
@ -8,7 +8,7 @@ AEnterLayerEvent::AEnterLayerEvent(
|
||||||
) : layerID(layerID),
|
) : layerID(layerID),
|
||||||
layer(layer) {}
|
layer(layer) {}
|
||||||
|
|
||||||
ListenerResult AEnterLayerFilter::handle(utils::MiniFunction<Callback> fn, AEnterLayerEvent* event) {
|
ListenerResult AEnterLayerFilter::handle(std::function<Callback> fn, AEnterLayerEvent* event) {
|
||||||
if (m_targetID == event->layerID) {
|
if (m_targetID == event->layerID) {
|
||||||
fn(event);
|
fn(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ using namespace geode::prelude;
|
||||||
|
|
||||||
bool MDPopup::setup(
|
bool MDPopup::setup(
|
||||||
std::string const& title, std::string const& info, char const* btn1Text, char const* btn2Text,
|
std::string const& title, std::string const& info, char const* btn1Text, char const* btn2Text,
|
||||||
utils::MiniFunction<void(bool)> onClick
|
std::function<void(bool)> onClick
|
||||||
) {
|
) {
|
||||||
this->setTitle(title.c_str(), "goldFont.fnt", .9f, 33.f);
|
this->setTitle(title.c_str(), "goldFont.fnt", .9f, 33.f);
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ float MDPopup::estimateHeight(std::string const& content) {
|
||||||
|
|
||||||
MDPopup* MDPopup::create(
|
MDPopup* MDPopup::create(
|
||||||
std::string const& title, std::string const& content, char const* btn1, char const* btn2,
|
std::string const& title, std::string const& content, char const* btn1, char const* btn2,
|
||||||
utils::MiniFunction<void(bool)> onClick
|
std::function<void(bool)> onClick
|
||||||
) {
|
) {
|
||||||
auto ret = new MDPopup();
|
auto ret = new MDPopup();
|
||||||
if (ret->initAnchored(
|
if (ret->initAnchored(
|
||||||
|
|
|
@ -71,7 +71,7 @@ using namespace geode::prelude;
|
||||||
|
|
||||||
class QuickPopup : public FLAlertLayer, public FLAlertLayerProtocol {
|
class QuickPopup : public FLAlertLayer, public FLAlertLayerProtocol {
|
||||||
protected:
|
protected:
|
||||||
MiniFunction<void(FLAlertLayer*, bool)> m_selected;
|
std::function<void(FLAlertLayer*, bool)> m_selected;
|
||||||
bool m_cancelledByEscape;
|
bool m_cancelledByEscape;
|
||||||
bool m_usedEscape = false;
|
bool m_usedEscape = false;
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
static QuickPopup* create(
|
static QuickPopup* create(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||||
float width, MiniFunction<void(FLAlertLayer*, bool)> selected, bool cancelledByEscape
|
float width, std::function<void(FLAlertLayer*, bool)> selected, bool cancelledByEscape
|
||||||
) {
|
) {
|
||||||
auto inst = new QuickPopup;
|
auto inst = new QuickPopup;
|
||||||
inst->m_selected = selected;
|
inst->m_selected = selected;
|
||||||
|
@ -109,7 +109,7 @@ public:
|
||||||
|
|
||||||
FLAlertLayer* geode::createQuickPopup(
|
FLAlertLayer* geode::createQuickPopup(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2, float width,
|
char const* title, std::string const& content, char const* btn1, char const* btn2, float width,
|
||||||
MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow
|
std::function<void(FLAlertLayer*, bool)> selected, bool doShow
|
||||||
) {
|
) {
|
||||||
auto ret = QuickPopup::create(title, content, btn1, btn2, width, selected, false);
|
auto ret = QuickPopup::create(title, content, btn1, btn2, width, selected, false);
|
||||||
if (doShow) {
|
if (doShow) {
|
||||||
|
@ -120,14 +120,14 @@ FLAlertLayer* geode::createQuickPopup(
|
||||||
|
|
||||||
FLAlertLayer* geode::createQuickPopup(
|
FLAlertLayer* geode::createQuickPopup(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||||
MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow
|
std::function<void(FLAlertLayer*, bool)> selected, bool doShow
|
||||||
) {
|
) {
|
||||||
return createQuickPopup(title, content, btn1, btn2, 350.f, selected, doShow);
|
return createQuickPopup(title, content, btn1, btn2, 350.f, selected, doShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLAlertLayer* geode::createQuickPopup(
|
FLAlertLayer* geode::createQuickPopup(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2, float width,
|
char const* title, std::string const& content, char const* btn1, char const* btn2, float width,
|
||||||
MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow, bool cancelledByEscape
|
std::function<void(FLAlertLayer*, bool)> selected, bool doShow, bool cancelledByEscape
|
||||||
) {
|
) {
|
||||||
auto ret = QuickPopup::create(title, content, btn1, btn2, width, selected, cancelledByEscape);
|
auto ret = QuickPopup::create(title, content, btn1, btn2, width, selected, cancelledByEscape);
|
||||||
if (doShow) {
|
if (doShow) {
|
||||||
|
@ -138,7 +138,7 @@ FLAlertLayer* geode::createQuickPopup(
|
||||||
|
|
||||||
FLAlertLayer* geode::createQuickPopup(
|
FLAlertLayer* geode::createQuickPopup(
|
||||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||||
MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow, bool cancelledByEscape
|
std::function<void(FLAlertLayer*, bool)> selected, bool doShow, bool cancelledByEscape
|
||||||
) {
|
) {
|
||||||
return createQuickPopup(title, content, btn1, btn2, 350.f, selected, doShow, cancelledByEscape);
|
return createQuickPopup(title, content, btn1, btn2, 350.f, selected, doShow, cancelledByEscape);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ using namespace geode::prelude;
|
||||||
ColorProvidedEvent::ColorProvidedEvent(std::string const& id, cocos2d::ccColor4B const& color)
|
ColorProvidedEvent::ColorProvidedEvent(std::string const& id, cocos2d::ccColor4B const& color)
|
||||||
: id(id), color(color) {}
|
: id(id), color(color) {}
|
||||||
|
|
||||||
ListenerResult ColorProvidedFilter::handle(MiniFunction<Callback> fn, ColorProvidedEvent* event) {
|
ListenerResult ColorProvidedFilter::handle(std::function<Callback> fn, ColorProvidedEvent* event) {
|
||||||
if (event->id == m_id) {
|
if (event->id == m_id) {
|
||||||
fn(event);
|
fn(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,7 @@ private:
|
||||||
int32_t m_mode;
|
int32_t m_mode;
|
||||||
std::variant<Path, ByteVector> m_srcDest;
|
std::variant<Path, ByteVector> m_srcDest;
|
||||||
std::unordered_map<Path, ZipEntry, path_hash_t> m_entries;
|
std::unordered_map<Path, ZipEntry, path_hash_t> m_entries;
|
||||||
utils::MiniFunction<void(uint32_t, uint32_t)> m_progressCallback;
|
std::function<void(uint32_t, uint32_t)> m_progressCallback;
|
||||||
|
|
||||||
Result<> init() {
|
Result<> init() {
|
||||||
// open stream from file
|
// open stream from file
|
||||||
|
@ -295,7 +295,7 @@ public:
|
||||||
return Ok(std::move(ret));
|
return Ok(std::move(ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setProgressCallback(utils::MiniFunction<void(uint32_t, uint32_t)> callback) {
|
void setProgressCallback(std::function<void(uint32_t, uint32_t)> callback) {
|
||||||
m_progressCallback = callback;
|
m_progressCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ Unzip::Path Unzip::getPath() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unzip::setProgressCallback(
|
void Unzip::setProgressCallback(
|
||||||
utils::MiniFunction<void(uint32_t, uint32_t)> callback
|
std::function<void(uint32_t, uint32_t)> callback
|
||||||
) {
|
) {
|
||||||
return m_impl->setProgressCallback(callback);
|
return m_impl->setProgressCallback(callback);
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,7 @@ Result<> Unzip::intoDir(
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<> Unzip::intoDir(
|
Result<> Unzip::intoDir(
|
||||||
utils::MiniFunction<void(uint32_t, uint32_t)> progressCallback,
|
std::function<void(uint32_t, uint32_t)> progressCallback,
|
||||||
Path const& from,
|
Path const& from,
|
||||||
Path const& to,
|
Path const& to,
|
||||||
bool deleteZipAfter
|
bool deleteZipAfter
|
||||||
|
@ -677,7 +677,7 @@ std::filesystem::path FileWatchEvent::getPath() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ListenerResult FileWatchFilter::handle(
|
ListenerResult FileWatchFilter::handle(
|
||||||
MiniFunction<Callback> callback,
|
std::function<Callback> callback,
|
||||||
FileWatchEvent* event
|
FileWatchEvent* event
|
||||||
) {
|
) {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
|
|
@ -12,7 +12,7 @@ std::string TestEvent::getData() const {
|
||||||
|
|
||||||
TestEvent::TestEvent(std::string const& data) : data(data) {}
|
TestEvent::TestEvent(std::string const& data) : data(data) {}
|
||||||
|
|
||||||
ListenerResult TestEventFilter::handle(utils::MiniFunction<Callback> fn, TestEvent* event) {
|
ListenerResult TestEventFilter::handle(std::function<Callback> fn, TestEvent* event) {
|
||||||
fn(event);
|
fn(event);
|
||||||
return ListenerResult::Propagate;
|
return ListenerResult::Propagate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class GEODE_TESTDEP_DLL TestEventFilter : public EventFilter<TestEvent> {
|
||||||
public:
|
public:
|
||||||
using Callback = void(TestEvent*);
|
using Callback = void(TestEvent*);
|
||||||
|
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, TestEvent* event);
|
ListenerResult handle(std::function<Callback> fn, TestEvent* event);
|
||||||
TestEventFilter();
|
TestEventFilter();
|
||||||
TestEventFilter(TestEventFilter const&) = default;
|
TestEventFilter(TestEventFilter const&) = default;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue