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 <map>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
12#include "absl/strings/string_view.h"
13#include "core/features.h"
14#include "core/hack_manifest.h"
15#include "core/rom_settings.h"
17
18namespace yaze {
19namespace project {
20
25enum class ProjectFormat {
26 kYazeNative, // .yaze - YAZE native format
27 kZScreamCompat // .zsproj - ZScream compatibility format
28};
29
35 std::string version = "2.0";
36 std::string created_by = "YAZE";
37 std::string created_date;
38 std::string last_modified;
39 std::string yaze_version;
40 std::string description;
41 std::vector<std::string> tags;
42 std::string author;
43 std::string license;
44 std::string project_id;
45
46 // ZScream compatibility
47 bool zscream_compatible = false;
48 std::string zscream_version;
49};
50
56 // Display settings
57 float font_global_scale = 1.0f;
58 bool dark_mode = true;
59 std::string ui_theme = "default";
60
61 // Layout settings
62 std::string last_layout_preset;
63 std::vector<std::string> saved_layouts;
64 std::string window_layout_data; // ImGui .ini data
65
66 // Editor preferences
67 bool autosave_enabled = true;
68 float autosave_interval_secs = 300.0f; // 5 minutes
69 bool backup_on_save = true;
70 bool show_grid = true;
71 bool show_collision = false;
72
73 // Backup management
74 int backup_retention_count = 20; // Keep last N backups (0 = unlimited)
75 bool backup_keep_daily = true; // Keep one backup per day
76 int backup_keep_daily_days = 14; // Days to retain daily snapshots
77
78 // Label preferences
79 bool prefer_hmagic_names = true; // Prefer Hyrule Magic sprite names
80
81 // Advanced settings
82 std::map<std::string, std::string> custom_keybindings;
83 std::vector<std::string> recent_files;
84 std::map<std::string, bool> editor_visibility;
85};
86
92 // Collision tile IDs used by minecart tracks and interactions.
93 std::vector<uint16_t> track_tiles;
94 std::vector<uint16_t> track_stop_tiles;
95 std::vector<uint16_t> track_switch_tiles;
96
97 // Object/Sprite IDs used for minecart tooling and validation.
98 std::vector<uint16_t> track_object_ids;
99 std::vector<uint16_t> minecart_sprite_ids;
100};
101
104
110
111std::string RomRoleToString(RomRole role);
112RomRole ParseRomRole(absl::string_view value);
113std::string RomWritePolicyToString(RomWritePolicy policy);
114RomWritePolicy ParseRomWritePolicy(absl::string_view value);
115
121 // Basic project info
123 std::string name;
124 std::string filepath;
126
127 // ROM and resources
128 std::string rom_filename;
129 std::string rom_backup_folder;
130 std::vector<std::string> additional_roms; // For multi-ROM projects
132
133 // Code and assets
134 std::string code_folder;
135 std::string assets_folder;
136 std::string patches_folder;
137 std::string labels_filename;
138 std::string symbols_filename;
139 std::string
140 custom_objects_folder; // Folder containing custom object .bin files
141 std::string
142 hack_manifest_file; // Path to hack_manifest.json (ASM integration)
143
144 // Optional custom object file mapping (object_id -> filenames per subtype).
145 std::unordered_map<int, std::vector<std::string>> custom_object_files;
146
147 // Consolidated settings (previously scattered across multiple files)
152 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
154
155 // Embedded labels flag - when true, resource_labels contains all default
156 // Zelda3 labels
158
159 // ASM hack integration manifest (loaded from hack_manifest_file)
161
162 // Build and deployment
163 std::string build_script;
164 std::string output_folder;
165 std::vector<std::string> build_configurations;
166 std::string build_target;
167 std::string asm_entry_point;
168 std::vector<std::string> asm_sources;
169
170 // Version control integration
171 std::string git_repository;
172 bool track_changes = true;
173 std::string last_build_hash;
175
176 // AI Agent Settings
178 std::string ai_provider =
179 "auto"; // auto, gemini, anthropic, openai, ollama, mock
180 std::string ai_model; // e.g., "gemini-2.5-flash", "llama3:latest"
181 std::string ollama_host = "http://localhost:11434";
182 std::string gemini_api_key; // Optional, can use env var
183 std::string
184 custom_system_prompt; // Path to custom prompt (relative to project)
185 bool use_custom_prompt = false;
186 bool show_reasoning = true;
187 bool verbose = false;
190 float temperature = 0.25f;
191 float top_p = 0.95f;
193 bool stream_responses = false;
194 std::vector<std::string> favorite_models;
195 std::vector<std::string> model_chain;
196 int chain_mode = 0;
202 bool enable_tool_gui = true;
203 bool enable_tool_music = true;
207 std::string builder_blueprint_path; // Saved agent builder configuration
209
210 // ZScream compatibility (for importing existing projects)
211 std::string zscream_project_file; // Path to original .zsproj if importing
212 std::map<std::string, std::string> zscream_mappings; // Field mappings
213
214 // WASM persistence (project + music state in IndexedDB)
220
221 // Bundle resolution
222 // Walk up the path hierarchy to find the first ancestor directory whose
223 // filename ends with ".yazeproj". If `path` itself is a .yazeproj directory,
224 // returns it as-is. Returns an empty string when no bundle root is found.
225 static std::string ResolveBundleRoot(const std::string& path);
226
227 // Methods
228 absl::Status Create(const std::string& project_name,
229 const std::string& base_path);
230 absl::Status Open(const std::string& project_path);
231 absl::Status Save();
232 absl::Status SaveAs(const std::string& new_path);
233 absl::Status ImportZScreamProject(const std::string& zscream_project_path);
234 absl::Status ExportForZScream(const std::string& target_path);
235
236 // Settings management
237 absl::Status LoadAllSettings();
238 absl::Status SaveAllSettings();
239 absl::Status ResetToDefaults();
240
241 // Labels management
242 absl::Status InitializeEmbeddedLabels(
243 const std::unordered_map<std::string,
244 std::unordered_map<std::string, std::string>>&
245 labels); // Load all default Zelda3 labels
246 std::string GetLabel(const std::string& resource_type, int id,
247 const std::string& default_value = "") const;
248
254 absl::Status ImportLabelsFromZScream(const std::string& filepath);
255
261 absl::Status ImportLabelsFromZScreamContent(const std::string& content);
262
267
268 // Validation and integrity
269 absl::Status Validate() const;
270 std::vector<std::string> GetMissingFiles() const;
271 absl::Status RepairProject();
272
273 // Utilities
274 // Normalize filesystem paths to absolute paths based on the project file
275 // location. This avoids relying on the process working directory when
276 // opening ROMs/projects (important for iOS and portable bundles).
278 std::string GetDisplayName() const;
279 std::string GetRelativePath(const std::string& absolute_path) const;
280 std::string GetAbsolutePath(const std::string& relative_path) const;
281 bool IsEmpty() const;
282 std::string MakeStorageKey(absl::string_view suffix) const;
283
284 // Project state
285 bool project_opened() const { return !name.empty() && !filepath.empty(); }
286
287 // Hack manifest (ASM integration) reload hook (safe no-op if unset).
288 void ReloadHackManifest();
289
290 private:
291 absl::StatusOr<std::string> SerializeToString() const;
292 absl::Status ParseFromString(const std::string& content);
293 absl::Status LoadFromYazeFormat(const std::string& project_path);
294 absl::Status SaveToYazeFormat();
295 absl::Status ImportFromZScreamFormat(const std::string& project_path);
296
297#ifdef YAZE_ENABLE_JSON_PROJECT_FORMAT
298 absl::Status LoadFromJsonFormat(const std::string& project_path);
299 absl::Status SaveToJsonFormat();
300#endif
301
302 void InitializeDefaults();
303 void TryLoadHackManifest();
304 std::string GenerateProjectId() const;
305};
306
312 public:
313 // Project templates
315 std::string name;
316 std::string description;
317 std::string icon;
319 };
320
321 static std::vector<ProjectTemplate> GetProjectTemplates();
322 static absl::StatusOr<YazeProject> CreateFromTemplate(
323 const std::string& template_name, const std::string& project_name,
324 const std::string& base_path);
325
326 // Project discovery and management
327 static std::vector<std::string> FindProjectsInDirectory(
328 const std::string& directory);
329 static absl::Status BackupProject(const YazeProject& project);
330 static absl::Status RestoreProject(const std::string& backup_path);
331
332 // Format conversion utilities
333 static absl::Status ConvertProject(const std::string& source_path,
334 const std::string& target_path,
335 ProjectFormat target_format);
336
337 // Validation and repair
338 static absl::Status ValidateProjectStructure(const YazeProject& project);
339 static std::vector<std::string> GetRecommendedFixesForProject(
340 const YazeProject& project);
341};
342
343// Compatibility - ResourceLabelManager (still used by ROM class)
345 bool LoadLabels(const std::string& filename);
346 bool SaveLabels();
347 void DisplayLabels(bool* p_open);
348 void EditLabel(const std::string& type, const std::string& key,
349 const std::string& newValue);
350 void SelectableLabelWithNameEdit(bool selected, const std::string& type,
351 const std::string& key,
352 const std::string& defaultValue);
353 std::string GetLabel(const std::string& type, const std::string& key);
354 std::string CreateOrGetLabel(const std::string& type, const std::string& key,
355 const std::string& defaultValue);
356
357 bool labels_loaded_ = false;
358 std::string filename_;
360 std::string key_name;
362 };
363
364 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
366};
367
368// Compatibility - RecentFilesManager
369const std::string kRecentFilesFilename = "recent_files.txt";
370
372 public:
373 // Singleton pattern - get the global instance
375 static RecentFilesManager instance;
376 return instance;
377 }
378
379 // Delete copy constructor and assignment operator
382
383 void AddFile(const std::string& file_path) {
384 // Add a file to the list, avoiding duplicates
385 // Move to front if already exists (MRU - Most Recently Used)
386 auto it = std::find(recent_files_.begin(), recent_files_.end(), file_path);
387 if (it != recent_files_.end()) {
388 recent_files_.erase(it);
389 }
390 recent_files_.insert(recent_files_.begin(), file_path);
391
392 // Limit to 20 most recent files
393 if (recent_files_.size() > 20) {
394 recent_files_.resize(20);
395 }
396 }
397
398 void RemoveFile(const std::string& file_path) {
399 auto it = std::find(recent_files_.begin(), recent_files_.end(), file_path);
400 if (it != recent_files_.end()) {
401 recent_files_.erase(it);
402 }
403 }
404
405 void Save();
406
407 void Load();
408
409 const std::vector<std::string>& GetRecentFiles() const {
410 return recent_files_;
411 }
412
413 void Clear() { recent_files_.clear(); }
414
415 private:
417 Load(); // Load on construction
418 }
419
420 std::string GetFilePath() const;
421
422 std::vector<std::string> recent_files_;
423};
424
425} // namespace project
426} // namespace yaze
427
428#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:311
static std::vector< std::string > FindProjectsInDirectory(const std::string &directory)
Definition project.cc:1748
static absl::Status ValidateProjectStructure(const YazeProject &project)
Definition project.cc:1811
static absl::StatusOr< YazeProject > CreateFromTemplate(const std::string &template_name, const std::string &project_name, const std::string &base_path)
Definition project.cc:1706
static std::vector< std::string > GetRecommendedFixesForProject(const YazeProject &project)
Definition project.cc:1816
static std::vector< ProjectTemplate > GetProjectTemplates()
Definition project.cc:1559
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:1778
void RemoveFile(const std::string &file_path)
Definition project.h:398
std::string GetFilePath() const
Definition project.cc:2558
void AddFile(const std::string &file_path)
Definition project.h:383
static RecentFilesManager & GetInstance()
Definition project.h:374
const std::vector< std::string > & GetRecentFiles() const
Definition project.h:409
RecentFilesManager(const RecentFilesManager &)=delete
std::vector< std::string > recent_files_
Definition project.h:422
RecentFilesManager & operator=(const RecentFilesManager &)=delete
std::string RomRoleToString(RomRole role)
Definition project.cc:164
RomRole ParseRomRole(absl::string_view value)
Definition project.cc:178
const std::string kRecentFilesFilename
Definition project.h:369
ProjectFormat
Supported project file formats.
Definition project.h:25
RomWritePolicy ParseRomWritePolicy(absl::string_view value)
Definition project.cc:204
std::string RomWritePolicyToString(RomWritePolicy policy)
Definition project.cc:192
Dungeon overlay configuration (per-project).
Definition project.h:91
std::vector< uint16_t > track_object_ids
Definition project.h:98
std::vector< uint16_t > minecart_sprite_ids
Definition project.h:99
std::vector< uint16_t > track_stop_tiles
Definition project.h:94
std::vector< uint16_t > track_tiles
Definition project.h:93
std::vector< uint16_t > track_switch_tiles
Definition project.h:95
Enhanced metadata for project tracking.
Definition project.h:34
std::vector< std::string > tags
Definition project.h:41
std::string CreateOrGetLabel(const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:1966
std::string GetLabel(const std::string &type, const std::string &key)
Definition project.cc:1953
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
Definition project.cc:1935
bool LoadLabels(const std::string &filename)
Definition project.cc:1851
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:1941
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
Definition project.h:365
std::string expected_hash
Definition project.h:107
RomWritePolicy write_policy
Definition project.h:108
Consolidated workspace and UI settings.
Definition project.h:55
std::map< std::string, std::string > custom_keybindings
Definition project.h:82
std::vector< std::string > saved_layouts
Definition project.h:63
std::map< std::string, bool > editor_visibility
Definition project.h:84
std::vector< std::string > recent_files
Definition project.h:83
std::vector< std::string > favorite_models
Definition project.h:194
std::vector< std::string > model_chain
Definition project.h:195
Modern project structure with comprehensive settings consolidation.
Definition project.h:120
std::string rom_backup_folder
Definition project.h:129
std::unordered_map< int, std::vector< std::string > > custom_object_files
Definition project.h:145
absl::Status ResetToDefaults()
Definition project.cc:1165
std::string custom_objects_folder
Definition project.h:140
absl::Status RepairProject()
Definition project.cc:1226
std::string MakeStorageKey(absl::string_view suffix) const
Definition project.cc:452
static std::string ResolveBundleRoot(const std::string &path)
Definition project.cc:269
struct yaze::project::YazeProject::MusicPersistence music_persistence
bool project_opened() const
Definition project.h:285
absl::StatusOr< std::string > SerializeToString() const
Definition project.cc:468
std::string zscream_project_file
Definition project.h:211
absl::Status ExportForZScream(const std::string &target_path)
Definition project.cc:1132
ProjectMetadata metadata
Definition project.h:122
absl::Status ImportZScreamProject(const std::string &zscream_project_path)
Definition project.cc:1109
absl::Status SaveAllSettings()
Definition project.cc:1160
absl::Status ImportLabelsFromZScreamContent(const std::string &content)
Import labels from ZScream format content directly.
Definition project.cc:2074
std::string git_repository
Definition project.h:171
core::HackManifest hack_manifest
Definition project.h:160
void InitializeResourceLabelProvider()
Initialize the global ResourceLabelProvider with this project's labels.
Definition project.cc:2098
absl::Status ParseFromString(const std::string &content)
Definition project.cc:763
std::vector< std::string > additional_roms
Definition project.h:130
std::string patches_folder
Definition project.h:136
absl::Status LoadFromYazeFormat(const std::string &project_path)
Definition project.cc:1050
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > resource_labels
Definition project.h:153
std::string GenerateProjectId() const
Definition project.cc:1550
absl::Status Create(const std::string &project_name, const std::string &base_path)
Definition project.cc:216
std::string assets_folder
Definition project.h:135
absl::Status SaveToYazeFormat()
Definition project.cc:1071
absl::Status LoadAllSettings()
Definition project.cc:1154
std::string labels_filename
Definition project.h:137
std::vector< std::string > asm_sources
Definition project.h:168
std::string hack_manifest_file
Definition project.h:142
std::string GetDisplayName() const
Definition project.cc:1260
std::vector< std::string > GetMissingFiles() const
Definition project.cc:1205
WorkspaceSettings workspace_settings
Definition project.h:149
std::string output_folder
Definition project.h:164
std::string asm_entry_point
Definition project.h:167
std::string GetRelativePath(const std::string &absolute_path) const
Definition project.cc:1267
absl::Status InitializeEmbeddedLabels(const std::unordered_map< std::string, std::unordered_map< std::string, std::string > > &labels)
Definition project.cc:1981
absl::Status SaveAs(const std::string &new_path)
Definition project.cc:440
struct yaze::project::YazeProject::AgentSettings agent_settings
DungeonOverlaySettings dungeon_overlay
Definition project.h:150
absl::Status ImportFromZScreamFormat(const std::string &project_path)
Definition project.cc:1344
std::string GetAbsolutePath(const std::string &relative_path) const
Definition project.cc:1287
std::string GetLabel(const std::string &resource_type, int id, const std::string &default_value="") const
Definition project.cc:2039
absl::Status Open(const std::string &project_path)
Definition project.cc:295
absl::Status ImportLabelsFromZScream(const std::string &filepath)
Import labels from a ZScream DefaultNames.txt file.
Definition project.cc:2054
std::string last_build_hash
Definition project.h:173
std::map< std::string, std::string > zscream_mappings
Definition project.h:212
absl::Status Validate() const
Definition project.cc:1170
core::FeatureFlags::Flags feature_flags
Definition project.h:148
std::vector< std::string > build_configurations
Definition project.h:165
core::RomAddressOverrides rom_address_overrides
Definition project.h:151
std::string symbols_filename
Definition project.h:138