Squashed 'deps/nostalgia/' changes from e7a66390..a0c81463
a0c81463 [nostalgia/core/studio] East const some function args d5b232f5 [olympic/studio] Fix array bounds issue c79fe3be [buildcore] Make CMake configure failure trigger failed return code 1df4e780 [olympic/studio] Add new project menu, make file creation open file ffbdb09c [olympic/turbine/glfw] Add shift key support b35a956e [olympic/studio] Cleanup unused expression d3847caa [olympic/studio] Make Project::writeObj only write descriptor if it does not already exist or if debug build ae066a91 [olympic/studio] Fix Project::writeObj to ensure parent directory of file exists 67543af8 [ox/oc] Remove some unnecessary code 6b774ec2 [ox/oc] Fix array writing to write all values 4b9758f4 [nostalgia/core] Move most TileSheet member functions out of class bf12b15f [nostalgia/sample_project] Update some tilesheets to version 4 format a7328eb5 [nostalgia/core/studio] Reduce indent for Subsheet editor b52124a0 [nostalgia/core/studio] Revert new subsheet index increment to happen after index assignment eae9972f [nostalgia/sample_project] Add missing type descriptors d83e3929 [nostalgia/core] Cleanup, revert CompactTileSheet version to 1 e2d0a784 [olympic/keel] Cleanup f0882142 [nostalgia/core/studio] Change TileSheets to back to MC 6a2954f8 [nostalgia/core] Remove id from TileSheetV3::Subsheet, add TileSheetV4 9c19655c [nostalgia/core] Fix build, add SubSheet ID to SubSheet Editor view 087c834b [nostalgia/core/studio] Fix Add SubSheet to increment idIt before using it 79bdbf2e [nostalgia/core] Add id to TileSheetV3::SubSheet model 2bdc3def [nostalgia/core/opengl] Implement flip X and flip Y for BG tiles git-subtree-dir: deps/nostalgia git-subtree-split: a0c8146396a9e9c0dc48a2564f4e9870a212ed59
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -36,11 +36,21 @@ constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
|
||||
return substr(path, extStart + 1);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::StringView parentDir(ox::StringView path) noexcept {
|
||||
if (path.len() && path[path.len() - 1] == '/') {
|
||||
path = substr(path, 0, path.len() - 1);
|
||||
}
|
||||
auto const extStart = ox::find(path.crbegin(), path.crend(), '/').offset();
|
||||
return substr(path, 0, extStart);
|
||||
}
|
||||
|
||||
class Project {
|
||||
private:
|
||||
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;
|
||||
@@ -50,6 +60,9 @@ class Project {
|
||||
|
||||
ox::Error create() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::String const&projectPath() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::FileSystem *romFs() noexcept;
|
||||
|
||||
@@ -78,6 +91,8 @@ class Project {
|
||||
[[nodiscard]]
|
||||
ox::Vector<ox::String> const&fileList(ox::CRStringView ext) noexcept;
|
||||
|
||||
ox::Error writeAllTypeDescriptors() noexcept;
|
||||
|
||||
private:
|
||||
void buildFileIndex() noexcept;
|
||||
|
||||
@@ -108,21 +123,16 @@ template<typename T>
|
||||
ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat fmt) noexcept {
|
||||
oxRequireM(buff, ox::writeClaw(obj, fmt));
|
||||
// write to FS
|
||||
oxReturnError(mkdir(parentDir(path)));
|
||||
oxReturnError(writeBuff(path, buff));
|
||||
// write type descriptor
|
||||
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);
|
||||
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));
|
||||
oxRequire(desc, m_typeStore.get<T>());
|
||||
auto const descExists = m_fs.stat(ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc))).error != 0;
|
||||
if (!descExists || ox::defines::Debug) {
|
||||
oxReturnError(writeAllTypeDescriptors());
|
||||
}
|
||||
oxReturnError(keel::setAsset(m_ctx, path, obj));
|
||||
fileUpdated.emit(path);
|
||||
|
@@ -13,6 +13,11 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
static_assert(fileExt("main.c").value == "c");
|
||||
static_assert(fileExt("a.b.c").value == "c");
|
||||
static_assert(parentDir("/a/b/c") == "/a/b");
|
||||
static_assert(parentDir("/a/b/c/") == "/a/b");
|
||||
|
||||
static void generateTypes(ox::TypeStore &ts) noexcept {
|
||||
for (auto const mod : keel::modules()) {
|
||||
for (auto gen : mod->types()) {
|
||||
@@ -25,6 +30,7 @@ Project::Project(keel::Context &ctx, ox::String path, ox::CRStringView projectDa
|
||||
m_ctx(ctx),
|
||||
m_path(std::move(path)),
|
||||
m_projectDataDir(projectDataDir),
|
||||
m_typeDescPath(ox::sfmt("/{}/type_descriptors", m_projectDataDir)),
|
||||
m_typeStore(*m_ctx.rom, ox::sfmt("/{}/type_descriptors", projectDataDir)),
|
||||
m_fs(*m_ctx.rom) {
|
||||
oxTracef("studio", "Project: {}", m_path);
|
||||
@@ -38,6 +44,10 @@ ox::Error Project::create() noexcept {
|
||||
return OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed");
|
||||
}
|
||||
|
||||
ox::String const&Project::projectPath() const noexcept {
|
||||
return m_path;
|
||||
}
|
||||
|
||||
ox::FileSystem *Project::romFs() noexcept {
|
||||
return &m_fs;
|
||||
}
|
||||
@@ -60,6 +70,20 @@ ox::Vector<ox::String> const&Project::fileList(ox::CRStringView ext) noexcept {
|
||||
return m_fileExtFileMap[ext];
|
||||
}
|
||||
|
||||
ox::Error Project::writeAllTypeDescriptors() noexcept {
|
||||
// write all descriptors because we don't know which types T depends on
|
||||
oxReturnError(mkdir(m_typeDescPath));
|
||||
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("{}/{}", m_typeDescPath, buildTypeId(*t));
|
||||
oxReturnError(writeBuff(typePath, typeOut));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void Project::buildFileIndex() noexcept {
|
||||
auto [files, err] = listFiles();
|
||||
if (err) {
|
||||
|
Reference in New Issue
Block a user