mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-29 02:45:38 -05:00
Alias V3 settings to default
This commit is contained in:
parent
bed622243b
commit
8320cf6057
28 changed files with 167 additions and 126 deletions
|
@ -5,7 +5,7 @@
|
|||
#include "loader/Log.hpp"
|
||||
#include "loader/Mod.hpp"
|
||||
#include "loader/ModEvent.hpp"
|
||||
#include "loader/SettingV3.hpp"
|
||||
#include "loader/Setting.hpp"
|
||||
#include "loader/Dirs.hpp"
|
||||
|
||||
#include <Geode/DefaultInclude.hpp>
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace geode {
|
|||
|
||||
private:
|
||||
static DefaultEventListenerPool* create();
|
||||
DefaultEventListenerPool();
|
||||
|
||||
public:
|
||||
bool add(EventListenerProtocol* listener) override;
|
||||
|
@ -63,10 +64,7 @@ namespace geode {
|
|||
friend class DispatchEvent;
|
||||
|
||||
template <class... Args>
|
||||
friend class DispatchFilter;
|
||||
|
||||
// todo: make this private in Geode 4.0.0
|
||||
DefaultEventListenerPool();
|
||||
friend class DispatchFilter;
|
||||
};
|
||||
|
||||
class GEODE_DLL EventListenerProtocol {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "Loader.hpp" // very nice circular dependency fix
|
||||
#include "Hook.hpp"
|
||||
#include "ModMetadata.hpp"
|
||||
#include "SettingV3.hpp"
|
||||
#include "Setting.hpp"
|
||||
#include "Types.hpp"
|
||||
#include "Loader.hpp"
|
||||
|
||||
|
@ -22,9 +22,7 @@
|
|||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace geode {
|
||||
class SettingV3;
|
||||
|
||||
namespace geode {
|
||||
template <class T>
|
||||
struct HandleToSaved : public T {
|
||||
Mod* m_mod;
|
||||
|
@ -182,7 +180,7 @@ namespace geode {
|
|||
* `Mod::registerCustomSettingType`
|
||||
* @param key The key of the setting as defined in `mod.json`
|
||||
*/
|
||||
std::shared_ptr<SettingV3> getSettingV3(std::string_view const key) const;
|
||||
std::shared_ptr<Setting> getSetting(std::string_view const key) const;
|
||||
|
||||
/**
|
||||
* Register a custom setting type. See
|
||||
|
@ -245,7 +243,7 @@ namespace geode {
|
|||
template <class T>
|
||||
T getSettingValue(std::string_view const key) const {
|
||||
using S = typename SettingTypeForValueType<T>::SettingType;
|
||||
if (auto sett = cast::typeinfo_pointer_cast<S>(this->getSettingV3(key))) {
|
||||
if (auto sett = cast::typeinfo_pointer_cast<S>(this->getSetting(key))) {
|
||||
return sett->getValue();
|
||||
}
|
||||
return T();
|
||||
|
@ -254,7 +252,7 @@ namespace geode {
|
|||
template <class T>
|
||||
T setSettingValue(std::string_view const key, T const& value) {
|
||||
using S = typename SettingTypeForValueType<T>::SettingType;
|
||||
if (auto sett = cast::typeinfo_pointer_cast<S>(this->getSettingV3(key))) {
|
||||
if (auto sett = cast::typeinfo_pointer_cast<S>(this->getSetting(key))) {
|
||||
auto old = sett->getValue();
|
||||
sett->setValue(value);
|
||||
return old;
|
||||
|
|
|
@ -171,7 +171,7 @@ namespace geode {
|
|||
* Mod settings
|
||||
* @note Not a map because insertion order must be preserved
|
||||
*/
|
||||
[[nodiscard]] std::vector<std::pair<std::string, matjson::Value>> getSettingsV3() const;
|
||||
[[nodiscard]] std::vector<std::pair<std::string, matjson::Value>> getSettings() const;
|
||||
/**
|
||||
* Get the tags for this mod
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <Geode/DefaultInclude.hpp>
|
||||
#include "SettingV3.hpp"
|
||||
#include "Setting.hpp"
|
||||
|
||||
namespace geode {
|
||||
class Mod;
|
||||
|
@ -57,12 +57,8 @@ namespace geode {
|
|||
matjson::Value& getSaveData();
|
||||
|
||||
Result<> registerCustomSettingType(std::string_view type, SettingGenerator generator);
|
||||
// todo in v4: remove this
|
||||
Result<> registerLegacyCustomSetting(std::string_view key, std::unique_ptr<SettingValue>&& ptr);
|
||||
|
||||
std::shared_ptr<SettingV3> get(std::string_view key);
|
||||
std::shared_ptr<SettingValue> getLegacy(std::string_view key);
|
||||
std::optional<Setting> getLegacyDefinition(std::string_view key);
|
||||
std::shared_ptr<Setting> get(std::string_view key);
|
||||
|
||||
/**
|
||||
* Returns true if any setting with the `"restart-required"` attribute
|
||||
|
|
48
loader/include/Geode/loader/Setting.hpp
Normal file
48
loader/include/Geode/loader/Setting.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
#include "SettingV3.hpp"
|
||||
|
||||
namespace geode {
|
||||
using Setting = SettingV3;
|
||||
using SettingGenerator = SettingGeneratorV3;
|
||||
|
||||
template <class T, class V = T>
|
||||
using SettingBaseValue = SettingBaseValueV3<T, V>;
|
||||
|
||||
using TitleSetting = TitleSettingV3;
|
||||
using BoolSetting = BoolSettingV3;
|
||||
using IntSetting = IntSettingV3;
|
||||
using FloatSetting = FloatSettingV3;
|
||||
using StringSetting = StringSettingV3;
|
||||
using FileSetting = FileSettingV3;
|
||||
using Color3BSetting = Color3BSettingV3;
|
||||
using Color4BSetting = Color4BSettingV3;
|
||||
|
||||
using SettingNode = SettingNodeV3;
|
||||
template <class S>
|
||||
using SettingValueNode = SettingValueNodeV3<S>;
|
||||
|
||||
using SettingChangedEvent = SettingChangedEventV3;
|
||||
using SettingChangedFilter = SettingChangedFilterV3;
|
||||
using SettingNodeSizeChangeEvent = SettingNodeSizeChangeEventV3;
|
||||
using SettingNodeValueChangeEvent = SettingNodeValueChangeEventV3;
|
||||
|
||||
template <class T>
|
||||
using SettingTypeForValueType = SettingTypeForValueTypeV3<T>;
|
||||
|
||||
template <class T, class Lambda>
|
||||
EventListener<SettingChangedFilter>* listenForSettingChanges(std::string_view settingKey, Lambda&& callback, Mod* mod = getMod()) {
|
||||
return listenForSettingChangesV3<T>(settingKey, std::forward<Lambda>(callback), mod);
|
||||
}
|
||||
|
||||
template <class Lambda>
|
||||
EventListener<SettingChangedFilter>* listenForSettingChanges(std::string_view settingKey, Lambda&& callback, Mod* mod = getMod()) {
|
||||
return listenForSettingChangesV3(settingKey, std::forward<Lambda>(callback), mod);
|
||||
}
|
||||
|
||||
inline EventListener<SettingChangedFilter>* listenForAllSettingChanges(
|
||||
std::function<void(std::shared_ptr<SettingV3>)> const& callback,
|
||||
Mod* mod = getMod()
|
||||
) {
|
||||
return listenForAllSettingChangesV3(callback, mod);
|
||||
}
|
||||
}
|
|
@ -14,8 +14,6 @@ class ModSettingsPopup;
|
|||
namespace geode {
|
||||
class ModSettingsManager;
|
||||
class SettingNodeV3;
|
||||
// todo in v4: remove this
|
||||
class SettingValue;
|
||||
|
||||
class GEODE_DLL SettingV3 : public std::enable_shared_from_this<SettingV3> {
|
||||
private:
|
||||
|
@ -122,8 +120,6 @@ namespace geode {
|
|||
*/
|
||||
void markChanged();
|
||||
|
||||
friend class ::geode::SettingValue;
|
||||
|
||||
public:
|
||||
SettingV3();
|
||||
virtual ~SettingV3();
|
||||
|
@ -182,7 +178,7 @@ namespace geode {
|
|||
virtual void reset() = 0;
|
||||
};
|
||||
|
||||
using SettingGenerator = std::function<Result<std::shared_ptr<SettingV3>>(
|
||||
using SettingGeneratorV3 = std::function<Result<std::shared_ptr<SettingV3>>(
|
||||
std::string const& key,
|
||||
std::string const& modID,
|
||||
matjson::Value const& json
|
||||
|
@ -697,45 +693,45 @@ namespace geode {
|
|||
};
|
||||
|
||||
template <class T>
|
||||
struct SettingTypeForValueType {
|
||||
struct SettingTypeForValueTypeV3 {
|
||||
static_assert(
|
||||
!std::is_same_v<T, T>,
|
||||
"specialize the SettingTypeForValueType class to use Mod::getSettingValue for custom settings"
|
||||
"specialize the SettingTypeForValueTypeV3 class to use Mod::getSettingValue for custom settings"
|
||||
);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SettingTypeForValueType<bool> {
|
||||
struct SettingTypeForValueTypeV3<bool> {
|
||||
using SettingType = BoolSettingV3;
|
||||
};
|
||||
template <>
|
||||
struct SettingTypeForValueType<int64_t> {
|
||||
struct SettingTypeForValueTypeV3<int64_t> {
|
||||
using SettingType = IntSettingV3;
|
||||
};
|
||||
template <>
|
||||
struct SettingTypeForValueType<double> {
|
||||
struct SettingTypeForValueTypeV3<double> {
|
||||
using SettingType = FloatSettingV3;
|
||||
};
|
||||
template <>
|
||||
struct SettingTypeForValueType<std::string> {
|
||||
struct SettingTypeForValueTypeV3<std::string> {
|
||||
using SettingType = StringSettingV3;
|
||||
};
|
||||
template <>
|
||||
struct SettingTypeForValueType<std::filesystem::path> {
|
||||
struct SettingTypeForValueTypeV3<std::filesystem::path> {
|
||||
using SettingType = FileSettingV3;
|
||||
};
|
||||
template <>
|
||||
struct SettingTypeForValueType<cocos2d::ccColor3B> {
|
||||
struct SettingTypeForValueTypeV3<cocos2d::ccColor3B> {
|
||||
using SettingType = Color3BSettingV3;
|
||||
};
|
||||
template <>
|
||||
struct SettingTypeForValueType<cocos2d::ccColor4B> {
|
||||
struct SettingTypeForValueTypeV3<cocos2d::ccColor4B> {
|
||||
using SettingType = Color4BSettingV3;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
EventListener<SettingChangedFilterV3>* listenForSettingChanges(std::string_view settingKey, auto&& callback, Mod* mod = getMod()) {
|
||||
using Ty = typename SettingTypeForValueType<T>::SettingType;
|
||||
EventListener<SettingChangedFilterV3>* listenForSettingChangesV3(std::string_view settingKey, auto&& callback, Mod* mod = getMod()) {
|
||||
using Ty = typename SettingTypeForValueTypeV3<T>::SettingType;
|
||||
return new EventListener(
|
||||
[callback = std::move(callback)](std::shared_ptr<SettingV3> setting) {
|
||||
if (auto ty = geode::cast::typeinfo_pointer_cast<Ty>(setting)) {
|
||||
|
@ -745,11 +741,11 @@ namespace geode {
|
|||
SettingChangedFilterV3(mod, std::string(settingKey))
|
||||
);
|
||||
}
|
||||
EventListener<SettingChangedFilterV3>* listenForSettingChanges(std::string_view settingKey, auto&& callback, Mod* mod = getMod()) {
|
||||
EventListener<SettingChangedFilterV3>* listenForSettingChangesV3(std::string_view settingKey, auto&& callback, Mod* mod = getMod()) {
|
||||
using T = std::remove_cvref_t<utils::function::Arg<0, decltype(callback)>>;
|
||||
return listenForSettingChanges<T>(settingKey, std::move(callback), mod);
|
||||
return listenForSettingChangesV3<T>(settingKey, std::move(callback), mod);
|
||||
}
|
||||
GEODE_DLL EventListener<SettingChangedFilterV3>* listenForAllSettingChanges(
|
||||
GEODE_DLL EventListener<SettingChangedFilterV3>* listenForAllSettingChangesV3(
|
||||
std::function<void(std::shared_ptr<SettingV3>)> const& callback,
|
||||
Mod* mod = getMod()
|
||||
);
|
||||
|
|
|
@ -89,14 +89,11 @@ namespace geode {
|
|||
constexpr std::string_view GEODE_MOD_EXTENSION = ".geode";
|
||||
|
||||
class Mod;
|
||||
class Setting;
|
||||
class Loader;
|
||||
class Hook;
|
||||
class VersionInfo;
|
||||
|
||||
class Unknown;
|
||||
using unknownmemfn_t = void (Unknown::*)();
|
||||
using unknownfn_t = void (*)();
|
||||
|
||||
namespace modifier {
|
||||
template <class, class>
|
||||
|
|
|
@ -116,14 +116,22 @@ namespace geode {
|
|||
public:
|
||||
// todo in v4: make these flags and add archless Mac and Android as well as Desktop and Mobile and remove Linux
|
||||
enum {
|
||||
Unknown = -1,
|
||||
Windows = 0,
|
||||
MacIntel = 1,
|
||||
MacArm = 2,
|
||||
iOS = 3,
|
||||
Android32 = 4,
|
||||
Android64 = 5,
|
||||
Linux = 6,
|
||||
Unknown = 0b000000,
|
||||
Windows = 0b000001,
|
||||
Android32 = 0b000010,
|
||||
Android64 = 0b000100,
|
||||
MacIntel = 0b001000,
|
||||
MacArm = 0b010000,
|
||||
iOS = 0b100000,
|
||||
Android = Android32 | Android64,
|
||||
Mac = MacIntel | MacArm,
|
||||
Apple = Mac | iOS,
|
||||
X64 = MacIntel | Windows,
|
||||
X86 = Unknown,
|
||||
ArmV7 = Android32,
|
||||
ArmV8 = Android64 | MacArm | iOS,
|
||||
Desktop = Windows | Mac,
|
||||
Mobile = Android | iOS,
|
||||
};
|
||||
|
||||
using Type = decltype(Unknown);
|
||||
|
@ -190,7 +198,6 @@ namespace geode {
|
|||
case iOS: return "iOS";
|
||||
case Android32: return "Android32";
|
||||
case Android64: return "Android64";
|
||||
case Linux: return "Linux";
|
||||
default: break;
|
||||
}
|
||||
return "Undefined";
|
||||
|
@ -206,7 +213,6 @@ namespace geode {
|
|||
case iOS: return "ios";
|
||||
case Android32: return ignoreArch ? "android" : "android32";
|
||||
case Android64: return ignoreArch ? "android" : "android64";
|
||||
case Linux: return "linux";
|
||||
default: break;
|
||||
}
|
||||
return "undefined";
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <Geode/utils/cocos.hpp>
|
||||
|
||||
namespace geode {
|
||||
struct SceneSwitch;
|
||||
|
||||
class GEODE_DLL SceneManager final {
|
||||
protected:
|
||||
std::vector<Ref<cocos2d::CCNode>> m_persistedNodes;
|
||||
|
@ -15,6 +17,10 @@ namespace geode {
|
|||
|
||||
virtual ~SceneManager();
|
||||
|
||||
void willSwitchToScene(cocos2d::CCScene* scene);
|
||||
|
||||
friend struct SceneSwitch;
|
||||
|
||||
public:
|
||||
static SceneManager* get();
|
||||
|
||||
|
@ -34,9 +40,5 @@ namespace geode {
|
|||
* Gets a span of the persisted nodes. To add new nodes to the list, use keepAcrossScenes.
|
||||
*/
|
||||
std::span<Ref<cocos2d::CCNode> const> getPersistedNodes();
|
||||
|
||||
// This method should only be called by geode itself
|
||||
// TODO(v4): hide this
|
||||
void willSwitchToScene(cocos2d::CCScene* scene);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,10 +2,15 @@
|
|||
|
||||
using namespace geode::prelude;
|
||||
|
||||
#ifdef GEODE_IS_WINDOWS
|
||||
#include <Geode/modify/AppDelegate.hpp>
|
||||
#else
|
||||
#include <Geode/modify/AchievementNotifier.hpp>
|
||||
#endif
|
||||
|
||||
namespace geode {
|
||||
|
||||
#ifdef GEODE_IS_WINDOWS
|
||||
|
||||
#include <Geode/modify/AppDelegate.hpp>
|
||||
struct SceneSwitch : Modify<SceneSwitch, AppDelegate> {
|
||||
GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled")
|
||||
void willSwitchToScene(CCScene* scene) {
|
||||
|
@ -15,8 +20,6 @@ struct SceneSwitch : Modify<SceneSwitch, AppDelegate> {
|
|||
};
|
||||
|
||||
#else
|
||||
|
||||
#include <Geode/modify/AchievementNotifier.hpp>
|
||||
struct SceneSwitch : Modify<SceneSwitch, AchievementNotifier> {
|
||||
GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled")
|
||||
void willSwitchToScene(CCScene* scene) {
|
||||
|
@ -26,3 +29,5 @@ struct SceneSwitch : Modify<SceneSwitch, AchievementNotifier> {
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
|
@ -152,7 +152,7 @@ bool Mod::hasSetting(std::string_view const key) const {
|
|||
return m_impl->hasSetting(key);
|
||||
}
|
||||
|
||||
std::shared_ptr<SettingV3> Mod::getSettingV3(std::string_view const key) const {
|
||||
std::shared_ptr<Setting> Mod::getSetting(std::string_view const key) const {
|
||||
return m_impl->m_settings->get(std::string(key));
|
||||
}
|
||||
|
||||
|
|
|
@ -229,19 +229,19 @@ Result<> Mod::Impl::saveData() {
|
|||
}
|
||||
|
||||
bool Mod::Impl::hasSettings() const {
|
||||
return m_metadata.getSettingsV3().size();
|
||||
return m_metadata.getSettings().size();
|
||||
}
|
||||
|
||||
std::vector<std::string> Mod::Impl::getSettingKeys() const {
|
||||
std::vector<std::string> keys;
|
||||
for (auto& [key, _] : m_metadata.getSettingsV3()) {
|
||||
for (auto& [key, _] : m_metadata.getSettings()) {
|
||||
keys.push_back(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
bool Mod::Impl::hasSetting(std::string_view const key) const {
|
||||
for (auto& setting : m_metadata.getSettingsV3()) {
|
||||
for (auto& setting : m_metadata.getSettings()) {
|
||||
if (setting.first == key) {
|
||||
return true;
|
||||
}
|
||||
|
@ -681,8 +681,6 @@ ModJson Mod::Impl::getRuntimeInfo() const {
|
|||
for (auto patch : m_patches) {
|
||||
obj["patches"].as_array().push_back(ModJson(patch->getRuntimeInfo()));
|
||||
}
|
||||
// TODO: so which one is it
|
||||
// obj["enabled"] = m_enabled;
|
||||
obj["loaded"] = m_enabled;
|
||||
obj["temp-dir"] = this->getTempDir();
|
||||
obj["save-dir"] = this->getSaveDir();
|
||||
|
|
|
@ -519,7 +519,7 @@ std::vector<ModMetadata::Incompatibility> ModMetadata::getIncompatibilities() co
|
|||
std::vector<std::string> ModMetadata::getSpritesheets() const {
|
||||
return m_impl->m_spritesheets;
|
||||
}
|
||||
std::vector<std::pair<std::string, matjson::Value>> ModMetadata::getSettingsV3() const {
|
||||
std::vector<std::pair<std::string, matjson::Value>> ModMetadata::getSettings() const {
|
||||
return m_impl->m_settings;
|
||||
}
|
||||
std::unordered_set<std::string> ModMetadata::getTags() const {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <Geode/loader/Mod.hpp>
|
||||
#include <Geode/utils/JsonValidation.hpp>
|
||||
#include <Geode/utils/VersionInfo.hpp>
|
||||
#include <Geode/loader/SettingV3.hpp>
|
||||
#include <Geode/loader/Setting.hpp>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
|
|
|
@ -13,17 +13,17 @@ private:
|
|||
std::unordered_map<std::string, SettingGenerator> m_types;
|
||||
|
||||
SharedSettingTypesPool() : m_types({
|
||||
{ "title", &TitleSettingV3::parse },
|
||||
{ "bool", &BoolSettingV3::parse },
|
||||
{ "int", &IntSettingV3::parse },
|
||||
{ "float", &FloatSettingV3::parse },
|
||||
{ "string", &StringSettingV3::parse },
|
||||
{ "file", &FileSettingV3::parse },
|
||||
{ "folder", &FileSettingV3::parse },
|
||||
{ "path", &FileSettingV3::parse },
|
||||
{ "rgb", &Color3BSettingV3::parse },
|
||||
{ "color", &Color3BSettingV3::parse },
|
||||
{ "rgba", &Color4BSettingV3::parse },
|
||||
{ "title", &TitleSetting::parse },
|
||||
{ "bool", &BoolSetting::parse },
|
||||
{ "int", &IntSetting::parse },
|
||||
{ "float", &FloatSetting::parse },
|
||||
{ "string", &StringSetting::parse },
|
||||
{ "file", &FileSetting::parse },
|
||||
{ "folder", &FileSetting::parse },
|
||||
{ "path", &FileSetting::parse },
|
||||
{ "rgb", &Color3BSetting::parse },
|
||||
{ "color", &Color3BSetting::parse },
|
||||
{ "rgba", &Color4BSetting::parse },
|
||||
}) {}
|
||||
|
||||
public:
|
||||
|
@ -78,9 +78,7 @@ public:
|
|||
struct SettingInfo final {
|
||||
std::string type;
|
||||
matjson::Value json;
|
||||
std::shared_ptr<SettingV3> v3 = nullptr;
|
||||
// todo: remove in v4
|
||||
std::shared_ptr<SettingValue> legacy = nullptr;
|
||||
std::shared_ptr<Setting> v3 = nullptr;
|
||||
};
|
||||
std::string modID;
|
||||
std::unordered_map<std::string, SettingInfo> settings;
|
||||
|
@ -159,7 +157,7 @@ ModSettingsManager::ModSettingsManager(ModMetadata const& metadata)
|
|||
: m_impl(std::make_unique<Impl>())
|
||||
{
|
||||
m_impl->modID = metadata.getID();
|
||||
for (auto const& [key, json] : metadata.getSettingsV3()) {
|
||||
for (auto const& [key, json] : metadata.getSettings()) {
|
||||
auto setting = Impl::SettingInfo();
|
||||
setting.json = json;
|
||||
auto root = checkJson(json, "setting");
|
||||
|
@ -195,13 +193,6 @@ Result<> ModSettingsManager::registerCustomSettingType(std::string_view type, Se
|
|||
m_impl->createSettings();
|
||||
return Ok();
|
||||
}
|
||||
Result<> ModSettingsManager::registerLegacyCustomSetting(std::string_view key, std::unique_ptr<SettingValue>&& ptr) {
|
||||
auto id = std::string(key);
|
||||
if (!m_impl->settings.count(id)) {
|
||||
return Err("No such setting '{}' in mod {}", id, m_impl->modID);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
Result<> ModSettingsManager::load(matjson::Value const& json) {
|
||||
if (json.is_object()) {
|
||||
|
@ -225,7 +216,7 @@ matjson::Value& ModSettingsManager::getSaveData() {
|
|||
return m_impl->savedata;
|
||||
}
|
||||
|
||||
std::shared_ptr<SettingV3> ModSettingsManager::get(std::string_view key) {
|
||||
std::shared_ptr<Setting> ModSettingsManager::get(std::string_view key) {
|
||||
auto id = std::string(key);
|
||||
return m_impl->settings.count(id) ? m_impl->settings.at(id).v3 : nullptr;
|
||||
}
|
||||
|
|
16
loader/src/loader/SettingNode.hpp
Normal file
16
loader/src/loader/SettingNode.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
#include "SettingNodeV3.hpp"
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
using TitleSettingNode = TitleSettingNodeV3;
|
||||
using BoolSettingNode = BoolSettingNodeV3;
|
||||
template <class S>
|
||||
using NumberSettingNode = NumberSettingNodeV3<S>;
|
||||
using IntSettingNode = IntSettingNodeV3;
|
||||
using FloatSettingNode = FloatSettingNodeV3;
|
||||
using StringSettingNode = StringSettingNodeV3;
|
||||
using FileSettingNode = FileSettingNodeV3;
|
||||
using Color3BSettingNode = Color3BSettingNodeV3;
|
||||
using Color4BSettingNode = Color4BSettingNodeV3;
|
||||
using UnresolvedCustomSettingNode = UnresolvedCustomSettingNodeV3;
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <Geode/loader/SettingV3.hpp>
|
||||
#include <Geode/loader/Setting.hpp>
|
||||
#include <Geode/binding/CCMenuItemToggler.hpp>
|
||||
#include <Geode/binding/ColorChannelSprite.hpp>
|
||||
#include <Geode/binding/Slider.hpp>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include <Geode/loader/SettingV3.hpp>
|
||||
#include <Geode/loader/Setting.hpp>
|
||||
#include <Geode/loader/ModSettingsManager.hpp>
|
||||
#include <Geode/utils/ranges.hpp>
|
||||
#include <Geode/utils/string.hpp>
|
||||
|
@ -45,7 +45,7 @@ namespace enable_if_parsing {
|
|||
if (!mod->hasSetting(settingID)) {
|
||||
return Err("Mod '{}' does not have setting '{}'", mod->getName(), settingID);
|
||||
}
|
||||
if (!typeinfo_pointer_cast<BoolSettingV3>(mod->getSettingV3(settingID))) {
|
||||
if (!typeinfo_pointer_cast<BoolSettingV3>(mod->getSetting(settingID))) {
|
||||
return Err("Setting '{}' in mod '{}' is not a boolean setting", settingID, mod->getName());
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ namespace enable_if_parsing {
|
|||
// This is an if-check just in case, even though check() should already
|
||||
// make sure that getSettingV3 is guaranteed to return true
|
||||
auto name = settingID;
|
||||
if (auto sett = mod->getSettingV3(settingID)) {
|
||||
if (auto sett = mod->getSetting(settingID)) {
|
||||
name = sett->getDisplayName();
|
||||
}
|
||||
if (modID == defaultModID) {
|
||||
|
@ -446,7 +446,7 @@ SettingChangedFilterV3::SettingChangedFilterV3(Mod* mod, std::optional<std::stri
|
|||
|
||||
SettingChangedFilterV3::SettingChangedFilterV3(SettingChangedFilterV3 const&) = default;
|
||||
|
||||
EventListener<SettingChangedFilterV3>* geode::listenForAllSettingChanges(
|
||||
EventListener<SettingChangedFilterV3>* geode::listenForAllSettingChangesV3(
|
||||
std::function<void(std::shared_ptr<SettingV3>)> const& callback,
|
||||
Mod* mod
|
||||
) {
|
||||
|
@ -572,12 +572,6 @@ void SettingV3::markChanged() {
|
|||
manager->markRestartRequired();
|
||||
}
|
||||
SettingChangedEventV3(shared_from_this()).post();
|
||||
if (manager) {
|
||||
// TODO: v4
|
||||
// Use ModSettingsManager rather than convertToLegacyValue since it
|
||||
// caches the result and we want to have that for performance
|
||||
// SettingChangedEvent(this->getMod(), manager->getLegacy(this->getKey()).get()).post();
|
||||
}
|
||||
}
|
||||
class TitleSettingV3::Impl final {
|
||||
public:
|
||||
|
|
|
@ -90,7 +90,7 @@ bool ModsStatusNode::init() {
|
|||
|
||||
m_downloadListener.bind([this](auto) { this->updateState(); });
|
||||
|
||||
m_settingNodeListener.bind([this](SettingNodeValueChangeEventV3* ev) {
|
||||
m_settingNodeListener.bind([this](SettingNodeValueChangeEvent* ev) {
|
||||
this->updateState();
|
||||
return ListenerResult::Propagate;
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "sources/ModListSource.hpp"
|
||||
#include "UpdateModListState.hpp"
|
||||
#include <server/DownloadManager.hpp>
|
||||
#include <Geode/loader/SettingV3.hpp>
|
||||
#include <Geode/loader/Setting.hpp>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
|
@ -40,7 +40,7 @@ protected:
|
|||
EventListener<UpdateModListStateFilter> m_updateStateListener;
|
||||
EventListener<server::ModDownloadFilter> m_downloadListener;
|
||||
DownloadState m_lastState = DownloadState::None;
|
||||
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_settingNodeListener;
|
||||
EventListener<EventFilter<SettingNodeValueChangeEvent>> m_settingNodeListener;
|
||||
|
||||
bool init();
|
||||
void updateState();
|
||||
|
|
|
@ -303,7 +303,7 @@ bool ModItem::init(ModSource&& source) {
|
|||
m_downloadListener.bind([this](auto) { this->updateState(); });
|
||||
m_downloadListener.setFilter(server::ModDownloadFilter(m_source.getID()));
|
||||
|
||||
m_settingNodeListener.bind([this](SettingNodeValueChangeEventV3*) {
|
||||
m_settingNodeListener.bind([this](SettingNodeValueChangeEvent*) {
|
||||
this->updateState();
|
||||
return ListenerResult::Propagate;
|
||||
});
|
||||
|
|
|
@ -35,7 +35,7 @@ protected:
|
|||
EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener;
|
||||
EventListener<server::ModDownloadFilter> m_downloadListener;
|
||||
std::optional<server::ServerModUpdate> m_availableUpdate;
|
||||
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_settingNodeListener;
|
||||
EventListener<EventFilter<SettingNodeValueChangeEvent>> m_settingNodeListener;
|
||||
|
||||
/**
|
||||
* @warning Make sure `getMetadata` and `createModLogo` are callable
|
||||
|
|
|
@ -618,7 +618,7 @@ bool ModPopup::setup(ModSource&& src) {
|
|||
m_downloadListener.bind([this](auto) { this->updateState(); });
|
||||
m_downloadListener.setFilter(m_source.getID());
|
||||
|
||||
m_settingNodeListener.bind([this](SettingNodeValueChangeEventV3*) {
|
||||
m_settingNodeListener.bind([this](SettingNodeValueChangeEvent*) {
|
||||
this->updateState();
|
||||
return ListenerResult::Propagate;
|
||||
});
|
||||
|
|
|
@ -42,7 +42,7 @@ protected:
|
|||
EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener;
|
||||
EventListener<UpdateModListStateFilter> m_updateStateListener;
|
||||
EventListener<server::ModDownloadFilter> m_downloadListener;
|
||||
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_settingNodeListener;
|
||||
EventListener<EventFilter<SettingNodeValueChangeEvent>> m_settingNodeListener;
|
||||
|
||||
bool setup(ModSource&& src) override;
|
||||
void updateState();
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
#include <Geode/utils/cocos.hpp>
|
||||
#include <Geode/ui/General.hpp>
|
||||
#include <Geode/ui/Scrollbar.hpp>
|
||||
#include <loader/SettingNodeV3.hpp>
|
||||
#include <Geode/loader/Setting.hpp>
|
||||
#include <loader/SettingNode.hpp>
|
||||
// needed for weightedFuzzyMatch
|
||||
#include <ui/mods/sources/ModListSource.hpp>
|
||||
|
||||
static bool matchSearch(SettingNodeV3* node, std::string const& query) {
|
||||
if (typeinfo_cast<TitleSettingNodeV3*>(node)) {
|
||||
static bool matchSearch(SettingNode* node, std::string const& query) {
|
||||
if (typeinfo_cast<TitleSettingNode*>(node)) {
|
||||
return true;
|
||||
}
|
||||
bool addToList = false;
|
||||
|
@ -73,12 +74,12 @@ bool ModSettingsPopup::setup(Mod* mod) {
|
|||
m_list->setTouchEnabled(true);
|
||||
|
||||
for (auto& key : mod->getSettingKeys()) {
|
||||
SettingNodeV3* node;
|
||||
if (auto sett = mod->getSettingV3(key)) {
|
||||
SettingNode* node;
|
||||
if (auto sett = mod->getSetting(key)) {
|
||||
node = sett->createNode(layerSize.width);
|
||||
}
|
||||
else {
|
||||
node = UnresolvedCustomSettingNodeV3::create(key, mod, layerSize.width);
|
||||
node = UnresolvedCustomSettingNode::create(key, mod, layerSize.width);
|
||||
}
|
||||
|
||||
m_settings.push_back(node);
|
||||
|
@ -249,7 +250,7 @@ void ModSettingsPopup::onClearSearch(CCObject*) {
|
|||
m_list->moveToTop();
|
||||
}
|
||||
|
||||
void ModSettingsPopup::updateState(SettingNodeV3* invoker) {
|
||||
void ModSettingsPopup::updateState(SettingNode* invoker) {
|
||||
auto search = m_searchInput->getString();
|
||||
auto hasSearch = !search.empty();
|
||||
|
||||
|
@ -261,10 +262,10 @@ void ModSettingsPopup::updateState(SettingNodeV3* invoker) {
|
|||
|
||||
// Update search visibility + all settings with "enable-if" schemes +
|
||||
// checkerboard BG
|
||||
TitleSettingNodeV3* lastTitle = nullptr;
|
||||
TitleSettingNode* lastTitle = nullptr;
|
||||
bool bg = false;
|
||||
for (auto& sett : m_settings) {
|
||||
if (auto asTitle = typeinfo_cast<TitleSettingNodeV3*>(sett.data())) {
|
||||
if (auto asTitle = typeinfo_cast<TitleSettingNode*>(sett.data())) {
|
||||
lastTitle = asTitle;
|
||||
}
|
||||
sett->removeFromParent();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <Geode/loader/SettingV3.hpp>
|
||||
#include <Geode/loader/Setting.hpp>
|
||||
#include <Geode/ui/Popup.hpp>
|
||||
#include <Geode/utils/cocos.hpp>
|
||||
#include <Geode/ui/ScrollLayer.hpp>
|
||||
|
@ -14,17 +14,17 @@ class ModSettingsPopup : public GeodePopup<Mod*> {
|
|||
protected:
|
||||
Mod* m_mod;
|
||||
ScrollLayer* m_list;
|
||||
std::vector<Ref<SettingNodeV3>> m_settings;
|
||||
std::vector<Ref<SettingNode>> m_settings;
|
||||
CCMenu* m_applyMenu;
|
||||
CCMenuItemSpriteExtra* m_applyBtn;
|
||||
CCMenuItemSpriteExtra* m_restartBtn;
|
||||
ButtonSprite* m_applyBtnSpr;
|
||||
TextInput* m_searchInput;
|
||||
CCMenuItemSpriteExtra* m_searchClearBtn;
|
||||
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_changeListener;
|
||||
EventListener<EventFilter<SettingNodeValueChangeEvent>> m_changeListener;
|
||||
|
||||
bool setup(Mod* mod) override;
|
||||
void updateState(SettingNodeV3* invoker = nullptr);
|
||||
void updateState(SettingNode* invoker = nullptr);
|
||||
bool hasUncommitted() const;
|
||||
void onClose(CCObject*) override;
|
||||
void onApply(CCObject*);
|
||||
|
|
|
@ -33,8 +33,6 @@ PlatformID PlatformID::from(const char* str) {
|
|||
case hash("Android64"):
|
||||
case hash("android64"): return PlatformID::Android64;
|
||||
|
||||
case hash("Linux"):
|
||||
case hash("linux"): return PlatformID::Linux;
|
||||
default: return PlatformID::Unknown;
|
||||
}
|
||||
}
|
||||
|
@ -64,9 +62,6 @@ std::vector<PlatformID> PlatformID::getCovered(std::string_view str) {
|
|||
case hash("android"): return { PlatformID::Android32, PlatformID::Android64 };
|
||||
case hash("android32"): return { PlatformID::Android32 };
|
||||
case hash("android64"): return { PlatformID::Android64 };
|
||||
|
||||
// todo in v4: no linux
|
||||
case hash("linux"): return { PlatformID::Linux };
|
||||
|
||||
default: return {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue