[nostalgia] Add NewMenu for creating new files

This commit is contained in:
2022-07-29 21:38:18 -05:00
parent b14e41d057
commit 275e9dbff1
31 changed files with 630 additions and 120 deletions
+6 -12
View File
@@ -37,9 +37,6 @@ constexpr ox::Result<ox::String> fileExt(const ox::String &path) noexcept {
return path.substr(extStart + 1);
}
[[nodiscard]]
ox::String filePathToName(const ox::String &path, const ox::String &prefix, const ox::String &suffix) noexcept;
class NOSTALGIASTUDIO_EXPORT Project {
private:
ox::String m_path;
@@ -48,7 +45,7 @@ class NOSTALGIASTUDIO_EXPORT Project {
ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
public:
explicit Project(ox::FileSystem *fs, const ox::String &path) noexcept;
explicit Project(ox::FileSystem *fs, ox::String path) noexcept;
ox::Error create() noexcept;
@@ -60,7 +57,7 @@ class NOSTALGIASTUDIO_EXPORT Project {
/**
* Writes a MetalClaw object to the project at the given path.
*/
ox::Error writeObj(const ox::String &path, auto *obj) const noexcept;
ox::Error writeObj(const ox::String &path, auto *obj, ox::ClawFormat fmt = ox::ClawFormat::Metal) const noexcept;
template<typename T>
ox::Result<ox::UniquePtr<T>> loadObj(const ox::String &path) const noexcept;
@@ -100,9 +97,9 @@ class NOSTALGIASTUDIO_EXPORT Project {
};
ox::Error Project::writeObj(const ox::String &path, auto *obj) const noexcept {
ox::Error Project::writeObj(const ox::String &path, auto *obj, ox::ClawFormat fmt) const noexcept {
// write MetalClaw
oxRequireM(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
oxRequireM(buff, ox::writeClaw(obj, fmt));
// write to FS
oxReturnError(writeBuff(path, buff));
// write type descriptor
@@ -110,15 +107,12 @@ ox::Error Project::writeObj(const ox::String &path, auto *obj) const noexcept {
// write out type store
static constexpr auto descPath = "/.nostalgia/type_descriptors";
oxReturnError(mkdir(descPath));
for (const auto t : m_typeStore.typeList()) {
if (t->typeName.beginsWith("B:")) {
continue;
}
for (const auto &t : m_typeStore.typeList()) {
oxRequireM(typeOut, ox::writeClaw(t, ox::ClawFormat::Organic));
// replace garbage last character with new line
typeOut.back().value = '\n';
// write to FS
const auto typePath = ox::sfmt("{}/{}", descPath, t->typeName);
const auto typePath = ox::sfmt("{}/{};{}", descPath, t->typeName, t->typeVersion);
oxReturnError(writeBuff(typePath, typeOut));
}
fileUpdated.emit(path);