[nostalgia,studio] Cleanup

This commit is contained in:
Gary Talent 2023-12-03 19:59:27 -06:00
parent 5717d67462
commit d23b69ce17
24 changed files with 68 additions and 158 deletions

View File

@ -78,6 +78,6 @@ void setSprite(Context &ctx, Sprite const&s) noexcept;
} }
namespace nostalgia::core::gl { namespace nostalgia::core::gl {
void drawMainView(core::Context&, ox::Size const&) noexcept; void draw(core::Context&, ox::Size const&) noexcept;
} }

View File

@ -34,7 +34,7 @@ namespace renderer {
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {} Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
void Drawer::draw(turbine::Context &tctx) noexcept { void Drawer::draw(turbine::Context &tctx) noexcept {
core::gl::drawMainView(m_ctx, turbine::getScreenSize(tctx)); core::gl::draw(m_ctx, turbine::getScreenSize(tctx));
} }
constexpr ox::StringView bgvshadTmpl = R"( constexpr ox::StringView bgvshadTmpl = R"(
@ -633,7 +633,7 @@ void setTile(
namespace gl { namespace gl {
void drawMainView(core::Context &ctx, ox::Size const&renderSz) noexcept { void draw(core::Context &ctx, ox::Size const&renderSz) noexcept {
glViewport(0, 0, renderSz.width, renderSz.height); glViewport(0, 0, renderSz.width, renderSz.height);
glutils::clearScreen(); glutils::clearScreen();
auto &gctx = glctx(ctx); auto &gctx = glctx(ctx);

View File

@ -15,11 +15,11 @@
namespace nostalgia::core { namespace nostalgia::core {
PaletteEditorImGui::PaletteEditorImGui(turbine::Context *ctx, ox::String path): PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::String path):
m_ctx(ctx), m_ctx(ctx),
m_itemPath(std::move(path)), m_itemPath(std::move(path)),
m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)), m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)),
m_pal(*keel::readObj<Palette>(m_ctx->keelCtx, ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) { m_pal(*keel::readObj<Palette>(m_ctx.keelCtx, ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) {
} }
const ox::String &PaletteEditorImGui::itemName() const noexcept { const ox::String &PaletteEditorImGui::itemName() const noexcept {
@ -125,7 +125,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
int r = red16(c); int r = red16(c);
int g = green16(c); int g = green16(c);
int b = blue16(c); int b = blue16(c);
int a = alpha16(c); int const a = alpha16(c);
ImGui::InputInt("Red", &r, 1, 5); ImGui::InputInt("Red", &r, 1, 5);
ImGui::InputInt("Green", &g, 1, 5); ImGui::InputInt("Green", &g, 1, 5);
ImGui::InputInt("Blue", &b, 1, 5); ImGui::InputInt("Blue", &b, 1, 5);
@ -139,7 +139,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);
} }

View File

@ -14,16 +14,14 @@ namespace nostalgia::core {
class PaletteEditorImGui: public studio::Editor { class PaletteEditorImGui: public studio::Editor {
private: private:
turbine::Context *m_ctx = nullptr; turbine::Context &m_ctx;
ox::String m_itemPath; ox::String m_itemPath;
ox::String m_itemName; ox::String m_itemName;
Palette m_pal; Palette m_pal;
std::size_t m_selectedRow = 0; std::size_t m_selectedRow = 0;
PaletteEditorImGui() noexcept = default;
public: public:
PaletteEditorImGui(turbine::Context *ctx, ox::String path); PaletteEditorImGui(turbine::Context &ctx, ox::String path);
/** /**
* Returns the name of item being edited. * Returns the name of item being edited.

View File

@ -12,14 +12,14 @@
namespace nostalgia::core { 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), studio::editorMaker<TileSheetEditorImGui>(ctx, FileExt_ng),
studio::editorMaker<PaletteEditorImGui>(ctx, FileExt_npal), studio::editorMaker<PaletteEditorImGui>(ctx, FileExt_npal),
}; };
} }
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context*) const noexcept final { ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context&) const noexcept final {
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out; ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
out.emplace_back(ox::make<studio::ItemMakerT<core::TileSheet>>("Tile Sheet", "TileSheets", FileExt_ng)); out.emplace_back(ox::make<studio::ItemMakerT<core::TileSheet>>("Tile Sheet", "TileSheets", FileExt_ng));
out.emplace_back(ox::make<studio::ItemMakerT<core::Palette>>("Palette", "Palettes", FileExt_npal)); out.emplace_back(ox::make<studio::ItemMakerT<core::Palette>>("Palette", "Palettes", FileExt_npal));

View File

@ -38,14 +38,15 @@ ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const
return OxError(static_cast<ox::ErrorCode>(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8))); return OxError(static_cast<ox::ErrorCode>(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8)));
} }
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::String path): m_tileSheetEditor(ctx, path) { TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::String path):
m_ctx = ctx; m_ctx(ctx),
m_itemPath = std::move(path); m_itemPath(std::move(path)),
m_tileSheetEditor(m_ctx, m_itemPath) {
const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
m_itemName = m_itemPath.substr(lastSlash + 1); m_itemName = m_itemPath.substr(lastSlash + 1);
// init palette idx // init palette idx
const auto &palPath = model()->palPath(); const auto &palPath = model()->palPath();
auto sctx = applicationData<studio::StudioContext>(*m_ctx); auto sctx = applicationData<studio::StudioContext>(m_ctx);
const auto &palList = sctx->project->fileList(core::FileExt_npal); const auto &palList = sctx->project->fileList(core::FileExt_npal);
for (std::size_t i = 0; const auto &pal : palList) { for (std::size_t i = 0; const auto &pal : palList) {
if (palPath == pal) { if (palPath == pal) {
@ -305,7 +306,7 @@ void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) noexcept {
const auto wheelh = io.MouseWheelH; const auto wheelh = io.MouseWheelH;
if (wheel != 0) { if (wheel != 0) {
const auto zoomMod = ox::defines::OS == ox::OS::Darwin ? const auto zoomMod = ox::defines::OS == ox::OS::Darwin ?
io.KeySuper : turbine::buttonDown(*m_ctx, turbine::Key::Mod_Ctrl); io.KeySuper : turbine::buttonDown(m_ctx, turbine::Key::Mod_Ctrl);
m_tileSheetEditor.scrollV(fbSize, wheel, zoomMod); m_tileSheetEditor.scrollV(fbSize, wheel, zoomMod);
} }
if (wheelh != 0) { if (wheelh != 0) {
@ -345,7 +346,7 @@ void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) noexcept {
} }
void TileSheetEditorImGui::drawPaletteSelector() noexcept { void TileSheetEditorImGui::drawPaletteSelector() noexcept {
auto sctx = applicationData<studio::StudioContext>(*m_ctx); auto sctx = applicationData<studio::StudioContext>(m_ctx);
const auto &files = sctx->project->fileList(core::FileExt_npal); const auto &files = sctx->project->fileList(core::FileExt_npal);
const auto first = m_selectedPaletteIdx < files.size() ? const auto first = m_selectedPaletteIdx < files.size() ?
files[m_selectedPaletteIdx].c_str() : ""; files[m_selectedPaletteIdx].c_str() : "";

View File

@ -43,7 +43,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
void close() noexcept; void close() noexcept;
}; };
std::size_t m_selectedPaletteIdx = 0; std::size_t m_selectedPaletteIdx = 0;
turbine::Context *m_ctx = nullptr; turbine::Context &m_ctx;
ox::Vector<ox::String> m_paletteList; ox::Vector<ox::String> m_paletteList;
SubSheetEditor m_subsheetEditor; SubSheetEditor m_subsheetEditor;
ox::String m_itemPath; ox::String m_itemPath;
@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
Tool m_tool = Tool::Draw; Tool m_tool = Tool::Draw;
public: public:
TileSheetEditorImGui(turbine::Context *ctx, ox::String path); TileSheetEditorImGui(turbine::Context &ctx, ox::String path);
~TileSheetEditorImGui() override = default; ~TileSheetEditorImGui() override = default;

View File

@ -563,13 +563,13 @@ class PaletteChangeCommand: public TileSheetCommand {
}; };
TileSheetEditorModel::TileSheetEditorModel(turbine::Context *ctx, ox::StringView path): TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path):
m_ctx(ctx), m_ctx(ctx),
m_path(path) { m_path(path) {
oxRequireT(img, readObj<TileSheet>(ctx->keelCtx, m_path)); oxRequireT(img, readObj<TileSheet>(m_ctx.keelCtx, m_path));
m_img = *img; m_img = *img;
if (m_img.defaultPalette) { if (m_img.defaultPalette) {
oxThrowError(readObj<Palette>(ctx->keelCtx, m_img.defaultPalette).moveTo(&m_pal)); oxThrowError(readObj<Palette>(m_ctx.keelCtx, m_img.defaultPalette).moveTo(&m_pal));
} }
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated); m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId); m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
@ -592,7 +592,7 @@ void TileSheetEditorModel::cut() {
} }
const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin; const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin;
const auto pt2 = ox::Point(s->columns * TileWidth, s->rows * TileHeight); const auto pt2 = ox::Point(s->columns * TileWidth, s->rows * TileHeight);
turbine::setClipboardObject(*m_ctx, std::move(cb)); turbine::setClipboardObject(m_ctx, std::move(cb));
pushCommand(ox::make<CutPasteCommand<CommandId::Cut>>(m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); pushCommand(ox::make<CutPasteCommand<CommandId::Cut>>(m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb));
} }
@ -609,11 +609,11 @@ void TileSheetEditorModel::copy() {
cb->addPixel(pt, c); cb->addPixel(pt, c);
} }
} }
turbine::setClipboardObject(*m_ctx, std::move(cb)); turbine::setClipboardObject(m_ctx, std::move(cb));
} }
void TileSheetEditorModel::paste() { void TileSheetEditorModel::paste() {
auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(*m_ctx); auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(m_ctx);
if (err) { if (err) {
oxLogError(err); oxLogError(err);
oxErrf("Could not read clipboard: {}", toStr(err)); oxErrf("Could not read clipboard: {}", toStr(err));
@ -633,7 +633,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
constexpr ox::StringView uuidPrefix = "uuid://"; constexpr ox::StringView uuidPrefix = "uuid://";
if (ox::beginsWith(path, uuidPrefix)) { if (ox::beginsWith(path, uuidPrefix)) {
auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes()); auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes());
auto out = m_ctx->keelCtx.uuidToPath.at(uuid); auto out = m_ctx.keelCtx.uuidToPath.at(uuid);
if (out.error) { if (out.error) {
return {}; return {};
} }
@ -644,7 +644,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
} }
ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept { ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept {
oxRequire(uuid, m_ctx->keelCtx.pathToUuid.at(path)); oxRequire(uuid, m_ctx.keelCtx.pathToUuid.at(path));
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString())); pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString()));
return {}; return {};
} }
@ -752,7 +752,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(const studio::UndoCommand *cmd)
m_updated = true; m_updated = true;
const auto cmdId = cmd->commandId(); const auto cmdId = cmd->commandId();
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) { if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
oxReturnError(readObj<Palette>(m_ctx->keelCtx, ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal)); oxReturnError(readObj<Palette>(m_ctx.keelCtx, ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal));
} }
auto tsCmd = dynamic_cast<const TileSheetCommand*>(cmd); auto tsCmd = dynamic_cast<const TileSheetCommand*>(cmd);
auto idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx()); auto idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx());
@ -772,7 +772,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);
} }

View File

@ -29,14 +29,14 @@ class TileSheetEditorModel: public ox::SignalHandler {
studio::UndoStack m_undoStack; studio::UndoStack m_undoStack;
class DrawCommand *m_ongoingDrawCommand = nullptr; class DrawCommand *m_ongoingDrawCommand = nullptr;
bool m_updated = false; bool m_updated = false;
turbine::Context *m_ctx = nullptr; turbine::Context &m_ctx;
ox::String m_path; ox::String m_path;
bool m_selectionOngoing = false; bool m_selectionOngoing = false;
ox::Point m_selectionOrigin = {-1, -1}; ox::Point m_selectionOrigin = {-1, -1};
ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}};
public: public:
TileSheetEditorModel(turbine::Context *ctx, ox::StringView path); TileSheetEditorModel(turbine::Context &ctx, ox::StringView path);
~TileSheetEditorModel() override = default; ~TileSheetEditorModel() override = default;

View File

@ -11,8 +11,9 @@
namespace nostalgia::core { namespace nostalgia::core {
TileSheetEditorView::TileSheetEditorView(turbine::Context *ctx, ox::StringView path): TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path):
m_model(ctx, path), m_pixelsDrawer(&m_model) { m_model(ctx, path),
m_pixelsDrawer(&m_model) {
// build shaders // build shaders
oxThrowError(m_pixelsDrawer.buildShader()); oxThrowError(m_pixelsDrawer.buildShader());
oxThrowError(m_pixelGridDrawer.buildShader()); oxThrowError(m_pixelGridDrawer.buildShader());

View File

@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler {
std::size_t m_palIdx = 0; std::size_t m_palIdx = 0;
public: public:
TileSheetEditorView(turbine::Context *ctx, ox::StringView path); TileSheetEditorView(turbine::Context &ctx, ox::StringView path);
~TileSheetEditorView() override = default; ~TileSheetEditorView() override = default;

View File

@ -18,7 +18,7 @@ constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) no
} }
} }
constexpr void setLayerAttachments(unsigned layer, const TileDoc &srcTile, SceneStatic::Tile &dstTile) noexcept { constexpr void setLayerAttachments(unsigned layer, TileDoc const&srcTile, SceneStatic::Tile &dstTile) noexcept {
setTopEdge( setTopEdge(
dstTile.layerAttachments, dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[0])); adjustLayerAttachment(layer, srcTile.layerAttachments[0]));

View File

@ -10,11 +10,11 @@
namespace nostalgia::scene { namespace nostalgia::scene {
SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::String path): SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::StringView path):
m_ctx(ctx), m_ctx(ctx),
m_itemPath(std::move(path)), m_itemPath(std::move(path)),
m_editor(&m_ctx, m_itemPath), m_editor(m_ctx, m_itemPath),
m_view(&m_ctx, m_editor.scene()) { m_view(m_ctx, m_editor.scene()) {
const auto lastSlash = std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); const auto lastSlash = std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
m_itemName = m_itemPath.substr(lastSlash + 1); m_itemName = m_itemPath.substr(lastSlash + 1);
setRequiresConstantRefresh(false); setRequiresConstantRefresh(false);

View File

@ -23,7 +23,7 @@ class SceneEditorImGui: public studio::Editor {
SceneEditorView m_view; SceneEditorView m_view;
public: public:
SceneEditorImGui(turbine::Context &ctx, ox::String path); SceneEditorImGui(turbine::Context &ctx, ox::StringView path);
/** /**
* Returns the name of item being edited. * Returns the name of item being edited.

View File

@ -8,10 +8,9 @@
namespace nostalgia::scene { namespace nostalgia::scene {
SceneEditor::SceneEditor(turbine::Context *ctx, ox::CRStringView path) { SceneEditor::SceneEditor(turbine::Context &ctx, ox::CRStringView path):
m_ctx = ctx; m_ctx(ctx),
oxRequireT(scn, keel::readObj<SceneStatic>(m_ctx->keelCtx, path)); m_scene(*keel::readObj<SceneStatic>(m_ctx.keelCtx, path).unwrapThrow()) {
m_scene = *scn;
} }
} }

View File

@ -13,15 +13,16 @@ namespace nostalgia::scene {
class SceneEditor { class SceneEditor {
private: private:
turbine::Context *m_ctx = nullptr; turbine::Context &m_ctx;
ox::String m_itemName; ox::String m_itemName;
ox::String m_itemPath; ox::String m_itemPath;
SceneStatic m_scene; SceneStatic m_scene;
public: public:
SceneEditor(turbine::Context *ctx, ox::CRStringView path); SceneEditor(turbine::Context &ctx, ox::CRStringView path);
const SceneStatic &scene() noexcept { [[nodiscard]]
SceneStatic const&scene() const noexcept {
return m_scene; return m_scene;
} }

View File

@ -8,10 +8,10 @@
namespace nostalgia::scene { namespace nostalgia::scene {
SceneEditorView::SceneEditorView(turbine::Context *tctx, const SceneStatic &sceneStatic): SceneEditorView::SceneEditorView(turbine::Context &tctx, SceneStatic const&sceneStatic):
m_sceneStatic(sceneStatic), m_sceneStatic(sceneStatic),
m_scene(m_sceneStatic) { m_scene(m_sceneStatic) {
oxThrowError(core::init(*tctx, {.glInstallDrawer = false}).moveTo(&m_cctx)); oxThrowError(core::init(tctx, {.glInstallDrawer = false}).moveTo(&m_cctx));
} }
ox::Error SceneEditorView::setupScene() noexcept { ox::Error SceneEditorView::setupScene() noexcept {
@ -23,10 +23,10 @@ void SceneEditorView::draw(int width, int height) noexcept {
glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height); glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height);
} }
const glutils::FrameBufferBind frameBufferBind(m_frameBuffer); const glutils::FrameBufferBind frameBufferBind(m_frameBuffer);
core::gl::drawMainView(*m_cctx, {width, height}); core::gl::draw(*m_cctx, {width, height});
} }
const glutils::FrameBuffer &SceneEditorView::framebuffer() const noexcept { glutils::FrameBuffer const&SceneEditorView::framebuffer() const noexcept {
return m_frameBuffer; return m_frameBuffer;
} }

View File

@ -15,19 +15,19 @@ class SceneEditorView {
private: private:
ox::UPtr<core::Context> m_cctx; ox::UPtr<core::Context> m_cctx;
const SceneStatic &m_sceneStatic; SceneStatic const&m_sceneStatic;
Scene m_scene; Scene m_scene;
glutils::FrameBuffer m_frameBuffer; glutils::FrameBuffer m_frameBuffer;
public: public:
SceneEditorView(turbine::Context *ctx, const SceneStatic &sceneStatic); SceneEditorView(turbine::Context &ctx, SceneStatic const&sceneStatic);
ox::Error setupScene() noexcept; ox::Error setupScene() noexcept;
void draw(int width, int height) noexcept; void draw(int width, int height) noexcept;
[[nodiscard]] [[nodiscard]]
const glutils::FrameBuffer &framebuffer() const noexcept; glutils::FrameBuffer const&framebuffer() const noexcept;
}; };

View File

@ -10,22 +10,17 @@ namespace nostalgia::scene {
class StudioModule: public studio::Module { class StudioModule: public studio::Module {
public: public:
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) const noexcept override; ox::Vector<studio::EditorMaker> editors(turbine::Context &ctx) const noexcept override;
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context*) const noexcept override; ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context&) const noexcept override;
}; };
ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) const noexcept { ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context &ctx) const noexcept {
return { return {
{ studio::editorMaker<SceneEditorImGui>(ctx, "nscn"),
{ox::String("nscn")},
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
return ox::makeCatch<SceneEditorImGui>(*ctx, ox::String(path));
}
},
}; };
} }
ox::Vector<ox::UPtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context*) const noexcept { ox::Vector<ox::UPtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context&) const noexcept {
ox::Vector<ox::UPtr<studio::ItemMaker>> out; ox::Vector<ox::UPtr<studio::ItemMaker>> out;
return out; return out;
} }

View File

@ -1,68 +0,0 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/core/gfx.hpp>
#include <keel/media.hpp>
#include "typeconv.hpp"
namespace nostalgia::scene {
[[nodiscard]]
constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) noexcept {
if (attachment == 0) {
return layer;
} else {
return attachment - 1;
}
}
constexpr void setLayerAttachments(unsigned layer, const TileDoc &srcTile, SceneStatic::Tile &dstTile) noexcept {
setTopEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[0]));
setBottomEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[1]));
setLeftEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[2]));
setRightEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[3]));
}
ox::Error SceneDocToSceneStaticConverter::convert(
keel::Context *ctx,
SceneDoc *src,
SceneStatic *dst) const noexcept {
oxRequire(ts, keel::readObj<core::TileSheet>(ctx, src->tilesheet));
const auto layerCnt = src->tiles.size();
dst->setLayerCnt(layerCnt);
dst->tilesheet = ox::FileAddress(src->tilesheet);
dst->palettes.reserve(src->palettes.size());
for (const auto &pal : src->palettes) {
dst->palettes.emplace_back(pal);
}
for (auto layerIdx = 0u; const auto &layer : src->tiles) {
const auto layerDim = src->size(layerIdx);
auto dstLayer = dst->layer(layerIdx);
dstLayer.setDimensions(layerDim);
for (auto tileIdx = 0u; const auto &row : layer) {
for (const auto &srcTile : row) {
auto dstTile = dstLayer.tile(tileIdx);
dstTile.tileType = srcTile.type;
oxRequire(path, srcTile.getSubsheetPath(*ts));
oxRequire(mapIdx, ts->getTileOffset(path));
dstTile.tileMapIdx = static_cast<uint16_t>(mapIdx);
setLayerAttachments(layerIdx, srcTile, dstTile);
++tileIdx;
}
}
++layerIdx;
}
return {};
}
}

View File

@ -1,17 +0,0 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <keel/typeconv.hpp>
#include <nostalgia/scene/scenestatic.hpp>
namespace nostalgia::scene {
class SceneDocToSceneStaticConverter: public keel::Converter<SceneDoc, SceneStatic> {
ox::Error convert(keel::Context*, SceneDoc *src, SceneStatic *dst) const noexcept final;
};
}

View File

@ -260,10 +260,10 @@ void StudioUI::loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept
} }
void StudioUI::loadModule(const studio::Module *mod) noexcept { void StudioUI::loadModule(const studio::Module *mod) noexcept {
for (const auto &editorMaker : mod->editors(m_ctx)) { for (const auto &editorMaker : mod->editors(*m_ctx)) {
loadEditorMaker(editorMaker); loadEditorMaker(editorMaker);
} }
for (auto &im : mod->itemMakers(m_ctx)) { for (auto &im : mod->itemMakers(*m_ctx)) {
m_newMenu.addItemMaker(std::move(im)); m_newMenu.addItemMaker(std::move(im));
} }
} }

View File

@ -27,18 +27,18 @@ class Module {
public: public:
virtual ~Module() noexcept = default; virtual ~Module() noexcept = default;
virtual ox::Vector<EditorMaker> editors(turbine::Context *ctx) const; virtual ox::Vector<EditorMaker> editors(turbine::Context &ctx) const;
virtual ox::Vector<ox::UniquePtr<ItemMaker>> itemMakers(turbine::Context*) const; virtual ox::Vector<ox::UPtr<ItemMaker>> itemMakers(turbine::Context&) const;
}; };
template<typename Editor> template<typename Editor>
[[nodiscard]] [[nodiscard]]
studio::EditorMaker editorMaker(turbine::Context *ctx, ox::CRStringView ext) noexcept { studio::EditorMaker editorMaker(turbine::Context &ctx, ox::CRStringView ext) noexcept {
return { return {
{ox::String(ext)}, {ox::String(ext)},
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> { [&ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
return ox::makeCatch<Editor>(ctx, ox::String(path)); return ox::makeCatch<Editor>(ctx, ox::String(path));
} }
}; };

View File

@ -6,11 +6,11 @@
namespace studio { namespace studio {
ox::Vector<EditorMaker> Module::editors(turbine::Context*) const { ox::Vector<EditorMaker> Module::editors(turbine::Context&) const {
return {}; return {};
} }
ox::Vector<ox::UniquePtr<ItemMaker>> Module::itemMakers(turbine::Context*) const { ox::Vector<ox::UPtr<ItemMaker>> Module::itemMakers(turbine::Context&) const {
return {}; return {};
} }