Refactor project structure and enhance project management features

- Updated the Rom class to use core::ResourceLabelManager for better namespace clarity.
- Introduced a comprehensive YazeProject structure consolidating project metadata, settings, and resource management.
- Enhanced project management capabilities with methods for creating, opening, saving, and validating projects.
- Implemented support for ZScream project format import and export, improving compatibility with existing projects.
- Added workspace settings and feature flags to streamline user configurations and project setup.
This commit is contained in:
scawful
2025-09-26 18:02:04 -04:00
parent d21df011ae
commit 281fc84499
6 changed files with 1111 additions and 222 deletions

View File

@@ -2,59 +2,190 @@
#define YAZE_APP_CORE_PROJECT_H
#include <algorithm>
#include <chrono>
#include <fstream>
#include <map>
#include <string>
#include <vector>
#include <unordered_map>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/core/features.h"
namespace yaze {
const std::string kRecentFilesFilename = "recent_files.txt";
constexpr char kEndOfProjectFile[] = "EndOfProjectFile";
namespace core {
/**
* @struct Project
* @brief Represents a project in the application.
*
* A project is a collection of files and resources that are used in the
* creation of a Zelda3 hack that can be saved and loaded. This makes it so the
* user can have different rom file names for a single project and keep track of
* backups.
* @enum ProjectFormat
* @brief Supported project file formats
*/
struct Project {
absl::Status Create(const std::string& project_name) {
name = project_name;
project_opened_ = true;
return absl::OkStatus();
}
absl::Status CheckForEmptyFields() {
if (name.empty() || filepath.empty() || rom_filename_.empty() ||
code_folder_.empty() || labels_filename_.empty()) {
return absl::InvalidArgumentError(
"Project fields cannot be empty. Please load a rom file, set your "
"code folder, and set your labels file. See HELP for more details.");
}
return absl::OkStatus();
}
absl::Status Open(const std::string& project_path);
absl::Status Save();
bool project_opened_ = false;
std::string name;
std::string flags = "";
std::string filepath;
std::string rom_filename_ = "";
std::string code_folder_ = "";
std::string labels_filename_ = "";
std::string keybindings_file = "";
enum class ProjectFormat {
kYazeNative, // .yaze - YAZE native format
kZScreamCompat // .zsproj - ZScream compatibility format
};
// Default types
static constexpr absl::string_view kDefaultTypes[] = {
"Dungeon Names", "Dungeon Room Names", "Overworld Map Names"};
/**
* @struct ProjectMetadata
* @brief Enhanced metadata for project tracking
*/
struct ProjectMetadata {
std::string version = "2.0";
std::string created_by = "YAZE";
std::string created_date;
std::string last_modified;
std::string yaze_version;
std::string description;
std::vector<std::string> tags;
std::string author;
std::string license;
// ZScream compatibility
bool zscream_compatible = false;
std::string zscream_version;
};
/**
* @struct WorkspaceSettings
* @brief Consolidated workspace and UI settings
*/
struct WorkspaceSettings {
// Display settings
float font_global_scale = 1.0f;
bool dark_mode = true;
std::string ui_theme = "default";
// Layout settings
std::string last_layout_preset;
std::vector<std::string> saved_layouts;
std::string window_layout_data; // ImGui .ini data
// Editor preferences
bool autosave_enabled = true;
float autosave_interval_secs = 300.0f; // 5 minutes
bool backup_on_save = true;
bool show_grid = true;
bool show_collision = false;
// Advanced settings
std::map<std::string, std::string> custom_keybindings;
std::vector<std::string> recent_files;
std::map<std::string, bool> editor_visibility;
};
/**
* @struct YazeProject
* @brief Modern project structure with comprehensive settings consolidation
*/
struct YazeProject {
// Basic project info
ProjectMetadata metadata;
std::string name;
std::string filepath;
ProjectFormat format = ProjectFormat::kYazeNative;
// ROM and resources
std::string rom_filename;
std::string rom_backup_folder;
std::vector<std::string> additional_roms; // For multi-ROM projects
// Code and assets
std::string code_folder;
std::string assets_folder;
std::string patches_folder;
std::string labels_filename;
std::string symbols_filename;
// Consolidated settings (previously scattered across multiple files)
FeatureFlags::Flags feature_flags;
WorkspaceSettings workspace_settings;
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> resource_labels;
// Build and deployment
std::string build_script;
std::string output_folder;
std::vector<std::string> build_configurations;
// Version control integration
std::string git_repository;
bool track_changes = true;
// ZScream compatibility (for importing existing projects)
std::string zscream_project_file; // Path to original .zsproj if importing
std::map<std::string, std::string> zscream_mappings; // Field mappings
// Methods
absl::Status Create(const std::string& project_name, const std::string& base_path);
absl::Status Open(const std::string& project_path);
absl::Status Save();
absl::Status SaveAs(const std::string& new_path);
absl::Status ImportZScreamProject(const std::string& zscream_project_path);
absl::Status ExportForZScream(const std::string& target_path);
// Settings management
absl::Status LoadAllSettings();
absl::Status SaveAllSettings();
absl::Status ResetToDefaults();
// Validation and integrity
absl::Status Validate() const;
std::vector<std::string> GetMissingFiles() const;
absl::Status RepairProject();
// Utilities
std::string GetDisplayName() const;
std::string GetRelativePath(const std::string& absolute_path) const;
std::string GetAbsolutePath(const std::string& relative_path) const;
bool IsEmpty() const;
// Project state
bool project_opened() const { return !name.empty() && !filepath.empty(); }
private:
absl::Status LoadFromYazeFormat(const std::string& project_path);
absl::Status SaveToYazeFormat();
absl::Status ImportFromZScreamFormat(const std::string& project_path);
void InitializeDefaults();
std::string GenerateProjectId() const;
};
/**
* @class ProjectManager
* @brief Enhanced project management with templates and validation
*/
class ProjectManager {
public:
// Project templates
struct ProjectTemplate {
std::string name;
std::string description;
std::string icon;
YazeProject template_project;
};
static std::vector<ProjectTemplate> GetProjectTemplates();
static absl::StatusOr<YazeProject> CreateFromTemplate(
const std::string& template_name,
const std::string& project_name,
const std::string& base_path);
// Project discovery and management
static std::vector<std::string> FindProjectsInDirectory(const std::string& directory);
static absl::Status BackupProject(const YazeProject& project);
static absl::Status RestoreProject(const std::string& backup_path);
// Format conversion utilities
static absl::Status ConvertProject(const std::string& source_path,
const std::string& target_path,
ProjectFormat target_format);
// Validation and repair
static absl::Status ValidateProjectStructure(const YazeProject& project);
static std::vector<std::string> GetRecommendedFixesForProject(const YazeProject& project);
};
// Compatibility - ResourceLabelManager (still used by ROM class)
struct ResourceLabelManager {
bool LoadLabels(const std::string& filename);
bool SaveLabels();
@@ -79,6 +210,9 @@ struct ResourceLabelManager {
labels_;
};
// Compatibility - RecentFilesManager
const std::string kRecentFilesFilename = "recent_files.txt";
class RecentFilesManager {
public:
RecentFilesManager() : RecentFilesManager(kRecentFilesFilename) {}
@@ -127,15 +261,7 @@ class RecentFilesManager {
std::vector<std::string> recent_files_;
};
class VersionControlManager {
absl::Status Commit(const std::string& message);
absl::Status Pull();
absl::Status Push();
} // namespace core
} // namespace yaze
private:
std::string repository_path_;
};
} // namespace yaze
#endif // YAZE_APP_CORE_PROJECT_H
#endif // YAZE_APP_CORE_PROJECT_H