Merge commit '5649e72126d23e422a8eae29a0a2a2f7c8597f7d'

This commit is contained in:
2024-01-18 00:30:54 -06:00
15 changed files with 120 additions and 73 deletions

View File

@ -57,7 +57,7 @@ void NewMenu::addItemMaker(ox::UniquePtr<studio::ItemMaker> &&im) noexcept {
std::sort(
m_types.begin(), m_types.end(),
[](ox::UPtr<ItemMaker> const&im1, ox::UPtr<ItemMaker> const&im2) {
return im1->name < im2->name;
return im1->typeName < im2->typeName;
});
}
@ -65,7 +65,7 @@ void NewMenu::drawNewItemType(turbine::Context &ctx) noexcept {
drawWindow(ctx, &m_open, [this] {
auto items = ox_malloca(m_types.size() * sizeof(char const*), char const*, nullptr);
for (auto i = 0u; auto const&im : m_types) {
items.get()[i] = im->name.c_str();
items.get()[i] = im->typeName.c_str();
++i;
}
ImGui::ListBox("Item Type", &m_selectedType, items.get(), static_cast<int>(m_types.size()));
@ -115,7 +115,16 @@ void NewMenu::drawLastPageButtons(turbine::Context &ctx) noexcept {
}
void NewMenu::finish(turbine::Context &ctx) noexcept {
auto const [path, err] = m_types[static_cast<std::size_t>(m_selectedType)]->write(ctx, m_itemName);
if (m_itemName.len() == 0) {
return;
}
auto const sctx = turbine::applicationData<studio::StudioContext>(ctx);
auto const&typeMaker = *m_types[static_cast<std::size_t>(m_selectedType)];
if (sctx->project->exists(typeMaker.itemPath(m_itemName))) {
oxLogError(OxError(1, "New file error: File already exists"));
return;
}
auto const [path, err] = typeMaker.write(ctx, m_itemName);
if (err) {
oxLogError(err);
return;

View File

@ -15,16 +15,21 @@ namespace studio {
class ItemMaker {
public:
ox::String const name;
ox::String const typeName;
ox::String const parentDir;
ox::String const fileExt;
constexpr explicit ItemMaker(ox::StringView pName, ox::StringView pParentDir, ox::CRStringView pFileExt) noexcept:
name(pName),
typeName(pName),
parentDir(pParentDir),
fileExt(pFileExt) {
}
virtual ~ItemMaker() noexcept = default;
[[nodiscard]]
inline virtual ox::String itemPath(ox::StringView pName) const noexcept {
return ox::sfmt("/{}/{}.{}", parentDir, pName, fileExt);
}
/**
* Returns path of the file created.
* @param ctx
@ -69,8 +74,8 @@ class ItemMakerT: public ItemMaker {
m_fmt(pFmt) {
}
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);
auto const path = itemPath(pName);
auto const sctx = turbine::applicationData<studio::StudioContext>(ctx);
keel::createUuidMapping(keelCtx(ctx), path, ox::UUID::generate().unwrap());
oxReturnError(sctx->project->writeObj(path, m_item, m_fmt));
return path;

View File

@ -64,7 +64,7 @@ class Project {
ox::String const&projectPath() const noexcept;
[[nodiscard]]
ox::FileSystem *romFs() noexcept;
ox::FileSystem &romFs() noexcept;
ox::Error mkdir(ox::CRStringView path) const noexcept;

View File

@ -51,8 +51,8 @@ ox::String const&Project::projectPath() const noexcept {
return m_path;
}
ox::FileSystem *Project::romFs() noexcept {
return &m_fs;
ox::FileSystem &Project::romFs() noexcept {
return m_fs;
}
ox::Error Project::mkdir(ox::CRStringView path) const noexcept {