[jasper] Fixes for Studio changes, make EditWorldSizeCommand merge
All checks were successful
Build / build (push) Successful in 3m13s
All checks were successful
Build / build (push) Successful in 3m13s
This commit is contained in:
parent
3c593b8d58
commit
f920748e19
@ -7,24 +7,60 @@
|
|||||||
|
|
||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
EditWorldSize::EditWorldSize(WorldDoc &doc, ox::Size const&size):
|
EditWorldSizeCommand::EditWorldSizeCommand(
|
||||||
|
ObjectCache const&objCache,
|
||||||
|
WorldDoc &doc,
|
||||||
|
WorldStatic &worldStatic,
|
||||||
|
ox::Size const&size):
|
||||||
|
m_objCache(objCache),
|
||||||
m_doc(doc),
|
m_doc(doc),
|
||||||
|
m_worldStatic(worldStatic),
|
||||||
m_oldSize(m_doc.columns, m_doc.rows),
|
m_oldSize(m_doc.columns, m_doc.rows),
|
||||||
m_newVal(size) {
|
m_newSize(size) {}
|
||||||
}
|
|
||||||
|
|
||||||
void EditWorldSize::redo() noexcept {
|
void EditWorldSizeCommand::redo() noexcept {
|
||||||
m_oldMap = m_doc.tiles;
|
m_oldMap = m_doc.tiles;
|
||||||
resize(m_doc, m_newVal);
|
resize(m_doc, m_newSize);
|
||||||
|
oxLogError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditWorldSize::undo() noexcept {
|
void EditWorldSizeCommand::undo() noexcept {
|
||||||
resize(m_doc, m_oldSize);
|
resize(m_doc, m_oldSize);
|
||||||
m_doc.tiles = std::move(m_oldMap);
|
m_doc.tiles = std::move(m_oldMap);
|
||||||
|
oxLogError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic));
|
||||||
}
|
}
|
||||||
|
|
||||||
int EditWorldSize::commandId() const noexcept {
|
bool EditWorldSizeCommand::mergeWith(studio::UndoCommand const&cmd) noexcept {
|
||||||
|
auto const es = dynamic_cast<EditWorldSizeCommand const*>(&cmd);
|
||||||
|
if (!es || dimensionChanged() != es->dimensionChanged()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_newSize = es->m_newSize;
|
||||||
|
// undo
|
||||||
|
resize(m_doc, m_oldSize);
|
||||||
|
m_doc.tiles = std::move(m_oldMap);
|
||||||
|
// redo
|
||||||
|
m_oldMap = m_doc.tiles;
|
||||||
|
resize(m_doc, m_newSize);
|
||||||
|
oxLogError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EditWorldSizeCommand::commandId() const noexcept {
|
||||||
return static_cast<int>(WorldEditorCommand::EditWorldSize);
|
return static_cast<int>(WorldEditorCommand::EditWorldSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditWorldSizeCommand::Dimension EditWorldSizeCommand::dimensionChanged() const noexcept {
|
||||||
|
auto const xChanged = m_oldSize.width == m_newSize.width;
|
||||||
|
auto const yChanged = m_oldSize.height == m_newSize.height;
|
||||||
|
if (xChanged && !yChanged) {
|
||||||
|
return Dimension::X;
|
||||||
|
} else if (!xChanged && yChanged) {
|
||||||
|
return Dimension::Y;
|
||||||
|
} else if (xChanged && yChanged) {
|
||||||
|
return Dimension::Both;
|
||||||
|
}
|
||||||
|
return Dimension::Neither;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,23 +12,36 @@
|
|||||||
|
|
||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
class EditWorldSize: public studio::UndoCommand {
|
class EditWorldSizeCommand: public studio::UndoCommand {
|
||||||
private:
|
private:
|
||||||
|
ObjectCache const&m_objCache;
|
||||||
WorldDoc &m_doc;
|
WorldDoc &m_doc;
|
||||||
|
WorldStatic &m_worldStatic;
|
||||||
size_t m_insertIdx{};
|
size_t m_insertIdx{};
|
||||||
ox::Size const m_oldSize;
|
ox::Size const m_oldSize;
|
||||||
WorldDoc::TileMap m_oldMap;
|
WorldDoc::TileMap m_oldMap;
|
||||||
ox::Size const m_newVal;
|
ox::Size m_newSize;
|
||||||
public:
|
public:
|
||||||
EditWorldSize(WorldDoc &doc, ox::Size const&size);
|
EditWorldSizeCommand(
|
||||||
|
ObjectCache const&objCache,
|
||||||
|
WorldDoc &doc,
|
||||||
|
WorldStatic &worldStatic,
|
||||||
|
ox::Size const&size);
|
||||||
void redo() noexcept override;
|
void redo() noexcept override;
|
||||||
void undo() noexcept override;
|
void undo() noexcept override;
|
||||||
|
bool mergeWith(studio::UndoCommand const&cmd) noexcept override;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept override;
|
int commandId() const noexcept override;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline size_t insertIdx() const noexcept {
|
inline size_t insertIdx() const noexcept {
|
||||||
return m_insertIdx;
|
return m_insertIdx;
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
enum class Dimension {
|
||||||
|
X, Y, Both, Neither,
|
||||||
|
};
|
||||||
|
[[nodiscard]]
|
||||||
|
Dimension dimensionChanged() const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ static ox::Vec2 dropPos(ox::Vec2 dropPos) noexcept {
|
|||||||
return dropPos;
|
return dropPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Point fbPtToTileAddr(
|
constexpr ox::Point fbPtToTileAddr(
|
||||||
ox::Vec2 const&fbPt,
|
ox::Vec2 const&fbPt,
|
||||||
ox::Vec2 const&mapSz) noexcept {
|
ox::Vec2 const&mapSz) noexcept {
|
||||||
@ -159,10 +159,10 @@ void WorldEditorImGui::drawPropEditor() noexcept {
|
|||||||
int width{m_doc.columns};
|
int width{m_doc.columns};
|
||||||
int height{m_doc.rows};
|
int height{m_doc.rows};
|
||||||
if (ImGui::InputInt("Map Width", &width, 1)) {
|
if (ImGui::InputInt("Map Width", &width, 1)) {
|
||||||
pushCommand<EditWorldSize>(m_doc, ox::Size{width, m_doc.rows});
|
pushCommand<EditWorldSizeCommand>(m_objCache, m_doc, m_worldStatic, ox::Size{width, m_doc.rows});
|
||||||
}
|
}
|
||||||
if (ImGui::InputInt("Map Height", &height, 1)) {
|
if (ImGui::InputInt("Map Height", &height, 1)) {
|
||||||
pushCommand<EditWorldSize>(m_doc, ox::Size{m_doc.columns, height});
|
pushCommand<EditWorldSizeCommand>(m_objCache, m_doc, m_worldStatic, ox::Size{m_doc.columns, height});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ int EditObjectName::commandId() const noexcept {
|
|||||||
return static_cast<int>(WorldObjCommand::EditObjectName);
|
return static_cast<int>(WorldObjCommand::EditObjectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditObjectName::mergeWith(UndoCommand const*cmd) noexcept {
|
bool EditObjectName::mergeWith(UndoCommand const&cmd) noexcept {
|
||||||
auto const en = dynamic_cast<EditObjectName const*>(cmd);
|
auto const en = dynamic_cast<EditObjectName const*>(&cmd);
|
||||||
if (en && m_objIdx == en->m_objIdx) {
|
if (en && m_objIdx == en->m_objIdx) {
|
||||||
m_newVal = en->m_newVal;
|
m_newVal = en->m_newVal;
|
||||||
return true;
|
return true;
|
||||||
|
@ -24,7 +24,7 @@ class EditObjectName: public studio::UndoCommand {
|
|||||||
void undo() noexcept override;
|
void undo() noexcept override;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept override;
|
int commandId() const noexcept override;
|
||||||
bool mergeWith(UndoCommand const*cmd) noexcept override;
|
bool mergeWith(UndoCommand const&cmd) noexcept override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EditObjectSubSheet: public studio::UndoCommand {
|
class EditObjectSubSheet: public studio::UndoCommand {
|
||||||
|
@ -33,6 +33,7 @@ void World::setupLayer(
|
|||||||
ncore::Context &ctx,
|
ncore::Context &ctx,
|
||||||
uint_t lyr,
|
uint_t lyr,
|
||||||
uint_t cbb) const noexcept {
|
uint_t cbb) const noexcept {
|
||||||
|
ncore::clearBg(ctx, lyr);
|
||||||
ncore::setBgStatus(ctx, lyr, true);
|
ncore::setBgStatus(ctx, lyr, true);
|
||||||
ncore::setBgCbb(ctx, lyr, cbb);
|
ncore::setBgCbb(ctx, lyr, cbb);
|
||||||
auto const rows = ox::min<int>(m_worldStatic.rows, ncore::tileRows(ctx) / 2);
|
auto const rows = ox::min<int>(m_worldStatic.rows, ncore::tileRows(ctx) / 2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user