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