Alias V3 settings to default

This commit is contained in:
altalk23 2024-11-04 21:27:14 +03:00
parent bed622243b
commit 8320cf6057
28 changed files with 167 additions and 126 deletions

View file

@ -5,7 +5,7 @@
#include "loader/Log.hpp" #include "loader/Log.hpp"
#include "loader/Mod.hpp" #include "loader/Mod.hpp"
#include "loader/ModEvent.hpp" #include "loader/ModEvent.hpp"
#include "loader/SettingV3.hpp" #include "loader/Setting.hpp"
#include "loader/Dirs.hpp" #include "loader/Dirs.hpp"
#include <Geode/DefaultInclude.hpp> #include <Geode/DefaultInclude.hpp>

View file

@ -51,6 +51,7 @@ namespace geode {
private: private:
static DefaultEventListenerPool* create(); static DefaultEventListenerPool* create();
DefaultEventListenerPool();
public: public:
bool add(EventListenerProtocol* listener) override; bool add(EventListenerProtocol* listener) override;
@ -64,9 +65,6 @@ namespace geode {
template <class... Args> template <class... Args>
friend class DispatchFilter; friend class DispatchFilter;
// todo: make this private in Geode 4.0.0
DefaultEventListenerPool();
}; };
class GEODE_DLL EventListenerProtocol { class GEODE_DLL EventListenerProtocol {

View file

@ -9,7 +9,7 @@
#include "Loader.hpp" // very nice circular dependency fix #include "Loader.hpp" // very nice circular dependency fix
#include "Hook.hpp" #include "Hook.hpp"
#include "ModMetadata.hpp" #include "ModMetadata.hpp"
#include "SettingV3.hpp" #include "Setting.hpp"
#include "Types.hpp" #include "Types.hpp"
#include "Loader.hpp" #include "Loader.hpp"
@ -23,8 +23,6 @@
#include <vector> #include <vector>
namespace geode { namespace geode {
class SettingV3;
template <class T> template <class T>
struct HandleToSaved : public T { struct HandleToSaved : public T {
Mod* m_mod; Mod* m_mod;
@ -182,7 +180,7 @@ namespace geode {
* `Mod::registerCustomSettingType` * `Mod::registerCustomSettingType`
* @param key The key of the setting as defined in `mod.json` * @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 * Register a custom setting type. See
@ -245,7 +243,7 @@ namespace geode {
template <class T> template <class T>
T getSettingValue(std::string_view const key) const { T getSettingValue(std::string_view const key) const {
using S = typename SettingTypeForValueType<T>::SettingType; 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 sett->getValue();
} }
return T(); return T();
@ -254,7 +252,7 @@ namespace geode {
template <class T> template <class T>
T setSettingValue(std::string_view const key, T const& value) { T setSettingValue(std::string_view const key, T const& value) {
using S = typename SettingTypeForValueType<T>::SettingType; 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(); auto old = sett->getValue();
sett->setValue(value); sett->setValue(value);
return old; return old;

View file

@ -171,7 +171,7 @@ namespace geode {
* Mod settings * Mod settings
* @note Not a map because insertion order must be preserved * @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 * Get the tags for this mod
*/ */

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <Geode/DefaultInclude.hpp> #include <Geode/DefaultInclude.hpp>
#include "SettingV3.hpp" #include "Setting.hpp"
namespace geode { namespace geode {
class Mod; class Mod;
@ -57,12 +57,8 @@ namespace geode {
matjson::Value& getSaveData(); matjson::Value& getSaveData();
Result<> registerCustomSettingType(std::string_view type, SettingGenerator generator); 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<Setting> get(std::string_view key);
std::shared_ptr<SettingValue> getLegacy(std::string_view key);
std::optional<Setting> getLegacyDefinition(std::string_view key);
/** /**
* Returns true if any setting with the `"restart-required"` attribute * Returns true if any setting with the `"restart-required"` attribute

View 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);
}
}

View file

@ -14,8 +14,6 @@ class ModSettingsPopup;
namespace geode { namespace geode {
class ModSettingsManager; class ModSettingsManager;
class SettingNodeV3; class SettingNodeV3;
// todo in v4: remove this
class SettingValue;
class GEODE_DLL SettingV3 : public std::enable_shared_from_this<SettingV3> { class GEODE_DLL SettingV3 : public std::enable_shared_from_this<SettingV3> {
private: private:
@ -122,8 +120,6 @@ namespace geode {
*/ */
void markChanged(); void markChanged();
friend class ::geode::SettingValue;
public: public:
SettingV3(); SettingV3();
virtual ~SettingV3(); virtual ~SettingV3();
@ -182,7 +178,7 @@ namespace geode {
virtual void reset() = 0; 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& key,
std::string const& modID, std::string const& modID,
matjson::Value const& json matjson::Value const& json
@ -697,45 +693,45 @@ namespace geode {
}; };
template <class T> template <class T>
struct SettingTypeForValueType { struct SettingTypeForValueTypeV3 {
static_assert( static_assert(
!std::is_same_v<T, T>, !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 <> template <>
struct SettingTypeForValueType<bool> { struct SettingTypeForValueTypeV3<bool> {
using SettingType = BoolSettingV3; using SettingType = BoolSettingV3;
}; };
template <> template <>
struct SettingTypeForValueType<int64_t> { struct SettingTypeForValueTypeV3<int64_t> {
using SettingType = IntSettingV3; using SettingType = IntSettingV3;
}; };
template <> template <>
struct SettingTypeForValueType<double> { struct SettingTypeForValueTypeV3<double> {
using SettingType = FloatSettingV3; using SettingType = FloatSettingV3;
}; };
template <> template <>
struct SettingTypeForValueType<std::string> { struct SettingTypeForValueTypeV3<std::string> {
using SettingType = StringSettingV3; using SettingType = StringSettingV3;
}; };
template <> template <>
struct SettingTypeForValueType<std::filesystem::path> { struct SettingTypeForValueTypeV3<std::filesystem::path> {
using SettingType = FileSettingV3; using SettingType = FileSettingV3;
}; };
template <> template <>
struct SettingTypeForValueType<cocos2d::ccColor3B> { struct SettingTypeForValueTypeV3<cocos2d::ccColor3B> {
using SettingType = Color3BSettingV3; using SettingType = Color3BSettingV3;
}; };
template <> template <>
struct SettingTypeForValueType<cocos2d::ccColor4B> { struct SettingTypeForValueTypeV3<cocos2d::ccColor4B> {
using SettingType = Color4BSettingV3; using SettingType = Color4BSettingV3;
}; };
template <class T> template <class T>
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 Ty = typename SettingTypeForValueType<T>::SettingType; using Ty = typename SettingTypeForValueTypeV3<T>::SettingType;
return new EventListener( return new EventListener(
[callback = std::move(callback)](std::shared_ptr<SettingV3> setting) { [callback = std::move(callback)](std::shared_ptr<SettingV3> setting) {
if (auto ty = geode::cast::typeinfo_pointer_cast<Ty>(setting)) { if (auto ty = geode::cast::typeinfo_pointer_cast<Ty>(setting)) {
@ -745,11 +741,11 @@ namespace geode {
SettingChangedFilterV3(mod, std::string(settingKey)) 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)>>; 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, std::function<void(std::shared_ptr<SettingV3>)> const& callback,
Mod* mod = getMod() Mod* mod = getMod()
); );

View file

@ -89,14 +89,11 @@ namespace geode {
constexpr std::string_view GEODE_MOD_EXTENSION = ".geode"; constexpr std::string_view GEODE_MOD_EXTENSION = ".geode";
class Mod; class Mod;
class Setting;
class Loader; class Loader;
class Hook; class Hook;
class VersionInfo; class VersionInfo;
class Unknown; class Unknown;
using unknownmemfn_t = void (Unknown::*)();
using unknownfn_t = void (*)();
namespace modifier { namespace modifier {
template <class, class> template <class, class>

View file

@ -116,14 +116,22 @@ namespace geode {
public: public:
// todo in v4: make these flags and add archless Mac and Android as well as Desktop and Mobile and remove Linux // todo in v4: make these flags and add archless Mac and Android as well as Desktop and Mobile and remove Linux
enum { enum {
Unknown = -1, Unknown = 0b000000,
Windows = 0, Windows = 0b000001,
MacIntel = 1, Android32 = 0b000010,
MacArm = 2, Android64 = 0b000100,
iOS = 3, MacIntel = 0b001000,
Android32 = 4, MacArm = 0b010000,
Android64 = 5, iOS = 0b100000,
Linux = 6, 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); using Type = decltype(Unknown);
@ -190,7 +198,6 @@ namespace geode {
case iOS: return "iOS"; case iOS: return "iOS";
case Android32: return "Android32"; case Android32: return "Android32";
case Android64: return "Android64"; case Android64: return "Android64";
case Linux: return "Linux";
default: break; default: break;
} }
return "Undefined"; return "Undefined";
@ -206,7 +213,6 @@ namespace geode {
case iOS: return "ios"; case iOS: return "ios";
case Android32: return ignoreArch ? "android" : "android32"; case Android32: return ignoreArch ? "android" : "android32";
case Android64: return ignoreArch ? "android" : "android64"; case Android64: return ignoreArch ? "android" : "android64";
case Linux: return "linux";
default: break; default: break;
} }
return "undefined"; return "undefined";

View file

@ -8,6 +8,8 @@
#include <Geode/utils/cocos.hpp> #include <Geode/utils/cocos.hpp>
namespace geode { namespace geode {
struct SceneSwitch;
class GEODE_DLL SceneManager final { class GEODE_DLL SceneManager final {
protected: protected:
std::vector<Ref<cocos2d::CCNode>> m_persistedNodes; std::vector<Ref<cocos2d::CCNode>> m_persistedNodes;
@ -15,6 +17,10 @@ namespace geode {
virtual ~SceneManager(); virtual ~SceneManager();
void willSwitchToScene(cocos2d::CCScene* scene);
friend struct SceneSwitch;
public: public:
static SceneManager* get(); 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. * Gets a span of the persisted nodes. To add new nodes to the list, use keepAcrossScenes.
*/ */
std::span<Ref<cocos2d::CCNode> const> getPersistedNodes(); 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);
}; };
} }

View file

@ -2,10 +2,15 @@
using namespace geode::prelude; 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 #ifdef GEODE_IS_WINDOWS
#include <Geode/modify/AppDelegate.hpp>
struct SceneSwitch : Modify<SceneSwitch, AppDelegate> { struct SceneSwitch : Modify<SceneSwitch, AppDelegate> {
GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled") GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled")
void willSwitchToScene(CCScene* scene) { void willSwitchToScene(CCScene* scene) {
@ -15,8 +20,6 @@ struct SceneSwitch : Modify<SceneSwitch, AppDelegate> {
}; };
#else #else
#include <Geode/modify/AchievementNotifier.hpp>
struct SceneSwitch : Modify<SceneSwitch, AchievementNotifier> { struct SceneSwitch : Modify<SceneSwitch, AchievementNotifier> {
GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled") GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled")
void willSwitchToScene(CCScene* scene) { void willSwitchToScene(CCScene* scene) {
@ -26,3 +29,5 @@ struct SceneSwitch : Modify<SceneSwitch, AchievementNotifier> {
}; };
#endif #endif
}

View file

@ -152,7 +152,7 @@ bool Mod::hasSetting(std::string_view const key) const {
return m_impl->hasSetting(key); 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)); return m_impl->m_settings->get(std::string(key));
} }

View file

@ -229,19 +229,19 @@ Result<> Mod::Impl::saveData() {
} }
bool Mod::Impl::hasSettings() const { 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> Mod::Impl::getSettingKeys() const {
std::vector<std::string> keys; std::vector<std::string> keys;
for (auto& [key, _] : m_metadata.getSettingsV3()) { for (auto& [key, _] : m_metadata.getSettings()) {
keys.push_back(key); keys.push_back(key);
} }
return keys; return keys;
} }
bool Mod::Impl::hasSetting(std::string_view const key) const { 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) { if (setting.first == key) {
return true; return true;
} }
@ -681,8 +681,6 @@ ModJson Mod::Impl::getRuntimeInfo() const {
for (auto patch : m_patches) { for (auto patch : m_patches) {
obj["patches"].as_array().push_back(ModJson(patch->getRuntimeInfo())); obj["patches"].as_array().push_back(ModJson(patch->getRuntimeInfo()));
} }
// TODO: so which one is it
// obj["enabled"] = m_enabled;
obj["loaded"] = m_enabled; obj["loaded"] = m_enabled;
obj["temp-dir"] = this->getTempDir(); obj["temp-dir"] = this->getTempDir();
obj["save-dir"] = this->getSaveDir(); obj["save-dir"] = this->getSaveDir();

View file

@ -519,7 +519,7 @@ std::vector<ModMetadata::Incompatibility> ModMetadata::getIncompatibilities() co
std::vector<std::string> ModMetadata::getSpritesheets() const { std::vector<std::string> ModMetadata::getSpritesheets() const {
return m_impl->m_spritesheets; 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; return m_impl->m_settings;
} }
std::unordered_set<std::string> ModMetadata::getTags() const { std::unordered_set<std::string> ModMetadata::getTags() const {

View file

@ -4,7 +4,7 @@
#include <Geode/loader/Mod.hpp> #include <Geode/loader/Mod.hpp>
#include <Geode/utils/JsonValidation.hpp> #include <Geode/utils/JsonValidation.hpp>
#include <Geode/utils/VersionInfo.hpp> #include <Geode/utils/VersionInfo.hpp>
#include <Geode/loader/SettingV3.hpp> #include <Geode/loader/Setting.hpp>
using namespace geode::prelude; using namespace geode::prelude;

View file

@ -13,17 +13,17 @@ private:
std::unordered_map<std::string, SettingGenerator> m_types; std::unordered_map<std::string, SettingGenerator> m_types;
SharedSettingTypesPool() : m_types({ SharedSettingTypesPool() : m_types({
{ "title", &TitleSettingV3::parse }, { "title", &TitleSetting::parse },
{ "bool", &BoolSettingV3::parse }, { "bool", &BoolSetting::parse },
{ "int", &IntSettingV3::parse }, { "int", &IntSetting::parse },
{ "float", &FloatSettingV3::parse }, { "float", &FloatSetting::parse },
{ "string", &StringSettingV3::parse }, { "string", &StringSetting::parse },
{ "file", &FileSettingV3::parse }, { "file", &FileSetting::parse },
{ "folder", &FileSettingV3::parse }, { "folder", &FileSetting::parse },
{ "path", &FileSettingV3::parse }, { "path", &FileSetting::parse },
{ "rgb", &Color3BSettingV3::parse }, { "rgb", &Color3BSetting::parse },
{ "color", &Color3BSettingV3::parse }, { "color", &Color3BSetting::parse },
{ "rgba", &Color4BSettingV3::parse }, { "rgba", &Color4BSetting::parse },
}) {} }) {}
public: public:
@ -78,9 +78,7 @@ public:
struct SettingInfo final { struct SettingInfo final {
std::string type; std::string type;
matjson::Value json; matjson::Value json;
std::shared_ptr<SettingV3> v3 = nullptr; std::shared_ptr<Setting> v3 = nullptr;
// todo: remove in v4
std::shared_ptr<SettingValue> legacy = nullptr;
}; };
std::string modID; std::string modID;
std::unordered_map<std::string, SettingInfo> settings; std::unordered_map<std::string, SettingInfo> settings;
@ -159,7 +157,7 @@ ModSettingsManager::ModSettingsManager(ModMetadata const& metadata)
: m_impl(std::make_unique<Impl>()) : m_impl(std::make_unique<Impl>())
{ {
m_impl->modID = metadata.getID(); m_impl->modID = metadata.getID();
for (auto const& [key, json] : metadata.getSettingsV3()) { for (auto const& [key, json] : metadata.getSettings()) {
auto setting = Impl::SettingInfo(); auto setting = Impl::SettingInfo();
setting.json = json; setting.json = json;
auto root = checkJson(json, "setting"); auto root = checkJson(json, "setting");
@ -195,13 +193,6 @@ Result<> ModSettingsManager::registerCustomSettingType(std::string_view type, Se
m_impl->createSettings(); m_impl->createSettings();
return Ok(); 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) { Result<> ModSettingsManager::load(matjson::Value const& json) {
if (json.is_object()) { if (json.is_object()) {
@ -225,7 +216,7 @@ matjson::Value& ModSettingsManager::getSaveData() {
return m_impl->savedata; 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); auto id = std::string(key);
return m_impl->settings.count(id) ? m_impl->settings.at(id).v3 : nullptr; return m_impl->settings.count(id) ? m_impl->settings.at(id).v3 : nullptr;
} }

View 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;

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <Geode/loader/SettingV3.hpp> #include <Geode/loader/Setting.hpp>
#include <Geode/binding/CCMenuItemToggler.hpp> #include <Geode/binding/CCMenuItemToggler.hpp>
#include <Geode/binding/ColorChannelSprite.hpp> #include <Geode/binding/ColorChannelSprite.hpp>
#include <Geode/binding/Slider.hpp> #include <Geode/binding/Slider.hpp>

View file

@ -1,4 +1,4 @@
#include <Geode/loader/SettingV3.hpp> #include <Geode/loader/Setting.hpp>
#include <Geode/loader/ModSettingsManager.hpp> #include <Geode/loader/ModSettingsManager.hpp>
#include <Geode/utils/ranges.hpp> #include <Geode/utils/ranges.hpp>
#include <Geode/utils/string.hpp> #include <Geode/utils/string.hpp>
@ -45,7 +45,7 @@ namespace enable_if_parsing {
if (!mod->hasSetting(settingID)) { if (!mod->hasSetting(settingID)) {
return Err("Mod '{}' does not have setting '{}'", mod->getName(), 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()); 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 // This is an if-check just in case, even though check() should already
// make sure that getSettingV3 is guaranteed to return true // make sure that getSettingV3 is guaranteed to return true
auto name = settingID; auto name = settingID;
if (auto sett = mod->getSettingV3(settingID)) { if (auto sett = mod->getSetting(settingID)) {
name = sett->getDisplayName(); name = sett->getDisplayName();
} }
if (modID == defaultModID) { if (modID == defaultModID) {
@ -446,7 +446,7 @@ SettingChangedFilterV3::SettingChangedFilterV3(Mod* mod, std::optional<std::stri
SettingChangedFilterV3::SettingChangedFilterV3(SettingChangedFilterV3 const&) = default; SettingChangedFilterV3::SettingChangedFilterV3(SettingChangedFilterV3 const&) = default;
EventListener<SettingChangedFilterV3>* geode::listenForAllSettingChanges( EventListener<SettingChangedFilterV3>* geode::listenForAllSettingChangesV3(
std::function<void(std::shared_ptr<SettingV3>)> const& callback, std::function<void(std::shared_ptr<SettingV3>)> const& callback,
Mod* mod Mod* mod
) { ) {
@ -572,12 +572,6 @@ void SettingV3::markChanged() {
manager->markRestartRequired(); manager->markRestartRequired();
} }
SettingChangedEventV3(shared_from_this()).post(); 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 { class TitleSettingV3::Impl final {
public: public:

View file

@ -90,7 +90,7 @@ bool ModsStatusNode::init() {
m_downloadListener.bind([this](auto) { this->updateState(); }); m_downloadListener.bind([this](auto) { this->updateState(); });
m_settingNodeListener.bind([this](SettingNodeValueChangeEventV3* ev) { m_settingNodeListener.bind([this](SettingNodeValueChangeEvent* ev) {
this->updateState(); this->updateState();
return ListenerResult::Propagate; return ListenerResult::Propagate;
}); });

View file

@ -12,7 +12,7 @@
#include "sources/ModListSource.hpp" #include "sources/ModListSource.hpp"
#include "UpdateModListState.hpp" #include "UpdateModListState.hpp"
#include <server/DownloadManager.hpp> #include <server/DownloadManager.hpp>
#include <Geode/loader/SettingV3.hpp> #include <Geode/loader/Setting.hpp>
using namespace geode::prelude; using namespace geode::prelude;
@ -40,7 +40,7 @@ protected:
EventListener<UpdateModListStateFilter> m_updateStateListener; EventListener<UpdateModListStateFilter> m_updateStateListener;
EventListener<server::ModDownloadFilter> m_downloadListener; EventListener<server::ModDownloadFilter> m_downloadListener;
DownloadState m_lastState = DownloadState::None; DownloadState m_lastState = DownloadState::None;
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_settingNodeListener; EventListener<EventFilter<SettingNodeValueChangeEvent>> m_settingNodeListener;
bool init(); bool init();
void updateState(); void updateState();

View file

@ -303,7 +303,7 @@ bool ModItem::init(ModSource&& source) {
m_downloadListener.bind([this](auto) { this->updateState(); }); m_downloadListener.bind([this](auto) { this->updateState(); });
m_downloadListener.setFilter(server::ModDownloadFilter(m_source.getID())); m_downloadListener.setFilter(server::ModDownloadFilter(m_source.getID()));
m_settingNodeListener.bind([this](SettingNodeValueChangeEventV3*) { m_settingNodeListener.bind([this](SettingNodeValueChangeEvent*) {
this->updateState(); this->updateState();
return ListenerResult::Propagate; return ListenerResult::Propagate;
}); });

View file

@ -35,7 +35,7 @@ protected:
EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener; EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener;
EventListener<server::ModDownloadFilter> m_downloadListener; EventListener<server::ModDownloadFilter> m_downloadListener;
std::optional<server::ServerModUpdate> m_availableUpdate; std::optional<server::ServerModUpdate> m_availableUpdate;
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_settingNodeListener; EventListener<EventFilter<SettingNodeValueChangeEvent>> m_settingNodeListener;
/** /**
* @warning Make sure `getMetadata` and `createModLogo` are callable * @warning Make sure `getMetadata` and `createModLogo` are callable

View file

@ -618,7 +618,7 @@ bool ModPopup::setup(ModSource&& src) {
m_downloadListener.bind([this](auto) { this->updateState(); }); m_downloadListener.bind([this](auto) { this->updateState(); });
m_downloadListener.setFilter(m_source.getID()); m_downloadListener.setFilter(m_source.getID());
m_settingNodeListener.bind([this](SettingNodeValueChangeEventV3*) { m_settingNodeListener.bind([this](SettingNodeValueChangeEvent*) {
this->updateState(); this->updateState();
return ListenerResult::Propagate; return ListenerResult::Propagate;
}); });

View file

@ -42,7 +42,7 @@ protected:
EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener; EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener;
EventListener<UpdateModListStateFilter> m_updateStateListener; EventListener<UpdateModListStateFilter> m_updateStateListener;
EventListener<server::ModDownloadFilter> m_downloadListener; EventListener<server::ModDownloadFilter> m_downloadListener;
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_settingNodeListener; EventListener<EventFilter<SettingNodeValueChangeEvent>> m_settingNodeListener;
bool setup(ModSource&& src) override; bool setup(ModSource&& src) override;
void updateState(); void updateState();

View file

@ -6,12 +6,13 @@
#include <Geode/utils/cocos.hpp> #include <Geode/utils/cocos.hpp>
#include <Geode/ui/General.hpp> #include <Geode/ui/General.hpp>
#include <Geode/ui/Scrollbar.hpp> #include <Geode/ui/Scrollbar.hpp>
#include <loader/SettingNodeV3.hpp> #include <Geode/loader/Setting.hpp>
#include <loader/SettingNode.hpp>
// needed for weightedFuzzyMatch // needed for weightedFuzzyMatch
#include <ui/mods/sources/ModListSource.hpp> #include <ui/mods/sources/ModListSource.hpp>
static bool matchSearch(SettingNodeV3* node, std::string const& query) { static bool matchSearch(SettingNode* node, std::string const& query) {
if (typeinfo_cast<TitleSettingNodeV3*>(node)) { if (typeinfo_cast<TitleSettingNode*>(node)) {
return true; return true;
} }
bool addToList = false; bool addToList = false;
@ -73,12 +74,12 @@ bool ModSettingsPopup::setup(Mod* mod) {
m_list->setTouchEnabled(true); m_list->setTouchEnabled(true);
for (auto& key : mod->getSettingKeys()) { for (auto& key : mod->getSettingKeys()) {
SettingNodeV3* node; SettingNode* node;
if (auto sett = mod->getSettingV3(key)) { if (auto sett = mod->getSetting(key)) {
node = sett->createNode(layerSize.width); node = sett->createNode(layerSize.width);
} }
else { else {
node = UnresolvedCustomSettingNodeV3::create(key, mod, layerSize.width); node = UnresolvedCustomSettingNode::create(key, mod, layerSize.width);
} }
m_settings.push_back(node); m_settings.push_back(node);
@ -249,7 +250,7 @@ void ModSettingsPopup::onClearSearch(CCObject*) {
m_list->moveToTop(); m_list->moveToTop();
} }
void ModSettingsPopup::updateState(SettingNodeV3* invoker) { void ModSettingsPopup::updateState(SettingNode* invoker) {
auto search = m_searchInput->getString(); auto search = m_searchInput->getString();
auto hasSearch = !search.empty(); auto hasSearch = !search.empty();
@ -261,10 +262,10 @@ void ModSettingsPopup::updateState(SettingNodeV3* invoker) {
// Update search visibility + all settings with "enable-if" schemes + // Update search visibility + all settings with "enable-if" schemes +
// checkerboard BG // checkerboard BG
TitleSettingNodeV3* lastTitle = nullptr; TitleSettingNode* lastTitle = nullptr;
bool bg = false; bool bg = false;
for (auto& sett : m_settings) { for (auto& sett : m_settings) {
if (auto asTitle = typeinfo_cast<TitleSettingNodeV3*>(sett.data())) { if (auto asTitle = typeinfo_cast<TitleSettingNode*>(sett.data())) {
lastTitle = asTitle; lastTitle = asTitle;
} }
sett->removeFromParent(); sett->removeFromParent();

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <Geode/loader/SettingV3.hpp> #include <Geode/loader/Setting.hpp>
#include <Geode/ui/Popup.hpp> #include <Geode/ui/Popup.hpp>
#include <Geode/utils/cocos.hpp> #include <Geode/utils/cocos.hpp>
#include <Geode/ui/ScrollLayer.hpp> #include <Geode/ui/ScrollLayer.hpp>
@ -14,17 +14,17 @@ class ModSettingsPopup : public GeodePopup<Mod*> {
protected: protected:
Mod* m_mod; Mod* m_mod;
ScrollLayer* m_list; ScrollLayer* m_list;
std::vector<Ref<SettingNodeV3>> m_settings; std::vector<Ref<SettingNode>> m_settings;
CCMenu* m_applyMenu; CCMenu* m_applyMenu;
CCMenuItemSpriteExtra* m_applyBtn; CCMenuItemSpriteExtra* m_applyBtn;
CCMenuItemSpriteExtra* m_restartBtn; CCMenuItemSpriteExtra* m_restartBtn;
ButtonSprite* m_applyBtnSpr; ButtonSprite* m_applyBtnSpr;
TextInput* m_searchInput; TextInput* m_searchInput;
CCMenuItemSpriteExtra* m_searchClearBtn; CCMenuItemSpriteExtra* m_searchClearBtn;
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_changeListener; EventListener<EventFilter<SettingNodeValueChangeEvent>> m_changeListener;
bool setup(Mod* mod) override; bool setup(Mod* mod) override;
void updateState(SettingNodeV3* invoker = nullptr); void updateState(SettingNode* invoker = nullptr);
bool hasUncommitted() const; bool hasUncommitted() const;
void onClose(CCObject*) override; void onClose(CCObject*) override;
void onApply(CCObject*); void onApply(CCObject*);

View file

@ -33,8 +33,6 @@ PlatformID PlatformID::from(const char* str) {
case hash("Android64"): case hash("Android64"):
case hash("android64"): return PlatformID::Android64; case hash("android64"): return PlatformID::Android64;
case hash("Linux"):
case hash("linux"): return PlatformID::Linux;
default: return PlatformID::Unknown; default: return PlatformID::Unknown;
} }
} }
@ -65,9 +63,6 @@ std::vector<PlatformID> PlatformID::getCovered(std::string_view str) {
case hash("android32"): return { PlatformID::Android32 }; case hash("android32"): return { PlatformID::Android32 };
case hash("android64"): return { PlatformID::Android64 }; case hash("android64"): return { PlatformID::Android64 };
// todo in v4: no linux
case hash("linux"): return { PlatformID::Linux };
default: return {}; default: return {};
} }
} }