Squashed 'deps/nostalgia/' changes from eed115b2..7d9f363b
7d9f363b [nostalgia/core/studio] Show color names in TileSheetEditor ababc2a7 [nostalgia/core/studio] Add Name to colors table in PaletteEditor bfd4bc3c [nostalgia/core] Revise Palette system, give TileSheetEditor a config file 8826d51e [studio] Add configio.hpp to studio.hpp c021e5e7 [ox/oc] Fix OC not dealing with certain int types properly 7d8a8e0e [keel] Cleanup 95a69b72 [ox/std] Fix String::c_str to always retrun a valid C str e4c38660 [nostalgia/core] Fix subsheet resize not to read garbage 67cf3ae8 [ox/std] Ensure ox::String always has at least a null terminator 2761f23d [nostalgia/developer-handbook] Update serialization notes 6c170d31 [nostalgia/developer-handbook] Update serialization notes d20bfc77 [nostalgia/developer-handbook] Update serialization notes 07ecbde1 [nostalgia/developer-handbook] Update notes on error handling fbe2fcd3 [nostalgia/developer-handbook] Update notes on error handling a8bb99b6 [turbine] Remove ClipboardObject::typeMatches 667dd21a [turbine] Make ClipboardObject::typId return a StringView 5d89370c [turbine] Rework getClipboardObject to use ox::ModelTypeId_v b968ec8a [keel] Remove redundant move ec45ffb7 [studio] Fix build error 97dc0274 [nostalgia/core/studio] Add acceptsClipboardPayload to TileSheetEditor a138f60f [studio] Add acceptsClipboardPayload to Editor 791d1950 [turbine] Make ClipboardObject use ox::ModelTypeId_v for typeId 78eb8fca [keel] Cleanup pack logging 0b8051b6 [ox/preloader] Fix alignment issue 5a426829 [nostalgia/core/studio] Cleanup TileSheet selection, fix copy/paste bug 9d2fe0e8 [studio] Add size function to Selection f1894699 [keel] Remove setAsset 27b38ed2 [keel,studio] Fix hotloading for files that get loaded as multiple types 2bb7c514 [studio/modlib] Fix type desc writing logic inversion 5177cfb0 [studio/modlib] Make Project::mkdir only mkdir if dir does not exist f9a14433 [studio/modlib] Add variant of ComboBox that takes callback e62426b0 [keel] Ensure consistent asset IDs in AssetManager af634bd4 [ox/fs] Add FileSystem::exists 49b859ec [studio/modlib] Give Selection constructors 19a41201 [studio/modlib] Make iterateSelection return errors properly f69b8afa [nostalgia] Remove use of deleted function 9c98b5e2 [studio/modlib] Remove color.hpp 1f87216d [nostalgia/core] Add applySelectionColor 94c59604 [nostalgia/core/opengl] Fix for Ox changes 8ee016c1 [studio/modlib] Add SelectionTracker dc20c667 [ox/std] Add conversion functions for geo types, cleanup 407e5424 [ox/std] Remove SmallMap dtor, replace timing code with steady_clock 3b188696 [ox/claw] Remove enum type from ClawFormat 0fab6c7c [ox/preloader] Remove debug code a72b865d [studio/modlib] Add function for exporting selection color c0479604 [studio,nostalgia/studio] Make executing UndoCommands report errors a1c89906 [nostalgia/studio] Make UndoCommand undo/redo return ox::Error 7fb0549c [nostalgia/core] Revert some auto formatting done by CLion... 37e65ab0 [nostalgia/core/studio] Fix Subsheet width to update properly 9105b1ec [ox/std] Fix Linux build fbeb0815 [ox/model] Fix type params in buildTypeId b882a47e [ox/std] Fix resize to set null terminator 660f2f56 [ox/std] Rework FileReader into StreamReader aa83c2a6 [nostalgia/core/studio] Remove some unnecessary copying 4a2b1fd7 [studio,keel] Make fileChanged emit UUID as well as path, add uuidUrlToUuid 08f958fb [ox/std] Add IntegerRange_c a651d45a [ox/std] Fix Vector insert functions 9e9f317c [studio] Make UndoCommand::mergeWith take a reference f5a02ce9 [nostalgia/core/gba] Fix build 6971c310 [studio] Add NoChangeException c47f48eb [keel] Add/cleanup UUID/path lookup functions 76771e7b [nostalgia/core] Add tileColumns and tileRows functions f6a0ae20 [ox/std] Fix some Windows warnings 752c8c1d [glutils] Fix type conversion that happened on Windows af3bff1a [glutils] Add FrameBuffer::sizef 87416e13 [ox/std] Make MallocaPtr call destructor 047b4396 [ox/std] Make Point and Size members int32_t 40b8da4d [studio/modlib] Cleanup 123c4125 [ox/std] Add SmallMap::pairs(), SmallMap model 963ec5d3 [ox/std] Add operator-> to SpanIterator 6df77a23 [glutils] Add size function to FrameBuffer df412cf8 [ox/std] Add missing typenames ae30ef36 Merge commit 'b66cef7127e97269fc6072a6f66ccc08990f6d2e' 095a1135 Merge commit 'f48824793cfce315971fe2e699ece198c7a79407' ce1836ab Merge commit '1e041bd2ebfe5ace7bed3906faf60345aa98a8bc' 7d1641fa Merge commit '420fa96463f59c4a4a7cd66b16b0ad01ab0d55e6' 423212b2 [studio] Add missing include 60da1063 Merge commit 'bd416f82e25f1b710ab2b7890274571dd3fcd53d' 60d1996f [keel] Minor optimization git-subtree-dir: deps/nostalgia git-subtree-split: 7d9f363bfa7a2c64f5c4bcfd0b6686f3f5678119
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef OX_BARE_METAL
|
||||
#include <functional>
|
||||
#endif
|
||||
|
||||
#include <ox/event/signal.hpp>
|
||||
#include <ox/fs/fs.hpp>
|
||||
#include <ox/model/typenamecatcher.hpp>
|
||||
@@ -178,9 +182,11 @@ constexpr AssetRef<T>::AssetRef(AssetRef &&h) noexcept: m_ctr(h.m_ctr) {
|
||||
h.m_ctr = nullptr;
|
||||
}
|
||||
|
||||
class Context;
|
||||
|
||||
class AssetManager {
|
||||
private:
|
||||
class AssetTypeManagerBase {
|
||||
class AssetTypeManagerBase: public ox::SignalHandler {
|
||||
public:
|
||||
virtual ~AssetTypeManagerBase() = default;
|
||||
|
||||
@@ -189,31 +195,28 @@ class AssetManager {
|
||||
|
||||
template<typename T>
|
||||
class AssetTypeManager: public AssetTypeManagerBase {
|
||||
public:
|
||||
using Loader = std::function<ox::Result<T>(ox::StringView assetId)>;
|
||||
private:
|
||||
Loader m_loader{};
|
||||
ox::HashMap<ox::String, ox::UPtr<AssetContainer<T>>> m_cache;
|
||||
|
||||
public:
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringView const&assetId) const noexcept {
|
||||
auto out = m_cache.at(assetId);
|
||||
oxReturnError(out);
|
||||
return AssetRef<T>(out.value->get());
|
||||
}
|
||||
AssetTypeManager(Loader loader) noexcept: m_loader(loader) {}
|
||||
|
||||
ox::Result<AssetRef<T>> setAsset(ox::StringView const&assetId, T const&obj) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
if (!p) {
|
||||
p = ox::make_unique<AssetContainer<T>>(obj);
|
||||
} else {
|
||||
p->set(obj);
|
||||
p->updated.emit();
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringView const assetId) const noexcept {
|
||||
oxRequire(out, m_cache.at(assetId));
|
||||
if (!out || !*out) {
|
||||
return OxError(1, "asset is null");
|
||||
}
|
||||
return AssetRef<T>(p.get());
|
||||
return AssetRef<T>(out->get());
|
||||
}
|
||||
|
||||
ox::Result<AssetRef<T>> setAsset(ox::StringView const&assetId, T &&obj) noexcept {
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
oxRequireM(obj, m_loader(assetId));
|
||||
if (!p) {
|
||||
p = ox::make_unique<AssetContainer<T>>(obj);
|
||||
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
||||
} else {
|
||||
p->set(std::move(obj));
|
||||
p->updated.emit();
|
||||
@@ -221,6 +224,18 @@ class AssetManager {
|
||||
return AssetRef<T>(p.get());
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(ox::StringView const assetId) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
oxRequireM(obj, m_loader(assetId));
|
||||
if (!p) {
|
||||
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
||||
} else {
|
||||
p->set(std::move(obj));
|
||||
p->updated.emit();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void gc() noexcept final {
|
||||
for (auto const&ack : m_cache.keys()) {
|
||||
auto &ac = m_cache[ack];
|
||||
@@ -232,29 +247,48 @@ class AssetManager {
|
||||
};
|
||||
|
||||
ox::HashMap<ox::String, ox::UPtr<AssetTypeManagerBase>> m_assetTypeManagers;
|
||||
ox::HashMap<ox::String, ox::Signal<ox::Error(ox::StringView assetId)>> m_fileUpdated;
|
||||
|
||||
template<typename T>
|
||||
AssetTypeManager<T> *getTypeManager() noexcept {
|
||||
constexpr auto typeName = ox::requireModelTypeName<T>();
|
||||
static_assert(ox::StringView(typeName) != "", "Types must have TypeName to use AssetManager");
|
||||
auto &am = m_assetTypeManagers[typeName];
|
||||
if (!am) {
|
||||
am = ox::make_unique<AssetTypeManager<T>>();
|
||||
ox::Result<AssetTypeManager<T>*> getTypeManager() noexcept {
|
||||
constexpr auto &typeId = ox::ModelTypeId_v<T>;
|
||||
static_assert(typeId != "", "Types must have TypeName to use AssetManager");
|
||||
auto &am = m_assetTypeManagers[typeId];
|
||||
auto const out = dynamic_cast<AssetTypeManager<T>*>(am.get());
|
||||
if (!out) {
|
||||
return OxError(1, "no AssetTypeManager for type");
|
||||
}
|
||||
return dynamic_cast<AssetTypeManager<T>*>(am.get());
|
||||
return out;
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> getAsset(ox::CRStringView assetId) noexcept {
|
||||
auto m = getTypeManager<T>();
|
||||
return m->getAsset(assetId);
|
||||
void initTypeManager(auto const&makeLoader, Context &ctx) noexcept {
|
||||
constexpr auto &typeId = ox::ModelTypeId_v<T>;
|
||||
static_assert(typeId != "", "Types must have TypeName to use AssetManager");
|
||||
auto &am = m_assetTypeManagers[typeId];
|
||||
if (!am) {
|
||||
am = ox::make_unique<AssetTypeManager<T>>(makeLoader(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> setAsset(ox::CRStringView assetId, T const&obj) noexcept {
|
||||
auto m = getTypeManager<T>();
|
||||
return m->setAsset(assetId, obj);
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringView assetId) noexcept {
|
||||
oxRequire(m, getTypeManager<T>());
|
||||
return m->getAsset(assetId);
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(ox::StringView assetId) noexcept {
|
||||
m_fileUpdated[assetId].emit(assetId);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView assetId) noexcept {
|
||||
oxRequire(m, getTypeManager<T>());
|
||||
oxRequire(out, m->loadAsset(assetId));
|
||||
m_fileUpdated[assetId].connect(m, &AssetTypeManager<T>::reloadAsset);
|
||||
return out;
|
||||
}
|
||||
|
||||
void gc() noexcept {
|
||||
|
@@ -32,14 +32,43 @@ oxModelEnd()
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&file) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::CRStringView file) noexcept;
|
||||
|
||||
|
||||
void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uuid) noexcept;
|
||||
|
||||
ox::Error buildUuidMap(Context &ctx) noexcept;
|
||||
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::CRStringView path) noexcept;
|
||||
|
||||
ox::Result<ox::UUID> getUuid(Context &ctx, ox::FileAddress const&fileAddr) noexcept;
|
||||
|
||||
ox::Result<ox::UUID> getUuid(Context &ctx, ox::StringView path) noexcept;
|
||||
|
||||
ox::Result<ox::CStringView> getPath(Context &ctx, ox::FileAddress const&fileAddr) noexcept;
|
||||
|
||||
ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringView fileId) noexcept;
|
||||
|
||||
constexpr ox::Result<ox::UUID> uuidUrlToUuid(ox::StringView uuidUrl) noexcept {
|
||||
return ox::UUID::fromString(substr(uuidUrl, 7));
|
||||
}
|
||||
|
||||
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept;
|
||||
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept;
|
||||
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept;
|
||||
|
||||
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept;
|
||||
|
||||
#ifndef OX_BARE_METAL
|
||||
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObjFile(
|
||||
keel::Context &ctx,
|
||||
ox::StringView assetId,
|
||||
bool forceLoad) noexcept {
|
||||
constexpr auto readConvert = [](Context &ctx, const ox::Buffer &buff) -> ox::Result<T> {
|
||||
constexpr auto makeLoader(Context &ctx) {
|
||||
return [&ctx](ox::StringView assetId) -> ox::Result<T> {
|
||||
ox::StringView path;
|
||||
oxRequire(p, ctx.uuidToPath.at(assetId));
|
||||
path = *p;
|
||||
oxRequire(buff, ctx.rom->read(path));
|
||||
auto [obj, err] = readAsset<T>(buff);
|
||||
if (err) {
|
||||
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {
|
||||
@@ -49,25 +78,34 @@ ox::Result<keel::AssetRef<T>> readObjFile(
|
||||
}
|
||||
return std::move(obj);
|
||||
};
|
||||
ox::StringView path;
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObjFile(
|
||||
keel::Context &ctx,
|
||||
ox::StringView assetId,
|
||||
bool forceLoad) noexcept {
|
||||
ox::UUIDStr uuidStr;
|
||||
if (beginsWith(assetId, "uuid://")) {
|
||||
assetId = substr(assetId, 7);
|
||||
oxRequire(p, ctx.uuidToPath.at(assetId));
|
||||
path = *p;
|
||||
oxRequire(p, keel::uuidToPath(ctx, assetId));
|
||||
} else {
|
||||
path = assetId;
|
||||
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
|
||||
if (!uuidErr) {
|
||||
uuidStr = uuid.toString();
|
||||
assetId = uuidStr;
|
||||
}
|
||||
}
|
||||
if (forceLoad) {
|
||||
oxRequire(buff, ctx.rom->read(path));
|
||||
oxRequire(obj, readConvert(ctx, buff));
|
||||
oxRequire(cached, ctx.assetManager.setAsset(assetId, obj));
|
||||
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
|
||||
oxRequire(cached, ctx.assetManager.loadAsset<T>(assetId));
|
||||
return cached;
|
||||
} else {
|
||||
auto [cached, err] = ctx.assetManager.getAsset<T>(assetId);
|
||||
if (err) {
|
||||
oxRequire(buff, ctx.rom->read(path));
|
||||
oxRequire(obj, readConvert(ctx, buff));
|
||||
oxReturnError(ctx.assetManager.setAsset(assetId, obj).moveTo(cached));
|
||||
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
|
||||
oxReturnError(ctx.assetManager.loadAsset<T>(assetId).moveTo(cached));
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
@@ -89,34 +127,7 @@ ox::Result<keel::AssetRef<T>> readObjNoCache(
|
||||
|
||||
#endif
|
||||
|
||||
void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uuid) noexcept;
|
||||
|
||||
ox::Error buildUuidMap(Context &ctx) noexcept;
|
||||
|
||||
ox::Result<ox::String> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept;
|
||||
|
||||
ox::Result<ox::String> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept;
|
||||
|
||||
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> setAsset(keel::Context &ctx, ox::StringView assetId, T const&asset) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
if (assetId.len() == 0) {
|
||||
return OxError(1, "Invalid asset ID");
|
||||
}
|
||||
ox::UUIDStr idStr;
|
||||
if (assetId[0] == '/') {
|
||||
auto const [id, err] = ctx.pathToUuid.at(assetId);
|
||||
oxReturnError(err);
|
||||
idStr = id->toString();
|
||||
assetId = idStr;
|
||||
}
|
||||
return ctx.assetManager.setAsset(assetId, asset);
|
||||
#else
|
||||
return OxError(1, "Not supported on this platform");
|
||||
#endif
|
||||
}
|
||||
ox::Error reloadAsset(keel::Context &ctx, ox::StringView assetId) noexcept;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObj(
|
||||
|
@@ -86,19 +86,21 @@ ox::Error preloadObj(
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &romFs,
|
||||
ox::Preloader<PlatSpec> &pl,
|
||||
ox::CRStringView path) noexcept {
|
||||
ox::StringView const path) noexcept {
|
||||
// load file
|
||||
oxRequireM(buff, romFs.read(path));
|
||||
oxRequireM(obj, keel::readAsset(ts, buff));
|
||||
if (obj.type()->preloadable) {
|
||||
oxOutf("preloading {} as a {}\n", path, obj.type()->typeName);
|
||||
// preload
|
||||
oxRequire(a, pl.startAlloc(ox::sizeOf<GbaPlatSpec>(&obj), ox::alignOf<GbaPlatSpec>(obj)));
|
||||
auto const size = ox::sizeOf<GbaPlatSpec>(&obj);
|
||||
auto const alignment = ox::alignOf<GbaPlatSpec>(obj);
|
||||
oxRequire(a, pl.startAlloc(size, alignment));
|
||||
auto const err = ox::preload<GbaPlatSpec, ox::ModelObject>(&pl, &obj);
|
||||
oxReturnError(pl.endAlloc());
|
||||
oxReturnError(err);
|
||||
keel::PreloadPtr const p{.preloadAddr = static_cast<uint32_t>(a)};
|
||||
keel::PreloadPtr const p{.preloadAddr = a};
|
||||
oxReturnError(ox::writeMC(p).moveTo(buff));
|
||||
oxOutf("preloaded {} as a {} @ {} to {}\n", path, obj.type()->typeName, a, a + size);
|
||||
} else {
|
||||
// strip the Claw header (it is not needed after preloading) and write back out to dest fs
|
||||
oxReturnError(ox::writeMC(obj).moveTo(buff));
|
||||
|
@@ -83,19 +83,72 @@ ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::CRStringView path) noexcept {
|
||||
#endif
|
||||
}
|
||||
|
||||
ox::Result<ox::String> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept {
|
||||
ox::Result<ox::UUID> getUuid(Context &ctx, ox::FileAddress const&fileAddr) noexcept {
|
||||
oxRequire(path, fileAddr.getPath());
|
||||
return getUuid(ctx, path);
|
||||
}
|
||||
|
||||
ox::Result<ox::UUID> getUuid(Context &ctx, ox::StringView path) noexcept {
|
||||
if (beginsWith(path, "uuid://")) {
|
||||
auto const uuid = substr(path, 7);
|
||||
return ox::UUID::fromString(uuid);
|
||||
} else {
|
||||
return pathToUuid(ctx, path);
|
||||
}
|
||||
}
|
||||
|
||||
ox::Result<ox::CStringView> getPath(Context &ctx, ox::FileAddress const&fileAddr) noexcept {
|
||||
oxRequire(path, fileAddr.getPath());
|
||||
if (beginsWith(path, "uuid://")) {
|
||||
auto const uuid = substr(path, 7);
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequire(out, ctx.uuidToPath.at(uuid));
|
||||
return *out;
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView{*out};
|
||||
#else
|
||||
return OxError(1, "UUID to path conversion not supported on this platform");
|
||||
#endif
|
||||
} else {
|
||||
return ox::CStringView{path};
|
||||
}
|
||||
}
|
||||
|
||||
ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringView fileId) noexcept {
|
||||
if (beginsWith(fileId, "uuid://")) {
|
||||
auto const uuid = substr(fileId, 7);
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView{*out};
|
||||
#else
|
||||
return OxError(1, "UUID to path conversion not supported on this platform");
|
||||
#endif
|
||||
} else {
|
||||
return ox::CStringView{fileId};
|
||||
}
|
||||
}
|
||||
|
||||
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept {
|
||||
uuid = substr(uuid, 7);
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView(*out);
|
||||
#else
|
||||
return OxError(1, "UUID to path conversion not supported on this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
ox::Result<ox::String> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequire(out, ctx.uuidToPath.at(uuid.toString()));
|
||||
return *out;
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView(*out);
|
||||
#else
|
||||
return OxError(1, "UUID to path conversion not supported on this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid.toString()));
|
||||
return ox::CStringView(*out);
|
||||
#else
|
||||
return OxError(1, "UUID to path conversion not supported on this platform");
|
||||
#endif
|
||||
@@ -113,6 +166,21 @@ ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(keel::Context &ctx, ox::StringView assetId) noexcept {
|
||||
ox::UUIDStr uuidStr;
|
||||
if (beginsWith(assetId, "uuid://")) {
|
||||
assetId = substr(assetId, 7);
|
||||
oxRequire(p, keel::uuidToPath(ctx, assetId));
|
||||
} else {
|
||||
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
|
||||
if (!uuidErr) {
|
||||
uuidStr = uuid.toString();
|
||||
assetId = uuidStr;
|
||||
}
|
||||
}
|
||||
return ctx.assetManager.reloadAsset(assetId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -166,6 +234,10 @@ ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const
|
||||
return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset;
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(keel::Context&, ox::StringView) noexcept {
|
||||
return OxError(1, "reloadAsset is unsupported on this platform");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <keel/keel.hpp>
|
||||
|
||||
static ox::Error writeFileBuff(ox::StringView path, ox::Buffer const&buff) noexcept {
|
||||
static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) noexcept {
|
||||
try {
|
||||
std::ofstream f(std::string(toStdStringView(path)), std::ios::binary);
|
||||
f.write(buff.data(), static_cast<intptr_t>(buff.size()));
|
||||
@@ -39,10 +39,10 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
static ox::Error generateTypes(ox::TypeStore *ts) noexcept {
|
||||
static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
||||
for (auto const mod : keel::modules()) {
|
||||
for (auto gen : mod->types()) {
|
||||
oxReturnError(gen(*ts));
|
||||
oxReturnError(gen(ts));
|
||||
}
|
||||
}
|
||||
return {};
|
||||
@@ -54,7 +54,7 @@ static ox::Error pack(ox::StringView argSrc, ox::StringView argRomBin, ox::Strin
|
||||
ox::FileSystem32 dst(dstBuff);
|
||||
oxRequire(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
||||
keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir));
|
||||
oxReturnError(generateTypes(&ts));
|
||||
oxReturnError(generateTypes(ts));
|
||||
oxReturnError(keel::pack(*ctx, ts, dst));
|
||||
oxRequireM(pl, keel::GbaPreloader::make());
|
||||
oxReturnError(preload(ts, dst, *pl));
|
||||
@@ -62,14 +62,13 @@ static ox::Error pack(ox::StringView argSrc, ox::StringView argRomBin, ox::Strin
|
||||
// resize buffer
|
||||
oxRequire(dstSize, dst.size());
|
||||
dstBuff.resize(dstSize);
|
||||
|
||||
// concatenate ROM segments
|
||||
oxRequireM(romBuff, readFileBuff(argRomBin));
|
||||
oxReturnError(appendBinary(romBuff, dstBuff, *pl));
|
||||
|
||||
oxOutf("Input exe size: {} bytes\n", romBuff.size());
|
||||
oxOutf("Dest FS size: {} bytes\n", dstSize);
|
||||
oxOutf("Preload buff size: {} bytes\n", pl->buff().size());
|
||||
oxOutf("ROM buff size: {} bytes\n", romBuff.size());
|
||||
|
||||
oxReturnError(appendBinary(romBuff, dstBuff, *pl));
|
||||
oxOutf("Final ROM buff size: {} bytes\n", romBuff.size());
|
||||
oxReturnError(writeFileBuff(argRomBin, romBuff));
|
||||
return {};
|
||||
}
|
||||
|
@@ -30,11 +30,11 @@ static ox::Error pathToInode(
|
||||
}
|
||||
if (beginsWith(path, "uuid://")) {
|
||||
auto const uuid = ox::substr(path, 7);
|
||||
oxReturnError(keel::uuidToPath(ctx, uuid).moveTo(path));
|
||||
oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
|
||||
}
|
||||
oxRequire(s, dest.stat(path));
|
||||
oxReturnError(o.at("type").unwrap()->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
|
||||
oxOutf("path to inode: {} => {}\n", path, s.inode);
|
||||
oxOutf("\tpath to inode: {} => {}\n", path, s.inode);
|
||||
return data.set(2, s.inode);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ static ox::Error doTransformations(
|
||||
oxReturnError(keel::performPackTransforms(ctx, buff));
|
||||
// transform FileAddresses
|
||||
oxRequireM(obj, keel::readAsset(ts, buff));
|
||||
oxOutf("transforming {}\n", filePath);
|
||||
oxReturnError(transformFileAddressesObj(ctx, dest, obj));
|
||||
oxReturnError(ox::writeClaw(obj).moveTo(buff));
|
||||
// write file to dest
|
||||
@@ -143,16 +144,15 @@ static ox::Error copy(
|
||||
if (beginsWith(name, ".")) {
|
||||
continue;
|
||||
}
|
||||
oxOutf("reading {}\n", currentFile);
|
||||
oxRequire(stat, src.stat(currentFile));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
oxReturnError(dest.mkdir(currentFile, true));
|
||||
oxReturnError(copy(src, dest, currentFile + '/'));
|
||||
} else {
|
||||
// load file
|
||||
oxOutf("copying file: {}\n", currentFile);
|
||||
oxRequireM(buff, src.read(currentFile));
|
||||
// write file to dest
|
||||
oxOutf("writing {}\n", currentFile);
|
||||
oxReturnError(dest.write(currentFile, buff));
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
#include <imgui.h>
|
||||
@@ -196,10 +197,10 @@ void StudioUI::drawMenu() noexcept {
|
||||
if (ImGui::BeginMenu("Edit")) {
|
||||
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
|
||||
if (ImGui::MenuItem("Undo", "Ctrl+Z", false, undoStack && undoStack->canUndo())) {
|
||||
undoStack->undo();
|
||||
oxLogError(undoStack->undo());
|
||||
}
|
||||
if (ImGui::MenuItem("Redo", "Ctrl+Y", false, undoStack && undoStack->canRedo())) {
|
||||
undoStack->redo();
|
||||
oxLogError(undoStack->redo());
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Copy", "Ctrl+C", false, m_activeEditor && m_activeEditor->copyEnabled())) {
|
||||
@@ -208,7 +209,7 @@ void StudioUI::drawMenu() noexcept {
|
||||
if (ImGui::MenuItem("Cut", "Ctrl+X", false, m_activeEditor && m_activeEditor->cutEnabled())) {
|
||||
m_activeEditor->cut();
|
||||
}
|
||||
if (ImGui::MenuItem("Paste", "Ctrl+V", false, m_activeEditor && m_activeEditor->pasteEnabled()) && m_activeEditor) {
|
||||
if (ImGui::MenuItem("Paste", "Ctrl+V", false, m_activeEditor && m_activeEditor->pasteEnabled())) {
|
||||
m_activeEditor->paste();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
@@ -314,14 +315,14 @@ void StudioUI::toggleProjectExplorer() noexcept {
|
||||
void StudioUI::redo() noexcept {
|
||||
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
|
||||
if (undoStack && undoStack->canRedo()) {
|
||||
m_activeEditor->undoStack()->redo();
|
||||
oxLogError(m_activeEditor->undoStack()->redo());
|
||||
}
|
||||
}
|
||||
|
||||
void StudioUI::undo() noexcept {
|
||||
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
|
||||
if (undoStack && undoStack->canUndo()) {
|
||||
m_activeEditor->undoStack()->undo();
|
||||
oxLogError(m_activeEditor->undoStack()->undo());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,4 +22,9 @@ struct StudioContext {
|
||||
ui(pUi), tctx(pTctx) {}
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
inline keel::Context &keelCtx(StudioContext &ctx) noexcept {
|
||||
return keelCtx(ctx.tctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -43,6 +43,9 @@ class BaseEditor: public Widget {
|
||||
|
||||
virtual void paste();
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool acceptsClipboardPayload() const noexcept;
|
||||
|
||||
virtual void exportFile();
|
||||
|
||||
virtual void keyStateChanged(turbine::Key key, bool down);
|
||||
@@ -131,14 +134,14 @@ class Editor: public studio::BaseEditor {
|
||||
[[nodiscard]]
|
||||
UndoStack *undoStack() noexcept final;
|
||||
|
||||
void pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept;
|
||||
ox::Error pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept;
|
||||
|
||||
template<typename UC, typename ...Args>
|
||||
void pushCommand(Args&&... args) noexcept {
|
||||
ox::Error pushCommand(Args&&... args) noexcept {
|
||||
try {
|
||||
m_undoStack.push(ox::make_unique<UC>(ox::forward<Args>(args)...));
|
||||
return m_undoStack.push(ox::make_unique<UC>(ox::forward<Args>(args)...));
|
||||
} catch (ox::Exception const&ex) {
|
||||
oxLogError(ex.toError());
|
||||
return ex.toError();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,7 @@ ox::Result<T> getDragDropPayload(ox::CStringView name) noexcept {
|
||||
static_cast<size_t>(payload->DataSize)});
|
||||
}
|
||||
|
||||
ox::Error setDragDropPayload(ox::CStringView name, auto const &obj) noexcept {
|
||||
ox::Error setDragDropPayload(ox::CStringView name, auto const&obj) noexcept {
|
||||
oxRequire(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
|
||||
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
|
||||
return {};
|
||||
@@ -148,6 +148,19 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, Im
|
||||
*/
|
||||
bool ComboBox(ox::CStringView lbl, ox::SpanView<ox::String> list, size_t &selectedIdx) noexcept;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param lbl
|
||||
* @param callback
|
||||
* @param selectedIdx
|
||||
* @return true if new value selected, false otherwise
|
||||
*/
|
||||
bool ComboBox(
|
||||
ox::CStringView lbl,
|
||||
std::function<ox::CStringView(size_t)> const&f,
|
||||
size_t strCnt,
|
||||
size_t &selectedIdx) noexcept;
|
||||
|
||||
bool FileComboBox(
|
||||
ox::CStringView lbl,
|
||||
studio::StudioContext &sctx,
|
||||
|
@@ -31,7 +31,7 @@ enum class ProjectEvent {
|
||||
constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
|
||||
auto const extStart = ox::find(path.crbegin(), path.crend(), '.').offset();
|
||||
if (!extStart) {
|
||||
return OxError(1, "Cannot open a file without valid extension.");
|
||||
return OxError(1, "file path does not have valid extension");
|
||||
}
|
||||
return substr(path, extStart + 1);
|
||||
}
|
||||
@@ -47,6 +47,7 @@ constexpr ox::StringView parentDir(ox::StringView path) noexcept {
|
||||
|
||||
class Project {
|
||||
private:
|
||||
ox::SmallMap<ox::String, ox::Optional<ox::ClawFormat>> m_typeFmt;
|
||||
keel::Context &m_ctx;
|
||||
ox::String m_path;
|
||||
ox::String m_projectDataDir;
|
||||
@@ -75,7 +76,15 @@ class Project {
|
||||
ox::Error writeObj(
|
||||
ox::CRStringView path,
|
||||
T const&obj,
|
||||
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept;
|
||||
ox::ClawFormat fmt) noexcept;
|
||||
|
||||
/**
|
||||
* Writes a MetalClaw object to the project at the given path.
|
||||
*/
|
||||
template<typename T>
|
||||
ox::Error writeObj(
|
||||
ox::CRStringView path,
|
||||
T const&obj) noexcept;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<T> loadObj(ox::CRStringView path) const noexcept;
|
||||
@@ -115,7 +124,7 @@ class Project {
|
||||
// file.
|
||||
ox::Signal<ox::Error(ox::CRStringView)> fileRecognized;
|
||||
ox::Signal<ox::Error(ox::CRStringView)> fileDeleted;
|
||||
ox::Signal<ox::Error(ox::CRStringView)> fileUpdated;
|
||||
ox::Signal<ox::Error(ox::StringView, ox::UUID)> fileUpdated;
|
||||
|
||||
};
|
||||
|
||||
@@ -130,15 +139,24 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
|
||||
oxReturnError(ox::buildTypeDef(&m_typeStore, &obj));
|
||||
}
|
||||
oxRequire(desc, m_typeStore.get<T>());
|
||||
auto const descExists = m_fs.stat(ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc))).error != 0;
|
||||
auto const descPath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc));
|
||||
auto const descExists = m_fs.exists(descPath);
|
||||
if (!descExists) {
|
||||
oxReturnError(writeTypeStore());
|
||||
}
|
||||
oxReturnError(keel::setAsset(m_ctx, path, obj));
|
||||
fileUpdated.emit(path);
|
||||
oxReturnError(keel::reloadAsset(m_ctx, path));
|
||||
oxRequire(uuid, pathToUuid(m_ctx, path));
|
||||
fileUpdated.emit(path, uuid);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Error Project::writeObj(ox::CRStringView path, T const&obj) noexcept {
|
||||
oxRequire(ext, fileExt(path));
|
||||
auto const fmt = m_typeFmt[ext].or_value(ox::ClawFormat::Metal);
|
||||
return writeObj(path, obj, fmt);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<T> Project::loadObj(ox::CRStringView path) const noexcept {
|
||||
oxRequire(buff, loadBuff(path));
|
||||
|
133
src/olympic/studio/modlib/include/studio/selectiontracker.hpp
Normal file
133
src/olympic/studio/modlib/include/studio/selectiontracker.hpp
Normal file
@@ -0,0 +1,133 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <ox/std/math.hpp>
|
||||
#include <ox/std/point.hpp>
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/typetraits.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
struct Selection {
|
||||
ox::Point a, b;
|
||||
constexpr Selection() noexcept = default;
|
||||
constexpr Selection(ox::Point const&pA, ox::Point const&pB) noexcept: a(pA), b(pB) {}
|
||||
[[nodiscard]]
|
||||
constexpr ox::Size size() const noexcept {
|
||||
return {b.x - a.x, b.y - a.y};
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr bool contains(ox::Point const&pt) const noexcept {
|
||||
return a.x <= pt.x && a.y <= pt.y
|
||||
&& b.x >= pt.x && b.y >= pt.y;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr auto iterateSelection(studio::Selection const&sel, auto const&cb) {
|
||||
constexpr auto retErr = ox::is_same_v<decltype(cb(0, 0)), ox::Error>;
|
||||
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
|
||||
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
|
||||
if constexpr(retErr) {
|
||||
oxReturnError(cb(x, y));
|
||||
} else {
|
||||
cb(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if constexpr(retErr) {
|
||||
return ox::Error{};
|
||||
}
|
||||
};
|
||||
|
||||
constexpr auto iterateSelectionRows(studio::Selection const&sel, auto const&cb) {
|
||||
constexpr auto retErr = ox::is_same_v<decltype(cb(0, 0)), ox::Error>;
|
||||
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
|
||||
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
|
||||
if constexpr(retErr) {
|
||||
oxReturnError(cb(x, y));
|
||||
} else {
|
||||
cb(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if constexpr(retErr) {
|
||||
return ox::Error{};
|
||||
}
|
||||
};
|
||||
|
||||
class SelectionTracker {
|
||||
private:
|
||||
bool m_selectionOngoing{};
|
||||
ox::Point m_pointA;
|
||||
ox::Point m_pointB;
|
||||
public:
|
||||
[[nodiscard]]
|
||||
constexpr bool selectionOngoing() const noexcept {
|
||||
return m_selectionOngoing;
|
||||
}
|
||||
|
||||
constexpr void startSelection(ox::Point cursor) noexcept {
|
||||
m_pointA = cursor;
|
||||
m_pointB = cursor;
|
||||
m_selectionOngoing = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cursor
|
||||
* @param allowStart
|
||||
* @return true if changed, false otherwise
|
||||
*/
|
||||
constexpr bool updateCursorPoint(ox::Point cursor, bool allowStart = true) noexcept {
|
||||
auto changed = false;
|
||||
if (!m_selectionOngoing && allowStart) {
|
||||
m_pointA = cursor;
|
||||
m_selectionOngoing = true;
|
||||
}
|
||||
if (m_selectionOngoing) {
|
||||
m_pointB = cursor;
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
constexpr void updateCursorPoint(ox::Vec2 cursor, bool allowStart = true) noexcept {
|
||||
updateCursorPoint(
|
||||
ox::Point{
|
||||
static_cast<int32_t>(cursor.x),
|
||||
static_cast<int32_t>(cursor.y),
|
||||
},
|
||||
allowStart);
|
||||
}
|
||||
|
||||
constexpr void updateCursorPoint(ImVec2 cursor, bool allowStart = true) noexcept {
|
||||
updateCursorPoint(
|
||||
ox::Point{
|
||||
static_cast<int32_t>(cursor.x),
|
||||
static_cast<int32_t>(cursor.y),
|
||||
},
|
||||
allowStart);
|
||||
}
|
||||
|
||||
constexpr void finishSelection() noexcept {
|
||||
m_selectionOngoing = {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Selection selection() const noexcept {
|
||||
return {
|
||||
{
|
||||
ox::min(m_pointA.x, m_pointB.x),
|
||||
ox::min(m_pointA.y, m_pointB.y),
|
||||
},
|
||||
{
|
||||
ox::max(m_pointA.x, m_pointB.x),
|
||||
ox::max(m_pointA.y, m_pointB.y),
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/configio.hpp>
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/editor.hpp>
|
||||
#include <studio/filedialog.hpp>
|
||||
@@ -12,6 +13,7 @@
|
||||
#include <studio/itemmaker.hpp>
|
||||
#include <studio/popup.hpp>
|
||||
#include <studio/project.hpp>
|
||||
#include <studio/selectiontracker.hpp>
|
||||
#include <studio/task.hpp>
|
||||
#include <studio/undocommand.hpp>
|
||||
#include <studio/undostack.hpp>
|
||||
|
@@ -4,16 +4,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <source_location>
|
||||
|
||||
#include <ox/std/error.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
class NoChangesException: public ox::Exception {
|
||||
public:
|
||||
inline NoChangesException(std::source_location sloc = std::source_location::current()):
|
||||
ox::Exception(sloc.file_name(), sloc.line(), 1, "Command makes no changes.") {}
|
||||
};
|
||||
|
||||
class UndoCommand {
|
||||
public:
|
||||
virtual ~UndoCommand() noexcept = default;
|
||||
virtual void redo() noexcept = 0;
|
||||
virtual void undo() noexcept = 0;
|
||||
virtual ox::Error redo() noexcept = 0;
|
||||
virtual ox::Error undo() noexcept = 0;
|
||||
[[nodiscard]]
|
||||
virtual int commandId() const noexcept = 0;
|
||||
virtual bool mergeWith(UndoCommand const*cmd) noexcept;
|
||||
virtual bool mergeWith(UndoCommand const&cmd) noexcept;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -19,11 +19,11 @@ class UndoStack {
|
||||
std::size_t m_stackIdx = 0;
|
||||
|
||||
public:
|
||||
void push(ox::UPtr<UndoCommand> &&cmd) noexcept;
|
||||
ox::Error push(ox::UPtr<UndoCommand> &&cmd) noexcept;
|
||||
|
||||
void redo() noexcept;
|
||||
ox::Error redo() noexcept;
|
||||
|
||||
void undo() noexcept;
|
||||
ox::Error undo() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool canRedo() const noexcept {
|
||||
|
@@ -23,6 +23,10 @@ void BaseEditor::copy() {
|
||||
void BaseEditor::paste() {
|
||||
}
|
||||
|
||||
bool BaseEditor::acceptsClipboardPayload() const noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
void BaseEditor::exportFile() {
|
||||
}
|
||||
|
||||
@@ -95,7 +99,7 @@ void BaseEditor::setPasteEnabled(bool v) {
|
||||
}
|
||||
|
||||
bool BaseEditor::pasteEnabled() const noexcept {
|
||||
return m_pasteEnabled;
|
||||
return m_pasteEnabled && acceptsClipboardPayload();
|
||||
}
|
||||
|
||||
ox::Error BaseEditor::saveItem() noexcept {
|
||||
@@ -127,8 +131,8 @@ ox::CStringView Editor::itemDisplayName() const noexcept {
|
||||
return m_itemName;
|
||||
}
|
||||
|
||||
void Editor::pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
m_undoStack.push(std::move(cmd));
|
||||
ox::Error Editor::pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
return m_undoStack.push(std::move(cmd));
|
||||
}
|
||||
|
||||
UndoStack *Editor::undoStack() noexcept {
|
||||
|
@@ -100,6 +100,26 @@ bool ComboBox(
|
||||
return out;
|
||||
}
|
||||
|
||||
bool ComboBox(
|
||||
ox::CStringView lbl,
|
||||
std::function<ox::CStringView(size_t)> const&f,
|
||||
size_t strCnt,
|
||||
size_t &selectedIdx) noexcept {
|
||||
bool out{};
|
||||
auto const first = selectedIdx < strCnt ? f(selectedIdx).c_str() : "";
|
||||
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
|
||||
for (auto i = 0u; i < strCnt; ++i) {
|
||||
const auto selected = (selectedIdx == i);
|
||||
if (ImGui::Selectable(f(i).c_str(), selected) && selectedIdx != i) {
|
||||
selectedIdx = i;
|
||||
out = true;
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool FileComboBox(
|
||||
ox::CStringView lbl,
|
||||
studio::StudioContext &sctx,
|
||||
|
@@ -56,9 +56,13 @@ ox::FileSystem &Project::romFs() noexcept {
|
||||
}
|
||||
|
||||
ox::Error Project::mkdir(ox::CRStringView path) const noexcept {
|
||||
oxReturnError(m_fs.mkdir(path, true));
|
||||
fileUpdated.emit(path);
|
||||
return {};
|
||||
auto const [stat, err] = m_fs.stat(path);
|
||||
if (err) {
|
||||
oxReturnError(m_fs.mkdir(path, true));
|
||||
fileUpdated.emit(path, {});
|
||||
}
|
||||
return stat.fileType == ox::FileType::Directory ?
|
||||
ox::Error{} : OxError(1, "path exists as normal file");
|
||||
}
|
||||
|
||||
ox::Result<ox::FileStat> Project::stat(ox::CRStringView path) const noexcept {
|
||||
@@ -115,9 +119,9 @@ ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexc
|
||||
ox::Buffer outBuff;
|
||||
outBuff.reserve(buff.size() + HdrSz);
|
||||
ox::BufferWriter writer(&outBuff);
|
||||
auto const [uuid, err] = m_ctx.pathToUuid.at(path);
|
||||
auto const [uuid, err] = pathToUuid(m_ctx, path);
|
||||
if (!err) {
|
||||
oxReturnError(keel::writeUuidHeader(writer, *uuid));
|
||||
oxReturnError(keel::writeUuidHeader(writer, uuid));
|
||||
}
|
||||
oxReturnError(writer.write(buff.data(), buff.size()));
|
||||
auto const newFile = m_fs.stat(path).error != 0;
|
||||
@@ -126,7 +130,7 @@ ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexc
|
||||
fileAdded.emit(path);
|
||||
indexFile(path);
|
||||
} else {
|
||||
fileUpdated.emit(path);
|
||||
fileUpdated.emit(path, uuid);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
bool UndoCommand::mergeWith(UndoCommand const*) noexcept {
|
||||
bool UndoCommand::mergeWith(UndoCommand const&) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -6,35 +6,39 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
void UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
ox::Error UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
for (auto const i = m_stackIdx; i < m_stack.size();) {
|
||||
std::ignore = m_stack.erase(i);
|
||||
}
|
||||
cmd->redo();
|
||||
oxReturnError(cmd->redo());
|
||||
redoTriggered.emit(cmd.get());
|
||||
changeTriggered.emit(cmd.get());
|
||||
if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(cmd.get())) {
|
||||
if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(*cmd)) {
|
||||
m_stack.emplace_back(std::move(cmd));
|
||||
++m_stackIdx;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void UndoStack::redo() noexcept {
|
||||
ox::Error UndoStack::redo() noexcept {
|
||||
if (m_stackIdx < m_stack.size()) {
|
||||
auto &c = m_stack[m_stackIdx++];
|
||||
c->redo();
|
||||
auto &c = m_stack[m_stackIdx];
|
||||
oxReturnError(c->redo());
|
||||
++m_stackIdx;
|
||||
redoTriggered.emit(c.get());
|
||||
changeTriggered.emit(c.get());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void UndoStack::undo() noexcept {
|
||||
ox::Error UndoStack::undo() noexcept {
|
||||
if (m_stackIdx) {
|
||||
auto &c = m_stack[--m_stackIdx];
|
||||
c->undo();
|
||||
oxReturnError(c->undo());
|
||||
undoTriggered.emit(c.get());
|
||||
changeTriggered.emit(c.get());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,19 +17,14 @@ class BaseClipboardObject {
|
||||
virtual ~BaseClipboardObject() noexcept = default;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual ox::String typeId() const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto typeMatch(ox::StringView name, int version) const noexcept {
|
||||
return typeId() == ox::buildTypeId(name, version);
|
||||
}
|
||||
virtual ox::StringView typeId() const noexcept = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ClipboardObject: public BaseClipboardObject {
|
||||
[[nodiscard]]
|
||||
ox::String typeId() const noexcept final {
|
||||
return ox::buildTypeId(T::TypeName, T::TypeVersion);
|
||||
ox::StringView typeId() const noexcept final {
|
||||
return ox::ModelTypeId_v<T>;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -39,11 +34,11 @@ void setClipboardText(Context &ctx, ox::CRStringView text) noexcept;
|
||||
|
||||
void setClipboardObject(Context &ctx, ox::UPtr<BaseClipboardObject> &&obj) noexcept;
|
||||
|
||||
ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringView typeName, int typeVersion) noexcept;
|
||||
ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringView typeId) noexcept;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<T*> getClipboardObject(Context &ctx) noexcept {
|
||||
oxRequire(p, getClipboardData(ctx, T::TypeName, T::TypeVersion));
|
||||
oxRequire(p, getClipboardData(ctx, ox::ModelTypeId_v<T>));
|
||||
return dynamic_cast<T*>(p);
|
||||
}
|
||||
|
||||
|
@@ -26,8 +26,8 @@ void setClipboardObject(Context &ctx, ox::UPtr<BaseClipboardObject> &&obj) noexc
|
||||
ctx.clipboard = std::move(obj);
|
||||
}
|
||||
|
||||
ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringView typeName, int typeVersion) noexcept {
|
||||
if (ctx.clipboard && ctx.clipboard->typeMatch(typeName, typeVersion)) {
|
||||
ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringView typeId) noexcept {
|
||||
if (ctx.clipboard && ctx.clipboard->typeId() == typeId) {
|
||||
return ctx.clipboard.get();
|
||||
}
|
||||
return OxError(1);
|
||||
|
Reference in New Issue
Block a user