yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
project.h
Go to the documentation of this file.
1#ifndef YAZE_CORE_PROJECT_H
2#define YAZE_CORE_PROJECT_H
3
4#include <algorithm>
5#include <cstdint>
6#include <map>
7#include <optional>
8#include <string>
9#include <unordered_map>
10#include <vector>
11
12#include "absl/status/status.h"
13#include "absl/status/statusor.h"
14#include "absl/strings/string_view.h"
15#include "core/features.h"
16#include "core/hack_manifest.h"
17#include "core/rom_settings.h"
19
20namespace yaze {
21namespace project {
22
27enum class ProjectFormat {
28 kYazeNative, // .yaze - YAZE native format
29 kZScreamCompat // .zsproj - ZScream compatibility format
30};
31
37 std::string version = "2.0";
38 std::string created_by = "YAZE";
39 std::string created_date;
40 std::string last_modified;
41 std::string yaze_version;
42 std::string description;
43 std::vector<std::string> tags;
44 std::string author;
45 std::string license;
46 std::string project_id;
47
48 // ZScream compatibility
49 bool zscream_compatible = false;
50 std::string zscream_version;
51};
52
58 // Display settings
59 float font_global_scale = 1.0f;
60 bool dark_mode = true;
61 std::string ui_theme = "default";
62
63 // Layout settings
64 std::string last_layout_preset;
65 std::vector<std::string> saved_layouts;
66 std::string window_layout_data; // ImGui .ini data
67
68 // Editor preferences
69 bool autosave_enabled = true;
70 float autosave_interval_secs = 300.0f; // 5 minutes
71 bool backup_on_save = true;
72 bool show_grid = true;
73 bool show_collision = false;
74
75 // Backup management
76 int backup_retention_count = 20; // Keep last N backups (0 = unlimited)
77 bool backup_keep_daily = true; // Keep one backup per day
78 int backup_keep_daily_days = 14; // Days to retain daily snapshots
79
80 // Label preferences
81 bool prefer_hmagic_names = true; // Prefer Hyrule Magic sprite names
82
83 // Advanced settings
84 std::map<std::string, std::string> custom_keybindings;
85 std::vector<std::string> recent_files;
86 std::map<std::string, bool> editor_visibility;
87};
88
94 // Collision tile IDs used by minecart tracks and interactions.
95 std::vector<uint16_t> track_tiles;
96 std::vector<uint16_t> track_stop_tiles;
97 std::vector<uint16_t> track_switch_tiles;
98
99 // Object/Sprite IDs used for minecart tooling and validation.
100 std::vector<uint16_t> track_object_ids;
101 std::vector<uint16_t> minecart_sprite_ids;
102};
103
106
112
114 uint32_t start = 0;
115 uint32_t end = 0;
116 std::string reason;
117};
118
120 std::string symbols_mlb;
121 std::string sourcemap_json;
122 std::string annotations_json;
123 std::string hooks_json;
124 std::string lint_json;
125};
126
128 bool loaded = false;
129 std::string config_path;
130 std::string preset;
131 std::vector<std::string> include_paths;
132 std::vector<std::pair<std::string, std::string>> defines;
133 std::vector<std::string> emits;
134 std::vector<std::string> main_files;
135 std::string std_includes_path;
136 std::string std_defines_path;
137 std::string mapper;
138 int rom_size = 0;
139 std::string symbols_format;
140 std::string symbols_path;
141 std::vector<Z3dkMemoryRange> prohibited_memory_ranges;
142 std::optional<bool> lsp_log_enabled;
143 std::string lsp_log_path;
150 bool warn_hook_return = true;
151 std::string rom_path;
153};
154
155std::string RomRoleToString(RomRole role);
156RomRole ParseRomRole(absl::string_view value);
157std::string RomWritePolicyToString(RomWritePolicy policy);
158RomWritePolicy ParseRomWritePolicy(absl::string_view value);
159
165 // Basic project info
167 std::string name;
168 std::string filepath;
170
171 // ROM and resources
172 std::string rom_filename;
173 std::string rom_backup_folder;
174 std::vector<std::string> additional_roms; // For multi-ROM projects
176
177 // Code and assets
178 std::string code_folder;
179 std::string assets_folder;
180 std::string patches_folder;
181 std::string labels_filename;
182 std::string symbols_filename;
183 std::string
184 custom_objects_folder; // Folder containing custom object .bin files
185 std::string
186 hack_manifest_file; // Path to hack_manifest.json (ASM integration)
187
188 // Optional custom object file mapping (object_id -> filenames per subtype).
189 std::unordered_map<int, std::vector<std::string>> custom_object_files;
190
191 // Consolidated settings (previously scattered across multiple files)
196 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
198
199 // Embedded labels flag - when true, resource_labels contains all default
200 // Zelda3 labels
202
203 // ASM hack integration manifest (loaded from hack_manifest_file)
205
206 // Optional z3dk project configuration discovered from z3dk.toml.
208
209 // Build and deployment
210 std::string build_script;
211 std::string output_folder;
212 std::vector<std::string> build_configurations;
213 std::string build_target;
214 std::string asm_entry_point;
215 std::vector<std::string> asm_sources;
216
217 // Version control integration
218 std::string git_repository;
219 bool track_changes = true;
220 std::string last_build_hash;
222
223 // AI Agent Settings
225 std::string ai_provider =
226 "auto"; // auto, gemini, anthropic, openai, ollama, mock
227 std::string ai_model; // e.g., "gemini-2.5-flash", "llama3:latest"
228 std::string ollama_host = "http://localhost:11434";
229 std::string gemini_api_key; // Optional, can use env var
230 std::string
231 custom_system_prompt; // Path to custom prompt (relative to project)
232 bool use_custom_prompt = false;
233 bool show_reasoning = true;
234 bool verbose = false;
237 float temperature = 0.25f;
238 float top_p = 0.95f;
240 bool stream_responses = false;
241 std::vector<std::string> favorite_models;
242 std::vector<std::string> model_chain;
243 int chain_mode = 0;
249 bool enable_tool_gui = true;
250 bool enable_tool_music = true;
254 std::string builder_blueprint_path; // Saved agent builder configuration
256
257 // ZScream compatibility (for importing existing projects)
258 std::string zscream_project_file; // Path to original .zsproj if importing
259 std::map<std::string, std::string> zscream_mappings; // Field mappings
260
261 // WASM persistence (project + music state in IndexedDB)
267
268 // Bundle resolution
269 // Walk up the path hierarchy to find the first ancestor directory whose
270 // filename ends with ".yazeproj". If `path` itself is a .yazeproj directory,
271 // returns it as-is. Returns an empty string when no bundle root is found.
272 static std::string ResolveBundleRoot(const std::string& path);
273
274 // Methods
275 absl::Status Create(const std::string& project_name,
276 const std::string& base_path);
277 absl::Status Open(const std::string& project_path);
278 absl::Status Save();
279 absl::Status SaveAs(const std::string& new_path);
280 absl::Status ImportZScreamProject(const std::string& zscream_project_path);
281 absl::Status ExportForZScream(const std::string& target_path);
282
283 // Settings management
284 absl::Status LoadAllSettings();
285 absl::Status SaveAllSettings();
286 absl::Status ResetToDefaults();
287
288 // Labels management
289 absl::Status InitializeEmbeddedLabels(
290 const std::unordered_map<std::string,
291 std::unordered_map<std::string, std::string>>&
292 labels); // Load all default Zelda3 labels
293 std::string GetLabel(const std::string& resource_type, int id,
294 const std::string& default_value = "") const;
295
301 absl::Status ImportLabelsFromZScream(const std::string& filepath);
302
308 absl::Status ImportLabelsFromZScreamContent(const std::string& content);
309
314
315 // Validation and integrity
316 absl::Status Validate() const;
317 std::vector<std::string> GetMissingFiles() const;
318 absl::Status RepairProject();
319
320 // Utilities
321 // Normalize filesystem paths to absolute paths based on the project file
322 // location. This avoids relying on the process working directory when
323 // opening ROMs/projects (important for iOS and portable bundles).
325 std::string GetDisplayName() const;
326 std::string GetRelativePath(const std::string& absolute_path) const;
327 std::string GetAbsolutePath(const std::string& relative_path) const;
328 bool IsEmpty() const;
329 std::string MakeStorageKey(absl::string_view suffix) const;
330
331 // Project state
332 bool project_opened() const { return !name.empty() && !filepath.empty(); }
333
334 // Hack manifest (ASM integration) reload hook (safe no-op if unset).
335 void ReloadHackManifest();
336 void ReloadZ3dkSettings();
337 bool HasZ3dkConfig() const { return z3dk_settings.loaded; }
338 std::string GetZ3dkArtifactPath(absl::string_view artifact_name) const;
339
340 private:
341 absl::StatusOr<std::string> SerializeToString() const;
342 absl::Status ParseFromString(const std::string& content);
343 absl::Status LoadFromYazeFormat(const std::string& project_path);
344 absl::Status SaveToYazeFormat();
345 absl::Status ImportFromZScreamFormat(const std::string& project_path);
346
347#ifdef YAZE_ENABLE_JSON_PROJECT_FORMAT
348 absl::Status LoadFromJsonFormat(const std::string& project_path);
349 absl::Status SaveToJsonFormat();
350#endif
351
352 void InitializeDefaults();
353 void TryLoadZ3dkConfig();
354 void TryLoadHackManifest();
355 std::string GenerateProjectId() const;
356};
357
363 public:
364 // Project templates
366 std::string name;
367 std::string description;
368 std::string icon;
370 };
371
372 static std::vector<ProjectTemplate> GetProjectTemplates();
373 static absl::StatusOr<YazeProject> CreateFromTemplate(
374 const std::string& template_name, const std::string& project_name,
375 const std::string& base_path);
376
377 // Project discovery and management
378 static std::vector<std::string> FindProjectsInDirectory(
379 const std::string& directory);
380 static absl::Status BackupProject(const YazeProject& project);
381 static absl::Status RestoreProject(const std::string& backup_path);
382
383 // Format conversion utilities
384 static absl::Status ConvertProject(const std::string& source_path,
385 const std::string& target_path,
386 ProjectFormat target_format);
387
388 // Validation and repair
389 static absl::Status ValidateProjectStructure(const YazeProject& project);
390 static std::vector<std::string> GetRecommendedFixesForProject(
391 const YazeProject& project);
392};
393
394// Compatibility - ResourceLabelManager (still used by ROM class)
396 bool LoadLabels(const std::string& filename);
397 bool SaveLabels();
398 void DisplayLabels(bool* p_open);
399 void EditLabel(const std::string& type, const std::string& key,
400 const std::string& newValue);
401 void SelectableLabelWithNameEdit(bool selected, const std::string& type,
402 const std::string& key,
403 const std::string& defaultValue);
404 std::string GetLabel(const std::string& type, const std::string& key);
405 std::string CreateOrGetLabel(const std::string& type, const std::string& key,
406 const std::string& defaultValue);
407
408 bool labels_loaded_ = false;
409 std::string filename_;
411 std::string key_name;
413 };
414
415 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
417};
418
419// Compatibility - RecentFilesManager
420const std::string kRecentFilesFilename = "recent_files.txt";
421
423 public:
424 // Singleton pattern - get the global instance
426 static RecentFilesManager instance;
427 return instance;
428 }
429
430 // Delete copy constructor and assignment operator
433
434 void AddFile(const std::string& file_path) {
435 // Add a file to the list, avoiding duplicates
436 // Move to front if already exists (MRU - Most Recently Used)
437 auto it = std::find(recent_files_.begin(), recent_files_.end(), file_path);
438 if (it != recent_files_.end()) {
439 recent_files_.erase(it);
440 }
441 recent_files_.insert(recent_files_.begin(), file_path);
442
443 // Limit to 20 most recent files
444 if (recent_files_.size() > 20) {
445 recent_files_.resize(20);
446 }
448 }
449
450 void RemoveFile(const std::string& file_path) {
451 auto it = std::find(recent_files_.begin(), recent_files_.end(), file_path);
452 if (it != recent_files_.end()) {
453 recent_files_.erase(it);
455 }
456 }
457
458 void Save();
459
460 void Load();
461
462 const std::vector<std::string>& GetRecentFiles() const {
463 return recent_files_;
464 }
465
466 void Clear() {
467 recent_files_.clear();
469 }
470
472 [[nodiscard]] std::uint64_t GetGeneration() const { return generation_; }
473
474 private:
476 Load(); // Load on construction
477 }
478
479 std::string GetFilePath() const;
480
482
483 std::vector<std::string> recent_files_;
484 std::uint64_t generation_ = 0;
485};
486
487} // namespace project
488} // namespace yaze
489
490#endif // YAZE_CORE_PROJECT_H
Loads and queries the hack manifest JSON for yaze-ASM integration.
Enhanced project management with templates and validation.
Definition project.h:362
static std::vector< std::string > FindProjectsInDirectory(const std::string &directory)
Definition project.cc:1975
static absl::Status ValidateProjectStructure(const YazeProject &project)
Definition project.cc:2038
static absl::StatusOr< YazeProject > CreateFromTemplate(const std::string &template_name, const std::string &project_name, const std::string &base_path)
Definition project.cc:1933
static std::vector< std::string > GetRecommendedFixesForProject(const YazeProject &project)
Definition project.cc:2043
static std::vector< ProjectTemplate > GetProjectTemplates()
Definition project.cc:1786
static absl::Status RestoreProject(const std::string &backup_path)
static absl::Status ConvertProject(const std::string &source_path, const std::string &target_path, ProjectFormat target_format)
static absl::Status BackupProject(const YazeProject &project)
Definition project.cc:2005
void RemoveFile(const std::string &file_path)
Definition project.h:450
std::string GetFilePath() const
Definition project.cc:2785
void AddFile(const std::string &file_path)
Definition project.h:434
static RecentFilesManager & GetInstance()
Definition project.h:425
std::uint64_t GetGeneration() const
Bumps when recent file list changes (add/remove/clear/load).
Definition project.h:472
const std::vector< std::string > & GetRecentFiles() const
Definition project.h:462
RecentFilesManager(const RecentFilesManager &)=delete
std::vector< std::string > recent_files_
Definition project.h:483
RecentFilesManager & operator=(const RecentFilesManager &)=delete
std::string RomRoleToString(RomRole role)
Definition project.cc:192
RomRole ParseRomRole(absl::string_view value)
Definition project.cc:206
const std::string kRecentFilesFilename
Definition project.h:420
ProjectFormat
Supported project file formats.
Definition project.h:27
RomWritePolicy ParseRomWritePolicy(absl::string_view value)
Definition project.cc:232
std::string RomWritePolicyToString(RomWritePolicy policy)
Definition project.cc:220
Dungeon overlay configuration (per-project).
Definition project.h:93
std::vector< uint16_t > track_object_ids
Definition project.h:100
std::vector< uint16_t > minecart_sprite_ids
Definition project.h:101
std::vector< uint16_t > track_stop_tiles
Definition project.h:96
std::vector< uint16_t > track_tiles
Definition project.h:95
std::vector< uint16_t > track_switch_tiles
Definition project.h:97
Enhanced metadata for project tracking.
Definition project.h:36
std::vector< std::string > tags
Definition project.h:43
std::string CreateOrGetLabel(const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:2193
std::string GetLabel(const std::string &type, const std::string &key)
Definition project.cc:2180
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
Definition project.cc:2162
bool LoadLabels(const std::string &filename)
Definition project.cc:2078
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:2168
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
Definition project.h:416
std::string expected_hash
Definition project.h:109
RomWritePolicy write_policy
Definition project.h:110
Consolidated workspace and UI settings.
Definition project.h:57
std::map< std::string, std::string > custom_keybindings
Definition project.h:84
std::vector< std::string > saved_layouts
Definition project.h:65
std::map< std::string, bool > editor_visibility
Definition project.h:86
std::vector< std::string > recent_files
Definition project.h:85
std::vector< std::string > favorite_models
Definition project.h:241
std::vector< std::string > model_chain
Definition project.h:242
Modern project structure with comprehensive settings consolidation.
Definition project.h:164
std::string rom_backup_folder
Definition project.h:173
std::unordered_map< int, std::vector< std::string > > custom_object_files
Definition project.h:189
absl::Status ResetToDefaults()
Definition project.cc:1197
std::string custom_objects_folder
Definition project.h:184
absl::Status RepairProject()
Definition project.cc:1258
std::string MakeStorageKey(absl::string_view suffix) const
Definition project.cc:484
static std::string ResolveBundleRoot(const std::string &path)
Definition project.cc:297
struct yaze::project::YazeProject::MusicPersistence music_persistence
bool project_opened() const
Definition project.h:332
absl::StatusOr< std::string > SerializeToString() const
Definition project.cc:500
std::string zscream_project_file
Definition project.h:258
absl::Status ExportForZScream(const std::string &target_path)
Definition project.cc:1164
ProjectMetadata metadata
Definition project.h:166
absl::Status ImportZScreamProject(const std::string &zscream_project_path)
Definition project.cc:1141
absl::Status SaveAllSettings()
Definition project.cc:1192
absl::Status ImportLabelsFromZScreamContent(const std::string &content)
Import labels from ZScream format content directly.
Definition project.cc:2301
std::string git_repository
Definition project.h:218
core::HackManifest hack_manifest
Definition project.h:204
void InitializeResourceLabelProvider()
Initialize the global ResourceLabelProvider with this project's labels.
Definition project.cc:2325
absl::Status ParseFromString(const std::string &content)
Definition project.cc:795
std::vector< std::string > additional_roms
Definition project.h:174
bool HasZ3dkConfig() const
Definition project.h:337
std::string patches_folder
Definition project.h:180
absl::Status LoadFromYazeFormat(const std::string &project_path)
Definition project.cc:1082
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > resource_labels
Definition project.h:197
std::string GenerateProjectId() const
Definition project.cc:1777
absl::Status Create(const std::string &project_name, const std::string &base_path)
Definition project.cc:244
std::string assets_folder
Definition project.h:179
absl::Status SaveToYazeFormat()
Definition project.cc:1103
absl::Status LoadAllSettings()
Definition project.cc:1186
std::string labels_filename
Definition project.h:181
std::vector< std::string > asm_sources
Definition project.h:215
std::string hack_manifest_file
Definition project.h:186
std::string GetDisplayName() const
Definition project.cc:1292
std::vector< std::string > GetMissingFiles() const
Definition project.cc:1237
WorkspaceSettings workspace_settings
Definition project.h:193
std::string GetZ3dkArtifactPath(absl::string_view artifact_name) const
Definition project.cc:1398
std::string output_folder
Definition project.h:211
std::string asm_entry_point
Definition project.h:214
std::string GetRelativePath(const std::string &absolute_path) const
Definition project.cc:1299
absl::Status InitializeEmbeddedLabels(const std::unordered_map< std::string, std::unordered_map< std::string, std::string > > &labels)
Definition project.cc:2208
absl::Status SaveAs(const std::string &new_path)
Definition project.cc:472
struct yaze::project::YazeProject::AgentSettings agent_settings
DungeonOverlaySettings dungeon_overlay
Definition project.h:194
absl::Status ImportFromZScreamFormat(const std::string &project_path)
Definition project.cc:1376
std::string GetAbsolutePath(const std::string &relative_path) const
Definition project.cc:1319
std::string GetLabel(const std::string &resource_type, int id, const std::string &default_value="") const
Definition project.cc:2266
absl::Status Open(const std::string &project_path)
Definition project.cc:323
absl::Status ImportLabelsFromZScream(const std::string &filepath)
Import labels from a ZScream DefaultNames.txt file.
Definition project.cc:2281
std::string last_build_hash
Definition project.h:220
std::map< std::string, std::string > zscream_mappings
Definition project.h:259
absl::Status Validate() const
Definition project.cc:1202
core::FeatureFlags::Flags feature_flags
Definition project.h:192
std::vector< std::string > build_configurations
Definition project.h:212
core::RomAddressOverrides rom_address_overrides
Definition project.h:195
std::string symbols_filename
Definition project.h:182
Z3dkSettings z3dk_settings
Definition project.h:207
std::vector< std::string > include_paths
Definition project.h:131
std::string std_includes_path
Definition project.h:135
std::vector< std::string > main_files
Definition project.h:134
std::vector< std::string > emits
Definition project.h:133
std::vector< std::pair< std::string, std::string > > defines
Definition project.h:132
Z3dkArtifactPaths artifact_paths
Definition project.h:152
std::optional< bool > lsp_log_enabled
Definition project.h:142
std::vector< Z3dkMemoryRange > prohibited_memory_ranges
Definition project.h:141
std::string std_defines_path
Definition project.h:136