From 5ff7eaa52623247bdd3e36b7f936918e4857d5b5 Mon Sep 17 00:00:00 2001 From: scawful Date: Tue, 31 Dec 2024 12:50:14 -0500 Subject: [PATCH] Add yaze_config.h for version management and update version check logic --- CMakeLists.txt | 1 + src/app/app.cmake | 56 ++++----- src/app/core/common.cc | 12 -- src/app/core/common.h | 9 +- src/app/editor/editor_manager.cc | 202 ++++++++++++++----------------- src/app/editor/editor_manager.h | 7 ++ src/yaze.cc | 16 ++- src/yaze_config.h.in | 4 + 8 files changed, 147 insertions(+), 160 deletions(-) create mode 100644 src/yaze_config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4128e3a9..05d73aa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.10) project(yaze VERSION 0.2.0 DESCRIPTION "Yet Another Zelda3 Editor" LANGUAGES CXX) +configure_file(src/yaze_config.h.in yaze_config.h) # Build Flags set(YAZE_BUILD_APP ON) diff --git a/src/app/app.cmake b/src/app/app.cmake index db1def10..b93f3aa7 100644 --- a/src/app/app.cmake +++ b/src/app/app.cmake @@ -5,35 +5,34 @@ include(app/gui/gui.cmake) include(app/zelda3/zelda3.cmake) if (APPLE) -add_executable( - yaze - MACOSX_BUNDLE - app/main.cc - app/rom.cc - ${YAZE_APP_EMU_SRC} - ${YAZE_APP_CORE_SRC} - ${YAZE_APP_EDITOR_SRC} - ${YAZE_APP_GFX_SRC} - ${YAZE_APP_ZELDA3_SRC} - ${YAZE_GUI_SRC} - ${IMGUI_SRC} - - # Bundled Resources - ${YAZE_RESOURCE_FILES} -) + add_executable( + yaze + MACOSX_BUNDLE + app/main.cc + app/rom.cc + ${YAZE_APP_EMU_SRC} + ${YAZE_APP_CORE_SRC} + ${YAZE_APP_EDITOR_SRC} + ${YAZE_APP_GFX_SRC} + ${YAZE_APP_ZELDA3_SRC} + ${YAZE_GUI_SRC} + ${IMGUI_SRC} + # Bundled Resources + ${YAZE_RESOURCE_FILES} + ) else() -add_executable( - yaze - app/main.cc - app/rom.cc - ${YAZE_APP_EMU_SRC} - ${YAZE_APP_CORE_SRC} - ${YAZE_APP_EDITOR_SRC} - ${YAZE_APP_GFX_SRC} - ${YAZE_APP_ZELDA3_SRC} - ${YAZE_GUI_SRC} - ${IMGUI_SRC} -) + add_executable( + yaze + app/main.cc + app/rom.cc + ${YAZE_APP_EMU_SRC} + ${YAZE_APP_CORE_SRC} + ${YAZE_APP_EDITOR_SRC} + ${YAZE_APP_GFX_SRC} + ${YAZE_APP_ZELDA3_SRC} + ${YAZE_GUI_SRC} + ${IMGUI_SRC} + ) endif() target_include_directories( @@ -46,6 +45,7 @@ target_include_directories( ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine ${PNG_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} ) target_link_libraries( diff --git a/src/app/core/common.cc b/src/app/core/common.cc index 626f0e6f..18e28907 100644 --- a/src/app/core/common.cc +++ b/src/app/core/common.cc @@ -361,17 +361,5 @@ void ApplyBpsPatch(const std::vector &source, } } -absl::StatusOr CheckVersion(const char *version) { - std::string version_string = version; - if (version_string != kYazeVersion) { - std::string message = - absl::StrFormat("Yaze version mismatch: expected %s, got %s", - kYazeVersion.data(), version_string.c_str()); - return absl::InvalidArgumentError(message); - } - return version_string; -} - } // namespace core - } // namespace yaze diff --git a/src/app/core/common.h b/src/app/core/common.h index e0c2c018..fa78aeee 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -313,12 +313,7 @@ void ApplyBpsPatch(const std::vector &source, const std::vector &patch, std::vector &target); -constexpr std::string_view kYazeVersion = "0.2.1"; - -absl::StatusOr CheckVersion(const char *version); - -} // namespace core - -} // namespace yaze +} // namespace core +} // namespace yaze #endif diff --git a/src/app/editor/editor_manager.cc b/src/app/editor/editor_manager.cc index ccdc9b0f..7b813d72 100644 --- a/src/app/editor/editor_manager.cc +++ b/src/app/editor/editor_manager.cc @@ -46,7 +46,7 @@ bool IsEditorActive(Editor *editor, std::vector &active_editors) { active_editors.end(); } -} // namespace +} // namespace void EditorManager::Initialize(std::string filename) { if (!filename.empty()) { @@ -77,8 +77,7 @@ absl::Status EditorManager::Update() { void EditorManager::ManageActiveEditors() { // Show popup pane to select an editor to add static bool show_add_editor = false; - if (show_add_editor) - OpenPopup("AddEditor"); + if (show_add_editor) OpenPopup("AddEditor"); if (BeginPopup("AddEditor", ImGuiWindowFlags_AlwaysAutoResize)) { if (MenuItem("Overworld", nullptr, false, @@ -143,85 +142,85 @@ void EditorManager::ManageActiveEditors() { for (auto editor : active_editors_) { bool open = true; switch (editor->type()) { - case EditorType::kOverworld: - if (overworld_editor_.jump_to_tab() == -1) { - if (BeginTabItem("Overworld", &open)) { - current_editor_ = &overworld_editor_; - status_ = overworld_editor_.Update(); + case EditorType::kOverworld: + if (overworld_editor_.jump_to_tab() == -1) { + if (BeginTabItem("Overworld", &open)) { + current_editor_ = &overworld_editor_; + status_ = overworld_editor_.Update(); + EndTabItem(); + } + } + break; + case EditorType::kDungeon: + if (BeginTabItem("Dungeon", &open)) { + current_editor_ = &dungeon_editor_; + status_ = dungeon_editor_.Update(); + if (overworld_editor_.jump_to_tab() != -1) { + dungeon_editor_.add_room(overworld_editor_.jump_to_tab()); + overworld_editor_.jump_to_tab_ = -1; + } EndTabItem(); } - } - break; - case EditorType::kDungeon: - if (BeginTabItem("Dungeon", &open)) { - current_editor_ = &dungeon_editor_; - status_ = dungeon_editor_.Update(); - if (overworld_editor_.jump_to_tab() != -1) { - dungeon_editor_.add_room(overworld_editor_.jump_to_tab()); - overworld_editor_.jump_to_tab_ = -1; + break; + case EditorType::kGraphics: + if (BeginTabItem("Graphics", &open)) { + current_editor_ = &graphics_editor_; + status_ = graphics_editor_.Update(); + EndTabItem(); } - EndTabItem(); - } - break; - case EditorType::kGraphics: - if (BeginTabItem("Graphics", &open)) { - current_editor_ = &graphics_editor_; - status_ = graphics_editor_.Update(); - EndTabItem(); - } - break; - case EditorType::kMusic: - if (BeginTabItem("Music", &open)) { - current_editor_ = &music_editor_; + break; + case EditorType::kMusic: + if (BeginTabItem("Music", &open)) { + current_editor_ = &music_editor_; - status_ = music_editor_.Update(); - EndTabItem(); - } - break; - case EditorType::kPalette: - if (BeginTabItem("Palette", &open)) { - current_editor_ = &palette_editor_; - status_ = palette_editor_.Update(); - EndTabItem(); - } - break; - case EditorType::kScreen: - if (BeginTabItem("Screen", &open)) { - current_editor_ = &screen_editor_; - status_ = screen_editor_.Update(); - EndTabItem(); - } - break; - case EditorType::kSprite: - if (BeginTabItem("Sprite", &open)) { - current_editor_ = &sprite_editor_; - status_ = sprite_editor_.Update(); - EndTabItem(); - } - break; - case EditorType::kAssembly: - if (BeginTabItem("Code", &open)) { - current_editor_ = &assembly_editor_; - assembly_editor_.UpdateCodeView(); - EndTabItem(); - } - break; - case EditorType::kSettings: - if (BeginTabItem("Settings", &open)) { - current_editor_ = &settings_editor_; - status_ = settings_editor_.Update(); - EndTabItem(); - } - break; - case EditorType::kMessage: - if (BeginTabItem("Message", &open)) { - current_editor_ = &message_editor_; - status_ = message_editor_.Update(); - EndTabItem(); - } - break; - default: - break; + status_ = music_editor_.Update(); + EndTabItem(); + } + break; + case EditorType::kPalette: + if (BeginTabItem("Palette", &open)) { + current_editor_ = &palette_editor_; + status_ = palette_editor_.Update(); + EndTabItem(); + } + break; + case EditorType::kScreen: + if (BeginTabItem("Screen", &open)) { + current_editor_ = &screen_editor_; + status_ = screen_editor_.Update(); + EndTabItem(); + } + break; + case EditorType::kSprite: + if (BeginTabItem("Sprite", &open)) { + current_editor_ = &sprite_editor_; + status_ = sprite_editor_.Update(); + EndTabItem(); + } + break; + case EditorType::kAssembly: + if (BeginTabItem("Code", &open)) { + current_editor_ = &assembly_editor_; + assembly_editor_.UpdateCodeView(); + EndTabItem(); + } + break; + case EditorType::kSettings: + if (BeginTabItem("Settings", &open)) { + current_editor_ = &settings_editor_; + status_ = settings_editor_.Update(); + EndTabItem(); + } + break; + case EditorType::kMessage: + if (BeginTabItem("Message", &open)) { + current_editor_ = &message_editor_; + status_ = message_editor_.Update(); + EndTabItem(); + } + break; + default: + break; } if (!open) { active_editors_.erase( @@ -326,10 +325,9 @@ void EditorManager::DrawStatusPopup() { } void EditorManager::DrawAboutPopup() { - if (about_) - OpenPopup("About"); + if (about_) OpenPopup("About"); if (BeginPopupModal("About", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - Text("Yet Another Zelda3 Editor - v%s", core::kYazeVersion.data()); + Text("Yet Another Zelda3 Editor - v%s", version_.c_str()); Text("Written by: scawful"); Spacing(); Text("Special Thanks: Zarby89, JaredBrian"); @@ -344,8 +342,7 @@ void EditorManager::DrawAboutPopup() { } void EditorManager::DrawInfoPopup() { - if (rom_info_) - OpenPopup("ROM Information"); + if (rom_info_) OpenPopup("ROM Information"); if (BeginPopupModal("ROM Information", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { Text("Title: %s", rom()->title().c_str()); @@ -372,7 +369,7 @@ void EditorManager::DrawYazeMenu() { show_display_settings = !show_display_settings; } PopStyleColor(); - Text("yaze v%s", core::kYazeVersion.data()); + Text("yaze v%s", version_.c_str()); EndMenuBar(); } @@ -540,14 +537,10 @@ void EditorManager::DrawYazeMenuBar() { static bool show_palette_editor = false; static bool show_emulator = false; - if (show_imgui_demo) - ShowDemoWindow(); - if (show_imgui_metrics) - ShowMetricsWindow(&show_imgui_metrics); - if (show_memory_editor) - memory_editor_.Update(show_memory_editor); - if (show_asm_editor) - assembly_editor_.Update(show_asm_editor); + if (show_imgui_demo) ShowDemoWindow(); + if (show_imgui_metrics) ShowMetricsWindow(&show_imgui_metrics); + if (show_memory_editor) memory_editor_.Update(show_memory_editor); + if (show_asm_editor) assembly_editor_.Update(show_asm_editor); if (show_emulator) { Begin("Emulator", &show_emulator, ImGuiWindowFlags_MenuBar); @@ -592,20 +585,15 @@ void EditorManager::DrawYazeMenuBar() { static bool open_supported_features = false; static bool open_manage_project = false; if (BeginMenu("Help")) { - if (MenuItem("How to open a ROM")) - open_rom_help = true; - if (MenuItem("Supported Features")) - open_supported_features = true; - if (MenuItem("How to manage a project")) - open_manage_project = true; + if (MenuItem("How to open a ROM")) open_rom_help = true; + if (MenuItem("Supported Features")) open_supported_features = true; + if (MenuItem("How to manage a project")) open_manage_project = true; - if (MenuItem("About", "F1")) - about_ = true; + if (MenuItem("About", "F1")) about_ = true; EndMenu(); } - if (open_supported_features) - OpenPopup("Supported Features"); + if (open_supported_features) OpenPopup("Supported Features"); if (BeginPopupModal("Supported Features", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { Text("Overworld"); @@ -638,8 +626,7 @@ void EditorManager::DrawYazeMenuBar() { EndPopup(); } - if (open_rom_help) - OpenPopup("Open a ROM"); + if (open_rom_help) OpenPopup("Open a ROM"); if (BeginPopupModal("Open a ROM", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { Text("File -> Open"); @@ -656,8 +643,7 @@ void EditorManager::DrawYazeMenuBar() { EndPopup(); } - if (open_manage_project) - OpenPopup("Manage Project"); + if (open_manage_project) OpenPopup("Manage Project"); if (BeginPopupModal("Manage Project", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { Text("Project Menu"); @@ -740,5 +726,5 @@ absl::Status EditorManager::OpenProject() { return absl::OkStatus(); } -} // namespace editor -} // namespace yaze +} // namespace editor +} // namespace yaze diff --git a/src/app/editor/editor_manager.h b/src/app/editor/editor_manager.h index a62f74d1..5dcaaa51 100644 --- a/src/app/editor/editor_manager.h +++ b/src/app/editor/editor_manager.h @@ -19,6 +19,7 @@ #include "app/emu/emulator.h" #include "app/gui/input.h" #include "app/rom.h" +#include "yaze_config.h" namespace yaze { namespace editor { @@ -45,6 +46,10 @@ class EditorManager : public SharedRom, public core::ExperimentFlags { active_editors_.push_back(&sprite_editor_); active_editors_.push_back(&message_editor_); active_editors_.push_back(&screen_editor_); + std::stringstream ss; + ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "." + << YAZE_VERSION_PATCH; + ss >> version_; } void Initialize(std::string filename = ""); @@ -78,6 +83,8 @@ class EditorManager : public SharedRom, public core::ExperimentFlags { bool show_status_ = false; bool rom_assets_loaded_ = false; + std::string version_ = ""; + absl::Status status_; emu::Emulator emulator_; std::vector active_editors_; diff --git a/src/yaze.cc b/src/yaze.cc index 49a2a0a6..08d10b15 100644 --- a/src/yaze.cc +++ b/src/yaze.cc @@ -1,19 +1,25 @@ #include "yaze.h" #include +#include #include "app/rom.h" #include "app/zelda3/overworld/overworld.h" #include "dungeon.h" +#include "yaze_config.h" void yaze_check_version(const char *version) { - std::cout << "Yaze version: " << version << std::endl; - auto version_check = yaze::core::CheckVersion(version); - if (!version_check.ok()) { - std::cout << version_check.status().message() << std::endl; + std::string current_version; + std::stringstream ss; + ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "." + << YAZE_VERSION_PATCH; + ss >> current_version; + + if (version != current_version) { + std::cout << "Yaze version mismatch: expected " << current_version + << ", got " << version << std::endl; exit(1); } - return; } int yaze_init(yaze_editor_context *yaze_ctx) { diff --git a/src/yaze_config.h.in b/src/yaze_config.h.in new file mode 100644 index 00000000..511af1a4 --- /dev/null +++ b/src/yaze_config.h.in @@ -0,0 +1,4 @@ +// yaze config file +#define YAZE_VERSION_MAJOR @yaze_VERSION_MAJOR@ +#define YAZE_VERSION_MINOR @yaze_VERSION_MINOR@ +#define YAZE_VERSION_PATCH @yaze_VERSION_PATCH@