[nostalgia/gfx/studio/tilesheet] Ensure config file has a Claw header

This commit is contained in:
Gary Talent 2025-05-24 00:48:54 -05:00
parent 78379f58c8
commit 1e21778059
2 changed files with 27 additions and 24 deletions

View File

@ -36,7 +36,7 @@ OX_MODEL_BEGIN(TileSheetEditorConfig)
OX_MODEL_END()
static ox::Vector<uint32_t> normalizePixelSizes(
ox::Vector<uint8_t> const&inPixels) noexcept {
ox::Vector<uint8_t> const &inPixels) noexcept {
ox::Vector<uint32_t> outPixels;
outPixels.reserve(inPixels.size());
outPixels.resize(inPixels.size());
@ -47,7 +47,7 @@ static ox::Vector<uint32_t> normalizePixelSizes(
}
static ox::Vector<uint32_t> normalizePixelArrangement(
ox::Vector<uint32_t> const&inPixels,
ox::Vector<uint32_t> const &inPixels,
int const cols,
int const scale) {
auto const scalePt = ox::Point{scale, scale};
@ -67,10 +67,10 @@ static ox::Vector<uint32_t> normalizePixelArrangement(
}
static ox::Error toPngFile(
ox::CStringView const&path,
ox::CStringViewCR path,
ox::Vector<uint32_t> &&pixels,
Palette const&pal,
size_t page,
Palette const &pal,
size_t const page,
unsigned const width,
unsigned const height) noexcept {
for (auto &c : pixels) {
@ -88,7 +88,7 @@ static ox::Error toPngFile(
}
TileSheetEditorImGui::TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path):
Editor(sctx, std::move(path)),
Editor{sctx, std::move(path)},
m_sctx{sctx},
m_tctx{m_sctx.tctx},
m_palPicker{"Palette Chooser", keelCtx(sctx), FileExt_npal},
@ -98,8 +98,11 @@ TileSheetEditorImGui::TileSheetEditorImGui(studio::Context &sctx, ox::StringPara
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubsheetToPng);
// load config
auto const&config = studio::readConfig<TileSheetEditorConfig>(
keelCtx(m_sctx), itemPath());
auto &kctx = keelCtx(m_sctx);
auto const ip = itemPath();
oxLogError(studio::headerizeConfigFile<TileSheetEditorConfig>(kctx, ip));
auto const &config =
studio::readConfig<TileSheetEditorConfig>(kctx, ip);
if (config.ok()) {
m_model.setActiveSubsheet(validateSubSheetIdx(m_model.img(), config.value.activeSubsheet));
}
@ -192,7 +195,7 @@ void TileSheetEditorImGui::draw(studio::Context&) noexcept {
if (ig::mainWinHasFocus() && m_tool == TileSheetTool::Select) {
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl) && !m_palPathFocused) {
if (ImGui::IsKeyPressed(ImGuiKey_A)) {
auto const&img = m_model.activeSubSheet();
auto const &img = m_model.activeSubSheet();
m_model.setSelection({{}, {img.columns * TileWidth - 1, img.rows * TileHeight - 1}});
} else if (ImGui::IsKeyPressed(ImGuiKey_G)) {
m_model.clearSelection();
@ -271,14 +274,14 @@ void TileSheetEditorImGui::draw(studio::Context&) noexcept {
auto constexpr btnSize = ImVec2{btnHeight, btnHeight};
if (ig::PushButton("+", btnSize)) {
auto insertOnIdx = m_model.activeSubSheetIdx();
auto const&parent = m_model.activeSubSheet();
auto const &parent = m_model.activeSubSheet();
m_model.addSubsheet(insertOnIdx);
insertOnIdx.emplace_back(parent.subsheets.size() - 1);
setActiveSubsheet(insertOnIdx);
}
ImGui::SameLine();
if (ig::PushButton("-", btnSize)) {
auto const&activeSubsheetIdx = m_model.activeSubSheetIdx();
auto const &activeSubsheetIdx = m_model.activeSubSheetIdx();
if (!activeSubsheetIdx.empty()) {
m_model.rmSubsheet(activeSubsheetIdx);
}
@ -378,7 +381,7 @@ void TileSheetEditorImGui::drawSubsheetSelector(
}
[[nodiscard]]
ox::Vec2 TileSheetEditorImGui::clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept {
ox::Vec2 TileSheetEditorImGui::clickPos(ImVec2 const &winPos, ox::Vec2 clickPos) noexcept {
clickPos.x -= winPos.x + 10;
clickPos.y -= winPos.y + 10;
return clickPos;
@ -400,7 +403,7 @@ void TileSheetEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
}
void TileSheetEditorImGui::showSubsheetEditor() noexcept {
auto const&sheet = m_model.activeSubSheet();
auto const &sheet = m_model.activeSubSheet();
if (!sheet.subsheets.empty()) {
m_subsheetEditor.show(sheet.name, -1, -1);
} else {
@ -411,8 +414,8 @@ void TileSheetEditorImGui::showSubsheetEditor() noexcept {
ox::Error TileSheetEditorImGui::exportSubsheetToPng(int const scale) const noexcept {
OX_REQUIRE(path, studio::saveFile({{"PNG", "png"}}));
// subsheet to png
auto const&s = m_model.activeSubSheet();
auto const&pal = m_model.pal();
auto const &s = m_model.activeSubSheet();
auto const &pal = m_model.pal();
auto const width = s.columns * TileWidth;
auto const height = s.rows * TileHeight;
auto pixels = normalizePixelSizes(s.pixels);
@ -430,7 +433,7 @@ ox::Error TileSheetEditorImGui::exportSubsheetToPng(int const scale) const noexc
return err;
}
void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const &fbSize) noexcept {
auto const winPos = ImGui::GetWindowPos();
auto const fbSizei = ox::Size{static_cast<int>(fbSize.x), static_cast<int>(fbSize.y)};
if (m_framebuffer.width != fbSizei.width || m_framebuffer.height != fbSizei.height) {
@ -451,7 +454,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
{0, 1},
{1, 0});
// handle input, this must come after drawing
auto const&io = ImGui::GetIO();
auto const &io = ImGui::GetIO();
auto const mousePos = ox::Vec2{ImGui::GetMousePos()};
if (ImGui::IsItemHovered()) {
auto const wheel = io.MouseWheel;
@ -556,9 +559,9 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
ImGui::TableSetupColumn("Color16", 0, 3);
ImGui::TableHeadersRow();
{
auto const&pal = m_model.pal();
auto const &pal = m_model.pal();
if (pal.pages.size() > m_model.palettePage()) {
for (auto i = 0u; auto const&c: pal.pages[m_model.palettePage()].colors) {
for (auto i = 0u; auto const &c: pal.pages[m_model.palettePage()].colors) {
ImGui::TableNextRow();
ImGui::PushID(static_cast<int>(i));
// Column: color idx
@ -580,7 +583,7 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
auto const ic = ImGui::GetColorU32({redf(c), greenf(c), bluef(c), 1});
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ic);
ImGui::TableNextColumn();
auto const&name = i < pal.colorNames.size() ? pal.colorNames[i].c_str() : "";
auto const &name = i < pal.colorNames.size() ? pal.colorNames[i].c_str() : "";
ImGui::Text("%s", name);
ImGui::TableNextColumn();
ImGui::Text("(%02d, %02d, %02d)", red16(c), green16(c), blue16(c));
@ -594,7 +597,7 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
}
ox::Error TileSheetEditorImGui::updateActiveSubsheet(
ox::StringView const&name, int const cols, int const rows) noexcept {
ox::StringViewCR name, int const cols, int const rows) noexcept {
return m_model.updateSubsheet(m_model.activeSubSheetIdx(), name, cols, rows);
}

View File

@ -82,7 +82,7 @@ class TileSheetEditorImGui: public studio::Editor {
void drawSubsheetSelector(TileSheet::SubSheet&, TileSheet::SubSheetIdx &path);
[[nodiscard]]
static ox::Vec2 clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept;
static ox::Vec2 clickPos(ImVec2 const &winPos, ox::Vec2 clickPos) noexcept;
protected:
ox::Error saveItem() noexcept override;
@ -94,11 +94,11 @@ class TileSheetEditorImGui: public studio::Editor {
ox::Error exportSubsheetToPng(int scale) const noexcept;
void drawTileSheet(ox::Vec2 const&fbSize) noexcept;
void drawTileSheet(ox::Vec2 const &fbSize) noexcept;
void drawPaletteMenu() noexcept;
ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept;
ox::Error updateActiveSubsheet(ox::StringViewCR name, int cols, int rows) noexcept;
void setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept;