[nostalgia,studio] Cleanup
This commit is contained in:
parent
5717d67462
commit
d23b69ce17
@ -78,6 +78,6 @@ void setSprite(Context &ctx, Sprite const&s) noexcept;
|
||||
}
|
||||
|
||||
namespace nostalgia::core::gl {
|
||||
void drawMainView(core::Context&, ox::Size const&) noexcept;
|
||||
void draw(core::Context&, ox::Size const&) noexcept;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace renderer {
|
||||
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
|
||||
|
||||
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"(
|
||||
@ -633,7 +633,7 @@ void setTile(
|
||||
|
||||
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);
|
||||
glutils::clearScreen();
|
||||
auto &gctx = glctx(ctx);
|
||||
|
@ -15,11 +15,11 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
PaletteEditorImGui::PaletteEditorImGui(turbine::Context *ctx, ox::String path):
|
||||
PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::String path):
|
||||
m_ctx(ctx),
|
||||
m_itemPath(std::move(path)),
|
||||
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 {
|
||||
@ -125,7 +125,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
|
||||
int r = red16(c);
|
||||
int g = green16(c);
|
||||
int b = blue16(c);
|
||||
int a = alpha16(c);
|
||||
int const a = alpha16(c);
|
||||
ImGui::InputInt("Red", &r, 1, 5);
|
||||
ImGui::InputInt("Green", &g, 1, 5);
|
||||
ImGui::InputInt("Blue", &b, 1, 5);
|
||||
@ -139,7 +139,7 @@ void PaletteEditorImGui::draw(turbine::Context*) 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);
|
||||
}
|
||||
|
||||
|
@ -14,16 +14,14 @@ namespace nostalgia::core {
|
||||
class PaletteEditorImGui: public studio::Editor {
|
||||
|
||||
private:
|
||||
turbine::Context *m_ctx = nullptr;
|
||||
turbine::Context &m_ctx;
|
||||
ox::String m_itemPath;
|
||||
ox::String m_itemName;
|
||||
Palette m_pal;
|
||||
std::size_t m_selectedRow = 0;
|
||||
|
||||
PaletteEditorImGui() noexcept = default;
|
||||
|
||||
public:
|
||||
PaletteEditorImGui(turbine::Context *ctx, ox::String path);
|
||||
PaletteEditorImGui(turbine::Context &ctx, ox::String path);
|
||||
|
||||
/**
|
||||
* Returns the name of item being edited.
|
||||
|
@ -12,14 +12,14 @@
|
||||
namespace nostalgia::core {
|
||||
|
||||
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 {
|
||||
studio::editorMaker<TileSheetEditorImGui>(ctx, FileExt_ng),
|
||||
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;
|
||||
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));
|
||||
|
@ -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)));
|
||||
}
|
||||
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::String path): m_tileSheetEditor(ctx, path) {
|
||||
m_ctx = ctx;
|
||||
m_itemPath = std::move(path);
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::String path):
|
||||
m_ctx(ctx),
|
||||
m_itemPath(std::move(path)),
|
||||
m_tileSheetEditor(m_ctx, m_itemPath) {
|
||||
const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
|
||||
m_itemName = m_itemPath.substr(lastSlash + 1);
|
||||
// init palette idx
|
||||
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);
|
||||
for (std::size_t i = 0; const auto &pal : palList) {
|
||||
if (palPath == pal) {
|
||||
@ -305,7 +306,7 @@ void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) noexcept {
|
||||
const auto wheelh = io.MouseWheelH;
|
||||
if (wheel != 0) {
|
||||
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);
|
||||
}
|
||||
if (wheelh != 0) {
|
||||
@ -345,7 +346,7 @@ void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) 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 first = m_selectedPaletteIdx < files.size() ?
|
||||
files[m_selectedPaletteIdx].c_str() : "";
|
||||
|
@ -43,7 +43,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
|
||||
void close() noexcept;
|
||||
};
|
||||
std::size_t m_selectedPaletteIdx = 0;
|
||||
turbine::Context *m_ctx = nullptr;
|
||||
turbine::Context &m_ctx;
|
||||
ox::Vector<ox::String> m_paletteList;
|
||||
SubSheetEditor m_subsheetEditor;
|
||||
ox::String m_itemPath;
|
||||
@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
|
||||
Tool m_tool = Tool::Draw;
|
||||
|
||||
public:
|
||||
TileSheetEditorImGui(turbine::Context *ctx, ox::String path);
|
||||
TileSheetEditorImGui(turbine::Context &ctx, ox::String path);
|
||||
|
||||
~TileSheetEditorImGui() override = default;
|
||||
|
||||
|
@ -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_path(path) {
|
||||
oxRequireT(img, readObj<TileSheet>(ctx->keelCtx, m_path));
|
||||
oxRequireT(img, readObj<TileSheet>(m_ctx.keelCtx, m_path));
|
||||
m_img = *img;
|
||||
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_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 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));
|
||||
}
|
||||
|
||||
@ -609,11 +609,11 @@ void TileSheetEditorModel::copy() {
|
||||
cb->addPixel(pt, c);
|
||||
}
|
||||
}
|
||||
turbine::setClipboardObject(*m_ctx, std::move(cb));
|
||||
turbine::setClipboardObject(m_ctx, std::move(cb));
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::paste() {
|
||||
auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(*m_ctx);
|
||||
auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(m_ctx);
|
||||
if (err) {
|
||||
oxLogError(err);
|
||||
oxErrf("Could not read clipboard: {}", toStr(err));
|
||||
@ -633,7 +633,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||
constexpr ox::StringView uuidPrefix = "uuid://";
|
||||
if (ox::beginsWith(path, uuidPrefix)) {
|
||||
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) {
|
||||
return {};
|
||||
}
|
||||
@ -644,7 +644,7 @@ ox::StringView TileSheetEditorModel::palPath() const 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()));
|
||||
return {};
|
||||
}
|
||||
@ -752,7 +752,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(const studio::UndoCommand *cmd)
|
||||
m_updated = true;
|
||||
const auto cmdId = cmd->commandId();
|
||||
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 idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx());
|
||||
@ -772,7 +772,7 @@ void TileSheetEditorModel::ackUpdate() 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);
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,14 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
studio::UndoStack m_undoStack;
|
||||
class DrawCommand *m_ongoingDrawCommand = nullptr;
|
||||
bool m_updated = false;
|
||||
turbine::Context *m_ctx = nullptr;
|
||||
turbine::Context &m_ctx;
|
||||
ox::String m_path;
|
||||
bool m_selectionOngoing = false;
|
||||
ox::Point m_selectionOrigin = {-1, -1};
|
||||
ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}};
|
||||
|
||||
public:
|
||||
TileSheetEditorModel(turbine::Context *ctx, ox::StringView path);
|
||||
TileSheetEditorModel(turbine::Context &ctx, ox::StringView path);
|
||||
|
||||
~TileSheetEditorModel() override = default;
|
||||
|
||||
|
@ -11,8 +11,9 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
TileSheetEditorView::TileSheetEditorView(turbine::Context *ctx, ox::StringView path):
|
||||
m_model(ctx, path), m_pixelsDrawer(&m_model) {
|
||||
TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path):
|
||||
m_model(ctx, path),
|
||||
m_pixelsDrawer(&m_model) {
|
||||
// build shaders
|
||||
oxThrowError(m_pixelsDrawer.buildShader());
|
||||
oxThrowError(m_pixelGridDrawer.buildShader());
|
||||
|
@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler {
|
||||
std::size_t m_palIdx = 0;
|
||||
|
||||
public:
|
||||
TileSheetEditorView(turbine::Context *ctx, ox::StringView path);
|
||||
TileSheetEditorView(turbine::Context &ctx, ox::StringView path);
|
||||
|
||||
~TileSheetEditorView() override = default;
|
||||
|
||||
|
@ -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(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[0]));
|
||||
|
@ -10,11 +10,11 @@
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::String path):
|
||||
SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::StringView path):
|
||||
m_ctx(ctx),
|
||||
m_itemPath(std::move(path)),
|
||||
m_editor(&m_ctx, m_itemPath),
|
||||
m_view(&m_ctx, m_editor.scene()) {
|
||||
m_editor(m_ctx, m_itemPath),
|
||||
m_view(m_ctx, m_editor.scene()) {
|
||||
const auto lastSlash = std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
|
||||
m_itemName = m_itemPath.substr(lastSlash + 1);
|
||||
setRequiresConstantRefresh(false);
|
||||
|
@ -23,7 +23,7 @@ class SceneEditorImGui: public studio::Editor {
|
||||
SceneEditorView m_view;
|
||||
|
||||
public:
|
||||
SceneEditorImGui(turbine::Context &ctx, ox::String path);
|
||||
SceneEditorImGui(turbine::Context &ctx, ox::StringView path);
|
||||
|
||||
/**
|
||||
* Returns the name of item being edited.
|
||||
|
@ -8,10 +8,9 @@
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
SceneEditor::SceneEditor(turbine::Context *ctx, ox::CRStringView path) {
|
||||
m_ctx = ctx;
|
||||
oxRequireT(scn, keel::readObj<SceneStatic>(m_ctx->keelCtx, path));
|
||||
m_scene = *scn;
|
||||
SceneEditor::SceneEditor(turbine::Context &ctx, ox::CRStringView path):
|
||||
m_ctx(ctx),
|
||||
m_scene(*keel::readObj<SceneStatic>(m_ctx.keelCtx, path).unwrapThrow()) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,15 +13,16 @@ namespace nostalgia::scene {
|
||||
class SceneEditor {
|
||||
|
||||
private:
|
||||
turbine::Context *m_ctx = nullptr;
|
||||
turbine::Context &m_ctx;
|
||||
ox::String m_itemName;
|
||||
ox::String m_itemPath;
|
||||
SceneStatic m_scene;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,10 @@
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
SceneEditorView::SceneEditorView(turbine::Context *tctx, const SceneStatic &sceneStatic):
|
||||
SceneEditorView::SceneEditorView(turbine::Context &tctx, SceneStatic const&sceneStatic):
|
||||
m_sceneStatic(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 {
|
||||
@ -23,10 +23,10 @@ void SceneEditorView::draw(int width, int height) noexcept {
|
||||
glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -15,19 +15,19 @@ class SceneEditorView {
|
||||
|
||||
private:
|
||||
ox::UPtr<core::Context> m_cctx;
|
||||
const SceneStatic &m_sceneStatic;
|
||||
SceneStatic const&m_sceneStatic;
|
||||
Scene m_scene;
|
||||
glutils::FrameBuffer m_frameBuffer;
|
||||
|
||||
public:
|
||||
SceneEditorView(turbine::Context *ctx, const SceneStatic &sceneStatic);
|
||||
SceneEditorView(turbine::Context &ctx, SceneStatic const&sceneStatic);
|
||||
|
||||
ox::Error setupScene() noexcept;
|
||||
|
||||
void draw(int width, int height) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
const glutils::FrameBuffer &framebuffer() const noexcept;
|
||||
glutils::FrameBuffer const&framebuffer() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
@ -10,22 +10,17 @@ namespace nostalgia::scene {
|
||||
|
||||
class StudioModule: public studio::Module {
|
||||
public:
|
||||
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<studio::EditorMaker> editors(turbine::Context &ctx) 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 {
|
||||
{
|
||||
{ox::String("nscn")},
|
||||
[ctx](ox::CRStringView path) -> ox::Result<studio::BaseEditor*> {
|
||||
return ox::makeCatch<SceneEditorImGui>(*ctx, ox::String(path));
|
||||
}
|
||||
},
|
||||
studio::editorMaker<SceneEditorImGui>(ctx, "nscn"),
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
return out;
|
||||
}
|
||||
|
@ -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 {};
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
@ -260,10 +260,10 @@ void StudioUI::loadEditorMaker(const studio::EditorMaker &editorMaker) 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);
|
||||
}
|
||||
for (auto &im : mod->itemMakers(m_ctx)) {
|
||||
for (auto &im : mod->itemMakers(*m_ctx)) {
|
||||
m_newMenu.addItemMaker(std::move(im));
|
||||
}
|
||||
}
|
||||
|
@ -27,18 +27,18 @@ class Module {
|
||||
public:
|
||||
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>
|
||||
[[nodiscard]]
|
||||
studio::EditorMaker editorMaker(turbine::Context *ctx, ox::CRStringView ext) noexcept {
|
||||
studio::EditorMaker editorMaker(turbine::Context &ctx, ox::CRStringView ext) noexcept {
|
||||
return {
|
||||
{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));
|
||||
}
|
||||
};
|
||||
|
@ -6,11 +6,11 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
ox::Vector<EditorMaker> Module::editors(turbine::Context*) const {
|
||||
ox::Vector<EditorMaker> Module::editors(turbine::Context&) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UniquePtr<ItemMaker>> Module::itemMakers(turbine::Context*) const {
|
||||
ox::Vector<ox::UPtr<ItemMaker>> Module::itemMakers(turbine::Context&) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user