Add scad_format for CGX, COL, OBJ files

This commit is contained in:
scawful
2023-08-09 00:19:07 -04:00
parent a3f68b70b4
commit c336c60066
12 changed files with 485 additions and 91 deletions

View File

@@ -11,6 +11,8 @@
#include "app/editor/palette_editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/compression.h"
#include "app/gfx/scad_format.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/gui/canvas.h"
#include "app/gui/input.h"
@@ -114,7 +116,10 @@ absl::Status GraphicsEditor::DrawCgxImport() {
strncpy(cgx_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(cgx_file_name_));
status_ = temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false);
// status_ = temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false);
status_ = gfx::DecodeCgxFile(cgx_file_path_, cgx_data_, extra_cgx_data_,
decoded_cgx_);
auto cgx_header = gfx::ExtractCgxHeader(extra_cgx_data_);
is_open_ = true;
cgx_loaded_ = true;
});
@@ -122,17 +127,69 @@ absl::Status GraphicsEditor::DrawCgxImport() {
[this]() { ImGui::SetClipboardText(cgx_file_path_); });
core::ButtonPipe("Decompress CGX Data", [this]() {
/*
cgx_viewer_.LoadCgx(temp_rom_);
auto all_tiles_data = cgx_viewer_.GetCgxData();
cgx_bitmap_.Create(core::kTilesheetWidth, 8192, core::kTilesheetDepth,
all_tiles_data.data(), all_tiles_data.size());
*/
// cgx_surface_ = gfx::CreateCgxPreviewImage(current_palette_index_,
// cgx_data_,
// extra_cgx_data_, decoded_col_);
// cgx_bitmap_.CreateFromSurface(cgx_surface_);
cgx_bitmap_.Create(0x80, 0x200, 8, decoded_cgx_);
if (col_file_) {
cgx_bitmap_.ApplyPalette(col_file_palette_);
// cgx_bitmap_.ApplyPalette(col_file_palette_);
cgx_bitmap_.ApplyPalette(decoded_col_);
rom_.RenderBitmap(&cgx_bitmap_);
}
});
CLEAR_AND_RETURN_STATUS(status_)
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawPaletteControls() {
gui::TextWithSeparators("COL Import");
ImGui::InputText("##ColFile", col_file_name_, sizeof(col_file_name_));
ImGui::SameLine();
core::FileDialogPipeline(
"ImportColKey", ".COL,.col,.BAK,.bak\0", "Open COL", [this]() {
strncpy(col_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(col_file_path_));
strncpy(col_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(col_file_name_));
status_ = temp_rom_.LoadFromFile(col_file_path_,
/*z3_load=*/false);
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
if (col_file_palette_group_.size() != 0) {
col_file_palette_group_.Clear();
}
col_file_palette_group_ = gfx::CreatePaletteGroupFromColFile(col_data_);
col_file_palette_ = gfx::SNESPalette(col_data_);
// gigaleak dev format based code
decoded_col_ = gfx::DecodeColFile(col_file_path_);
col_file_ = true;
is_open_ = true;
});
core::ButtonPipe("Copy COL Path",
[this]() { ImGui::SetClipboardText(col_file_path_); });
if (rom_.isLoaded()) {
gui::TextWithSeparators("ROM Palette");
gui::InputHex("Palette Index", &current_palette_index_);
ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys,
IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
}
if (col_file_palette_.size() != 0) {
core::SelectablePalettePipeline(current_palette_index_, refresh_graphics_,
col_file_palette_);
}
return absl::OkStatus();
}
@@ -167,49 +224,6 @@ absl::Status GraphicsEditor::DrawFileImport() {
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawPaletteControls() {
gui::TextWithSeparators("COL Import");
ImGui::InputText("##ColFile", col_file_name_, sizeof(col_file_name_));
ImGui::SameLine();
core::FileDialogPipeline(
"ImportColKey", ".COL,.col,.BAK,.bak\0", "Open COL", [this]() {
strncpy(col_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(col_file_path_));
strncpy(col_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(col_file_name_));
status_ = temp_rom_.LoadFromFile(col_file_path_,
/*z3_load=*/false);
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
if (col_file_palette_group_.size() != 0) {
col_file_palette_group_.Clear();
}
col_file_palette_group_ = gfx::CreatePaletteGroupFromColFile(col_data_);
col_file_palette_ = gfx::SNESPalette(col_data_);
col_file_ = true;
is_open_ = true;
});
core::ButtonPipe("Copy COL Path",
[this]() { ImGui::SetClipboardText(col_file_path_); });
if (rom_.isLoaded()) {
gui::TextWithSeparators("ROM Palette");
gui::InputHex("Palette Index", &current_palette_index_);
ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys,
IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
}
if (col_file_palette_.size() != 0) {
core::SelectablePalettePipeline(current_palette_index_, refresh_graphics_,
col_file_palette_);
}
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawClipboardImport() {
gui::TextWithSeparators("Clipboard Import");
core::ButtonPipe("Paste from Clipboard", [this]() {

View File

@@ -111,6 +111,13 @@ class GraphicsEditor {
Bytes import_data_;
Bytes graphics_buffer_;
std::vector<uint8_t> decoded_cgx_;
std::vector<uint8_t> cgx_data_;
std::vector<uint8_t> extra_cgx_data_;
std::vector<SDL_Color> decoded_col_;
SDL_Surface* cgx_surface_;
MemoryEditor cgx_memory_editor_;
MemoryEditor col_memory_editor_;

View File

@@ -36,14 +36,14 @@ namespace editor {
absl::Status PaletteEditor::Update() {
for (int i = 0; i < kNumPalettes; ++i) {
if (ImGui::TreeNode(kPaletteCategoryNames[i].data())) {
DrawPaletteGroup(i);
RETURN_IF_ERROR(DrawPaletteGroup(i))
ImGui::TreePop();
}
}
return absl::OkStatus();
}
void PaletteEditor::DrawPaletteGroup(int i) {
absl::Status PaletteEditor::DrawPaletteGroup(int i) {
auto size = rom_.GetPaletteGroup(kPaletteGroupNames[i].data()).size();
auto palettes = rom_.GetPaletteGroup(kPaletteGroupNames[i].data());
for (int j = 0; j < size; j++) {
@@ -73,8 +73,8 @@ void PaletteEditor::DrawPaletteGroup(int i) {
if (ImGui::ColorEdit4(
"Edit Color", col.data(),
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha)) {
rom_.UpdatePaletteColor(kPaletteGroupNames[i].data(), j, n,
palette[n]);
RETURN_IF_ERROR(rom_.UpdatePaletteColor(kPaletteGroupNames[i].data(),
j, n, palette[n]))
}
if (ImGui::Button("Copy as..", ImVec2(-1, 0))) ImGui::OpenPopup("Copy");
if (ImGui::BeginPopup("Copy")) {
@@ -99,6 +99,7 @@ void PaletteEditor::DrawPaletteGroup(int i) {
ImGui::PopID();
}
}
return absl::OkStatus();
}
void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {

View File

@@ -36,7 +36,7 @@ class PaletteEditor {
auto SetupROM(ROM& rom) { rom_ = rom; }
private:
void DrawPaletteGroup(int i);
absl::Status DrawPaletteGroup(int i);
ImVec4 saved_palette_[256] = {};
ImVec4 current_color_;