[nostalgia,studio] Cleanup Studio
This commit is contained in:
parent
c085c50b30
commit
e543131f0d
@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ox/std/stringliteral.hpp>
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
constexpr auto TileWidth = 8;
|
constexpr auto TileWidth = 8;
|
||||||
constexpr auto TileHeight = 8;
|
constexpr auto TileHeight = 8;
|
||||||
constexpr auto PixelsPerTile = TileWidth * TileHeight;
|
constexpr auto PixelsPerTile = TileWidth * TileHeight;
|
||||||
|
|
||||||
constexpr auto FileExt_ng = "ng";
|
constexpr ox::StringLiteral FileExt_ng("ng");
|
||||||
constexpr auto FileExt_npal = "npal";
|
constexpr ox::StringLiteral FileExt_npal("npal");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
|
|||||||
|
|
||||||
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
||||||
const auto sctx = applicationData<studio::StudioContext>(*m_ctx);
|
const auto sctx = applicationData<studio::StudioContext>(*m_ctx);
|
||||||
return sctx->project->writeObj(m_itemPath, &m_pal);
|
return sctx->project->writeObj(m_itemPath, m_pal);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,18 +14,8 @@ namespace nostalgia::core {
|
|||||||
class StudioModule: public studio::Module {
|
class StudioModule: public studio::Module {
|
||||||
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) const noexcept final {
|
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) const noexcept final {
|
||||||
return {
|
return {
|
||||||
{
|
studio::editorMaker<TileSheetEditorImGui>(ctx, FileExt_ng),
|
||||||
{FileExt_ng},
|
studio::editorMaker<PaletteEditorImGui>(ctx, FileExt_npal),
|
||||||
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
|
|
||||||
return ox::makeCatch<TileSheetEditorImGui>(ctx, ox::String(path));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{FileExt_npal},
|
|
||||||
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
|
|
||||||
return ox::makeCatch<PaletteEditorImGui>(ctx, ox::String(path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -773,7 +773,7 @@ void TileSheetEditorModel::ackUpdate() noexcept {
|
|||||||
|
|
||||||
ox::Error TileSheetEditorModel::saveFile() noexcept {
|
ox::Error TileSheetEditorModel::saveFile() noexcept {
|
||||||
const auto sctx = applicationData<studio::StudioContext>(*m_ctx);
|
const auto sctx = applicationData<studio::StudioContext>(*m_ctx);
|
||||||
return sctx->project->writeObj(m_path, &m_img);
|
return sctx->project->writeObj(m_path, m_img);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {
|
bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {
|
||||||
|
@ -49,7 +49,7 @@ void SceneEditorImGui::onActivated() noexcept {
|
|||||||
|
|
||||||
ox::Error SceneEditorImGui::saveItem() noexcept {
|
ox::Error SceneEditorImGui::saveItem() noexcept {
|
||||||
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||||
oxReturnError(sctx->project->writeObj(m_itemPath, &m_editor.scene()));
|
oxReturnError(sctx->project->writeObj(m_itemPath, m_editor.scene()));
|
||||||
oxReturnError(m_ctx.keelCtx.assetManager.setAsset(m_itemPath, m_editor.scene()));
|
oxReturnError(m_ctx.keelCtx.assetManager.setAsset(m_itemPath, m_editor.scene()));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ class ItemMaker {
|
|||||||
const ox::String name;
|
const ox::String name;
|
||||||
const ox::String parentDir;
|
const ox::String parentDir;
|
||||||
const ox::String fileExt;
|
const ox::String fileExt;
|
||||||
constexpr explicit ItemMaker(ox::String pName, ox::String pParentDir, ox::String pFileExt) noexcept:
|
constexpr explicit ItemMaker(ox::String pName, ox::String pParentDir, ox::CRStringView pFileExt) noexcept:
|
||||||
name(std::move(pName)),
|
name(std::move(pName)),
|
||||||
parentDir(std::move(pParentDir)),
|
parentDir(std::move(pParentDir)),
|
||||||
fileExt(std::move(pFileExt)) {
|
fileExt(pFileExt) {
|
||||||
}
|
}
|
||||||
virtual ~ItemMaker() noexcept = default;
|
virtual ~ItemMaker() noexcept = default;
|
||||||
virtual ox::Error write(turbine::Context *ctx, ox::CRStringView pName) const noexcept = 0;
|
virtual ox::Error write(turbine::Context *ctx, ox::CRStringView pName) const noexcept = 0;
|
||||||
@ -33,25 +33,39 @@ class ItemMakerT: public ItemMaker {
|
|||||||
const T item;
|
const T item;
|
||||||
const ox::ClawFormat fmt;
|
const ox::ClawFormat fmt;
|
||||||
public:
|
public:
|
||||||
constexpr explicit ItemMakerT(ox::String pDisplayName, ox::String pParentDir, ox::String fileExt, ox::ClawFormat pFmt = ox::ClawFormat::Metal) noexcept:
|
constexpr explicit ItemMakerT(
|
||||||
ItemMaker(std::move(pDisplayName), std::move(pParentDir), std::move(fileExt)),
|
ox::String pDisplayName,
|
||||||
|
ox::String pParentDir,
|
||||||
|
ox::CRStringView fileExt,
|
||||||
|
ox::ClawFormat pFmt = ox::ClawFormat::Metal) noexcept:
|
||||||
|
ItemMaker(std::move(pDisplayName), std::move(pParentDir), fileExt),
|
||||||
fmt(pFmt) {
|
fmt(pFmt) {
|
||||||
}
|
}
|
||||||
constexpr ItemMakerT(ox::String pDisplayName, ox::String pParentDir, ox::String fileExt, const T &pItem, ox::ClawFormat pFmt) noexcept:
|
constexpr ItemMakerT(
|
||||||
ItemMaker(std::move(pDisplayName), std::move(pParentDir), std::move(fileExt)),
|
ox::String pDisplayName,
|
||||||
|
ox::String pParentDir,
|
||||||
|
ox::CRStringView fileExt,
|
||||||
|
T pItem,
|
||||||
|
ox::ClawFormat pFmt) noexcept:
|
||||||
|
ItemMaker(std::move(pDisplayName), std::move(pParentDir), fileExt),
|
||||||
item(pItem),
|
item(pItem),
|
||||||
fmt(pFmt) {
|
fmt(pFmt) {
|
||||||
}
|
}
|
||||||
constexpr ItemMakerT(ox::String pDisplayName, ox::String pParentDir, T &&pItem, ox::ClawFormat pFmt) noexcept:
|
constexpr ItemMakerT(
|
||||||
ItemMaker(std::move(pDisplayName), std::move(pParentDir), std::move(fileExt)),
|
ox::String pDisplayName,
|
||||||
item(std::forward(pItem)),
|
ox::String pParentDir,
|
||||||
|
ox::CRStringView fileExt,
|
||||||
|
T &&pItem,
|
||||||
|
ox::ClawFormat pFmt) noexcept:
|
||||||
|
ItemMaker(std::move(pDisplayName), std::move(pParentDir), fileExt),
|
||||||
|
item(std::move(pItem)),
|
||||||
fmt(pFmt) {
|
fmt(pFmt) {
|
||||||
}
|
}
|
||||||
ox::Error write(turbine::Context *ctx, ox::CRStringView pName) const noexcept override {
|
ox::Error write(turbine::Context *ctx, ox::CRStringView pName) const noexcept override {
|
||||||
const auto path = ox::sfmt("/{}/{}.{}", parentDir, pName, fileExt);
|
const auto path = ox::sfmt("/{}/{}.{}", parentDir, pName, fileExt);
|
||||||
auto sctx = turbine::applicationData<studio::StudioContext>(*ctx);
|
auto sctx = turbine::applicationData<studio::StudioContext>(*ctx);
|
||||||
keel::createUuidMapping(&ctx->keelCtx, path, ox::UUID::generate().unwrap());
|
keel::createUuidMapping(&ctx->keelCtx, path, ox::UUID::generate().unwrap());
|
||||||
return sctx->project->writeObj(path, &item, fmt);
|
return sctx->project->writeObj(path, item, fmt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,4 +33,26 @@ class Module {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Editor>
|
||||||
|
[[nodiscard]]
|
||||||
|
studio::EditorMaker editorMaker(turbine::Context *ctx, ox::CRStringView ext) noexcept {
|
||||||
|
return {
|
||||||
|
{ox::String(ext)},
|
||||||
|
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
|
||||||
|
return ox::makeCatch<Editor>(ctx, ox::String(path));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Editor>
|
||||||
|
[[nodiscard]]
|
||||||
|
studio::EditorMaker editorMaker(turbine::Context *ctx, ox::Vector<ox::String> exts) noexcept {
|
||||||
|
return {
|
||||||
|
std::move(exts),
|
||||||
|
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
|
||||||
|
return ox::makeCatch<Editor>(ctx, ox::String(path));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
|
|||||||
|
|
||||||
class Project {
|
class Project {
|
||||||
private:
|
private:
|
||||||
keel::Context *m_ctx = nullptr;
|
keel::Context &m_ctx;
|
||||||
ox::String m_path;
|
ox::String m_path;
|
||||||
ox::String m_projectDataDir;
|
ox::String m_projectDataDir;
|
||||||
mutable keel::TypeStore m_typeStore;
|
mutable keel::TypeStore m_typeStore;
|
||||||
@ -60,12 +60,12 @@ class Project {
|
|||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Error writeObj(
|
ox::Error writeObj(
|
||||||
const ox::StringView &path,
|
ox::CRStringView path,
|
||||||
const T *obj,
|
T const&obj,
|
||||||
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept;
|
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<T> loadObj(const ox::StringView &path) const noexcept;
|
ox::Result<T> loadObj(ox::CRStringView path) const noexcept;
|
||||||
|
|
||||||
ox::Result<ox::FileStat> stat(ox::CRStringView path) const noexcept;
|
ox::Result<ox::FileStat> stat(ox::CRStringView path) const noexcept;
|
||||||
|
|
||||||
@ -83,9 +83,9 @@ class Project {
|
|||||||
|
|
||||||
void indexFile(ox::CRStringView path) noexcept;
|
void indexFile(ox::CRStringView path) noexcept;
|
||||||
|
|
||||||
ox::Error writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept;
|
ox::Error writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexcept;
|
||||||
|
|
||||||
ox::Result<ox::Buffer> loadBuff(const ox::StringView &path) const noexcept;
|
ox::Result<ox::Buffer> loadBuff(ox::CRStringView path) const noexcept;
|
||||||
|
|
||||||
ox::Error lsProcDir(ox::Vector<ox::String> *paths, ox::CRStringView path) const noexcept;
|
ox::Error lsProcDir(ox::Vector<ox::String> *paths, ox::CRStringView path) const noexcept;
|
||||||
|
|
||||||
@ -105,14 +105,14 @@ class Project {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Error Project::writeObj(const ox::StringView &path, const T *obj, ox::ClawFormat fmt) noexcept {
|
ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat fmt) noexcept {
|
||||||
// write MetalClaw
|
// write MetalClaw
|
||||||
oxRequireM(buff, ox::writeClaw(*obj, fmt));
|
oxRequireM(buff, ox::writeClaw(obj, fmt));
|
||||||
// write to FS
|
// write to FS
|
||||||
oxReturnError(writeBuff(path, buff));
|
oxReturnError(writeBuff(path, buff));
|
||||||
// write type descriptor
|
// write type descriptor
|
||||||
if (m_typeStore.get<T>().error) {
|
if (m_typeStore.get<T>().error) {
|
||||||
oxReturnError(ox::buildTypeDef(&m_typeStore, obj));
|
oxReturnError(ox::buildTypeDef(&m_typeStore, &obj));
|
||||||
}
|
}
|
||||||
// write out type store
|
// write out type store
|
||||||
const auto descPath = ox::sfmt("/.{}/type_descriptors", m_projectDataDir);
|
const auto descPath = ox::sfmt("/.{}/type_descriptors", m_projectDataDir);
|
||||||
@ -125,13 +125,13 @@ ox::Error Project::writeObj(const ox::StringView &path, const T *obj, ox::ClawFo
|
|||||||
const auto typePath = ox::sfmt("/{}/{}", descPath, buildTypeId(*t));
|
const auto typePath = ox::sfmt("/{}/{}", descPath, buildTypeId(*t));
|
||||||
oxReturnError(writeBuff(typePath, typeOut));
|
oxReturnError(writeBuff(typePath, typeOut));
|
||||||
}
|
}
|
||||||
oxReturnError(keel::setAsset(m_ctx, path, *obj));
|
oxReturnError(keel::setAsset(&m_ctx, path, obj));
|
||||||
fileUpdated.emit(path);
|
fileUpdated.emit(path);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<T> Project::loadObj(const ox::StringView &path) const noexcept {
|
ox::Result<T> Project::loadObj(ox::CRStringView path) const noexcept {
|
||||||
oxRequire(buff, loadBuff(path));
|
oxRequire(buff, loadBuff(path));
|
||||||
if constexpr (ox::is_same_v<T, ox::ModelObject>) {
|
if constexpr (ox::is_same_v<T, ox::ModelObject>) {
|
||||||
return keel::readAsset(&m_typeStore, buff);
|
return keel::readAsset(&m_typeStore, buff);
|
||||||
@ -151,7 +151,7 @@ ox::Error Project::subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&s
|
|||||||
case ProjectEvent::FileRecognized:
|
case ProjectEvent::FileRecognized:
|
||||||
{
|
{
|
||||||
oxRequire(files, listFiles());
|
oxRequire(files, listFiles());
|
||||||
for (const auto &f : files) {
|
for (auto const&f : files) {
|
||||||
slot(f);
|
slot(f);
|
||||||
}
|
}
|
||||||
connect(this, &Project::fileRecognized, tgt, slot);
|
connect(this, &Project::fileRecognized, tgt, slot);
|
||||||
@ -164,7 +164,7 @@ ox::Error Project::subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&s
|
|||||||
connect(this, &Project::fileUpdated, tgt, slot);
|
connect(this, &Project::fileUpdated, tgt, slot);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return OxError(0);
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ static void generateTypes(ox::TypeStore *ts) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Project::Project(keel::Context *ctx, ox::String path, ox::CRStringView projectDataDir) noexcept:
|
Project::Project(keel::Context *ctx, ox::String path, ox::CRStringView projectDataDir) noexcept:
|
||||||
m_ctx(ctx),
|
m_ctx(*ctx),
|
||||||
m_path(std::move(path)),
|
m_path(std::move(path)),
|
||||||
m_projectDataDir(projectDataDir),
|
m_projectDataDir(projectDataDir),
|
||||||
m_typeStore(ctx->rom.get(), ox::sfmt("/.{}/type_descriptors", projectDataDir)),
|
m_typeStore(ctx->rom.get(), ox::sfmt("/.{}/type_descriptors", projectDataDir)),
|
||||||
@ -45,7 +45,7 @@ ox::FileSystem *Project::romFs() noexcept {
|
|||||||
ox::Error Project::mkdir(ox::CRStringView path) const noexcept {
|
ox::Error Project::mkdir(ox::CRStringView path) const noexcept {
|
||||||
oxReturnError(m_fs->mkdir(path, true));
|
oxReturnError(m_fs->mkdir(path, true));
|
||||||
fileUpdated.emit(path);
|
fileUpdated.emit(path);
|
||||||
return OxError(0);
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::FileStat> Project::stat(ox::CRStringView path) const noexcept {
|
ox::Result<ox::FileStat> Project::stat(ox::CRStringView path) const noexcept {
|
||||||
@ -83,12 +83,12 @@ void Project::indexFile(ox::CRStringView path) noexcept {
|
|||||||
m_fileExtFileMap[ext].emplace_back(path);
|
m_fileExtFileMap[ext].emplace_back(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept {
|
ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexcept {
|
||||||
constexpr auto HdrSz = 40;
|
constexpr auto HdrSz = 40;
|
||||||
ox::Buffer outBuff;
|
ox::Buffer outBuff;
|
||||||
outBuff.reserve(buff.size() + HdrSz);
|
outBuff.reserve(buff.size() + HdrSz);
|
||||||
ox::BufferWriter writer(&outBuff);
|
ox::BufferWriter writer(&outBuff);
|
||||||
const auto [uuid, err] = m_ctx->pathToUuid.at(path);
|
const auto [uuid, err] = m_ctx.pathToUuid.at(path);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
oxReturnError(keel::writeUuidHeader(writer, *uuid));
|
oxReturnError(keel::writeUuidHeader(writer, *uuid));
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::Buffer> Project::loadBuff(const ox::StringView &path) const noexcept {
|
ox::Result<ox::Buffer> Project::loadBuff(ox::CRStringView path) const noexcept {
|
||||||
return m_fs->read(path);
|
return m_fs->read(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ ox::Error Project::lsProcDir(ox::Vector<ox::String> *paths, ox::CRStringView pat
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OxError(0);
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::Vector<ox::String>> Project::listFiles(ox::CRStringView path) const noexcept {
|
ox::Result<ox::Vector<ox::String>> Project::listFiles(ox::CRStringView path) const noexcept {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user