[studio/modlib] Fix type desc writing logic inversion
Also, provide foundation for making file types configurable for default Claw format.
This commit is contained in:
parent
5177cfb0e3
commit
2bb7c51425
@ -31,7 +31,7 @@ enum class ProjectEvent {
|
|||||||
constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
|
constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
|
||||||
auto const extStart = ox::find(path.crbegin(), path.crend(), '.').offset();
|
auto const extStart = ox::find(path.crbegin(), path.crend(), '.').offset();
|
||||||
if (!extStart) {
|
if (!extStart) {
|
||||||
return OxError(1, "Cannot open a file without valid extension.");
|
return OxError(1, "file path does not have valid extension");
|
||||||
}
|
}
|
||||||
return substr(path, extStart + 1);
|
return substr(path, extStart + 1);
|
||||||
}
|
}
|
||||||
@ -47,6 +47,7 @@ constexpr ox::StringView parentDir(ox::StringView path) noexcept {
|
|||||||
|
|
||||||
class Project {
|
class Project {
|
||||||
private:
|
private:
|
||||||
|
ox::SmallMap<ox::String, ox::Optional<ox::ClawFormat>> m_typeFmt;
|
||||||
keel::Context &m_ctx;
|
keel::Context &m_ctx;
|
||||||
ox::String m_path;
|
ox::String m_path;
|
||||||
ox::String m_projectDataDir;
|
ox::String m_projectDataDir;
|
||||||
@ -75,7 +76,15 @@ class Project {
|
|||||||
ox::Error writeObj(
|
ox::Error writeObj(
|
||||||
ox::CRStringView path,
|
ox::CRStringView path,
|
||||||
T const&obj,
|
T const&obj,
|
||||||
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept;
|
ox::ClawFormat fmt) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a MetalClaw object to the project at the given path.
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
ox::Error writeObj(
|
||||||
|
ox::CRStringView path,
|
||||||
|
T const&obj) noexcept;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<T> loadObj(ox::CRStringView path) const noexcept;
|
ox::Result<T> loadObj(ox::CRStringView path) const noexcept;
|
||||||
@ -130,7 +139,8 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
|
|||||||
oxReturnError(ox::buildTypeDef(&m_typeStore, &obj));
|
oxReturnError(ox::buildTypeDef(&m_typeStore, &obj));
|
||||||
}
|
}
|
||||||
oxRequire(desc, m_typeStore.get<T>());
|
oxRequire(desc, m_typeStore.get<T>());
|
||||||
auto const descExists = m_fs.stat(ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc))).error != 0;
|
auto const descPath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc));
|
||||||
|
auto const descExists = m_fs.exists(descPath);
|
||||||
if (!descExists) {
|
if (!descExists) {
|
||||||
oxReturnError(writeTypeStore());
|
oxReturnError(writeTypeStore());
|
||||||
}
|
}
|
||||||
@ -140,6 +150,13 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
ox::Error Project::writeObj(ox::CRStringView path, T const&obj) noexcept {
|
||||||
|
oxRequire(ext, fileExt(path));
|
||||||
|
auto const fmt = m_typeFmt[ext].or_value(ox::ClawFormat::Metal);
|
||||||
|
return writeObj(path, obj, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<T> Project::loadObj(ox::CRStringView path) const noexcept {
|
ox::Result<T> Project::loadObj(ox::CRStringView path) const noexcept {
|
||||||
oxRequire(buff, loadBuff(path));
|
oxRequire(buff, loadBuff(path));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user