Merge branch 'geode-sdk:main' into copy-mods

This commit is contained in:
Justin 2024-09-10 16:17:50 -04:00 committed by GitHub
commit a4bd588d4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View file

@ -453,13 +453,28 @@ bool FileSettingNodeV3::init(std::shared_ptr<FileSettingV3> setting, float width
} }
void FileSettingNodeV3::updateState(CCNode* invoker) { void FileSettingNodeV3::updateState(CCNode* invoker) {
// This is because people tend to put `"default": "Please pick a good file"`
// which is clever and good UX but also a hack so I also need to hack to support that
const auto isTextualDefaultValue = [this, setting = this->getSetting()]() {
if (this->hasNonDefaultValue()) return false;
std::error_code ec;
return setting->isFolder() ?
!std::filesystem::is_directory(setting->getDefaultValue(), ec) :
!std::filesystem::is_regular_file(setting->getDefaultValue(), ec);
}();
SettingValueNodeV3::updateState(invoker); SettingValueNodeV3::updateState(invoker);
m_fileIcon->setDisplayFrame(CCSpriteFrameCache::get()->spriteFrameByName( m_fileIcon->setDisplayFrame(CCSpriteFrameCache::get()->spriteFrameByName(
this->getSetting()->isFolder() ? "folderIcon_001.png" : "file.png"_spr this->getSetting()->isFolder() ? "folderIcon_001.png" : "file.png"_spr
)); ));
limitNodeSize(m_fileIcon, ccp(10, 10), 1.f, .1f); limitNodeSize(m_fileIcon, ccp(10, 10), 1.f, .1f);
if (this->getValue().empty()) { if (this->getValue().empty() || isTextualDefaultValue) {
if (isTextualDefaultValue) {
m_nameLabel->setString(this->getSetting()->getDefaultValue().string().c_str());
}
else {
m_nameLabel->setString(this->getSetting()->isFolder() ? "No Folder Selected" : "No File Selected"); m_nameLabel->setString(this->getSetting()->isFolder() ? "No Folder Selected" : "No File Selected");
}
m_nameLabel->setColor(ccGRAY); m_nameLabel->setColor(ccGRAY);
m_nameLabel->setOpacity(155); m_nameLabel->setOpacity(155);
} }

View file

@ -1106,6 +1106,11 @@ Result<std::shared_ptr<FileSettingV3>> FileSettingV3::parse(std::string const& k
} }
Result<> FileSettingV3::isValid(std::filesystem::path const& value) const { Result<> FileSettingV3::isValid(std::filesystem::path const& value) const {
// This is because people tend to put `"default": "Please pick a good file"`
// which is clever and good UX but also a hack so I also need to hack to support that
if (value == this->getDefaultValue()) {
return Ok();
}
std::error_code ec; std::error_code ec;
if (m_impl->folder) { if (m_impl->folder) {
if (!std::filesystem::is_directory(value, ec)) { if (!std::filesystem::is_directory(value, ec)) {