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

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

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 yaze

View File

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

View File

@@ -46,7 +46,7 @@ bool IsEditorActive(Editor *editor, std::vector<Editor *> &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

View File

@@ -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<Editor *> active_editors_;

View File

@@ -1,19 +1,25 @@
#include "yaze.h"
#include <iostream>
#include <sstream>
#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) {

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@