[olympic/studio] Add new project menu, make file creation open file
Some checks failed
Build / build (push) Failing after 2m7s

This commit is contained in:
2023-12-28 23:44:25 -06:00
parent ffbdb09c31
commit 1df4e78084
9 changed files with 228 additions and 27 deletions

View File

@ -24,7 +24,14 @@ class ItemMaker {
fileExt(pFileExt) {
}
virtual ~ItemMaker() noexcept = default;
virtual ox::Error write(turbine::Context &ctx, ox::CRStringView pName) const noexcept = 0;
/**
* Returns path of the file created.
* @param ctx
* @param pName
* @return path of file or error in Result
*/
virtual ox::Result<ox::String> write(turbine::Context &ctx, ox::CRStringView pName) const noexcept = 0;
};
template<typename T>
@ -61,11 +68,12 @@ class ItemMakerT: public ItemMaker {
m_item(std::move(pItem)),
m_fmt(pFmt) {
}
ox::Error write(turbine::Context &ctx, ox::CRStringView pName) const noexcept override {
ox::Result<ox::String> write(turbine::Context &ctx, ox::CRStringView pName) const noexcept override {
auto const path = ox::sfmt("/{}/{}.{}", parentDir, pName, fileExt);
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
keel::createUuidMapping(keelCtx(ctx), path, ox::UUID::generate().unwrap());
return sctx->project->writeObj(path, m_item, m_fmt);
oxReturnError(sctx->project->writeObj(path, m_item, m_fmt));
return path;
}
};

View File

@ -50,6 +50,7 @@ class Project {
keel::Context &m_ctx;
ox::String m_path;
ox::String m_projectDataDir;
ox::String m_typeDescPath;
mutable keel::TypeStore m_typeStore;
ox::FileSystem &m_fs;
ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
@ -59,6 +60,9 @@ class Project {
ox::Error create() noexcept;
[[nodiscard]]
ox::String const&projectPath() const noexcept;
[[nodiscard]]
ox::FileSystem *romFs() noexcept;
@ -87,6 +91,8 @@ class Project {
[[nodiscard]]
ox::Vector<ox::String> const&fileList(ox::CRStringView ext) noexcept;
ox::Error writeAllTypeDescriptors() noexcept;
private:
void buildFileIndex() noexcept;
@ -123,21 +129,10 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
if (m_typeStore.get<T>().error) {
oxReturnError(ox::buildTypeDef(&m_typeStore, &obj));
}
// write out type store
auto const descPath = ox::sfmt("/{}/type_descriptors", m_projectDataDir);
oxRequire(desc, m_typeStore.get<T>());
auto const descExists = m_fs.stat(ox::sfmt("{}/{}", descPath, buildTypeId(*desc))).error != 0;
auto const descExists = m_fs.stat(ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc))).error != 0;
if (!descExists || ox::defines::Debug) {
// write all descriptors because we don't know which types T depends on
oxReturnError(mkdir(descPath));
for (auto const &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
auto const typePath = ox::sfmt("/{}/{}", descPath, buildTypeId(*t));
oxReturnError(writeBuff(typePath, typeOut));
}
oxReturnError(writeAllTypeDescriptors());
}
oxReturnError(keel::setAsset(m_ctx, path, obj));
fileUpdated.emit(path);