Add GraphicsEditor class

Super donkey proto graphics import experiment

removed snes_spc and asar_static because of macOS M1 build issues.

music player using snes_spc disabled

included macOS build configuration as it currently is.
This commit is contained in:
scawful
2023-07-08 09:03:27 -04:00
parent 3ada9988aa
commit 931560cfb1
16 changed files with 267 additions and 92 deletions

6
docs/macos-build.md Normal file
View File

@@ -0,0 +1,6 @@
Taking note of this because of how stupid it is.
Clang 15.0.1 x86_64-apple-darrwin22.5.0
SDL2 Source v2.26.5
Removed snes_spc
Removed asar_static

View File

@@ -9,6 +9,7 @@ set(
YAZE_APP_EDITOR_SRC YAZE_APP_EDITOR_SRC
app/editor/assembly_editor.cc app/editor/assembly_editor.cc
app/editor/dungeon_editor.cc app/editor/dungeon_editor.cc
app/editor/graphics_editor.cc
app/editor/master_editor.cc app/editor/master_editor.cc
app/editor/music_editor.cc app/editor/music_editor.cc
app/editor/overworld_editor.cc app/editor/overworld_editor.cc
@@ -54,8 +55,8 @@ add_executable(
${YAZE_APP_GFX_SRC} ${YAZE_APP_GFX_SRC}
${YAZE_APP_ZELDA3_SRC} ${YAZE_APP_ZELDA3_SRC}
${YAZE_GUI_SRC} ${YAZE_GUI_SRC}
${ASAR_STATIC_SRC} # ${ASAR_STATIC_SRC}
${SNES_SPC_SOURCES} # ${SNES_SPC_SOURCES}
${IMGUI_SRC} ${IMGUI_SRC}
) )
@@ -70,8 +71,8 @@ target_include_directories(
${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR}
lib/SDL_mixer/include/ lib/SDL_mixer/include/
${GLEW_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS}
lib/asar/src/asar/ # lib/asar/src/asar/
lib/snes_spc/snes_spc/ # lib/snes_spc/snes_spc/
) )
set(SDL_TARGETS SDL2::SDL2) set(SDL_TARGETS SDL2::SDL2)
@@ -93,8 +94,8 @@ target_link_libraries(
${GLEW_LIBRARIES} ${GLEW_LIBRARIES}
${OPENGL_LIBRARIES} ${OPENGL_LIBRARIES}
${CMAKE_DL_LIBS} ${CMAKE_DL_LIBS}
asar-static # asar-static
snes_spc # snes_spc
ImGui ImGui
) )

View File

