[olympic] Cleanup
This commit is contained in:
parent
e452d9db4f
commit
f1609519a7
@ -5,7 +5,6 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include <ox/logconn/logconn.hpp>
|
#include <ox/logconn/logconn.hpp>
|
||||||
#include <ox/logconn/def.hpp>
|
|
||||||
#include <ox/std/trace.hpp>
|
#include <ox/std/trace.hpp>
|
||||||
#include <ox/std/uuid.hpp>
|
#include <ox/std/uuid.hpp>
|
||||||
#include <keel/media.hpp>
|
#include <keel/media.hpp>
|
||||||
@ -31,21 +30,19 @@ class StudioUIDrawer: public turbine::gl::Drawer {
|
|||||||
|
|
||||||
static int updateHandler(turbine::Context &ctx) noexcept {
|
static int updateHandler(turbine::Context &ctx) noexcept {
|
||||||
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
||||||
auto ui = dynamic_cast<StudioUI*>(sctx->ui);
|
sctx->ui->update();
|
||||||
ui->update();
|
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept {
|
static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept {
|
||||||
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
||||||
auto ui = dynamic_cast<StudioUI*>(sctx->ui);
|
sctx->ui->handleKeyEvent(key, down);
|
||||||
ui->handleKeyEvent(key, down);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ox::Error runApp(
|
static ox::Error runApp(
|
||||||
ox::CRStringView appName,
|
ox::CRStringView appName,
|
||||||
ox::CRStringView projectDataDir,
|
ox::CRStringView projectDataDir,
|
||||||
ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
ox::UPtr<ox::FileSystem> &&fs) noexcept {
|
||||||
oxRequireM(ctx, turbine::init(std::move(fs), appName));
|
oxRequireM(ctx, turbine::init(std::move(fs), appName));
|
||||||
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
|
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
|
||||||
turbine::setUpdateHandler(*ctx, updateHandler);
|
turbine::setUpdateHandler(*ctx, updateHandler);
|
||||||
|
@ -334,13 +334,15 @@ ox::Error StudioUI::createOpenProject(ox::CRStringView path) noexcept {
|
|||||||
std::filesystem::create_directories(toStdStringView(path), ec);
|
std::filesystem::create_directories(toStdStringView(path), ec);
|
||||||
oxReturnError(OxError(ec.value() != 0, "Could not create project directory"));
|
oxReturnError(OxError(ec.value() != 0, "Could not create project directory"));
|
||||||
oxReturnError(openProjectPath(path));
|
oxReturnError(openProjectPath(path));
|
||||||
return m_project->writeAllTypeDescriptors();
|
return m_project->writeTypeStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error StudioUI::openProjectPath(ox::CRStringView path) noexcept {
|
ox::Error StudioUI::openProjectPath(ox::CRStringView path) noexcept {
|
||||||
oxRequireM(fs, keel::loadRomFs(path));
|
oxRequireM(fs, keel::loadRomFs(path));
|
||||||
oxReturnError(keel::setRomFs(keelCtx(m_ctx), std::move(fs)));
|
oxReturnError(keel::setRomFs(keelCtx(m_ctx), std::move(fs)));
|
||||||
m_project = ox::make_unique<studio::Project>(keelCtx(m_ctx), ox::String(path), m_projectDataDir);
|
oxReturnError(
|
||||||
|
ox::make_unique_catch<studio::Project>(keelCtx(m_ctx), ox::String(path), m_projectDataDir)
|
||||||
|
.moveTo(m_project));
|
||||||
auto const sctx = applicationData<studio::StudioContext>(m_ctx);
|
auto const sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||||
sctx->project = m_project.get();
|
sctx->project = m_project.get();
|
||||||
turbine::setWindowTitle(m_ctx, ox::sfmt("{} - {}", keelCtx(m_ctx).appName, m_project->projectPath()));
|
turbine::setWindowTitle(m_ctx, ox::sfmt("{} - {}", keelCtx(m_ctx).appName, m_project->projectPath()));
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
struct StudioContext {
|
struct StudioContext {
|
||||||
ox::SignalHandler *ui = nullptr;
|
class StudioUI *ui = nullptr;
|
||||||
Project *project = nullptr;
|
Project *project = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class Project {
|
|||||||
ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
|
ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Project(keel::Context &ctx, ox::String path, ox::CRStringView projectDataDir) noexcept;
|
explicit Project(keel::Context &ctx, ox::String path, ox::CRStringView projectDataDir);
|
||||||
|
|
||||||
ox::Error create() noexcept;
|
ox::Error create() noexcept;
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class Project {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::Vector<ox::String> const&fileList(ox::CRStringView ext) noexcept;
|
ox::Vector<ox::String> const&fileList(ox::CRStringView ext) noexcept;
|
||||||
|
|
||||||
ox::Error writeAllTypeDescriptors() noexcept;
|
ox::Error writeTypeStore() noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildFileIndex() noexcept;
|
void buildFileIndex() noexcept;
|
||||||
@ -131,8 +131,8 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
|
|||||||
}
|
}
|
||||||
oxRequire(desc, m_typeStore.get<T>());
|
oxRequire(desc, m_typeStore.get<T>());
|
||||||
auto const descExists = m_fs.stat(ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc))).error != 0;
|
auto const descExists = m_fs.stat(ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc))).error != 0;
|
||||||
if (!descExists || ox::defines::Debug) {
|
if (!descExists) {
|
||||||
oxReturnError(writeAllTypeDescriptors());
|
oxReturnError(writeTypeStore());
|
||||||
}
|
}
|
||||||
oxReturnError(keel::setAsset(m_ctx, path, obj));
|
oxReturnError(keel::setAsset(m_ctx, path, obj));
|
||||||
fileUpdated.emit(path);
|
fileUpdated.emit(path);
|
||||||
|
@ -26,7 +26,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):
|
||||||
m_ctx(ctx),
|
m_ctx(ctx),
|
||||||
m_path(std::move(path)),
|
m_path(std::move(path)),
|
||||||
m_projectDataDir(projectDataDir),
|
m_projectDataDir(projectDataDir),
|
||||||
@ -35,6 +35,9 @@ Project::Project(keel::Context &ctx, ox::String path, ox::CRStringView projectDa
|
|||||||
m_fs(*m_ctx.rom) {
|
m_fs(*m_ctx.rom) {
|
||||||
oxTracef("studio", "Project: {}", m_path);
|
oxTracef("studio", "Project: {}", m_path);
|
||||||
generateTypes(m_typeStore);
|
generateTypes(m_typeStore);
|
||||||
|
if (ox::defines::Debug) {
|
||||||
|
oxThrowError(writeTypeStore());
|
||||||
|
}
|
||||||
buildFileIndex();
|
buildFileIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +73,7 @@ ox::Vector<ox::String> const&Project::fileList(ox::CRStringView ext) noexcept {
|
|||||||
return m_fileExtFileMap[ext];
|
return m_fileExtFileMap[ext];
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error Project::writeAllTypeDescriptors() noexcept {
|
ox::Error Project::writeTypeStore() noexcept {
|
||||||
// write all descriptors because we don't know which types T depends on
|
// write all descriptors because we don't know which types T depends on
|
||||||
oxReturnError(mkdir(m_typeDescPath));
|
oxReturnError(mkdir(m_typeDescPath));
|
||||||
for (auto const &t: m_typeStore.typeList()) {
|
for (auto const &t: m_typeStore.typeList()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user