Add yaze_config.h for version management and update version check logic

This commit is contained in:
scawful
2024-12-31 12:50:14 -05:00
parent bac4660bac
commit 5ff7eaa526
8 changed files with 147 additions and 160 deletions

View File

@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.10)
project(yaze VERSION 0.2.0 project(yaze VERSION 0.2.0
DESCRIPTION "Yet Another Zelda3 Editor" DESCRIPTION "Yet Another Zelda3 Editor"
LANGUAGES CXX) LANGUAGES CXX)
configure_file(src/yaze_config.h.in yaze_config.h)
# Build Flags # Build Flags
set(YAZE_BUILD_APP ON) set(YAZE_BUILD_APP ON)

View File

@@ -17,7 +17,6 @@ add_executable(
${YAZE_APP_ZELDA3_SRC} ${YAZE_APP_ZELDA3_SRC}
${YAZE_GUI_SRC} ${YAZE_GUI_SRC}
${IMGUI_SRC} ${IMGUI_SRC}
# Bundled Resources # Bundled Resources
${YAZE_RESOURCE_FILES} ${YAZE_RESOURCE_FILES}
) )
@@ -46,6 +45,7 @@ target_include_directories(
${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine
${PNG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR}
${PROJECT_BINARY_DIR}
) )
target_link_libraries( target_link_libraries(

View File

@@ -361,17 +361,5 @@ void ApplyBpsPatch(const std::vector<uint8_t> &source,
} }
} }
absl::StatusOr<std::string> 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 core
} // namespace yaze } // namespace yaze

View File

@@ -313,12 +313,7 @@ void ApplyBpsPatch(const std::vector<uint8_t> &source,
const std::vector<uint8_t> &patch, const std::vector<uint8_t> &patch,
std::vector<uint8_t> &target); std::vector<uint8_t> &target);
constexpr std::string_view kYazeVersion = "0.2.1";
absl::StatusOr<std::string> CheckVersion(const char *version);
} // namespace core } // namespace core
} // namespace yaze } // namespace yaze
#endif #endif

View File