@@ -3,7 +3,7 @@
#include <SDL.h> #include <SDL.h>
#include <SDL_mixer.h> #include <SDL_mixer.h>
#include <imgui/backends/imgui_impl_sdl2.h> #include <imgui/backends/imgui_impl_sdl2.h>
#include <imgui/backends/imgui_impl_sdlrenderer.h> #include <imgui/backends/imgui_impl_sdlrenderer2.h>
#include <imgui/imgui.h> #include <imgui/imgui.h>
#include <imgui/imgui_internal.h> #include <imgui/imgui_internal.h>
@@ -138,12 +138,12 @@ void Controller::onLoad() { master_editor_.UpdateScreen(); }
void Controller::doRender() const { void Controller::doRender() const {
SDL_RenderClear(renderer_.get()); SDL_RenderClear(renderer_.get());
ImGui::Render(); ImGui::Render();
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(renderer_.get()); SDL_RenderPresent(renderer_.get());
} }
void Controller::onExit() const { void Controller::onExit() const {
ImGui_ImplSDLRenderer_Shutdown(); ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
SDL_Quit(); SDL_Quit();
@@ -195,7 +195,7 @@ absl::Status Controller::CreateGuiContext() const {
// Initialize ImGui for SDL // Initialize ImGui for SDL
ImGui_ImplSDL2_InitForSDLRenderer(window_.get(), renderer_.get()); ImGui_ImplSDL2_InitForSDLRenderer(window_.get(), renderer_.get());
ImGui_ImplSDLRenderer_Init(renderer_.get()); ImGui_ImplSDLRenderer2_Init(renderer_.get());
// Load available fonts // Load available fonts
const ImGuiIO &io = ImGui::GetIO(); const ImGuiIO &io = ImGui::GetIO();
@@ -218,7 +218,7 @@ absl::Status Controller::CreateGuiContext() const {
gui::ColorsYaze(); gui::ColorsYaze();
// Build a new ImGui frame // Build a new ImGui frame
ImGui_ImplSDLRenderer_NewFrame(); ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame(window_.get()); ImGui_ImplSDL2_NewFrame(window_.get());
return absl::OkStatus(); return absl::OkStatus();

View File

@@ -3,7 +3,7 @@
#include <SDL.h> #include <SDL.h>
#include <imgui/backends/imgui_impl_sdl2.h> #include <imgui/backends/imgui_impl_sdl2.h>
#include <imgui/backends/imgui_impl_sdlrenderer.h> #include <imgui/backends/imgui_impl_sdlrenderer2.h>
#include <imgui/imgui.h> #include <imgui/imgui.h>
#include <imgui/imgui_internal.h> #include <imgui/imgui_internal.h>

View File

@@ -0,0 +1,89 @@
#include "app/editor/graphics_editor.h"
#include <ImGuiFileDialog/ImGuiFileDialog.h>
#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <imgui_memory_editor.h>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/gfx/bitmap.h"
#include "app/gui/canvas.h"
#include "app/gui/input.h"
#include "app/rom.h"
namespace yaze {
namespace app {
namespace editor {
absl::Status GraphicsEditor::Update() {
DrawImport();
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawImport() {
static int offset = 0;
static int size = 0;
static char filePath[256] = "";
ImGui::InputText("File", filePath, sizeof(filePath));
// Open the file dialog when the user clicks the "Browse" button
if (ImGui::Button("Browse")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportDlgKey", "Choose File",
".bin\0", ".");
}
// Draw the file dialog
if (ImGuiFileDialog::Instance()->Display("ImportDlgKey")) {
// If the user made a selection, copy the filename to the filePath buffer
if (ImGuiFileDialog::Instance()->IsOk()) {
strncpy(filePath, ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(filePath));
}
// Close the modal
ImGuiFileDialog::Instance()->Close();
}
gui::InputHex("Offset", &offset);
gui::InputHex("Size ", &size);
if (ImGui::Button("Import")) {
if (strlen(filePath) > 0) {
// Add your importing code here, using filePath and offset as parameters
RETURN_IF_ERROR(DecompressImportData(filePath, offset, size))
} else {
// Show an error message if no file has been selected
ImGui::Text("Please select a file before importing.");
}
}
import_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
import_canvas_.DrawContextMenu();
import_canvas_.DrawBitmap(bitmap_, 2, gfx_loaded_);
import_canvas_.DrawTileSelector(32);
import_canvas_.DrawGrid(32.0f);
import_canvas_.DrawOverlay();
return absl::OkStatus();
}
absl::Status GraphicsEditor::DecompressImportData(char *filePath, int offset,
int size) {
RETURN_IF_ERROR(temp_rom.LoadFromFile(filePath))
ASSIGN_OR_RETURN(import_data_, temp_rom.DecompressGraphics(offset, size))
bitmap_.Create(core::kTilesheetWidth, core::kTilesheetHeight * 0x10,
core::kTilesheetDepth, import_data_.data());
rom_.RenderBitmap(&bitmap_);
gfx_loaded_ = true;
return absl::OkStatus();
}
} // namespace editor
} // namespace app
} // namespace yaze

View File

@@ -0,0 +1,45 @@
#ifndef YAZE_APP_EDITOR_GRAPHICS_EDITOR_H
#define YAZE_APP_EDITOR_GRAPHICS_EDITOR_H
#include <ImGuiFileDialog/ImGuiFileDialog.h>
#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <imgui_memory_editor.h>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/gfx/bitmap.h"
#include "app/gui/canvas.h"
#include "app/gui/input.h"
#include "app/rom.h"
namespace yaze {
namespace app {
namespace editor {
class GraphicsEditor {
public:
absl::Status Update();
void SetupROM(ROM &rom) { rom_ = rom; }
private:
absl::Status DrawImport();
absl::Status DecompressImportData(char *filePath, int offset, int size);
ROM rom_;
ROM temp_rom;
gfx::Bitmap bitmap_;
gui::Canvas import_canvas_;
Bytes import_data_;
bool gfx_loaded_ = false;
};
} // namespace editor
} // namespace app
} // namespace yaze
#endif // YAZE_APP_EDITOR_GRAPHICS_EDITOR_H

View File

@@ -73,6 +73,7 @@ void MasterEditor::UpdateScreen() {
TAB_BAR("##TabBar") TAB_BAR("##TabBar")
DrawOverworldEditor(); DrawOverworldEditor();
DrawDungeonEditor(); DrawDungeonEditor();
DrawGraphicsEditor();
DrawMusicEditor(); DrawMusicEditor();
DrawSpriteEditor(); DrawSpriteEditor();
DrawScreenEditor(); DrawScreenEditor();
@@ -88,6 +89,7 @@ void MasterEditor::DrawFileDialog() {
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
status_ = rom_.LoadFromFile(filePathName); status_ = rom_.LoadFromFile(filePathName);
overworld_editor_.SetupROM(rom_); overworld_editor_.SetupROM(rom_);
graphics_editor_.SetupROM(rom_);
screen_editor_.SetupROM(rom_); screen_editor_.SetupROM(rom_);
palette_editor_.SetupROM(rom_); palette_editor_.SetupROM(rom_);
music_editor_.SetupROM(rom_); music_editor_.SetupROM(rom_);
@@ -162,6 +164,8 @@ void MasterEditor::DrawYazeMenu() {
} }
void MasterEditor::DrawFileMenu() { void MasterEditor::DrawFileMenu() {
static bool save_as_menu = false;
if (ImGui::BeginMenu("File")) { if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Open", "Ctrl+O")) { if (ImGui::MenuItem("Open", "Ctrl+O")) {
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Open ROM", ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Open ROM",
@@ -169,7 +173,7 @@ void MasterEditor::DrawFileMenu() {
} }
MENU_ITEM2("Save", "Ctrl+S") { status_ = rom_.SaveToFile(backup_rom_); } MENU_ITEM2("Save", "Ctrl+S") { status_ = rom_.SaveToFile(backup_rom_); }
MENU_ITEM("Save As..") {} MENU_ITEM("Save As..") { save_as_menu = true; }
ImGui::Separator(); ImGui::Separator();
@@ -179,6 +183,19 @@ void MasterEditor::DrawFileMenu() {
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (save_as_menu) {
static std::string save_as_filename = "";
ImGui::Begin("Save As..", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::InputText("Filename", &save_as_filename);
if (ImGui::Button("Save", ImVec2(200, 0))) {
status_ = rom_.SaveToFile(backup_rom_, save_as_filename);
}
if (ImGui::Button("Cancel", ImVec2(200, 0))) {
save_as_menu = false;
}
ImGui::End();
}
} }
void MasterEditor::DrawEditMenu() { void MasterEditor::DrawEditMenu() {
@@ -294,6 +311,12 @@ void MasterEditor::DrawDungeonEditor() {
END_TAB_ITEM() END_TAB_ITEM()
} }
void MasterEditor::DrawGraphicsEditor() {
TAB_ITEM("Graphics")
graphics_editor_.Update();
END_TAB_ITEM()
}
void MasterEditor::DrawPaletteEditor() { void MasterEditor::DrawPaletteEditor() {
TAB_ITEM("Palettes") TAB_ITEM("Palettes")
status_ = palette_editor_.Update(); status_ = palette_editor_.Update();

View File

@@ -11,16 +11,17 @@
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/editor/assembly_editor.h" #include "app/editor/assembly_editor.h"
#include "app/editor/dungeon_editor.h" #include "app/editor/dungeon_editor.h"
#include "app/editor/graphics_editor.h"
#include "app/editor/music_editor.h" #include "app/editor/music_editor.h"
#include "app/editor/overworld_editor.h" #include "app/editor/overworld_editor.h"
#include "app/editor/palette_editor.h" #include "app/editor/palette_editor.h"
#include "app/editor/screen_editor.h" #include "app/editor/screen_editor.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/gui/icons.h" #include "app/gui/icons.h"
#include "app/gui/input.h" #include "app/gui/input.h"
#include "app/rom.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -45,6 +46,7 @@ class MasterEditor {
void DrawOverworldEditor(); void DrawOverworldEditor();
void DrawDungeonEditor(); void DrawDungeonEditor();
void DrawGraphicsEditor();
void DrawPaletteEditor(); void DrawPaletteEditor();
void DrawMusicEditor(); void DrawMusicEditor();
void DrawScreenEditor(); void DrawScreenEditor();
@@ -61,6 +63,7 @@ class MasterEditor {
AssemblyEditor assembly_editor_; AssemblyEditor assembly_editor_;
DungeonEditor dungeon_editor_; DungeonEditor dungeon_editor_;
GraphicsEditor graphics_editor_;
OverworldEditor overworld_editor_; OverworldEditor overworld_editor_;
PaletteEditor palette_editor_; PaletteEditor palette_editor_;
ScreenEditor screen_editor_; ScreenEditor screen_editor_;

View File

@@ -8,9 +8,9 @@
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/gui/icons.h" #include "app/gui/icons.h"
#include "app/gui/input.h" #include "app/gui/input.h"
#include "snes_spc/demo/demo_util.h" // #include "snes_spc/demo/demo_util.h"
#include "snes_spc/demo/wave_writer.h" // #include "snes_spc/demo/wave_writer.h"
#include "snes_spc/snes_spc/spc.h" // #include "snes_spc/snes_spc/spc.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -21,46 +21,46 @@ namespace {
#define BUF_SIZE 2048 #define BUF_SIZE 2048
void PlaySPC() { void PlaySPC() {
/* Create emulator and filter */ // /* Create emulator and filter */
SNES_SPC* snes_spc = spc_new(); // SNES_SPC* snes_spc = spc_new();
SPC_Filter* filter = spc_filter_new(); // SPC_Filter* filter = spc_filter_new();
if (!snes_spc || !filter) error("Out of memory"); // if (!snes_spc || !filter) error("Out of memory");
/* Load SPC */ // /* Load SPC */
{ // {
/* Load file into memory */ // /* Load file into memory */
long spc_size; // long spc_size;
void* spc = load_file("assets/music/hyrule_field.spc", &spc_size); // void* spc = load_file("assets/music/hyrule_field.spc", &spc_size);
/* Load SPC data into emulator */ // /* Load SPC data into emulator */
error(spc_load_spc(snes_spc, spc, spc_size)); // error(spc_load_spc(snes_spc, spc, spc_size));
free(spc); /* emulator makes copy of data */ // free(spc); /* emulator makes copy of data */
/* Most SPC files have garbage data in the echo buffer, so clear that */ // /* Most SPC files have garbage data in the echo buffer, so clear that */
spc_clear_echo(snes_spc); // spc_clear_echo(snes_spc);
/* Clear filter before playing */ // /* Clear filter before playing */
spc_filter_clear(filter); // spc_filter_clear(filter);
} // }
/* Record 20 seconds to wave file */ // /* Record 20 seconds to wave file */
wave_open(spc_sample_rate, "out.wav"); // wave_open(spc_sample_rate, "out.wav");
wave_enable_stereo(); // wave_enable_stereo();
while (wave_sample_count() < 30 * spc_sample_rate * 2) { // while (wave_sample_count() < 30 * spc_sample_rate * 2) {
/* Play into buffer */ // /* Play into buffer */
short buf[BUF_SIZE]; // short buf[BUF_SIZE];
error(spc_play(snes_spc, BUF_SIZE, buf)); // error(spc_play(snes_spc, BUF_SIZE, buf));
/* Filter samples */ // /* Filter samples */
spc_filter_run(filter, buf, BUF_SIZE); // spc_filter_run(filter, buf, BUF_SIZE);
wave_write(buf, BUF_SIZE); // wave_write(buf, BUF_SIZE);
} // }
/* Cleanup */ // /* Cleanup */
spc_filter_delete(filter); // spc_filter_delete(filter);
spc_delete(snes_spc); // spc_delete(snes_spc);
wave_close(); // wave_close();
} }
} // namespace } // namespace
@@ -223,10 +223,10 @@ void MusicEditor::DrawToolset() {
if (is_playing) { if (is_playing) {
if (!has_loaded_song) { if (!has_loaded_song) {
PlaySPC(); // PlaySPC();
current_song_ = Mix_LoadMUS("out.wav"); // current_song_ = Mix_LoadMUS("out.wav");
Mix_PlayMusic(current_song_, -1); // Mix_PlayMusic(current_song_, -1);
has_loaded_song = true; // has_loaded_song = true;
} }
// // If there is no music playing // // If there is no music playing

View File

@@ -11,9 +11,9 @@
#include "app/gui/input.h" #include "app/gui/input.h"
#include "app/rom.h" #include "app/rom.h"
#include "app/zelda3/music/tracker.h" #include "app/zelda3/music/tracker.h"
#include "snes_spc/demo/demo_util.h" // #include "snes_spc/demo/demo_util.h"
#include "snes_spc/demo/wave_writer.h" // #include "snes_spc/demo/wave_writer.h"
#include "snes_spc/snes_spc/spc.h" // #include "snes_spc/snes_spc/spc.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -69,7 +69,7 @@ class MusicEditor {
zelda3::Tracker music_tracker_; zelda3::Tracker music_tracker_;
ROM rom_; ROM rom_;
Mix_Music* current_song_ = NULL; // Mix_Music* current_song_ = NULL;
AssemblyEditor assembly_editor_; AssemblyEditor assembly_editor_;
ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit; ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit;

View File

@@ -185,7 +185,7 @@ void OverworldEditor::DrawOverworldSprites() {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void OverworldEditor::DrawOverworldEdits() { void OverworldEditor::DrawOverworldEdits() const {
auto mouse_position = ow_map_canvas_.GetCurrentDrawnTilePosition(); auto mouse_position = ow_map_canvas_.GetCurrentDrawnTilePosition();
auto canvas_size = ow_map_canvas_.GetCanvasSize(); auto canvas_size = ow_map_canvas_.GetCanvasSize();
int x = mouse_position.x / canvas_size.x; int x = mouse_position.x / canvas_size.x;
@@ -379,16 +379,16 @@ absl::Status OverworldEditor::LoadGraphics() {
} }
// Render the sprites for each Overworld map // Render the sprites for each Overworld map
// for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
// for (auto &sprite : overworld_.Sprites(i)) { for (auto &sprite : overworld_.Sprites(i)) {
// int width = sprite.Width(); int width = sprite.Width();
// int height = sprite.Height(); int height = sprite.Height();
// int depth = 0x40; int depth = 0x40;
// auto spr_gfx = sprite.PreviewGraphics().data(); auto spr_gfx = sprite.PreviewGraphics().data();
// sprite_previews_[sprite.id()].Create(width, height, depth, spr_gfx); sprite_previews_[sprite.id()].Create(width, height, depth, spr_gfx);
// sprite_previews_[sprite.id()].ApplyPalette(palette_); sprite_previews_[sprite.id()].ApplyPalette(palette_);
// rom_.RenderBitmap(&(sprite_previews_[sprite.id()])); rom_.RenderBitmap(&(sprite_previews_[sprite.id()]));
// } }
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -58,7 +58,7 @@ class OverworldEditor {
void DrawOverworldEntrances(); void DrawOverworldEntrances();
void DrawOverworldMaps(); void DrawOverworldMaps();
void DrawOverworldSprites(); void DrawOverworldSprites();
void DrawOverworldEdits(); void DrawOverworldEdits() const;
void DrawOverworldCanvas(); void DrawOverworldCanvas();
void DrawTile16Selector(); void DrawTile16Selector();

View File

@@ -47,7 +47,9 @@ struct SNESColor {
void setSNES(uint16_t); void setSNES(uint16_t);
void setTransparent(bool t) { transparent = t; } void setTransparent(bool t) { transparent = t; }
auto RGB() { return ImVec4(rgb.x / 255, rgb.y / 255, rgb.z / 255, rgb.w); } auto RGB() const {
return ImVec4(rgb.x / 255, rgb.y / 255, rgb.z / 255, rgb.w);
}
float* ToFloatArray() { float* ToFloatArray() {
static std::vector<float> colorArray(4); static std::vector<float> colorArray(4);
@@ -123,8 +125,7 @@ struct PaletteGroup {
} }
void AddColor(SNESColor color) { void AddColor(SNESColor color) {
if (size_ == 0) { if (size_ == 0) {
SNESPalette empty_pal; palettes.emplace_back();
palettes.emplace_back(empty_pal);
} }
palettes[0].AddColor(color); palettes[0].AddColor(color);
} }

View File

@@ -1,7 +1,7 @@
#include "rom.h" #include "rom.h"
#include <SDL.h> #include <SDL.h>
#include <asar/src/asar/interface-lib.h> // #include <asar/src/asar/interface-lib.h>
#include <cstddef> #include <cstddef>
#include <cstdio> #include <cstdio>
@@ -817,18 +817,24 @@ void ROM::SaveAllPalettes() {
// ============================================================================ // ============================================================================
absl::Status ROM::SaveToFile(bool backup) { absl::Status ROM::SaveToFile(bool backup, absl::string_view filename) {
if (rom_data_.empty()) { if (rom_data_.empty()) {
return absl::InternalError("ROM data is empty."); return absl::InternalError("ROM data is empty.");
} }
// Check if filename is empty
// If it is, use the filename_ member variable
if (filename == "") {
filename = filename_;
}
// Check if backup is enabled // Check if backup is enabled
if (backup) { if (backup) {
// Create a backup file with timestamp in its name // Create a backup file with timestamp in its name
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
auto now_c = std::chrono::system_clock::to_time_t(now); auto now_c = std::chrono::system_clock::to_time_t(now);
std::string backup_filename = std::string backup_filename =
absl::StrCat(filename_, "_backup_", std::ctime(&now_c)); absl::StrCat(filename, "_backup_", std::ctime(&now_c));
// Remove newline character from ctime() // Remove newline character from ctime()
backup_filename.erase( backup_filename.erase(
@@ -839,17 +845,18 @@ absl::Status ROM::SaveToFile(bool backup) {
std::replace(backup_filename.begin(), backup_filename.end(), ' ', '_'); std::replace(backup_filename.begin(), backup_filename.end(), ' ', '_');
// Now, copy the original file to the backup file // Now, copy the original file to the backup file
std::filesystem::copy(filename_, backup_filename, std::filesystem::copy(filename, backup_filename,
std::filesystem::copy_options::overwrite_existing); std::filesystem::copy_options::overwrite_existing);
} }
// Run the other save functions // Run the other save functions
SaveAllPalettes(); SaveAllPalettes();
std::fstream file(filename_.data(), std::ios::binary | std::ios::out); // Open the file that we know exists for writing
std::fstream file(filename.data(), std::ios::binary | std::ios::out);
if (!file.is_open()) { if (!file.is_open()) {
return absl::InternalError( return absl::InternalError(
absl::StrCat("Could not open ROM file: ", filename_)); absl::StrCat("Could not open ROM file: ", filename));
} }
// Save the data to the file // Save the data to the file
@@ -860,7 +867,7 @@ absl::Status ROM::SaveToFile(bool backup) {
// Check for write errors // Check for write errors
if (!file.good()) { if (!file.good()) {
return absl::InternalError( return absl::InternalError(
absl::StrCat("Error while writing to ROM file: ", filename_)); absl::StrCat("Error while writing to ROM file: ", filename));
} }
return absl::OkStatus(); return absl::OkStatus();
@@ -940,14 +947,14 @@ uint32_t ROM::GetPaletteAddress(const std::string& groupName,
absl::Status ROM::ApplyAssembly(const absl::string_view& filename, absl::Status ROM::ApplyAssembly(const absl::string_view& filename,
size_t patch_size) { size_t patch_size) {
int count = 0; // int count = 0;
auto patch = filename.data(); // auto patch = filename.data();
auto data = (char*)rom_data_.data(); // auto data = (char*)rom_data_.data();
if (int size = size_; !asar_patch(patch, data, patch_size, &size)) { // if (int size = size_; !asar_patch(patch, data, patch_size, &size)) {
auto asar_error = asar_geterrors(&count); // auto asar_error = asar_geterrors(&count);
auto full_error = asar_error->fullerrdata; // auto full_error = asar_error->fullerrdata;
return absl::InternalError(absl::StrCat("ASAR Error: ", full_error)); // return absl::InternalError(absl::StrCat("ASAR Error: ", full_error));
} // }
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -139,7 +139,7 @@ class ROM {
void LoadAllPalettes(); void LoadAllPalettes();
// Save functions // Save functions
absl::Status SaveToFile(bool backup); absl::Status SaveToFile(bool backup, absl::string_view filename = "");
void UpdatePaletteColor(const std::string& groupName, size_t paletteIndex, void UpdatePaletteColor(const std::string& groupName, size_t paletteIndex,
size_t colorIndex, const gfx::SNESColor& newColor); size_t colorIndex, const gfx::SNESColor& newColor);
void SaveAllPalettes(); void SaveAllPalettes();

View File

@@ -19,14 +19,14 @@ add_executable(
../src/app/gfx/snes_tile.cc ../src/app/gfx/snes_tile.cc
../src/app/gfx/snes_palette.cc ../src/app/gfx/snes_palette.cc
../src/app/core/common.cc ../src/app/core/common.cc
${ASAR_STATIC_SRC} # ${ASAR_STATIC_SRC}
) )
target_include_directories( target_include_directories(
yaze_test PUBLIC yaze_test PUBLIC
../src/ ../src/
../src/lib/ ../src/lib/
../src/lib/asar/src/asar/ # ../src/lib/asar/src/asar/
${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR}
) )
@@ -38,8 +38,8 @@ target_link_libraries(
${GLEW_LIBRARIES} ${GLEW_LIBRARIES}
${OPENGL_LIBRARIES} ${OPENGL_LIBRARIES}
${CMAKE_DL_LIBS} ${CMAKE_DL_LIBS}
asar-static # asar-static
snes_spc # snes_spc
ImGui ImGui
gmock_main gmock_main
gmock gmock