mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-26 17:36:05 -05:00
Merge pull request #417 from dankmeme01/main
use string_view instead of string& in Mod
This commit is contained in:
commit
e1161a96c6
4 changed files with 46 additions and 43 deletions
|
@ -119,9 +119,9 @@ namespace geode {
|
|||
|
||||
bool hasSettings() const;
|
||||
std::vector<std::string> getSettingKeys() const;
|
||||
bool hasSetting(std::string const& key) const;
|
||||
std::optional<Setting> getSettingDefinition(std::string const& key) const;
|
||||
SettingValue* getSetting(std::string const& key) const;
|
||||
bool hasSetting(std::string_view const key) const;
|
||||
std::optional<Setting> getSettingDefinition(std::string_view const key) const;
|
||||
SettingValue* getSetting(std::string_view const key) const;
|
||||
|
||||
/**
|
||||
* Register a custom setting's value class. See Mod::addCustomSetting
|
||||
|
@ -133,7 +133,7 @@ namespace geode {
|
|||
* @param value The SettingValue class that shall handle this setting
|
||||
* @see addCustomSetting
|
||||
*/
|
||||
void registerCustomSetting(std::string const& key, std::unique_ptr<SettingValue> value);
|
||||
void registerCustomSetting(std::string_view const key, std::unique_ptr<SettingValue> value);
|
||||
/**
|
||||
* Register a custom setting's value class. The new SettingValue class
|
||||
* will be created in-place using `std::make_unique`. See
|
||||
|
@ -147,14 +147,14 @@ namespace geode {
|
|||
* }
|
||||
*/
|
||||
template <class T, class V>
|
||||
void addCustomSetting(std::string const& key, V const& value) {
|
||||
void addCustomSetting(std::string_view const key, V const& value) {
|
||||
this->registerCustomSetting(key, std::make_unique<T>(key, this->getID(), value));
|
||||
}
|
||||
|
||||
matjson::Value& getSaveContainer();
|
||||
|
||||
template <class T>
|
||||
T getSettingValue(std::string const& key) const {
|
||||
T getSettingValue(std::string_view const key) const {
|
||||
if (auto sett = this->getSetting(key)) {
|
||||
return SettingValueSetter<T>::get(sett);
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ namespace geode {
|
|||
}
|
||||
|
||||
template <class T>
|
||||
T setSettingValue(std::string const& key, T const& value) {
|
||||
T setSettingValue(std::string_view const key, T const& value) {
|
||||
if (auto sett = this->getSetting(key)) {
|
||||
auto old = this->getSettingValue<T>(key);
|
||||
SettingValueSetter<T>::set(sett, value);
|
||||
|
@ -171,10 +171,10 @@ namespace geode {
|
|||
return T();
|
||||
}
|
||||
|
||||
bool hasSavedValue(std::string const& key);
|
||||
bool hasSavedValue(std::string_view const key);
|
||||
|
||||
template <class T>
|
||||
T getSavedValue(std::string const& key) {
|
||||
T getSavedValue(std::string_view const key) {
|
||||
auto& saved = this->getSaveContainer();
|
||||
if (saved.contains(key)) {
|
||||
try {
|
||||
|
@ -188,7 +188,7 @@ namespace geode {
|
|||
}
|
||||
|
||||
template <class T>
|
||||
T getSavedValue(std::string const& key, T const& defaultValue) {
|
||||
T getSavedValue(std::string_view const key, T const& defaultValue) {
|
||||
auto& saved = this->getSaveContainer();
|
||||
if (saved.contains(key)) {
|
||||
try {
|
||||
|
@ -210,7 +210,7 @@ namespace geode {
|
|||
* @returns The old value
|
||||
*/
|
||||
template <class T>
|
||||
T setSavedValue(std::string const& key, T const& value) {
|
||||
T setSavedValue(std::string_view const key, T const& value) {
|
||||
auto& saved = this->getSaveContainer();
|
||||
auto old = this->getSavedValue<T>(key);
|
||||
saved[key] = value;
|
||||
|
@ -335,7 +335,7 @@ namespace geode {
|
|||
* Check whether or not this Mod
|
||||
* depends on another mod
|
||||
*/
|
||||
bool depends(std::string const& id) const;
|
||||
bool depends(std::string_view const id) const;
|
||||
|
||||
/**
|
||||
* Check whether all the required
|
||||
|
|
|
@ -105,19 +105,19 @@ std::vector<std::string> Mod::getSettingKeys() const {
|
|||
return m_impl->getSettingKeys();
|
||||
}
|
||||
|
||||
bool Mod::hasSetting(std::string const& key) const {
|
||||
bool Mod::hasSetting(std::string_view const key) const {
|
||||
return m_impl->hasSetting(key);
|
||||
}
|
||||
|
||||
std::optional<Setting> Mod::getSettingDefinition(std::string const& key) const {
|
||||
std::optional<Setting> Mod::getSettingDefinition(std::string_view const key) const {
|
||||
return m_impl->getSettingDefinition(key);
|
||||
}
|
||||
|
||||
SettingValue* Mod::getSetting(std::string const& key) const {
|
||||
SettingValue* Mod::getSetting(std::string_view const key) const {
|
||||
return m_impl->getSetting(key);
|
||||
}
|
||||
|
||||
void Mod::registerCustomSetting(std::string const& key, std::unique_ptr<SettingValue> value) {
|
||||
void Mod::registerCustomSetting(std::string_view const key, std::unique_ptr<SettingValue> value) {
|
||||
return m_impl->registerCustomSetting(key, std::move(value));
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ ModRequestedAction Mod::getRequestedAction() const {
|
|||
return m_impl->getRequestedAction();
|
||||
}
|
||||
|
||||
bool Mod::depends(std::string const& id) const {
|
||||
bool Mod::depends(std::string_view const id) const {
|
||||
return m_impl->depends(id);
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ void Mod::setLoggingEnabled(bool enabled) {
|
|||
m_impl->setLoggingEnabled(enabled);
|
||||
}
|
||||
|
||||
bool Mod::hasSavedValue(std::string const& key) {
|
||||
bool Mod::hasSavedValue(std::string_view const key) {
|
||||
return this->getSaveContainer().contains(key);
|
||||
}
|
||||
|
||||
|
|
|
@ -258,13 +258,14 @@ void Mod::Impl::setupSettings() {
|
|||
}
|
||||
}
|
||||
|
||||
void Mod::Impl::registerCustomSetting(std::string const& key, std::unique_ptr<SettingValue> value) {
|
||||
if (!m_settings.count(key)) {
|
||||
void Mod::Impl::registerCustomSetting(std::string_view const key, std::unique_ptr<SettingValue> value) {
|
||||
auto keystr = std::string(key);
|
||||
if (!m_settings.count(keystr)) {
|
||||
// load data
|
||||
if (m_savedSettingsData.contains(key)) {
|
||||
value->load(m_savedSettingsData[key]);
|
||||
}
|
||||
m_settings.emplace(key, std::move(value));
|
||||
m_settings.emplace(keystr, std::move(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +281,7 @@ std::vector<std::string> Mod::Impl::getSettingKeys() const {
|
|||
return keys;
|
||||
}
|
||||
|
||||
std::optional<Setting> Mod::Impl::getSettingDefinition(std::string const& key) const {
|
||||
std::optional<Setting> Mod::Impl::getSettingDefinition(std::string_view const key) const {
|
||||
for (auto& setting : m_metadata.getSettings()) {
|
||||
if (setting.first == key) {
|
||||
return setting.second;
|
||||
|
@ -289,14 +290,16 @@ std::optional<Setting> Mod::Impl::getSettingDefinition(std::string const& key) c
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
SettingValue* Mod::Impl::getSetting(std::string const& key) const {
|
||||
if (m_settings.count(key)) {
|
||||
return m_settings.at(key).get();
|
||||
SettingValue* Mod::Impl::getSetting(std::string_view const key) const {
|
||||
auto keystr = std::string(key);
|
||||
|
||||
if (m_settings.count(keystr)) {
|
||||
return m_settings.at(keystr).get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Mod::Impl::hasSetting(std::string const& key) const {
|
||||
bool Mod::Impl::hasSetting(std::string_view const key) const {
|
||||
for (auto& setting : m_metadata.getSettings()) {
|
||||
if (setting.first == key) {
|
||||
return true;
|
||||
|
@ -449,7 +452,7 @@ bool Mod::Impl::hasUnresolvedIncompatibilities() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Mod::Impl::depends(std::string const& id) const {
|
||||
bool Mod::Impl::depends(std::string_view const id) const {
|
||||
return utils::ranges::contains(m_metadata.getDependencies(), [id](ModMetadata::Dependency const& t) {
|
||||
return t.id == id;
|
||||
});
|
||||
|
|
|
@ -109,10 +109,10 @@ namespace geode {
|
|||
|
||||
bool hasSettings() const;
|
||||
std::vector<std::string> getSettingKeys() const;
|
||||
bool hasSetting(std::string const& key) const;
|
||||
std::optional<Setting> getSettingDefinition(std::string const& key) const;
|
||||
SettingValue* getSetting(std::string const& key) const;
|
||||
void registerCustomSetting(std::string const& key, std::unique_ptr<SettingValue> value);
|
||||
bool hasSetting(std::string_view const key) const;
|
||||
std::optional<Setting> getSettingDefinition(std::string_view const key) const;
|
||||
SettingValue* getSetting(std::string_view const key) const;
|
||||
void registerCustomSetting(std::string_view const key, std::unique_ptr<SettingValue> value);
|
||||
|
||||
std::vector<Hook*> getHooks() const;
|
||||
Result<Hook*> addHook(Hook* hook);
|
||||
|
@ -129,7 +129,7 @@ namespace geode {
|
|||
// 1.3.0 additions
|
||||
ModRequestedAction getRequestedAction() const;
|
||||
|
||||
bool depends(std::string const& id) const;
|
||||
bool depends(std::string_view const id) const;
|
||||
Result<> updateDependencies();
|
||||
bool hasUnresolvedDependencies() const;
|
||||
bool hasUnresolvedIncompatibilities() const;
|
||||
|
|
Loading…
Reference in a new issue