[jasper/world] Update coding style
All checks were successful
Build / build (push) Successful in 1m47s
All checks were successful
Build / build (push) Successful in 1m47s
This commit is contained in:
@ -20,13 +20,13 @@ class World {
|
|||||||
turbine::TimeMs nextUpdateTime{};
|
turbine::TimeMs nextUpdateTime{};
|
||||||
};
|
};
|
||||||
ngfx::Context &m_nctx;
|
ngfx::Context &m_nctx;
|
||||||
WorldStatic const&m_worldStatic;
|
WorldStatic const &m_worldStatic;
|
||||||
ox::Vector<keel::AssetRef<ngfx::CompactTileSheet>, 32> m_tilesheets;
|
ox::Vector<keel::AssetRef<ngfx::CompactTileSheet>, 32> m_tilesheets;
|
||||||
ox::Vector<ObjState, 128> m_objStates;
|
ox::Vector<ObjState, 128> m_objStates;
|
||||||
turbine::TimeMs m_currentTicks{};
|
turbine::TimeMs m_currentTicks{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit World(ngfx::Context &nctx, WorldStatic const&worldStatic) noexcept;
|
explicit World(ngfx::Context &nctx, WorldStatic const &worldStatic) noexcept;
|
||||||
|
|
||||||
ox::Error setupDisplay() noexcept;
|
ox::Error setupDisplay() noexcept;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ struct DocObjRef {
|
|||||||
bool unique{};
|
bool unique{};
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr bool operator==(DocObjRef const&a, DocObjRef const&b) noexcept {
|
constexpr bool operator==(DocObjRef const &a, DocObjRef const &b) noexcept {
|
||||||
return a.worldObjectSetId == b.worldObjectSetId
|
return a.worldObjectSetId == b.worldObjectSetId
|
||||||
&& a.worldObjectId == b.worldObjectId
|
&& a.worldObjectId == b.worldObjectId
|
||||||
&& a.unique == b.unique;
|
&& a.unique == b.unique;
|
||||||
@ -97,9 +97,9 @@ struct WorldDoc {
|
|||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Result<ox::String> objectSetPath(
|
constexpr ox::Result<ox::String> objectSetPath(
|
||||||
WorldDoc const&wd, uint64_t setId) noexcept {
|
WorldDoc const &wd, uint64_t setId) noexcept {
|
||||||
auto const obj = ox::find_if(wd.objSets.begin(), wd.objSets.end(),
|
auto const obj = ox::find_if(wd.objSets.begin(), wd.objSets.end(),
|
||||||
[setId](ObjectSetEntry const&e) {
|
[setId](ObjectSetEntry const &e) {
|
||||||
return e.id == setId;
|
return e.id == setId;
|
||||||
});
|
});
|
||||||
OX_RETURN_ERROR(ox::Error(obj == wd.objSets.end(), "Obj set not found"));
|
OX_RETURN_ERROR(ox::Error(obj == wd.objSets.end(), "Obj set not found"));
|
||||||
@ -108,9 +108,9 @@ constexpr ox::Result<ox::String> objectSetPath(
|
|||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Result<uint64_t> objectSetId(
|
constexpr ox::Result<uint64_t> objectSetId(
|
||||||
WorldDoc const&wd, ox::StringViewCR setPath) noexcept {
|
WorldDoc const &wd, ox::StringViewCR setPath) noexcept {
|
||||||
auto const obj = ox::find_if(wd.objSets.begin(), wd.objSets.end(),
|
auto const obj = ox::find_if(wd.objSets.begin(), wd.objSets.end(),
|
||||||
[setPath](ObjectSetEntry const&e) {
|
[setPath](ObjectSetEntry const &e) {
|
||||||
return e.path == setPath;
|
return e.path == setPath;
|
||||||
});
|
});
|
||||||
OX_RETURN_ERROR(ox::Error(obj == wd.objSets.end(), "Obj set not found"));
|
OX_RETURN_ERROR(ox::Error(obj == wd.objSets.end(), "Obj set not found"));
|
||||||
@ -126,7 +126,7 @@ OX_MODEL_BEGIN(WorldDoc)
|
|||||||
OX_MODEL_END()
|
OX_MODEL_END()
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool valid(WorldDoc const&doc) noexcept {
|
constexpr bool valid(WorldDoc const &doc) noexcept {
|
||||||
for (auto &lyr : doc.tiles) {
|
for (auto &lyr : doc.tiles) {
|
||||||
if (lyr.size() < static_cast<size_t>(doc.rows)) {
|
if (lyr.size() < static_cast<size_t>(doc.rows)) {
|
||||||
return false;
|
return false;
|
||||||
@ -157,14 +157,14 @@ auto &tile(
|
|||||||
return doc.tiles[lyr][static_cast<size_t>(row)][static_cast<size_t>(col)];
|
return doc.tiles[lyr][static_cast<size_t>(row)][static_cast<size_t>(col)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(WorldDoc &doc, ox::Size const&sz) noexcept;
|
void resize(WorldDoc &doc, ox::Size const &sz) noexcept;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ox::hash<jasper::world::DocObjRef> {
|
struct ox::hash<jasper::world::DocObjRef> {
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr size_t operator()(jasper::world::DocObjRef const&v) const noexcept {
|
constexpr size_t operator()(jasper::world::DocObjRef const &v) const noexcept {
|
||||||
return static_cast<uint32_t>(v.worldObjectSetId)
|
return static_cast<uint32_t>(v.worldObjectSetId)
|
||||||
| (static_cast<uint32_t>(v.worldObjectId) << 15)
|
| (static_cast<uint32_t>(v.worldObjectId) << 15)
|
||||||
| (static_cast<uint32_t>(v.unique) << 31);
|
| (static_cast<uint32_t>(v.unique) << 31);
|
||||||
|
@ -102,7 +102,7 @@ OX_MODEL_BEGIN(ObjTileRefSet)
|
|||||||
OX_MODEL_END()
|
OX_MODEL_END()
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool operator==(ObjTileRefSet const&a, ObjTileRefSet const&b) noexcept {
|
constexpr bool operator==(ObjTileRefSet const &a, ObjTileRefSet const &b) noexcept {
|
||||||
return
|
return
|
||||||
a.tilesheetIdx == b.tilesheetIdx &&
|
a.tilesheetIdx == b.tilesheetIdx &&
|
||||||
a.cbbIdx == b.cbbIdx &&
|
a.cbbIdx == b.cbbIdx &&
|
||||||
@ -138,17 +138,17 @@ OX_MODEL_BEGIN(WorldStatic)
|
|||||||
OX_MODEL_END()
|
OX_MODEL_END()
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool valid(WorldStatic const&ws) noexcept {
|
constexpr bool valid(WorldStatic const &ws) noexcept {
|
||||||
auto const tileCnt = static_cast<size_t>(ws.columns * ws.rows);
|
auto const tileCnt = static_cast<size_t>(ws.columns * ws.rows);
|
||||||
return
|
return
|
||||||
!ws.objTileRefSets.empty() &&
|
!ws.objTileRefSets.empty() &&
|
||||||
ox::all_of(ws.map.begin(), ws.map.end(), [tileCnt](BgLayer const&v) {
|
ox::all_of(ws.map.begin(), ws.map.end(), [tileCnt](BgLayer const &v) {
|
||||||
return v.tiles.size() == tileCnt;
|
return v.tiles.size() == tileCnt;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr size_t layers(WorldStatic const&ws) noexcept {
|
constexpr size_t layers(WorldStatic const &ws) noexcept {
|
||||||
return ws.map.size();
|
return ws.map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ class WorldStaticLoader {
|
|||||||
private:
|
private:
|
||||||
keel::Context &m_kctx;
|
keel::Context &m_kctx;
|
||||||
WorldStatic &m_worldStatic;
|
WorldStatic &m_worldStatic;
|
||||||
WorldDoc const&m_doc;
|
WorldDoc const &m_doc;
|
||||||
struct CacheEntry {
|
struct CacheEntry {
|
||||||
uint8_t value{};
|
uint8_t value{};
|
||||||
int refCnt{};
|
int refCnt{};
|
||||||
@ -187,7 +187,7 @@ class WorldStaticLoader {
|
|||||||
bool m_loaded{};
|
bool m_loaded{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WorldStaticLoader(keel::Context &kctx, WorldStatic &worldStatic, WorldDoc const&doc);
|
WorldStaticLoader(keel::Context &kctx, WorldStatic &worldStatic, WorldDoc const &doc);
|
||||||
|
|
||||||
ox::Error loadWorldStatic() noexcept;
|
ox::Error loadWorldStatic() noexcept;
|
||||||
|
|
||||||
@ -195,18 +195,18 @@ class WorldStaticLoader {
|
|||||||
uint32_t layer,
|
uint32_t layer,
|
||||||
uint32_t col,
|
uint32_t col,
|
||||||
uint32_t row,
|
uint32_t row,
|
||||||
TileDoc const&oldSrc) noexcept;
|
TileDoc const &oldSrc) noexcept;
|
||||||
|
|
||||||
void loadTile(
|
void loadTile(
|
||||||
TileStatic &dst,
|
TileStatic &dst,
|
||||||
TileDoc const&src) noexcept;
|
TileDoc const &src) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
ox::Result<uint8_t> setupTileResrc(DocObjRef const&docObjRef) noexcept;
|
ox::Result<uint8_t> setupTileResrc(DocObjRef const &docObjRef) noexcept;
|
||||||
|
|
||||||
void deleteRefSet(uint8_t refIdx, DocObjRef const&oldObjRef) noexcept;
|
void deleteRefSet(uint8_t refIdx, DocObjRef const &oldObjRef) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ MapTileHighlighter::MapTileHighlighter() {
|
|||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error MapTileHighlighter::setup(ox::Size const&sz) noexcept {
|
ox::Error MapTileHighlighter::setup(ox::Size const &sz) noexcept {
|
||||||
m_subsheetTilesWidth = sz.width;
|
m_subsheetTilesWidth = sz.width;
|
||||||
m_subsheetTilesHeight = sz.height;
|
m_subsheetTilesHeight = sz.height;
|
||||||
initGlBuffers();
|
initGlBuffers();
|
||||||
@ -67,7 +67,7 @@ void MapTileHighlighter::draw() noexcept {
|
|||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error MapTileHighlighter::setTileHighlight(ox::Point const&addr, bool const hl) noexcept {
|
ox::Error MapTileHighlighter::setTileHighlight(ox::Point const &addr, bool const hl) noexcept {
|
||||||
if (addr.x >= m_subsheetTilesWidth || addr.y >= m_subsheetTilesHeight) {
|
if (addr.x >= m_subsheetTilesWidth || addr.y >= m_subsheetTilesHeight) {
|
||||||
return ox::Error(1, "tile addr out of bounds");
|
return ox::Error(1, "tile addr out of bounds");
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ class MapTileHighlighter {
|
|||||||
public:
|
public:
|
||||||
MapTileHighlighter();
|
MapTileHighlighter();
|
||||||
|
|
||||||
ox::Error setup(ox::Size const&sz) noexcept;
|
ox::Error setup(ox::Size const &sz) noexcept;
|
||||||
|
|
||||||
void draw() noexcept;
|
void draw() noexcept;
|
||||||
|
|
||||||
ox::Error setTileHighlight(ox::Point const&addr, bool hl) noexcept;
|
ox::Error setTileHighlight(ox::Point const &addr, bool hl) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static int scale() noexcept;
|
static int scale() noexcept;
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
AddObjectSet::AddObjectSet(WorldDoc &doc, ox::UUID const&objSetUuid):
|
AddObjectSet::AddObjectSet(WorldDoc &doc, ox::UUID const &objSetUuid):
|
||||||
m_doc(doc),
|
m_doc(doc),
|
||||||
m_path(ox::sfmt("uuid://{}", objSetUuid.toString())) {
|
m_path(ox::sfmt("uuid://{}", objSetUuid.toString())) {
|
||||||
for (auto const&o : m_doc.objSets) {
|
for (auto const &o : m_doc.objSets) {
|
||||||
if (o.path > m_path) {
|
if (o.path > m_path) {
|
||||||
break;
|
break;
|
||||||
} else if (o.path == m_path) {
|
} else if (o.path == m_path) {
|
||||||
|
@ -18,7 +18,7 @@ class AddObjectSet: public studio::UndoCommand {
|
|||||||
size_t m_insertIdx{};
|
size_t m_insertIdx{};
|
||||||
ox::String m_path;
|
ox::String m_path;
|
||||||
public:
|
public:
|
||||||
AddObjectSet(WorldDoc &doc, ox::UUID const&objSetUuid);
|
AddObjectSet(WorldDoc &doc, ox::UUID const &objSetUuid);
|
||||||
ox::Error redo() noexcept override;
|
ox::Error redo() noexcept override;
|
||||||
ox::Error undo() noexcept override;
|
ox::Error undo() noexcept override;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
@ -10,7 +10,7 @@ namespace jasper::world {
|
|||||||
EditWorldSizeCommand::EditWorldSizeCommand(
|
EditWorldSizeCommand::EditWorldSizeCommand(
|
||||||
WorldStaticLoader &loader,
|
WorldStaticLoader &loader,
|
||||||
WorldDoc &doc,
|
WorldDoc &doc,
|
||||||
ox::Size const&size):
|
ox::Size const &size):
|
||||||
m_loader{loader},
|
m_loader{loader},
|
||||||
m_doc{doc},
|
m_doc{doc},
|
||||||
m_oldSize{m_doc.columns, m_doc.rows},
|
m_oldSize{m_doc.columns, m_doc.rows},
|
||||||
|
@ -21,7 +21,7 @@ class EditWorldSizeCommand: public studio::UndoCommand {
|
|||||||
EditWorldSizeCommand(
|
EditWorldSizeCommand(
|
||||||
WorldStaticLoader &loader,
|
WorldStaticLoader &loader,
|
||||||
WorldDoc &doc,
|
WorldDoc &doc,
|
||||||
ox::Size const&size);
|
ox::Size const &size);
|
||||||
ox::Error redo() noexcept override;
|
ox::Error redo() noexcept override;
|
||||||
ox::Error undo() noexcept override;
|
ox::Error undo() noexcept override;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
@ -16,8 +16,8 @@ ModifyTilesCommand::ModifyTilesCommand(
|
|||||||
m_loader{loader},
|
m_loader{loader},
|
||||||
m_doc{doc},
|
m_doc{doc},
|
||||||
m_mods{std::move(mods)} {
|
m_mods{std::move(mods)} {
|
||||||
auto const unchanged = [this](Mod const&mod) {
|
auto const unchanged = [this](Mod const &mod) {
|
||||||
auto const&docTile = tile(m_doc, mod.layer, mod.tileAddr.x, mod.tileAddr.y);
|
auto const &docTile = tile(m_doc, mod.layer, mod.tileAddr.x, mod.tileAddr.y);
|
||||||
return docTile.obj.worldObjectId == mod.objId && docTile.obj.worldObjectSetId == mod.setId;
|
return docTile.obj.worldObjectId == mod.objId && docTile.obj.worldObjectSetId == mod.setId;
|
||||||
};
|
};
|
||||||
if (ox::all_of(m_mods.begin(), m_mods.end(), unchanged)) {
|
if (ox::all_of(m_mods.begin(), m_mods.end(), unchanged)) {
|
||||||
|
@ -18,7 +18,7 @@ void ObjectExplorerModel::draw(turbine::Context &ctx) const noexcept {
|
|||||||
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||||
if (!m_children.empty()) {
|
if (!m_children.empty()) {
|
||||||
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
||||||
for (auto const&child : m_children) {
|
for (auto const &child : m_children) {
|
||||||
child->draw(ctx);
|
child->draw(ctx);
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
TileClipboard::TileClipboard(ox::UUID assetId, ox::Size selSz) noexcept:
|
TileClipboard::TileClipboard(ox::UUID const &assetId, ox::Size selSz) noexcept:
|
||||||
m_assetId(assetId), m_selSz(selSz) {
|
m_assetId(assetId), m_selSz(selSz) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ ox::Size TileClipboard::selectionSize() const noexcept {
|
|||||||
return m_selSz;
|
return m_selSz;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileClipboard::addTile(const ModifyTilesCommand::Mod&mod) noexcept {
|
void TileClipboard::addTile(ModifyTilesCommand::Mod const &mod) noexcept {
|
||||||
m_tileMods.emplace_back(mod);
|
m_tileMods.emplace_back(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,17 +21,17 @@ class TileClipboard : public turbine::ClipboardObject<TileClipboard> {
|
|||||||
ox::Vector<ModifyTilesCommand::Mod> m_tileMods;
|
ox::Vector<ModifyTilesCommand::Mod> m_tileMods;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TileClipboard(ox::UUID assetId, ox::Size selSz) noexcept;
|
TileClipboard(ox::UUID const &assetId, ox::Size selSz) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::Size selectionSize() const noexcept;
|
ox::Size selectionSize() const noexcept;
|
||||||
|
|
||||||
void addTile(ModifyTilesCommand::Mod const&mod) noexcept;
|
void addTile(ModifyTilesCommand::Mod const &mod) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::SpanView<ModifyTilesCommand::Mod> tiles() const noexcept;
|
ox::SpanView<ModifyTilesCommand::Mod> tiles() const noexcept;
|
||||||
|
|
||||||
constexpr ox::UUID const&assetId() const noexcept {
|
constexpr ox::UUID const &assetId() const noexcept {
|
||||||
return m_assetId;
|
return m_assetId;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -59,8 +59,8 @@ static ox::Vec2 fbPos(ox::Vec2 fbPos) noexcept {
|
|||||||
|
|
||||||
[[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 {
|
||||||
constexpr auto ColumnsOnScrn = 15;
|
constexpr auto ColumnsOnScrn = 15;
|
||||||
constexpr auto RowsOnScrn = 10;
|
constexpr auto RowsOnScrn = 10;
|
||||||
auto const fbX = static_cast<float>(fbPt.x);
|
auto const fbX = static_cast<float>(fbPt.x);
|
||||||
@ -86,7 +86,7 @@ WorldEditorImGui::WorldEditorImGui(studio::Context &sctx, ox::StringParam path):
|
|||||||
m_loader.tileUpdated.connect(&m_view, &WorldEditorView::setupTile);
|
m_loader.tileUpdated.connect(&m_view, &WorldEditorView::setupTile);
|
||||||
oxLogError(studio::headerizeConfigFile<WorldEditorConfig>(keelCtx(m_sctx), itemPath()));
|
oxLogError(studio::headerizeConfigFile<WorldEditorConfig>(keelCtx(m_sctx), itemPath()));
|
||||||
studio::openConfig<WorldEditorConfig>(
|
studio::openConfig<WorldEditorConfig>(
|
||||||
keelCtx(m_sctx), itemPath(), [this](WorldEditorConfig const&config) {
|
keelCtx(m_sctx), itemPath(), [this](WorldEditorConfig const &config) {
|
||||||
m_view.setAnimate(config.animateBg);
|
m_view.setAnimate(config.animateBg);
|
||||||
});
|
});
|
||||||
undoStack()->changeTriggered.connect(this, &WorldEditorImGui::handleUndoStackChange);
|
undoStack()->changeTriggered.connect(this, &WorldEditorImGui::handleUndoStackChange);
|
||||||
@ -162,7 +162,7 @@ void WorldEditorImGui::paste() {
|
|||||||
sel.b.y = ox::min(sel.a.y + selSz.height, m_doc.rows - 1);
|
sel.b.y = ox::min(sel.a.y + selSz.height, m_doc.rows - 1);
|
||||||
m_view.setSelection(sel);
|
m_view.setSelection(sel);
|
||||||
ox::Vector<ModifyTilesCommand::Mod> mods;
|
ox::Vector<ModifyTilesCommand::Mod> mods;
|
||||||
for (auto const&m : cb->tiles()) {
|
for (auto const &m : cb->tiles()) {
|
||||||
mods.emplace_back(ModifyTilesCommand::Mod{
|
mods.emplace_back(ModifyTilesCommand::Mod{
|
||||||
.layer = m_activeLayer,
|
.layer = m_activeLayer,
|
||||||
.tileAddr = m.tileAddr + sel.a,
|
.tileAddr = m.tileAddr + sel.a,
|
||||||
@ -202,7 +202,7 @@ void WorldEditorImGui::drawObjSelector() noexcept {
|
|||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
ImGui::BeginChild("ObjTree");
|
ImGui::BeginChild("ObjTree");
|
||||||
{
|
{
|
||||||
for (auto const&[uuidUrl, setId, set] : m_objSets) {
|
for (auto const &[uuidUrl, setId, set] : m_objSets) {
|
||||||
auto flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
auto flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||||
auto [setName, err] = uuidUrlToPath(keelCtx(m_sctx), uuidUrl);
|
auto [setName, err] = uuidUrlToPath(keelCtx(m_sctx), uuidUrl);
|
||||||
auto const uuid = substr(uuidUrl, 7);
|
auto const uuid = substr(uuidUrl, 7);
|
||||||
@ -216,7 +216,7 @@ void WorldEditorImGui::drawObjSelector() noexcept {
|
|||||||
if (ImGui::IsItemClicked()) {
|
if (ImGui::IsItemClicked()) {
|
||||||
m_objMgr.selectedObjSet = uuid;
|
m_objMgr.selectedObjSet = uuid;
|
||||||
}
|
}
|
||||||
for (auto const&obj : set->objects) {
|
for (auto const &obj : set->objects) {
|
||||||
if (ImGui::TreeNodeEx(obj.name.c_str(), ImGuiTreeNodeFlags_Leaf)) {
|
if (ImGui::TreeNodeEx(obj.name.c_str(), ImGuiTreeNodeFlags_Leaf)) {
|
||||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
||||||
studio::navigateTo(m_sctx, setName, obj.name);
|
studio::navigateTo(m_sctx, setName, obj.name);
|
||||||
@ -414,13 +414,13 @@ void WorldEditorImGui::rmObjSet() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error WorldEditorImGui::handleDepUpdate(ox::StringViewCR, ox::UUID const&uuid) noexcept {
|
ox::Error WorldEditorImGui::handleDepUpdate(ox::StringViewCR, ox::UUID const &uuid) noexcept {
|
||||||
auto &kctx = keelCtx(m_sctx);
|
auto &kctx = keelCtx(m_sctx);
|
||||||
auto const objSetMatches = [&uuid, &kctx](ObjectSetEntry const&set) {
|
auto const objSetMatches = [&uuid, &kctx](ObjectSetEntry const &set) {
|
||||||
auto const [setUuid, err] = getUuid(kctx, set.path);
|
auto const [setUuid, err] = getUuid(kctx, set.path);
|
||||||
return !err && setUuid == uuid;
|
return !err && setUuid == uuid;
|
||||||
};
|
};
|
||||||
auto const depMatches = [&uuid](ox::SmallMap<ox::UUID, bool>::Pair const&set) {
|
auto const depMatches = [&uuid](ox::SmallMap<ox::UUID, bool>::Pair const &set) {
|
||||||
return set.key == uuid;
|
return set.key == uuid;
|
||||||
};
|
};
|
||||||
auto const depUpdated = ox::any_of(m_doc.objSets.begin(), m_doc.objSets.end(), objSetMatches)
|
auto const depUpdated = ox::any_of(m_doc.objSets.begin(), m_doc.objSets.end(), objSetMatches)
|
||||||
@ -436,10 +436,10 @@ ox::Error WorldEditorImGui::loadObjectSets() noexcept {
|
|||||||
m_objSets.clear();
|
m_objSets.clear();
|
||||||
m_dependencies.clear();
|
m_dependencies.clear();
|
||||||
auto &kctx = keelCtx(m_sctx);
|
auto &kctx = keelCtx(m_sctx);
|
||||||
for (auto const&set : m_doc.objSets) {
|
for (auto const &set : m_doc.objSets) {
|
||||||
OX_REQUIRE_M(os, readObj<WorldObjectSet>(kctx, set.path));
|
OX_REQUIRE_M(os, readObj<WorldObjectSet>(kctx, set.path));
|
||||||
oxLogError(addDependency(os->tilesheet));
|
oxLogError(addDependency(os->tilesheet));
|
||||||
for (auto const&pal : os->palettes) {
|
for (auto const &pal : os->palettes) {
|
||||||
oxLogError(addDependency(pal));
|
oxLogError(addDependency(pal));
|
||||||
}
|
}
|
||||||
m_objSets.emplace_back(ox::String(set.path), set.id, std::move(os));
|
m_objSets.emplace_back(ox::String(set.path), set.id, std::move(os));
|
||||||
@ -447,7 +447,7 @@ ox::Error WorldEditorImGui::loadObjectSets() noexcept {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WorldEditorImGui::tileSelected(ox::Point const&pt) const noexcept {
|
bool WorldEditorImGui::tileSelected(ox::Point const &pt) const noexcept {
|
||||||
return m_selection && m_selection->contains(pt);
|
return m_selection && m_selection->contains(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,7 +463,7 @@ ox::Result<ox::UUID> WorldEditorImGui::assetId() const noexcept {
|
|||||||
return getUuid(keelCtx(m_sctx), itemPath());
|
return getUuid(keelCtx(m_sctx), itemPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error WorldEditorImGui::addDependency(ox::FileAddress const&fileAddr) noexcept {
|
ox::Error WorldEditorImGui::addDependency(ox::FileAddress const &fileAddr) noexcept {
|
||||||
auto &kctx = keelCtx(m_sctx);
|
auto &kctx = keelCtx(m_sctx);
|
||||||
OX_REQUIRE(uuid, getUuid(kctx, fileAddr));
|
OX_REQUIRE(uuid, getUuid(kctx, fileAddr));
|
||||||
m_dependencies[uuid] = true;
|
m_dependencies[uuid] = true;
|
||||||
|
@ -86,18 +86,18 @@ class WorldEditorImGui: public studio::Editor {
|
|||||||
void rmObjSet() noexcept;
|
void rmObjSet() noexcept;
|
||||||
|
|
||||||
// handles the updating of an object set in case it is one used by this world
|
// handles the updating of an object set in case it is one used by this world
|
||||||
ox::Error handleDepUpdate(ox::StringViewCR path, ox::UUID const&) noexcept;
|
ox::Error handleDepUpdate(ox::StringViewCR path, ox::UUID const &) noexcept;
|
||||||
|
|
||||||
ox::Error loadObjectSets() noexcept;
|
ox::Error loadObjectSets() noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool tileSelected(ox::Point const&pt) const noexcept;
|
bool tileSelected(ox::Point const &pt) const noexcept;
|
||||||
|
|
||||||
void clearSelection() noexcept;
|
void clearSelection() noexcept;
|
||||||
|
|
||||||
ox::Result<ox::UUID> assetId() const noexcept;
|
ox::Result<ox::UUID> assetId() const noexcept;
|
||||||
|
|
||||||
ox::Error addDependency(ox::FileAddress const&fileAddr) noexcept;
|
ox::Error addDependency(ox::FileAddress const &fileAddr) noexcept;
|
||||||
|
|
||||||
ox::Error handleUndoStackChange(studio::UndoCommand const*) noexcept;
|
ox::Error handleUndoStackChange(studio::UndoCommand const*) noexcept;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
WorldEditorView::WorldEditorView(studio::Context &sctx, WorldStatic const&worldStatic):
|
WorldEditorView::WorldEditorView(studio::Context &sctx, WorldStatic const &worldStatic):
|
||||||
m_sctx{sctx},
|
m_sctx{sctx},
|
||||||
m_nctx{ngfx::init(m_sctx.tctx, {.glInstallDrawer = false}).unwrapThrow()},
|
m_nctx{ngfx::init(m_sctx.tctx, {.glInstallDrawer = false}).unwrapThrow()},
|
||||||
m_worldStatic{worldStatic},
|
m_worldStatic{worldStatic},
|
||||||
@ -37,7 +37,7 @@ ox::Error WorldEditorView::setupWorld() noexcept {
|
|||||||
return m_world.setupDisplay();
|
return m_world.setupDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldEditorView::draw(ox::Size const&targetSz) noexcept {
|
void WorldEditorView::draw(ox::Size const &targetSz) noexcept {
|
||||||
auto const scaleSz = targetSz / ngfx::gl::drawSize(1);
|
auto const scaleSz = targetSz / ngfx::gl::drawSize(1);
|
||||||
if (m_scaleSz != scaleSz) [[unlikely]] {
|
if (m_scaleSz != scaleSz) [[unlikely]] {
|
||||||
m_scale = ox::max(1, ox::max(scaleSz.width, scaleSz.height));
|
m_scale = ox::max(1, ox::max(scaleSz.width, scaleSz.height));
|
||||||
@ -63,7 +63,7 @@ void WorldEditorView::clearSelection() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldEditorView::setSelection(studio::Selection const&sel) noexcept {
|
void WorldEditorView::setSelection(studio::Selection const &sel) noexcept {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
m_selection.emplace(sel);
|
m_selection.emplace(sel);
|
||||||
studio::iterateSelection(*m_selection, [this](int32_t x, int32_t y) {
|
studio::iterateSelection(*m_selection, [this](int32_t x, int32_t y) {
|
||||||
@ -71,7 +71,7 @@ void WorldEditorView::setSelection(studio::Selection const&sel) noexcept {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
glutils::FrameBuffer const&WorldEditorView::framebuffer() const noexcept {
|
glutils::FrameBuffer const &WorldEditorView::framebuffer() const noexcept {
|
||||||
return m_frameBuffer;
|
return m_frameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class WorldEditorView: public ox::SignalHandler {
|
|||||||
private:
|
private:
|
||||||
studio::Context &m_sctx;
|
studio::Context &m_sctx;
|
||||||
ox::UPtr<ngfx::Context> m_nctx;
|
ox::UPtr<ngfx::Context> m_nctx;
|
||||||
WorldStatic const&m_worldStatic;
|
WorldStatic const &m_worldStatic;
|
||||||
int m_columns{}, m_rows{};
|
int m_columns{}, m_rows{};
|
||||||
World m_world;
|
World m_world;
|
||||||
glutils::FrameBuffer m_frameBuffer;
|
glutils::FrameBuffer m_frameBuffer;
|
||||||
@ -35,7 +35,7 @@ class WorldEditorView: public ox::SignalHandler {
|
|||||||
bool m_animateWorld{};
|
bool m_animateWorld{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WorldEditorView(studio::Context &ctx, WorldStatic const&worldStatic);
|
WorldEditorView(studio::Context &ctx, WorldStatic const &worldStatic);
|
||||||
|
|
||||||
ox::Error setupTile(uint32_t lyr, uint32_t x, uint32_t y) noexcept;
|
ox::Error setupTile(uint32_t lyr, uint32_t x, uint32_t y) noexcept;
|
||||||
|
|
||||||
@ -43,11 +43,11 @@ class WorldEditorView: public ox::SignalHandler {
|
|||||||
|
|
||||||
ox::Error setupWorld() noexcept;
|
ox::Error setupWorld() noexcept;
|
||||||
|
|
||||||
void draw(ox::Size const&targetSz) noexcept;
|
void draw(ox::Size const &targetSz) noexcept;
|
||||||
|
|
||||||
void clearSelection() noexcept;
|
void clearSelection() noexcept;
|
||||||
|
|
||||||
void setSelection(studio::Selection const&sel) noexcept;
|
void setSelection(studio::Selection const &sel) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool animate() const noexcept { return m_animateWorld; }
|
bool animate() const noexcept { return m_animateWorld; }
|
||||||
@ -55,7 +55,7 @@ class WorldEditorView: public ox::SignalHandler {
|
|||||||
void setAnimate(bool animate) noexcept { m_animateWorld = animate; }
|
void setAnimate(bool animate) noexcept { m_animateWorld = animate; }
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
glutils::FrameBuffer const&framebuffer() const noexcept;
|
glutils::FrameBuffer const &framebuffer() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr int scale() const noexcept { return m_scale; }
|
constexpr int scale() const noexcept { return m_scale; }
|
||||||
|
@ -20,8 +20,8 @@ CollisionView::CollisionView(studio::Context &sctx):
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error CollisionView::setup(
|
ox::Error CollisionView::setup(
|
||||||
ox::FileAddress const&tsAddr,
|
ox::FileAddress const &tsAddr,
|
||||||
ox::FileAddress const&palAddr,
|
ox::FileAddress const &palAddr,
|
||||||
int const w,
|
int const w,
|
||||||
int const h,
|
int const h,
|
||||||
uint_t tile,
|
uint_t tile,
|
||||||
@ -47,11 +47,11 @@ int CollisionView::scale() const noexcept {
|
|||||||
return s_scale;
|
return s_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
glutils::FrameBuffer const&CollisionView::framebuffer() const noexcept {
|
glutils::FrameBuffer const &CollisionView::framebuffer() const noexcept {
|
||||||
return m_frameBuffer;
|
return m_frameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CollisionView::click(ox::Vec2 const&pos, CollisionMap &colMap) noexcept {
|
bool CollisionView::click(ox::Vec2 const &pos, CollisionMap &colMap) noexcept {
|
||||||
auto const inMap = colMap;
|
auto const inMap = colMap;
|
||||||
auto const x = static_cast<uint64_t>(pos.x * static_cast<float>(m_subsheetTilesWidth)) / 2;
|
auto const x = static_cast<uint64_t>(pos.x * static_cast<float>(m_subsheetTilesWidth)) / 2;
|
||||||
auto const y = static_cast<uint64_t>(pos.y * static_cast<float>(m_subsheetTilesHeight)) / 2;
|
auto const y = static_cast<uint64_t>(pos.y * static_cast<float>(m_subsheetTilesHeight)) / 2;
|
||||||
|
@ -31,8 +31,8 @@ class CollisionView {
|
|||||||
CollisionView(studio::Context &sctx);
|
CollisionView(studio::Context &sctx);
|
||||||
|
|
||||||
ox::Error setup(
|
ox::Error setup(
|
||||||
ox::FileAddress const&tsAddr,
|
ox::FileAddress const &tsAddr,
|
||||||
ox::FileAddress const&palAddr,
|
ox::FileAddress const &palAddr,
|
||||||
int w,
|
int w,
|
||||||
int h,
|
int h,
|
||||||
uint_t tile,
|
uint_t tile,
|
||||||
@ -44,12 +44,12 @@ class CollisionView {
|
|||||||
int scale() const noexcept;
|
int scale() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
glutils::FrameBuffer const&framebuffer() const noexcept;
|
glutils::FrameBuffer const &framebuffer() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if colMap changes
|
* @return true if colMap changes
|
||||||
*/
|
*/
|
||||||
bool click(ox::Vec2 const&pos, CollisionMap &colMap) noexcept;
|
bool click(ox::Vec2 const &pos, CollisionMap &colMap) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildGlBuffers(CollisionMap colMap) noexcept;
|
void buildGlBuffers(CollisionMap colMap) noexcept;
|
||||||
|
@ -11,7 +11,7 @@ AddObject::AddObject(WorldObjectSet &doc) noexcept:
|
|||||||
m_doc(doc) {
|
m_doc(doc) {
|
||||||
m_obj.id = m_doc.objIdIdx + 1;
|
m_obj.id = m_doc.objIdIdx + 1;
|
||||||
m_obj.name = ox::sfmt("Object {}", m_obj.id);
|
m_obj.name = ox::sfmt("Object {}", m_obj.id);
|
||||||
for (auto const&o : m_doc.objects) {
|
for (auto const &o : m_doc.objects) {
|
||||||
if (o.name > m_obj.name) {
|
if (o.name > m_obj.name) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ AddPalette::AddPalette(WorldObjectSet &doc, ox::FileAddress palAddr) noexcept:
|
|||||||
ox::Error AddPalette::redo() noexcept {
|
ox::Error AddPalette::redo() noexcept {
|
||||||
m_doc.palettes.emplace_back(m_palAddr);
|
m_doc.palettes.emplace_back(m_palAddr);
|
||||||
//std::sort(m_doc.palettes.begin(), m_doc.palettes.end(),
|
//std::sort(m_doc.palettes.begin(), m_doc.palettes.end(),
|
||||||
// [this](ox::FileAddress const&a, ox::FileAddress const&b) {
|
// [this](ox::FileAddress const &a, ox::FileAddress const &b) {
|
||||||
// auto const aPath = uuidUrlToPath(m_kctx, a.getPath().or_value("")).or_value("");
|
// auto const aPath = uuidUrlToPath(m_kctx, a.getPath().or_value("")).or_value("");
|
||||||
// auto const bPath = uuidUrlToPath(m_kctx, b.getPath().or_value("")).or_value("");
|
// auto const bPath = uuidUrlToPath(m_kctx, b.getPath().or_value("")).or_value("");
|
||||||
// return aPath < bPath;
|
// return aPath < bPath;
|
||||||
@ -29,7 +29,7 @@ ox::Error AddPalette::redo() noexcept {
|
|||||||
|
|
||||||
ox::Error AddPalette::undo() noexcept {
|
ox::Error AddPalette::undo() noexcept {
|
||||||
auto const idx = std::find_if(m_doc.palettes.begin(), m_doc.palettes.end(),
|
auto const idx = std::find_if(m_doc.palettes.begin(), m_doc.palettes.end(),
|
||||||
[this](ox::FileAddress const&v) {
|
[this](ox::FileAddress const &v) {
|
||||||
return v == m_palAddr;
|
return v == m_palAddr;
|
||||||
});
|
});
|
||||||
return m_doc.palettes.erase(idx).error;
|
return m_doc.palettes.erase(idx).error;
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
template<
|
template<
|
||||||
WorldObjCommand cmd, auto getVar, auto hasMerge = false,
|
WorldObjCommand cmd,
|
||||||
|
auto getVar,
|
||||||
|
auto hasMerge = false,
|
||||||
typename ValType = std::remove_reference_t<decltype(getVar(*new WorldObject))>>
|
typename ValType = std::remove_reference_t<decltype(getVar(*new WorldObject))>>
|
||||||
class EditObject: public studio::UndoCommand {
|
class EditObject: public studio::UndoCommand {
|
||||||
private:
|
private:
|
||||||
|
@ -13,7 +13,7 @@ RmPalette::RmPalette(WorldObjectSet &doc, size_t const rmIdx) noexcept:
|
|||||||
m_doc(doc),
|
m_doc(doc),
|
||||||
m_rmIdx(rmIdx) {
|
m_rmIdx(rmIdx) {
|
||||||
m_objUpdates.reserve(m_doc.objects.size());
|
m_objUpdates.reserve(m_doc.objects.size());
|
||||||
for (size_t i = 0; auto const&obj : m_doc.objects) {
|
for (size_t i = 0; auto const &obj : m_doc.objects) {
|
||||||
if (obj.palBank >= m_rmIdx) {
|
if (obj.palBank >= m_rmIdx) {
|
||||||
uint8_t const newPalBank = obj.palBank == m_rmIdx ?
|
uint8_t const newPalBank = obj.palBank == m_rmIdx ?
|
||||||
0 : obj.palBank - 1;
|
0 : obj.palBank - 1;
|
||||||
@ -30,7 +30,7 @@ RmPalette::RmPalette(WorldObjectSet &doc, size_t const rmIdx) noexcept:
|
|||||||
ox::Error RmPalette::redo() noexcept {
|
ox::Error RmPalette::redo() noexcept {
|
||||||
m_pal = std::move(m_doc.palettes[m_rmIdx]);
|
m_pal = std::move(m_doc.palettes[m_rmIdx]);
|
||||||
std::ignore = m_doc.palettes.erase(m_rmIdx);
|
std::ignore = m_doc.palettes.erase(m_rmIdx);
|
||||||
for (auto const&u : m_objUpdates) {
|
for (auto const &u : m_objUpdates) {
|
||||||
m_doc.objects[u.idx].palBank = u.newPalBank;
|
m_doc.objects[u.idx].palBank = u.newPalBank;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
@ -39,10 +39,10 @@ ox::Error RmPalette::redo() noexcept {
|
|||||||
ox::Error RmPalette::undo() noexcept {
|
ox::Error RmPalette::undo() noexcept {
|
||||||
m_doc.palettes.emplace_back(std::move(m_pal));
|
m_doc.palettes.emplace_back(std::move(m_pal));
|
||||||
std::sort(m_doc.palettes.begin(), m_doc.palettes.end(),
|
std::sort(m_doc.palettes.begin(), m_doc.palettes.end(),
|
||||||
[](ox::FileAddress const&a, ox::FileAddress const&b) {
|
[](ox::FileAddress const &a, ox::FileAddress const &b) {
|
||||||
return a.getPath().or_value("") < b.getPath().or_value("");
|
return a.getPath().or_value("") < b.getPath().or_value("");
|
||||||
});
|
});
|
||||||
for (auto const&u : m_objUpdates) {
|
for (auto const &u : m_objUpdates) {
|
||||||
m_doc.objects[u.idx].palBank = u.oldPalBank;
|
m_doc.objects[u.idx].palBank = u.oldPalBank;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
@ -92,7 +92,7 @@ void WorldObjectSetEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldObject const&WorldObjectSetEditorImGui::activeObj() const noexcept {
|
WorldObject const &WorldObjectSetEditorImGui::activeObj() const noexcept {
|
||||||
return m_doc.objects[m_selectedObj];
|
return m_doc.objects[m_selectedObj];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ WorldObject &WorldObjectSetEditorImGui::activeObj() noexcept {
|
|||||||
|
|
||||||
void WorldObjectSetEditorImGui::buildPaletteDisplayNameList() noexcept {
|
void WorldObjectSetEditorImGui::buildPaletteDisplayNameList() noexcept {
|
||||||
m_paletteDisplayNames.clear();
|
m_paletteDisplayNames.clear();
|
||||||
for (auto i = 1u; auto const&pal : m_doc.palettes) {
|
for (auto i = 1u; auto const &pal : m_doc.palettes) {
|
||||||
auto const path = keel::getPath(keelCtx(m_sctx.tctx), pal).or_value("Invalid path");
|
auto const path = keel::getPath(keelCtx(m_sctx.tctx), pal).or_value("Invalid path");
|
||||||
m_paletteDisplayNames.emplace_back(ox::sfmt("{}: {}", i, path));
|
m_paletteDisplayNames.emplace_back(ox::sfmt("{}: {}", i, path));
|
||||||
++i;
|
++i;
|
||||||
@ -147,7 +147,7 @@ ox::Error WorldObjectSetEditorImGui::loadObj() noexcept {
|
|||||||
if (m_selectedObj >= m_doc.objects.size()) {
|
if (m_selectedObj >= m_doc.objects.size()) {
|
||||||
return ox::Error{1};
|
return ox::Error{1};
|
||||||
}
|
}
|
||||||
auto const&obj = activeObj();
|
auto const &obj = activeObj();
|
||||||
auto &nameBuff = m_objEditor.nameBuff;
|
auto &nameBuff = m_objEditor.nameBuff;
|
||||||
nameBuff = obj.name;
|
nameBuff = obj.name;
|
||||||
m_objEditor.palette = obj.palBank;
|
m_objEditor.palette = obj.palBank;
|
||||||
@ -166,7 +166,7 @@ ox::Error WorldObjectSetEditorImGui::loadObj() noexcept {
|
|||||||
auto const tileIdx = getTileIdx(
|
auto const tileIdx = getTileIdx(
|
||||||
*m_tileSheet,
|
*m_tileSheet,
|
||||||
subsheetId).or_value(0);
|
subsheetId).or_value(0);
|
||||||
auto const&palAddr = m_doc.palettes.size() > obj.palBank ?
|
auto const &palAddr = m_doc.palettes.size() > obj.palBank ?
|
||||||
m_doc.palettes[obj.palBank] : ox::FileAddress{};
|
m_doc.palettes[obj.palBank] : ox::FileAddress{};
|
||||||
return m_colView.setup(
|
return m_colView.setup(
|
||||||
m_doc.tilesheet,
|
m_doc.tilesheet,
|
||||||
@ -178,7 +178,10 @@ ox::Error WorldObjectSetEditorImGui::loadObj() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static ox::Vec2 clickPos(ImVec2 const&imgSz, ImVec2 const&offset, ox::Vec2 clickPos) noexcept {
|
static ox::Vec2 clickPos(
|
||||||
|
ImVec2 const &imgSz,
|
||||||
|
ImVec2 const &offset,
|
||||||
|
ox::Vec2 clickPos) noexcept {
|
||||||
clickPos.x -= offset.x;
|
clickPos.x -= offset.x;
|
||||||
clickPos.y -= offset.y;
|
clickPos.y -= offset.y;
|
||||||
clickPos.x /= imgSz.x;
|
clickPos.x /= imgSz.x;
|
||||||
@ -235,7 +238,7 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept {
|
|||||||
ImGui::Text("Collision Map:");
|
ImGui::Text("Collision Map:");
|
||||||
ig::IndentStackItem const indent2{30};
|
ig::IndentStackItem const indent2{30};
|
||||||
m_colView.draw();
|
m_colView.draw();
|
||||||
auto const&fb = m_colView.framebuffer();
|
auto const &fb = m_colView.framebuffer();
|
||||||
uintptr_t const buffId = fb.color.id;
|
uintptr_t const buffId = fb.color.id;
|
||||||
auto const scale = static_cast<float>(m_colView.scale());
|
auto const scale = static_cast<float>(m_colView.scale());
|
||||||
auto const width = static_cast<float>(m_visibleSubsheet->columns * ngfx::TileWidth);
|
auto const width = static_cast<float>(m_visibleSubsheet->columns * ngfx::TileWidth);
|
||||||
@ -249,7 +252,7 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept {
|
|||||||
imageSz,
|
imageSz,
|
||||||
{0, 1.0},
|
{0, 1.0},
|
||||||
{horzPct, 1 - vertPct});
|
{horzPct, 1 - vertPct});
|
||||||
auto const&io = ImGui::GetIO();
|
auto const &io = ImGui::GetIO();
|
||||||
if (ImGui::IsItemClicked()) {
|
if (ImGui::IsItemClicked()) {
|
||||||
auto const mousePos = clickPos(imageSz, imagePos, ox::Vec2{io.MousePos});
|
auto const mousePos = clickPos(imageSz, imagePos, ox::Vec2{io.MousePos});
|
||||||
auto &obj = activeObj();
|
auto &obj = activeObj();
|
||||||
@ -261,9 +264,9 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldObjectSetEditorImGui::drawSubSheetNode(ngfx::TileSheet::SubSheet const&ss) noexcept {
|
void WorldObjectSetEditorImGui::drawSubSheetNode(ngfx::TileSheet::SubSheet const &ss) noexcept {
|
||||||
auto constexpr dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
auto constexpr dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||||
auto const&obj = activeObj();
|
auto const &obj = activeObj();
|
||||||
auto const selected = ss.id == obj.subsheetId ? ImGuiTreeNodeFlags_Selected : 0;
|
auto const selected = ss.id == obj.subsheetId ? ImGuiTreeNodeFlags_Selected : 0;
|
||||||
ig::IDStackItem const idStackItem{ss.name};
|
ig::IDStackItem const idStackItem{ss.name};
|
||||||
if (!ss.subsheets.empty()) {
|
if (!ss.subsheets.empty()) {
|
||||||
@ -275,7 +278,7 @@ void WorldObjectSetEditorImGui::drawSubSheetNode(ngfx::TileSheet::SubSheet const
|
|||||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
||||||
ngfx::navigateToTileSheet(m_sctx, m_tilesheetPath, ss.id);
|
ngfx::navigateToTileSheet(m_sctx, m_tilesheetPath, ss.id);
|
||||||
}
|
}
|
||||||
for (auto const&child : ss.subsheets) {
|
for (auto const &child : ss.subsheets) {
|
||||||
drawSubSheetNode(child);
|
drawSubSheetNode(child);
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
@ -324,7 +327,7 @@ void WorldObjectSetEditorImGui::drawPaletteList() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldObjectSetEditorImGui::drawPaletteListItems() noexcept {
|
void WorldObjectSetEditorImGui::drawPaletteListItems() noexcept {
|
||||||
for (auto i = 0u; auto const&pal : m_doc.palettes) {
|
for (auto i = 0u; auto const &pal : m_doc.palettes) {
|
||||||
ig::IDStackItem const idStackItem{static_cast<int>(i)};
|
ig::IDStackItem const idStackItem{static_cast<int>(i)};
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
@ -398,7 +401,7 @@ ox::Error WorldObjectSetEditorImGui::handleCmd(studio::UndoCommand const*cmd) no
|
|||||||
dynamic_cast<RmPalette const*>(cmd)) {
|
dynamic_cast<RmPalette const*>(cmd)) {
|
||||||
buildPaletteDisplayNameList();
|
buildPaletteDisplayNameList();
|
||||||
} else if (dynamic_cast<EditObjectPalette const*>(cmd)) {
|
} else if (dynamic_cast<EditObjectPalette const*>(cmd)) {
|
||||||
auto const&obj = activeObj();
|
auto const &obj = activeObj();
|
||||||
m_objEditor.palette = obj.palBank;
|
m_objEditor.palette = obj.palBank;
|
||||||
}
|
}
|
||||||
return loadObj();
|
return loadObj();
|
||||||
|
@ -44,7 +44,7 @@ class WorldObjectSetEditorImGui: public studio::Editor {
|
|||||||
void navigateTo(ox::StringViewCR arg) noexcept override;
|
void navigateTo(ox::StringViewCR arg) noexcept override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WorldObject const&activeObj() const noexcept;
|
WorldObject const &activeObj() const noexcept;
|
||||||
|
|
||||||
WorldObject &activeObj() noexcept;
|
WorldObject &activeObj() noexcept;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ class WorldObjectSetEditorImGui: public studio::Editor {
|
|||||||
|
|
||||||
void drawObjEditor() noexcept;
|
void drawObjEditor() noexcept;
|
||||||
|
|
||||||
void drawSubSheetNode(ngfx::TileSheet::SubSheet const&ss) noexcept;
|
void drawSubSheetNode(ngfx::TileSheet::SubSheet const &ss) noexcept;
|
||||||
|
|
||||||
void drawPaletteList() noexcept;
|
void drawPaletteList() noexcept;
|
||||||
|
|
||||||
|
@ -11,13 +11,13 @@
|
|||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static bool isUpdatingObj(ObjTileRefSet const&obj) noexcept {
|
bool isUpdatingObj(ObjTileRefSet const &obj) noexcept {
|
||||||
return obj.frames > 1;
|
return obj.frames > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
World::World(ngfx::Context &nctx, WorldStatic const&worldStatic) noexcept:
|
World::World(ngfx::Context &nctx, WorldStatic const &worldStatic) noexcept:
|
||||||
m_nctx(nctx),
|
m_nctx{nctx},
|
||||||
m_worldStatic(worldStatic) {}
|
m_worldStatic{worldStatic} {}
|
||||||
|
|
||||||
ox::Error World::setupDisplay() noexcept {
|
ox::Error World::setupDisplay() noexcept {
|
||||||
if (m_worldStatic.objTileRefSets.empty()) {
|
if (m_worldStatic.objTileRefSets.empty()) {
|
||||||
@ -37,18 +37,18 @@ ox::Error World::setupDisplay() noexcept {
|
|||||||
}
|
}
|
||||||
if (m_tilesheets.empty()) {
|
if (m_tilesheets.empty()) {
|
||||||
auto &kctx = keelCtx(m_nctx);
|
auto &kctx = keelCtx(m_nctx);
|
||||||
for (auto const&tsAddr : m_worldStatic.tilesheets) {
|
for (auto const &tsAddr : m_worldStatic.tilesheets) {
|
||||||
OX_REQUIRE_M(ts, keel::readObj<ngfx::CompactTileSheet>(kctx, tsAddr));
|
OX_REQUIRE_M(ts, keel::readObj<ngfx::CompactTileSheet>(kctx, tsAddr));
|
||||||
m_tilesheets.emplace_back(std::move(ts));
|
m_tilesheets.emplace_back(std::move(ts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto i = 0u; auto const&palAddr : m_worldStatic.palettes) {
|
for (auto i = 0u; auto const &palAddr : m_worldStatic.palettes) {
|
||||||
OX_RETURN_ERROR(ngfx::loadBgPalette(m_nctx, i, palAddr));
|
OX_RETURN_ERROR(ngfx::loadBgPalette(m_nctx, i, palAddr));
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
ngfx::clearCbbs(m_nctx);
|
ngfx::clearCbbs(m_nctx);
|
||||||
for (size_t i = 1; i < m_worldStatic.objTileRefSets.size(); ++i) {
|
for (size_t i = 1; i < m_worldStatic.objTileRefSets.size(); ++i) {
|
||||||
auto const&rs = m_worldStatic.objTileRefSets[i];
|
auto const &rs = m_worldStatic.objTileRefSets[i];
|
||||||
OX_RETURN_ERROR(ngfx::loadBgTileSheet(
|
OX_RETURN_ERROR(ngfx::loadBgTileSheet(
|
||||||
m_nctx,
|
m_nctx,
|
||||||
rs.cbb,
|
rs.cbb,
|
||||||
@ -74,7 +74,7 @@ ox::Result<int> World::update() noexcept {
|
|||||||
void World::setupTiles() noexcept {
|
void World::setupTiles() noexcept {
|
||||||
m_currentTicks = ticksMs(turbineCtx(m_nctx));
|
m_currentTicks = ticksMs(turbineCtx(m_nctx));
|
||||||
ngfx::setBgStatus(m_nctx, 0); // disable all backgrounds
|
ngfx::setBgStatus(m_nctx, 0); // disable all backgrounds
|
||||||
for (auto layerNo = 0u; auto const&layer : m_worldStatic.map) {
|
for (auto layerNo = 0u; auto const &layer : m_worldStatic.map) {
|
||||||
setupLayer(layerNo, layer.cbb);
|
setupLayer(layerNo, layer.cbb);
|
||||||
++layerNo;
|
++layerNo;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
void resize(WorldDoc &doc, ox::Size const&sz) noexcept {
|
void resize(WorldDoc &doc, ox::Size const &sz) noexcept {
|
||||||
doc.columns = sz.width;
|
doc.columns = sz.width;
|
||||||
doc.rows = sz.height;
|
doc.rows = sz.height;
|
||||||
for (auto &layer : doc.tiles) {
|
for (auto &layer : doc.tiles) {
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace jasper::world {
|
namespace jasper::world {
|
||||||
|
|
||||||
static void ensureInVec(ox::Vector<ox::FileAddress> &vec, ox::FileAddress const&val) {
|
static void ensureInVec(ox::Vector<ox::FileAddress> &vec, ox::FileAddress const &val) {
|
||||||
if (!vec.contains(val)) {
|
if (!vec.contains(val)) {
|
||||||
vec.emplace_back(val);
|
vec.emplace_back(val);
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ static void ensureInVec(ox::Vector<ox::FileAddress> &vec, ox::FileAddress const&
|
|||||||
// If the root subsheet is not a leaf node, it will return the
|
// If the root subsheet is not a leaf node, it will return the
|
||||||
// tile count of the first leaf node that it finds.
|
// tile count of the first leaf node that it finds.
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static uint8_t subsheetTileCnt(ngfx::TileSheet::SubSheet const&ss) noexcept {
|
static uint8_t subsheetTileCnt(ngfx::TileSheet::SubSheet const &ss) noexcept {
|
||||||
if (ss.subsheets.empty()) {
|
if (ss.subsheets.empty()) {
|
||||||
return static_cast<uint8_t>(ss.size());
|
return static_cast<uint8_t>(ss.size());
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ static uint8_t subsheetTileCnt(ngfx::TileSheet::SubSheet const&ss) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WorldStaticLoader::WorldStaticLoader(keel::Context &kctx, WorldStatic &worldStatic, WorldDoc const&doc):
|
WorldStaticLoader::WorldStaticLoader(keel::Context &kctx, WorldStatic &worldStatic, WorldDoc const &doc):
|
||||||
m_kctx{kctx},
|
m_kctx{kctx},
|
||||||
m_worldStatic{worldStatic},
|
m_worldStatic{worldStatic},
|
||||||
m_doc{doc} {}
|
m_doc{doc} {}
|
||||||
@ -37,13 +37,13 @@ ox::Error WorldStaticLoader::loadWorldStatic() noexcept {
|
|||||||
reset();
|
reset();
|
||||||
auto const tilesPerLayer =
|
auto const tilesPerLayer =
|
||||||
static_cast<size_t>(m_doc.columns) * static_cast<size_t>(m_doc.rows);
|
static_cast<size_t>(m_doc.columns) * static_cast<size_t>(m_doc.rows);
|
||||||
for (auto const&setRef : m_doc.objSets) {
|
for (auto const &setRef : m_doc.objSets) {
|
||||||
auto const [set, err] =
|
auto const [set, err] =
|
||||||
keel::readObj<WorldObjectSet>(m_kctx, setRef.path);
|
keel::readObj<WorldObjectSet>(m_kctx, setRef.path);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
m_objSets[setRef.id] = *set;
|
m_objSets[setRef.id] = *set;
|
||||||
ensureInVec(m_worldStatic.tilesheets, set->tilesheet);
|
ensureInVec(m_worldStatic.tilesheets, set->tilesheet);
|
||||||
for (auto const&pal : set->palettes) {
|
for (auto const &pal : set->palettes) {
|
||||||
ensureInVec(m_worldStatic.palettes, pal);
|
ensureInVec(m_worldStatic.palettes, pal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ ox::Error WorldStaticLoader::updateTile(
|
|||||||
uint32_t const layer,
|
uint32_t const layer,
|
||||||
uint32_t const col,
|
uint32_t const col,
|
||||||
uint32_t const row,
|
uint32_t const row,
|
||||||
TileDoc const&oldSrc) noexcept {
|
TileDoc const &oldSrc) noexcept {
|
||||||
auto &dst = tile(m_worldStatic, layer, col, row);
|
auto &dst = tile(m_worldStatic, layer, col, row);
|
||||||
auto &newSrc = tile(m_doc, layer, col, row);
|
auto &newSrc = tile(m_doc, layer, col, row);
|
||||||
if (oldSrc.obj.unique) {
|
if (oldSrc.obj.unique) {
|
||||||
@ -100,7 +100,7 @@ ox::Error WorldStaticLoader::updateTile(
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldStaticLoader::loadTile(TileStatic &dst, TileDoc const&src) noexcept {
|
void WorldStaticLoader::loadTile(TileStatic &dst, TileDoc const &src) noexcept {
|
||||||
dst.tileType = src.type;
|
dst.tileType = src.type;
|
||||||
setTopEdge(dst.layerAttachments, src.topLayerAttachment);
|
setTopEdge(dst.layerAttachments, src.topLayerAttachment);
|
||||||
setBottomEdge(dst.layerAttachments, src.bottomLayerAttachment);
|
setBottomEdge(dst.layerAttachments, src.bottomLayerAttachment);
|
||||||
@ -131,7 +131,7 @@ void WorldStaticLoader::reset() {
|
|||||||
/**
|
/**
|
||||||
* Returns the index in rsrcs for the given docObjRef.
|
* Returns the index in rsrcs for the given docObjRef.
|
||||||
*/
|
*/
|
||||||
ox::Result<uint8_t> WorldStaticLoader::setupTileResrc(DocObjRef const&docObjRef) noexcept {
|
ox::Result<uint8_t> WorldStaticLoader::setupTileResrc(DocObjRef const &docObjRef) noexcept {
|
||||||
if (!docObjRef.unique) {
|
if (!docObjRef.unique) {
|
||||||
auto const [out, err] = m_cache.at(docObjRef);
|
auto const [out, err] = m_cache.at(docObjRef);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@ -142,7 +142,7 @@ ox::Result<uint8_t> WorldStaticLoader::setupTileResrc(DocObjRef const&docObjRef)
|
|||||||
OX_REQUIRE(objSet, m_objSets.at(docObjRef.worldObjectSetId));
|
OX_REQUIRE(objSet, m_objSets.at(docObjRef.worldObjectSetId));
|
||||||
auto const obj = ox::find_if(
|
auto const obj = ox::find_if(
|
||||||
objSet->objects.begin(), objSet->objects.end(),
|
objSet->objects.begin(), objSet->objects.end(),
|
||||||
[&docObjRef](WorldObject const&o) {
|
[&docObjRef](WorldObject const &o) {
|
||||||
return o.id == docObjRef.worldObjectId;
|
return o.id == docObjRef.worldObjectId;
|
||||||
});
|
});
|
||||||
if (obj == objSet->objects.end()) {
|
if (obj == objSet->objects.end()) {
|
||||||
@ -160,7 +160,7 @@ ox::Result<uint8_t> WorldStaticLoader::setupTileResrc(DocObjRef const&docObjRef)
|
|||||||
return ox::Error{1, "could not find subsheet"};
|
return ox::Error{1, "could not find subsheet"};
|
||||||
}
|
}
|
||||||
auto const out = static_cast<uint8_t>(m_worldStatic.objTileRefSets.size());
|
auto const out = static_cast<uint8_t>(m_worldStatic.objTileRefSets.size());
|
||||||
auto const&refSet = m_worldStatic.objTileRefSets.emplace_back(ObjTileRefSet{
|
auto const &refSet = m_worldStatic.objTileRefSets.emplace_back(ObjTileRefSet{
|
||||||
.tilesheetIdx = static_cast<uint16_t>(*subsheetOffset),
|
.tilesheetIdx = static_cast<uint16_t>(*subsheetOffset),
|
||||||
.cbbIdx = m_cbbIt,
|
.cbbIdx = m_cbbIt,
|
||||||
.palBank = obj->palBank,
|
.palBank = obj->palBank,
|
||||||
@ -177,7 +177,7 @@ ox::Result<uint8_t> WorldStaticLoader::setupTileResrc(DocObjRef const&docObjRef)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldStaticLoader::deleteRefSet(uint8_t const refIdx, DocObjRef const&oldObjRef) noexcept {
|
void WorldStaticLoader::deleteRefSet(uint8_t const refIdx, DocObjRef const &oldObjRef) noexcept {
|
||||||
for (auto lyr = 0u; lyr < layers(m_worldStatic); ++lyr) {
|
for (auto lyr = 0u; lyr < layers(m_worldStatic); ++lyr) {
|
||||||
for (auto x = 0u; x < static_cast<size_t>(m_worldStatic.columns); ++x) {
|
for (auto x = 0u; x < static_cast<size_t>(m_worldStatic.columns); ++x) {
|
||||||
for (auto y = 0u; y < static_cast<size_t>(m_worldStatic.rows); ++y) {
|
for (auto y = 0u; y < static_cast<size_t>(m_worldStatic.rows); ++y) {
|
||||||
@ -194,7 +194,7 @@ void WorldStaticLoader::deleteRefSet(uint8_t const refIdx, DocObjRef const&oldOb
|
|||||||
--p.value.value;
|
--p.value.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto const&removedRefSet = m_worldStatic.objTileRefSets[refIdx];
|
auto const &removedRefSet = m_worldStatic.objTileRefSets[refIdx];
|
||||||
for (size_t i = refIdx + 1; i < m_worldStatic.objTileRefSets.size(); ++i) {
|
for (size_t i = refIdx + 1; i < m_worldStatic.objTileRefSets.size(); ++i) {
|
||||||
auto &refSet = m_worldStatic.objTileRefSets[i];
|
auto &refSet = m_worldStatic.objTileRefSets[i];
|
||||||
refSet.cbbIdx -= removedRefSet.frames;
|
refSet.cbbIdx -= removedRefSet.frames;
|
||||||
|
Reference in New Issue
Block a user