Brush Assets: Add catalog option to asset pushing operator #118382

Merged
Hans Goudey merged 26 commits from HooglyBoogly/blender:brush-assets-save-catalog-option into brush-assets-project 2024-02-21 14:03:41 +01:00
1 changed files with 18 additions and 19 deletions
Showing only changes of commit d6cef32e54 - Show all commits

View File

@ -30,37 +30,37 @@ AssetCatalogPath::AssetCatalogPath(AssetCatalogPath &&other_path) noexcept
uint64_t AssetCatalogPath::hash() const
{
std::hash<std::string> hasher{};
return hasher(this->path_);
return hasher(path_);
}
uint64_t AssetCatalogPath::length() const
{
return this->path_.length();
return path_.length();
}
const char *AssetCatalogPath::c_str() const
{
return this->path_.c_str();
return path_.c_str();
}
const std::string &AssetCatalogPath::str() const
{
return this->path_;
return path_;
}
StringRefNull AssetCatalogPath::name() const
{
const size_t last_sep_index = this->path_.rfind(SEPARATOR);
const size_t last_sep_index = path_.rfind(SEPARATOR);
if (last_sep_index == std::string::npos) {
return StringRefNull(this->path_);
return StringRefNull(path_);
}
return StringRefNull(this->path_.c_str() + last_sep_index + 1);
return StringRefNull(path_.c_str() + last_sep_index + 1);
}
bool AssetCatalogPath::operator==(const AssetCatalogPath &other_path) const
{
return this->path_ == other_path.path_;
return path_ == other_path.path_;
}
bool AssetCatalogPath::operator!=(const AssetCatalogPath &other_path) const
@ -70,7 +70,7 @@ bool AssetCatalogPath::operator!=(const AssetCatalogPath &other_path) const
bool AssetCatalogPath::operator<(const AssetCatalogPath &other_path) const
{
return this->path_ < other_path.path_;
return path_ < other_path.path_;
}
AssetCatalogPath AssetCatalogPath::operator/(const AssetCatalogPath &path_to_append) const
@ -84,13 +84,13 @@ AssetCatalogPath AssetCatalogPath::operator/(const AssetCatalogPath &path_to_app
}
std::stringstream new_path;
new_path << this->path_ << SEPARATOR << path_to_append.path_;
new_path << path_ << SEPARATOR << path_to_append.path_;
return AssetCatalogPath(new_path.str());
}
AssetCatalogPath::operator bool() const
{
return !this->path_.empty();
return !path_.empty();
}
std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)
@ -129,8 +129,7 @@ AssetCatalogPath AssetCatalogPath::cleanup() const
std::string AssetCatalogPath::cleanup_component(StringRef component)
{
// std::string cleaned = component.trim();
std::string cleaned = component;
std::string cleaned = component.trim();
/* Replace colons with something else, as those are used in the CDF file as delimiter. */
std::replace(cleaned.begin(), cleaned.end(), ':', '-');
return cleaned;
@ -143,7 +142,7 @@ bool AssetCatalogPath::is_contained_in(const AssetCatalogPath &other_path) const
return true;
}
if (this->path_ == other_path.path_) {
if (path_ == other_path.path_) {
/* Weak is-in relation: equal paths contain each other. */
return true;
}
@ -155,7 +154,7 @@ bool AssetCatalogPath::is_contained_in(const AssetCatalogPath &other_path) const
}
/* Create StringRef to be able to use .startswith(). */
const StringRef this_path(this->path_);
const StringRef this_path(path_);
const bool prefix_ok = this_path.startswith(other_path.path_);
const char next_char = this_path[other_path.length()];
return prefix_ok && next_char == SEPARATOR;
@ -166,18 +165,18 @@ AssetCatalogPath AssetCatalogPath::parent() const
if (!*this) {
return AssetCatalogPath("");
}
std::string::size_type last_sep_index = this->path_.rfind(SEPARATOR);
std::string::size_type last_sep_index = path_.rfind(SEPARATOR);
if (last_sep_index == std::string::npos) {
return AssetCatalogPath("");
}
return AssetCatalogPath(this->path_.substr(0, last_sep_index));
return AssetCatalogPath(path_.substr(0, last_sep_index));
}
void AssetCatalogPath::iterate_components(ComponentIteratorFn callback) const
{
const char *next_slash_ptr;
for (const char *path_component = this->path_.data(); path_component && path_component[0];
for (const char *path_component = path_.data(); path_component && path_component[0];
/* Jump to one after the next slash if there is any. */
path_component = next_slash_ptr ? next_slash_ptr + 1 : nullptr)
{
@ -216,7 +215,7 @@ AssetCatalogPath AssetCatalogPath::rebase(const AssetCatalogPath &from_path,
}
/* When from_path = "test", we need to skip "test/" to get the rest of the path, hence the +1. */
const StringRef suffix = StringRef(this->path_).substr(from_path.length() + 1);
const StringRef suffix = StringRef(path_).substr(from_path.length() + 1);
const AssetCatalogPath path_suffix(suffix);
return to_path / path_suffix;
}