[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:
		@@ -31,7 +31,7 @@ enum class ProjectEvent {
 | 
			
		||||
constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
 | 
			
		||||
	auto const extStart = ox::find(path.crbegin(), path.crend(), '.').offset();
 | 
			
		||||
	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);
 | 
			
		||||
}
 | 
			
		||||
@@ -47,6 +47,7 @@ constexpr ox::StringView parentDir(ox::StringView path) noexcept {
 | 
			
		||||
 | 
			
		||||
class Project {
 | 
			
		||||
	private:
 | 
			
		||||
		ox::SmallMap<ox::String, ox::Optional<ox::ClawFormat>> m_typeFmt;
 | 
			
		||||
		keel::Context &m_ctx;
 | 
			
		||||
		ox::String m_path;
 | 
			
		||||
		ox::String m_projectDataDir;
 | 
			
		||||
@@ -75,7 +76,15 @@ class Project {
 | 
			
		||||
		ox::Error writeObj(
 | 
			
		||||
				ox::CRStringView path,
 | 
			
		||||
				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>
 | 
			
		||||
		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));
 | 
			
		||||
	}
 | 
			
		||||
	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) {
 | 
			
		||||
		oxReturnError(writeTypeStore());
 | 
			
		||||
	}
 | 
			
		||||
@@ -140,6 +150,13 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
 | 
			
		||||
	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>
 | 
			
		||||
ox::Result<T> Project::loadObj(ox::CRStringView path) const noexcept {
 | 
			
		||||
	oxRequire(buff, loadBuff(path));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user