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
160#ifndef __EMSCRIPTEN__
161// Atomically writes project descriptor contents. When replace_existing is
162// false, a target created after preflight is rejected without mutation.
163absl::Status WriteProjectFileAtomically(absl::string_view target_path,
164 absl::string_view contents,
165 bool replace_existing);
166#endif
167
173 // Basic project info
175 std::string name;
176 std::string filepath;
178
179 // ROM and resources
180 std::string rom_filename;
181 std::string rom_backup_folder;
182 std::vector<std::string> additional_roms; // For multi-ROM projects
184
185 // Code and assets
186 std::string code_folder;
187 std::string assets_folder;
188 std::string patches_folder;
189 std::string labels_filename;
190 std::string symbols_filename;
191 std::string
192 custom_objects_folder; // Folder containing custom object .bin files
193 std::string
194 hack_manifest_file; // Path to hack_manifest.json (ASM integration)
195
196 // Optional custom object file mapping (object_id -> filenames per subtype).
197 std::unordered_map<int, std::vector<std::string>> custom_object_files;
198
199 // Consolidated settings (previously scattered across multiple files)
204 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
206
207 // Embedded labels flag - when true, resource_labels contains all default
208 // Zelda3 labels
210
211 // ASM hack integration manifest (loaded from hack_manifest_file)
213
214 // Optional z3dk project configuration discovered from z3dk.toml.
216
217 // Build and deployment
218 std::string build_script;
219 std::string output_folder;
220 std::vector<std::string> build_configurations;
221 std::string build_target;
222 std::string asm_entry_point;
223 std::vector<std::string> asm_sources;
224
225 // Version control integration
226 std::string git_repository;
227 bool track_changes = true;
228 std::string last_build_hash;
230
231 // AI Agent Settings
233 std::string ai_provider =
234 "auto"; // auto, gemini, anthropic, openai, ollama, mock
235 std::string ai_model; // e.g., "gemini-2.5-flash", "llama3:latest"
236 std::string ollama_host = "http://localhost:11434";
237 std::string gemini_api_key; // Optional, can use env var
238 std::string
239 custom_system_prompt; // Path to custom prompt (relative to project)
240 bool use_custom_prompt = false;
241 bool show_reasoning = true;
242 bool verbose = false;
245 float temperature = 0.25f;
246 float top_p = 0.95f;
248 bool stream_responses = false;
249 std::vector<std::string> favorite_models;
250 std::vector<std::string> model_chain;
251 int chain_mode = 0;
257 bool enable_tool_gui = true;
258 bool enable_tool_music = true;
262 std::string builder_blueprint_path; // Saved agent builder configuration
264
265 // ZScream compatibility (for importing existing projects)
266 std::string zscream_project_file; // Path to original .zsproj if importing
267 std::map<std::string, std::string> zscream_mappings; // Field mappings
268
269 // WASM persistence (project + music state in IndexedDB)
275
276 // Bundle resolution
277 // Walk up the path hierarchy to find the first ancestor directory whose
278 // filename ends with ".yazeproj". If `path` itself is a .yazeproj directory,
279 // returns it as-is. Returns an empty string when no bundle root is found.
280 static std::string ResolveBundleRoot(const std::string& path);
281
282 // Methods
283 absl::Status Create(const std::string& project_name,
284 const std::string& base_path);
285 absl::Status Open(const std::string& project_path);
286 // Parse an in-memory native project descriptor as if it lived at
287 // `project_path`. Used by the raw project editor to validate and adopt a
288 // draft before it replaces the active descriptor on disk.
289 absl::Status LoadFromString(const std::string& content,
290 const std::string& project_path);
291 absl::Status Save();
292 // Create a new descriptor without replacing a file that appeared after the
293 // caller's preflight check.
294 absl::Status SaveNew();
295 absl::Status SaveAs(const std::string& new_path);
296 absl::Status ImportZScreamProject(const std::string& zscream_project_path);
297 absl::Status ExportForZScream(const std::string& target_path);
298
299 // Settings management
300 absl::Status LoadAllSettings();
301 absl::Status SaveAllSettings();
302 absl::Status ResetToDefaults();
303
304 // Labels management
305 absl::Status InitializeEmbeddedLabels(
306 const std::unordered_map<std::string,
307 std::unordered_map<std::string, std::string>>&
308 labels); // Load all default Zelda3 labels
309 std::string GetLabel(const std::string& resource_type, int id,
310 const std::string& default_value = "") const;
311
317 absl::Status ImportLabelsFromZScream(const std::string& filepath);
318
324 absl::Status ImportLabelsFromZScreamContent(const std::string& content);
325
330
331 // Validation and integrity
332 absl::Status Validate() const;
333 std::vector<std::string> GetMissingFiles() const;
334 absl::Status RepairProject();
335
336 // Utilities
337 // Normalize filesystem paths to absolute paths based on the project file
338 // location. This avoids relying on the process working directory when
339 // opening ROMs/projects (important for iOS and portable bundles).
341 std::string GetDisplayName() const;
342 std::string GetRelativePath(const std::string& absolute_path) const;
343 std::string GetAbsolutePath(const std::string& relative_path) const;
344 bool IsEmpty() const;
345 std::string MakeStorageKey(absl::string_view suffix) const;
346
347 // Project state
348 bool project_opened() const { return !name.empty() && !filepath.empty(); }
349
350 // Hack manifest (ASM integration) reload hook (safe no-op if unset).
351 void ReloadHackManifest();
352 void ReloadZ3dkSettings();
353 bool HasZ3dkConfig() const { return z3dk_settings.loaded; }
354 std::string GetZ3dkArtifactPath(absl::string_view artifact_name) const;
355
356 private:
357 absl::StatusOr<std::string> SerializeToString() const;
358 absl::Status ParseFromString(const std::string& content);
359 absl::Status LoadFromYazeFormat(const std::string& project_path);
360 absl::Status SaveToYazeFormat(bool replace_existing = true);
361 absl::Status ImportFromZScreamFormat(const std::string& project_path);
362
363#ifdef YAZE_ENABLE_JSON_PROJECT_FORMAT
364 absl::Status LoadFromJsonFormat(const std::string& project_path);
365 absl::Status SaveToJsonFormat();
366#endif
367
368 void InitializeDefaults();
369 void TryLoadZ3dkConfig();
370 void TryLoadHackManifest();
371 std::string GenerateProjectId() const;
372};
373
379 public:
380 // Project templates
382 std::string name;
383 std::string description;
384 std::string icon;
386 };
387
388 static std::vector<ProjectTemplate> GetProjectTemplates();
389 static absl::StatusOr<YazeProject> CreateFromTemplate(
390 const std::string& template_name, const std::string& project_name,
391 const std::string& base_path);
392
393 // Project discovery and management
394 static std::vector<std::string> FindProjectsInDirectory(
395 const std::string& directory);
396 static absl::Status BackupProject(const YazeProject& project);
397 static absl::Status RestoreProject(const std::string& backup_path);
398
399 // Format conversion utilities
400 static absl::Status ConvertProject(const std::string& source_path,
401 const std::string& target_path,
402 ProjectFormat target_format);
403
404 // Validation and repair
405 static absl::Status ValidateProjectStructure(const YazeProject& project);
406 static std::vector<std::string> GetRecommendedFixesForProject(
407 const YazeProject& project);
408};
409
410// Compatibility - ResourceLabelManager (still used by ROM class)
412 bool LoadLabels(const std::string& filename);
413 bool SaveLabels();
414 void DisplayLabels(bool* p_open);
415 void EditLabel(const std::string& type, const std::string& key,
416 const std::string& newValue);
417 void SelectableLabelWithNameEdit(bool selected, const std::string& type,
418 const std::string& key,
419 const std::string& defaultValue);
420 std::string GetLabel(const std::string& type, const std::string& key);
421 std::string CreateOrGetLabel(const std::string& type, const std::string& key,
422 const std::string& defaultValue);
423
424 bool labels_loaded_ = false;
425 std::string filename_;
427 std::string key_name;
429 };
430
431 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
433};
434
435// Compatibility - RecentFilesManager
436const std::string kRecentFilesFilename = "recent_files.txt";
437
439 public:
440 // Singleton pattern - get the global instance
442 static RecentFilesManager instance;
443 return instance;
444 }
445
446 // Delete copy constructor and assignment operator
449
450 void AddFile(const std::string& file_path) {
451 // Add a file to the list, avoiding duplicates
452 // Move to front if already exists (MRU - Most Recently Used)
453 auto it = std::find(recent_files_.begin(), recent_files_.end(), file_path);
454 if (it != recent_files_.end()) {
455 recent_files_.erase(it);
456 }
457 recent_files_.insert(recent_files_.begin(), file_path);
458
459 // Limit to 20 most recent files
460 if (recent_files_.size() > 20) {
461 recent_files_.resize(20);
462 }
464 }
465
466 void RemoveFile(const std::string& file_path) {
467 auto it = std::find(recent_files_.begin(), recent_files_.end(), file_path);
468 if (it != recent_files_.end()) {
469 recent_files_.erase(it);
471 }
472 }
473
474 void Save();
475
476 void Load();
477
478 const std::vector<std::string>& GetRecentFiles() const {
479 return recent_files_;
480 }
481
482 void Clear() {
483 recent_files_.clear();
485 }
486
488 [[nodiscard]] std::uint64_t GetGeneration() const { return generation_; }
489
490 private:
492 Load(); // Load on construction
493 }
494
495 std::string GetFilePath() const;
496
498
499 std::vector<std::string> recent_files_;
500 std::uint64_t generation_ = 0;
501};
502
503} // namespace project
504} // namespace yaze
505
506#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:378
static std::vector< std::string > FindProjectsInDirectory(const std::string &directory)
Definition project.cc:2148
static absl::Status ValidateProjectStructure(const YazeProject &project)
Definition project.cc:2211
static absl::StatusOr< YazeProject > CreateFromTemplate(const std::string &template_name, const std::string &project_name, const std::string &base_path)
Definition project.cc:2106
static std::vector< std::string > GetRecommendedFixesForProject(const YazeProject &project)
Definition project.cc:2216
static std::vector< ProjectTemplate > GetProjectTemplates()
Definition project.cc:1959
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:2178
void RemoveFile(const std::string &file_path)
Definition project.h:466
std::string GetFilePath() const
Definition project.cc:2963
void AddFile(const std::string &file_path)
Definition project.h:450
static RecentFilesManager & GetInstance()
Definition project.h:441
std::uint64_t GetGeneration() const
Bumps when recent file list changes (add/remove/clear/load).
Definition project.h:488
const std::vector< std::string > & GetRecentFiles() const
Definition project.h:478
RecentFilesManager(const RecentFilesManager &)=delete
std::vector< std::string > recent_files_
Definition project.h:499
RecentFilesManager & operator=(const RecentFilesManager &)=delete
std::string RomRoleToString(RomRole role)
Definition project.cc:298
absl::Status WriteProjectFileAtomically(absl::string_view target_path, absl::string_view contents, bool replace_existing)
Definition project.cc:289
RomRole ParseRomRole(absl::string_view value)
Definition project.cc:312
const std::string kRecentFilesFilename
Definition project.h:436
ProjectFormat
Supported project file formats.
Definition project.h:27
RomWritePolicy ParseRomWritePolicy(absl::string_view value)
Definition project.cc:338
std::string RomWritePolicyToString(RomWritePolicy policy)
Definition project.cc:326
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:2366
std::string GetLabel(const std::string &type, const std::string &key)
Definition project.cc:2353
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
Definition project.cc:2335
bool LoadLabels(const std::string &filename)
Definition project.cc:2251
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:2341
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
Definition project.h:432
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:249
std::vector< std::string > model_chain
Definition project.h:250
Modern project structure with comprehensive settings consolidation.
Definition project.h:172
std::string rom_backup_folder
Definition project.h:181
std::unordered_map< int, std::vector< std::string > > custom_object_files
Definition project.h:197
absl::Status ResetToDefaults()
Definition project.cc:1350
std::string custom_objects_folder
Definition project.h:192
absl::Status RepairProject()
Definition project.cc:1425
std::string MakeStorageKey(absl::string_view suffix) const
Definition project.cc:638
static std::string ResolveBundleRoot(const std::string &path)
Definition project.cc:403
struct yaze::project::YazeProject::MusicPersistence music_persistence
bool project_opened() const
Definition project.h:348
absl::StatusOr< std::string > SerializeToString() const
Definition project.cc:654
std::string zscream_project_file
Definition project.h:266
absl::Status ExportForZScream(const std::string &target_path)
Definition project.cc:1317
ProjectMetadata metadata
Definition project.h:174
absl::Status SaveToYazeFormat(bool replace_existing=true)
Definition project.cc:1261
absl::Status ImportZScreamProject(const std::string &zscream_project_path)
Definition project.cc:1294
absl::Status SaveAllSettings()
Definition project.cc:1345
absl::Status LoadFromString(const std::string &content, const std::string &project_path)
Definition project.cc:595
absl::Status ImportLabelsFromZScreamContent(const std::string &content)
Import labels from ZScream format content directly.
Definition project.cc:2474
std::string git_repository
Definition project.h:226
core::HackManifest hack_manifest
Definition project.h:212
void InitializeResourceLabelProvider()
Initialize the global ResourceLabelProvider with this project's labels.
Definition project.cc:2498
absl::Status ParseFromString(const std::string &content)
Definition project.cc:951
std::vector< std::string > additional_roms
Definition project.h:182
bool HasZ3dkConfig() const
Definition project.h:353
std::string patches_folder
Definition project.h:188
absl::Status LoadFromYazeFormat(const std::string &project_path)
Definition project.cc:1240
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > resource_labels
Definition project.h:205
std::string GenerateProjectId() const
Definition project.cc:1950
absl::Status Create(const std::string &project_name, const std::string &base_path)
Definition project.cc:350
std::string assets_folder
Definition project.h:187
absl::Status LoadAllSettings()
Definition project.cc:1339
std::string labels_filename
Definition project.h:189
std::vector< std::string > asm_sources
Definition project.h:223
std::string hack_manifest_file
Definition project.h:194
std::string GetDisplayName() const
Definition project.cc:1459
std::vector< std::string > GetMissingFiles() const
Definition project.cc:1400
WorkspaceSettings workspace_settings
Definition project.h:201
std::string GetZ3dkArtifactPath(absl::string_view artifact_name) const
Definition project.cc:1565
std::string output_folder
Definition project.h:219
std::string asm_entry_point
Definition project.h:222
std::string GetRelativePath(const std::string &absolute_path) const
Definition project.cc:1466
absl::Status InitializeEmbeddedLabels(const std::unordered_map< std::string, std::unordered_map< std::string, std::string > > &labels)
Definition project.cc:2381
absl::Status SaveAs(const std::string &new_path)
Definition project.cc:626
absl::Status SaveNew()
Definition project.cc:591
struct yaze::project::YazeProject::AgentSettings agent_settings
DungeonOverlaySettings dungeon_overlay
Definition project.h:202
absl::Status ImportFromZScreamFormat(const std::string &project_path)
Definition project.cc:1543
std::string GetAbsolutePath(const std::string &relative_path) const
Definition project.cc:1486
std::string GetLabel(const std::string &resource_type, int id, const std::string &default_value="") const
Definition project.cc:2439
absl::Status Open(const std::string &project_path)
Definition project.cc:429
absl::Status ImportLabelsFromZScream(const std::string &filepath)
Import labels from a ZScream DefaultNames.txt file.
Definition project.cc:2454
std::string last_build_hash
Definition project.h:228
std::map< std::string, std::string > zscream_mappings
Definition project.h:267
absl::Status Validate() const
Definition project.cc:1355
core::FeatureFlags::Flags feature_flags
Definition project.h:200
std::vector< std::string > build_configurations
Definition project.h:220
core::RomAddressOverrides rom_address_overrides
Definition project.h:203
std::string symbols_filename
Definition project.h:190
Z3dkSettings z3dk_settings
Definition project.h:215
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