@@ -77,8 +77,7 @@ absl::Status EditorManager::Update() {
void EditorManager::ManageActiveEditors() { void EditorManager::ManageActiveEditors() {
// Show popup pane to select an editor to add // Show popup pane to select an editor to add
static bool show_add_editor = false; static bool show_add_editor = false;
if (show_add_editor) if (show_add_editor) OpenPopup("AddEditor");
OpenPopup("AddEditor");
if (BeginPopup("AddEditor", ImGuiWindowFlags_AlwaysAutoResize)) { if (BeginPopup("AddEditor", ImGuiWindowFlags_AlwaysAutoResize)) {
if (MenuItem("Overworld", nullptr, false, if (MenuItem("Overworld", nullptr, false,
@@ -326,10 +325,9 @@ void EditorManager::DrawStatusPopup() {
} }
void EditorManager::DrawAboutPopup() { void EditorManager::DrawAboutPopup() {
if (about_) if (about_) OpenPopup("About");
OpenPopup("About");
if (BeginPopupModal("About", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { 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"); Text("Written by: scawful");
Spacing(); Spacing();
Text("Special Thanks: Zarby89, JaredBrian"); Text("Special Thanks: Zarby89, JaredBrian");
@@ -344,8 +342,7 @@ void EditorManager::DrawAboutPopup() {
} }
void EditorManager::DrawInfoPopup() { void EditorManager::DrawInfoPopup() {
if (rom_info_) if (rom_info_) OpenPopup("ROM Information");
OpenPopup("ROM Information");
if (BeginPopupModal("ROM Information", nullptr, if (BeginPopupModal("ROM Information", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_AlwaysAutoResize)) {
Text("Title: %s", rom()->title().c_str()); Text("Title: %s", rom()->title().c_str());
@@ -372,7 +369,7 @@ void EditorManager::DrawYazeMenu() {
show_display_settings = !show_display_settings; show_display_settings = !show_display_settings;
} }
PopStyleColor(); PopStyleColor();
Text("yaze v%s", core::kYazeVersion.data()); Text("yaze v%s", version_.c_str());
EndMenuBar(); EndMenuBar();
} }
@@ -540,14 +537,10 @@ void EditorManager::DrawYazeMenuBar() {
static bool show_palette_editor = false; static bool show_palette_editor = false;
static bool show_emulator = false; static bool show_emulator = false;
if (show_imgui_demo) if (show_imgui_demo) ShowDemoWindow();
ShowDemoWindow(); if (show_imgui_metrics) ShowMetricsWindow(&show_imgui_metrics);
if (show_imgui_metrics) if (show_memory_editor) memory_editor_.Update(show_memory_editor);
ShowMetricsWindow(&show_imgui_metrics); if (show_asm_editor) assembly_editor_.Update(show_asm_editor);
if (show_memory_editor)
memory_editor_.Update(show_memory_editor);
if (show_asm_editor)
assembly_editor_.Update(show_asm_editor);
if (show_emulator) { if (show_emulator) {
Begin("Emulator", &show_emulator, ImGuiWindowFlags_MenuBar); Begin("Emulator", &show_emulator, ImGuiWindowFlags_MenuBar);
@@ -592,20 +585,15 @@ void EditorManager::DrawYazeMenuBar() {
static bool open_supported_features = false; static bool open_supported_features = false;
static bool open_manage_project = false; static bool open_manage_project = false;
if (BeginMenu("Help")) { if (BeginMenu("Help")) {
if (MenuItem("How to open a ROM")) if (MenuItem("How to open a ROM")) open_rom_help = true;
open_rom_help = true; if (MenuItem("Supported Features")) open_supported_features = true;
if (MenuItem("Supported Features")) if (MenuItem("How to manage a project")) open_manage_project = true;
open_supported_features = true;
if (MenuItem("How to manage a project"))
open_manage_project = true;
if (MenuItem("About", "F1")) if (MenuItem("About", "F1")) about_ = true;
about_ = true;
EndMenu(); EndMenu();
} }
if (open_supported_features) if (open_supported_features) OpenPopup("Supported Features");
OpenPopup("Supported Features");
if (BeginPopupModal("Supported Features", nullptr, if (BeginPopupModal("Supported Features", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_AlwaysAutoResize)) {
Text("Overworld"); Text("Overworld");
@@ -638,8 +626,7 @@ void EditorManager::DrawYazeMenuBar() {
EndPopup(); EndPopup();
} }
if (open_rom_help) if (open_rom_help) OpenPopup("Open a ROM");
OpenPopup("Open a ROM");
if (BeginPopupModal("Open a ROM", nullptr, if (BeginPopupModal("Open a ROM", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_AlwaysAutoResize)) {
Text("File -> Open"); Text("File -> Open");
@@ -656,8 +643,7 @@ void EditorManager::DrawYazeMenuBar() {
EndPopup(); EndPopup();
} }
if (open_manage_project) if (open_manage_project) OpenPopup("Manage Project");
OpenPopup("Manage Project");
if (BeginPopupModal("Manage Project", nullptr, if (BeginPopupModal("Manage Project", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_AlwaysAutoResize)) {
Text("Project Menu"); Text("Project Menu");

View File

@@ -19,6 +19,7 @@
#include "app/emu/emulator.h" #include "app/emu/emulator.h"
#include "app/gui/input.h" #include "app/gui/input.h"
#include "app/rom.h" #include "app/rom.h"
#include "yaze_config.h"
namespace yaze { namespace yaze {
namespace editor { namespace editor {
@@ -45,6 +46,10 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
active_editors_.push_back(&sprite_editor_); active_editors_.push_back(&sprite_editor_);
active_editors_.push_back(&message_editor_); active_editors_.push_back(&message_editor_);
active_editors_.push_back(&screen_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 = ""); void Initialize(std::string filename = "");
@@ -78,6 +83,8 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
bool show_status_ = false; bool show_status_ = false;
bool rom_assets_loaded_ = false; bool rom_assets_loaded_ = false;
std::string version_ = "";
absl::Status status_; absl::Status status_;
emu::Emulator emulator_; emu::Emulator emulator_;
std::vector<Editor *> active_editors_; std::vector<Editor *> active_editors_;

View File

@@ -1,19 +1,25 @@
#include "yaze.h" #include "yaze.h"
#include <iostream> #include <iostream>
#include <sstream>
#include "app/rom.h" #include "app/rom.h"
#include "app/zelda3/overworld/overworld.h" #include "app/zelda3/overworld/overworld.h"
#include "dungeon.h" #include "dungeon.h"
#include "yaze_config.h"
void yaze_check_version(const char *version) { void yaze_check_version(const char *version) {
std::cout << "Yaze version: " << version << std::endl; std::string current_version;
auto version_check = yaze::core::CheckVersion(version); std::stringstream ss;
if (!version_check.ok()) { ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "."
std::cout << version_check.status().message() << std::endl; << YAZE_VERSION_PATCH;
ss >> current_version;
if (version != current_version) {
std::cout << "Yaze version mismatch: expected " << current_version
<< ", got " << version << std::endl;
exit(1); exit(1);
} }
return;
} }
int yaze_init(yaze_editor_context *yaze_ctx) { int yaze_init(yaze_editor_context *yaze_ctx) {

4
src/yaze_config.h.in Normal file
View File

@@ -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@