mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
i hate exposing structs
why arent settings opaque pointers aaaaaaa (fixed the abi break on custom settings users)
This commit is contained in:
parent
d88a93e3cd
commit
5ed0ed5ba6
4 changed files with 57 additions and 20 deletions
|
@ -93,6 +93,7 @@ namespace geode {
|
|||
ValueType defaultValue;
|
||||
/**
|
||||
* A regex the string must successfully match against
|
||||
* For now merged with options, reenable for Geode 4.0.0
|
||||
*/
|
||||
std::optional<std::string> match;
|
||||
|
||||
|
@ -103,8 +104,9 @@ namespace geode {
|
|||
|
||||
/**
|
||||
* A list of options the user can choose from
|
||||
* Reenable for Geode 4.0.0
|
||||
*/
|
||||
std::optional<std::vector<std::string>> options;
|
||||
// std::optional<std::vector<std::string>> options;
|
||||
|
||||
static Result<StringSetting> parse(JsonMaybeObject& obj);
|
||||
};
|
||||
|
|
|
@ -196,6 +196,11 @@ Result<> Mod::Impl::loadData() {
|
|||
|
||||
m_savedSettingsData = json;
|
||||
|
||||
log::debug("settings of this mod: ");
|
||||
for (auto& [key, value] : m_settings) {
|
||||
log::debug("{}", key);
|
||||
}
|
||||
|
||||
for (auto& [key, value] : root.items()) {
|
||||
// check if this is a known setting
|
||||
if (auto setting = this->getSetting(key)) {
|
||||
|
@ -321,7 +326,14 @@ std::vector<std::string> Mod::Impl::getSettingKeys() const {
|
|||
|
||||
std::optional<Setting> Mod::Impl::getSettingDefinition(std::string_view const key) const {
|
||||
for (auto& setting : m_metadata.getSettings()) {
|
||||
log::debug("Checking setting {}", setting.first);
|
||||
if (setting.first == key) {
|
||||
log::debug("Found setting {}", setting.first);
|
||||
auto thing = setting.second.get<CustomSetting>();
|
||||
if (thing) {
|
||||
log::debug("Setting json: {}", thing->json->dump());
|
||||
}
|
||||
|
||||
return setting.second;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,12 @@ Result<StringSetting> StringSetting::parse(JsonMaybeObject& obj) {
|
|||
parseCommon(sett, obj);
|
||||
obj.has("match").into(sett.match);
|
||||
obj.has("filter").into(sett.filter);
|
||||
obj.has("one-of").into(sett.options);
|
||||
std::vector<std::string> options;
|
||||
obj.has("one-of").into(options);
|
||||
if (options.size()) {
|
||||
sett.filter = "one-of";
|
||||
sett.match = fmt::format("{}", fmt::join(options, "|"));
|
||||
}
|
||||
return Ok(sett);
|
||||
}
|
||||
|
||||
|
@ -367,7 +372,25 @@ IMPL_TO_VALID(Float) {
|
|||
|
||||
IMPL_TO_VALID(String) {
|
||||
if (m_definition.match) {
|
||||
if (!re2::RE2::FullMatch(value, m_definition.match.value())) {
|
||||
// hacky things ahead
|
||||
if (m_definition.filter == "one-of") {
|
||||
auto options = utils::string::split(m_definition.match.value(), "|");
|
||||
|
||||
if (std::find(
|
||||
options.begin(),
|
||||
options.end(),
|
||||
value
|
||||
) == options.end()) {
|
||||
return {
|
||||
m_definition.defaultValue,
|
||||
fmt::format(
|
||||
"Value must be one of {}",
|
||||
fmt::join(options, ", ")
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
else if (!re2::RE2::FullMatch(value, m_definition.match.value())) {
|
||||
return {
|
||||
m_definition.defaultValue,
|
||||
fmt::format(
|
||||
|
@ -377,21 +400,21 @@ IMPL_TO_VALID(String) {
|
|||
};
|
||||
}
|
||||
}
|
||||
else if (m_definition.options) {
|
||||
if (std::find(
|
||||
m_definition.options.value().begin(),
|
||||
m_definition.options.value().end(),
|
||||
value
|
||||
) == m_definition.options.value().end()) {
|
||||
return {
|
||||
m_definition.defaultValue,
|
||||
fmt::format(
|
||||
"Value must be one of {}",
|
||||
fmt::join(m_definition.options.value(), ", ")
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
// else if (m_definition.options) {
|
||||
// if (std::find(
|
||||
// m_definition.options.value().begin(),
|
||||
// m_definition.options.value().end(),
|
||||
// value
|
||||
// ) == m_definition.options.value().end()) {
|
||||
// return {
|
||||
// m_definition.defaultValue,
|
||||
// fmt::format(
|
||||
// "Value must be one of {}",
|
||||
// fmt::join(m_definition.options.value(), ", ")
|
||||
// )
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
return { value, std::nullopt };
|
||||
}
|
||||
|
||||
|
|
|
@ -341,8 +341,8 @@ void StringSettingNode::onArrow(CCObject* sender) {
|
|||
|
||||
bool StringSettingNode::setup(StringSettingValue* setting, float width) {
|
||||
m_width = width;
|
||||
if (setting->castDefinition().options && setting->castDefinition().options->size() > 0) {
|
||||
m_options = setting->castDefinition().options.value();
|
||||
if (setting->castDefinition().match == "one-of") {
|
||||
m_options = utils::string::split(setting->castDefinition().match.value(), "|");
|
||||
|
||||
m_selectedOption = 0;
|
||||
for (size_t i = 0; i < m_options.size(); i++) {
|
||||
|
|
Loading…
Reference in a new issue