diff --git a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp index db26fb4..de9b97b 100644 --- a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp @@ -130,18 +130,23 @@ void WorldObjectSetEditorImGui::loadObj() noexcept { } auto const&obj = activeObj(); auto &nameBuff = m_objEditor.nameBuff; - ox::strncpy(nameBuff.data(), obj.name.data(), nameBuff.size()); + nameBuff = obj.name; m_objEditor.palette = obj.palBank; m_objEditor.frames = obj.frames; m_objEditor.interval = obj.intervalMs; - m_subsheet = getSubsheet(*m_tileSheet, obj.subsheetId); + m_visibleSubsheet = getSubsheet(*m_tileSheet, obj.subsheetId); + auto const subsheetId = !m_visibleSubsheet || m_visibleSubsheet->subsheets.empty() ? + obj.subsheetId : m_visibleSubsheet->subsheets[0].id; + m_visibleSubsheet = getSubsheet(*m_tileSheet, subsheetId); int w = 0; int h = 0; - if (m_subsheet) { - w = m_subsheet->columns; - h = m_subsheet->rows; + if (m_visibleSubsheet) { + w = m_visibleSubsheet->columns; + h = m_visibleSubsheet->rows; } - auto const idx = getTileIdx(*m_tileSheet, obj.subsheetId).or_value(0); + auto const idx = getTileIdx( + *m_tileSheet, + subsheetId).or_value(0); oxLogError(m_colView.setup( m_doc.tilesheet, m_doc.palettes[obj.palBank], @@ -165,11 +170,11 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept { ig::IndentStackItem const indent1{10}; ImGui::NewLine(); auto &nameBuff = m_objEditor.nameBuff; - if (ImGui::InputText("Name", nameBuff.data(), nameBuff.size())) { + if (ig::InputText("Name", nameBuff)) { std::ignore = pushCommand( m_doc, m_selectedObj, - ox::String(nameBuff.data(), ox::strnlen(nameBuff.data(), nameBuff.size()))); + ox::String{nameBuff}); } // SubSheet Selector { @@ -200,7 +205,7 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept { ImGui::EndChild(); } // collision map - if (m_subsheet) { + if (m_visibleSubsheet) { ImGui::NewLine(); ImGui::Text("Collision Map:"); ig::IndentStackItem const indent2{30}; @@ -208,8 +213,8 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept { auto const&fb = m_colView.framebuffer(); uintptr_t const buffId = fb.color.id; auto const scale = static_cast(m_colView.scale()); - auto const width = static_cast(m_subsheet->columns * ncore::TileWidth); - auto const height = static_cast(m_subsheet->rows * ncore::TileHeight); + auto const width = static_cast(m_visibleSubsheet->columns * ncore::TileWidth); + auto const height = static_cast(m_visibleSubsheet->rows * ncore::TileHeight); auto const horzPct = width / 240.f; auto const vertPct = height / 160.f; auto const imageSz = ImVec2{width * scale, height * scale}; diff --git a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp index cb24178..9eee73a 100644 --- a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp @@ -19,7 +19,7 @@ class WorldObjectSetEditorImGui: public studio::Editor { ox::String m_itemPath; WorldObjectSet m_doc; keel::AssetRef m_tileSheet; - ncore::TileSheet::SubSheet const*m_subsheet = nullptr; + ncore::TileSheet::SubSheet const*m_visibleSubsheet = nullptr; ox::Vector m_paletteDisplayNames; size_t m_selectedObj{}; size_t m_selectedPal{}; @@ -30,7 +30,7 @@ class WorldObjectSetEditorImGui: public studio::Editor { } m_addPalPopup; CollisionView m_colView{m_sctx}; struct { - ox::Buffer nameBuff = ox::Buffer(256); + ox::IString<256> nameBuff; int frames{}; int interval{}; size_t palette{}; diff --git a/src/jasper/modules/world/src/worldstatic.cpp b/src/jasper/modules/world/src/worldstatic.cpp index d9c8bf4..73c26fd 100644 --- a/src/jasper/modules/world/src/worldstatic.cpp +++ b/src/jasper/modules/world/src/worldstatic.cpp @@ -11,12 +11,22 @@ namespace jasper::world { -inline void ensureInVec(ox::Vector &vec, ox::FileAddress const&val) { +static void ensureInVec(ox::Vector &vec, ox::FileAddress const&val) { if (!vec.contains(val)) { vec.emplace_back(val); } } +// If the root subsheet is not a leaf node, it will return the +// tile count of the first leaf node that it finds. +[[nodiscard]] +static uint8_t subsheetTileCnt(ncore::TileSheet::SubSheet const&ss) noexcept { + if (ss.subsheets.empty()) { + return static_cast(ss.size()); + } + return subsheetTileCnt(ss.subsheets[0]); +} + WorldStaticLoader::WorldStaticLoader(keel::Context &kctx, WorldStatic &worldStatic, WorldDoc const&doc): m_kctx{kctx}, @@ -155,7 +165,7 @@ ox::Result WorldStaticLoader::setupTileResrc(DocObjRef const&docObjRef) .tilesheetIdx = static_cast(*subsheetOffset), .cbbIdx = m_cbbIt, .tilesheetId = tsIdx, - .tileCnt = static_cast(subsheet->size()), + .tileCnt = subsheetTileCnt(*subsheet), .frames = obj->frames, }); m_cbbIt += refSet.tileCnt;