14#include "absl/strings/match.h"
15#include "absl/strings/str_format.h"
16#include "absl/strings/str_join.h"
17#include "absl/strings/str_split.h"
19#include "imgui/imgui.h"
25#include "yaze_config.h"
28#if defined(YAZE_WITH_Z3DK) && __has_include("z3dk_core/config.h")
29#include "z3dk_core/config.h"
51 value.begin(), value.end(), value.begin(),
52 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
57std::pair<std::string, std::string> ParseKeyValue(
const std::string& line) {
58 size_t eq_pos = line.find(
'=');
59 if (eq_pos == std::string::npos)
62 std::string key = line.substr(0, eq_pos);
63 std::string value = line.substr(eq_pos + 1);
66 key.erase(0, key.find_first_not_of(
" \t"));
67 key.erase(key.find_last_not_of(
" \t") + 1);
68 value.erase(0, value.find_first_not_of(
" \t"));
69 value.erase(value.find_last_not_of(
" \t") + 1);
75 return value ==
"true" || value ==
"1" || value ==
"yes";
80 return std::stof(value);
87 std::vector<std::string> result;
91 std::vector<std::string> parts = absl::StrSplit(value,
',');
92 for (
const auto& part : parts) {
93 std::string trimmed = std::string(part);
94 trimmed.erase(0, trimmed.find_first_not_of(
" \t"));
95 trimmed.erase(trimmed.find_last_not_of(
" \t") + 1);
96 if (!trimmed.empty()) {
97 result.push_back(trimmed);
104 std::vector<uint16_t> result;
110 result.reserve(parts.size());
111 for (
const auto& part : parts) {
112 std::string token = part;
113 if (token.rfind(
"0x", 0) == 0 || token.rfind(
"0X", 0) == 0) {
114 token = token.substr(2);
116 result.push_back(
static_cast<uint16_t
>(std::stoul(token,
nullptr, 16)));
122 result.push_back(
static_cast<uint16_t
>(std::stoul(token,
nullptr, 10)));
135 std::string token = value;
136 if (token.rfind(
"0x", 0) == 0 || token.rfind(
"0X", 0) == 0) {
137 token = token.substr(2);
139 return static_cast<uint32_t
>(std::stoul(token,
nullptr, 16));
145 return static_cast<uint32_t
>(std::stoul(token,
nullptr, 10));
152 return absl::StrJoin(values,
",", [](std::string* out, uint16_t value) {
153 out->append(absl::StrFormat(
"0x%02X", value));
158 return absl::StrFormat(
"0x%06X", value);
162 std::string key(input);
163 for (
char& c : key) {
164 if (!std::isalnum(
static_cast<unsigned char>(c))) {
175 auto [key, parsed_value] = ParseKeyValue(value);
179 return {key, parsed_value.empty() ?
"1" : parsed_value};
183 const std::string& value) {
187 std::filesystem::path path(value);
188 if (path.is_absolute()) {
189 return path.lexically_normal().string();
191 return (base_dir / path).lexically_normal().string();
195 return ToLowerCopy(std::filesystem::path(path).filename().
string());
198#ifndef __EMSCRIPTEN__
201 return static_cast<uint64_t
>(::GetCurrentProcessId());
203 return static_cast<uint64_t
>(::getpid());
208 const std::filesystem::path& target_path) {
209 static std::atomic<uint64_t> next_temp_id{0};
210 std::filesystem::path temp_path = target_path;
213 std::to_string(next_temp_id.fetch_add(1, std::memory_order_relaxed));
218 std::error_code remove_error;
219 std::filesystem::remove(temp_path, remove_error);
223 const std::filesystem::path& target_path, absl::string_view contents,
224 bool replace_existing) {
226 std::ofstream file(temp_path, std::ios::binary | std::ios::trunc);
227 if (!file.is_open()) {
228 return absl::InvalidArgumentError(absl::StrFormat(
229 "Cannot create temporary project file: %s", temp_path.string()));
232 file.write(contents.data(),
static_cast<std::streamsize
>(contents.size()));
237 return absl::InternalError(absl::StrFormat(
238 "Failed to write temporary project file: %s", temp_path.string()));
244 return absl::InternalError(absl::StrFormat(
245 "Failed to close temporary project file: %s", temp_path.string()));
248 std::error_code rename_error;
250 const DWORD move_flags =
251 MOVEFILE_WRITE_THROUGH |
252 (replace_existing ? MOVEFILE_REPLACE_EXISTING :
static_cast<DWORD
>(0));
253 if (!::MoveFileExW(temp_path.c_str(), target_path.c_str(), move_flags)) {
254 rename_error = std::error_code(
static_cast<int>(::GetLastError()),
255 std::system_category());
258 if (replace_existing) {
259 std::filesystem::rename(temp_path, target_path, rename_error);
260 }
else if (::link(temp_path.c_str(), target_path.c_str()) != 0) {
261 rename_error = std::error_code(errno, std::generic_category());
268 bool target_already_exists = rename_error == std::errc::file_exists;
270 target_already_exists = target_already_exists ||
271 rename_error.value() == ERROR_FILE_EXISTS ||
272 rename_error.value() == ERROR_ALREADY_EXISTS;
274 if (!replace_existing && target_already_exists) {
275 return absl::AlreadyExistsError(absl::StrFormat(
276 "Project file already exists: %s", target_path.string()));
278 return absl::InternalError(
279 absl::StrFormat(
"Failed to replace project file %s: %s",
280 target_path.string(), rename_error.message()));
283 return absl::OkStatus();
288#ifndef __EMSCRIPTEN__
290 absl::string_view contents,
291 bool replace_existing) {
292 return WriteProjectFileAtomicallyImpl(
293 std::filesystem::path(std::string(target_path)), contents,
313 std::string lower = ToLowerCopy(std::string(value));
314 if (lower ==
"base") {
317 if (lower ==
"patched") {
320 if (lower ==
"release") {
339 std::string lower = ToLowerCopy(std::string(value));
340 if (lower ==
"allow") {
343 if (lower ==
"block") {
351 const std::string& base_path) {
353 filepath = base_path +
"/" + project_name +
".yaze";
356 auto now = std::chrono::system_clock::now();
357 auto time_t = std::chrono::system_clock::to_time_t(now);
358 std::stringstream ss;
359 ss << std::put_time(std::localtime(&time_t),
"%Y-%m-%d %H:%M:%S");
370#ifndef __EMSCRIPTEN__
372 std::filesystem::path project_dir(base_path +
"/" + project_name);
373 std::filesystem::create_directories(project_dir);
374 std::filesystem::create_directories(project_dir /
"code");
375 std::filesystem::create_directories(project_dir /
"assets");
376 std::filesystem::create_directories(project_dir /
"patches");
377 std::filesystem::create_directories(project_dir /
"backups");
378 std::filesystem::create_directories(project_dir /
"output");
411 auto current = std::filesystem::path(path).lexically_normal();
413 for (; !current.empty(); current = current.parent_path()) {
414 if (current.extension() ==
".yazeproj") {
416 if (std::filesystem::is_directory(current, ec) && !ec) {
417 return current.string();
421 if (current == current.parent_path()) {
433 std::string resolved_path = project_path;
435 if (!bundle_root.empty() && bundle_root != project_path) {
437 resolved_path = bundle_root;
440#ifndef __EMSCRIPTEN__
445 std::error_code absolute_ec;
446 const auto absolute_path =
447 std::filesystem::absolute(resolved_path, absolute_ec).lexically_normal();
449 resolved_path = absolute_path.string();
458 auto storage_or = platform::WasmStorage::LoadProject(storage_key);
459 if (storage_or.ok()) {
465 absl::Status load_status;
466 if (resolved_path.ends_with(
".yazeproj")) {
469 const std::filesystem::path bundle_path(resolved_path);
471 if (!std::filesystem::exists(bundle_path, ec) || ec ||
472 !std::filesystem::is_directory(bundle_path, ec) || ec) {
473 return absl::InvalidArgumentError(
474 absl::StrFormat(
"Project bundle does not exist: %s", resolved_path));
479 const std::filesystem::path project_file = bundle_path /
"project.yaze";
482 if (!std::filesystem::exists(project_file, ec) || ec) {
485 name = bundle_path.stem().string();
488 auto now = std::chrono::system_clock::now();
489 auto time_t = std::chrono::system_clock::to_time_t(now);
490 std::stringstream ss;
491 ss << std::put_time(std::localtime(&time_t),
"%Y-%m-%d %H:%M:%S");
511 const std::filesystem::path rom_candidate = bundle_path /
"rom";
518 const std::filesystem::path project_dir = bundle_path /
"project";
519 const std::filesystem::path code_dir = bundle_path /
"code";
520 if (std::filesystem::exists(project_dir, ec) &&
521 std::filesystem::is_directory(project_dir, ec) && !ec) {
523 }
else if (std::filesystem::exists(code_dir, ec) &&
524 std::filesystem::is_directory(code_dir, ec) && !ec) {
539 }
else if (resolved_path.ends_with(
".yaze")) {
543 std::ifstream file(resolved_path);
544 if (file.is_open()) {
545 std::stringstream buffer;
546 buffer << file.rdbuf();
547 std::string content = buffer.str();
549#ifdef YAZE_ENABLE_JSON_PROJECT_FORMAT
550 if (!content.empty() && content.front() ==
'{') {
551 LOG_DEBUG(
"Project",
"Detected JSON format project file");
552 load_status = LoadFromJsonFormat(resolved_path);
560 return absl::InvalidArgumentError(
561 absl::StrFormat(
"Cannot open project file: %s", resolved_path));
563 }
else if (resolved_path.ends_with(
".zsproj")) {
567 return absl::InvalidArgumentError(
"Unsupported project file format");
570 if (!load_status.ok()) {
584 return absl::OkStatus();
596 const std::string& project_path) {
597 if (project_path.empty()) {
598 return absl::InvalidArgumentError(
"Project file path cannot be empty");
603#ifndef __EMSCRIPTEN__
605 const auto absolute_path =
606 std::filesystem::absolute(project_path, ec).lexically_normal();
608 ec ? std::filesystem::path(project_path).lexically_normal().string()
609 : absolute_path.string();
616 }
catch (
const std::exception& error) {
617 return absl::InvalidArgumentError(
618 absl::StrFormat(
"Invalid project file value: %s", error.what()));
623 return absl::OkStatus();
627 std::string old_filepath =
filepath;
630 auto status =
Save();
642 }
else if (!
name.empty()) {
645 base = std::filesystem::path(
filepath).stem().string();
647 base = SanitizeStorageKey(base);
648 if (suffix.empty()) {
651 return absl::StrFormat(
"%s_%s", base, suffix);
655 std::ostringstream file;
658 file <<
"# yaze Project File\n";
659 file <<
"# Format Version: 2.0\n";
664 file <<
"[project]\n";
665 file <<
"name=" <<
name <<
"\n";
675 file <<
"tags=" << absl::StrJoin(
metadata.
tags,
",") <<
"\n\n";
690 file <<
"additional_roms=" << absl::StrJoin(
additional_roms,
",") <<
"\n\n";
700 file <<
"[feature_flags]\n";
701 file <<
"load_custom_overworld="
704 file <<
"apply_zs_custom_overworld_asm="
708 file <<
"save_dungeon_maps="
710 file <<
"save_overworld_maps="
713 file <<
"save_overworld_entrances="
716 file <<
"save_overworld_exits="
719 file <<
"save_overworld_items="
722 file <<
"save_overworld_properties="
725 file <<
"save_dungeon_objects="
727 file <<
"save_dungeon_sprites="
729 file <<
"save_dungeon_room_headers="
731 file <<
"save_dungeon_torches="
733 file <<
"save_dungeon_pits="
735 file <<
"save_dungeon_blocks="
737 file <<
"save_dungeon_collision="
739 file <<
"save_dungeon_chests="
741 file <<
"save_dungeon_pot_items="
743 file <<
"save_dungeon_entrances="
745 file <<
"save_dungeon_palettes="
747 file <<
"save_graphics_sheet="
749 file <<
"save_all_palettes="
751 file <<
"save_gfx_groups="
755 file <<
"enable_custom_objects="
759 file <<
"[workspace]\n";
764 file <<
"autosave_enabled="
768 file <<
"backup_on_save="
772 file <<
"backup_keep_daily="
778 file <<
"show_collision="
780 file <<
"prefer_hmagic_names="
784 file <<
"saved_layouts="
791 if (track_tiles.empty()) {
792 for (uint16_t tile = 0xB0; tile <= 0xBE; ++tile) {
793 track_tiles.push_back(tile);
797 if (track_stop_tiles.empty()) {
798 track_stop_tiles = {0xB7, 0xB8, 0xB9, 0xBA};
801 if (track_switch_tiles.empty()) {
802 track_switch_tiles = {0xD0, 0xD1, 0xD2, 0xD3};
805 if (track_object_ids.empty()) {
806 track_object_ids = {0x31};
809 if (minecart_sprite_ids.empty()) {
810 minecart_sprite_ids = {0xA3};
812 file <<
"[dungeon_overlay]\n";
813 file <<
"track_tiles=" << FormatHexUintList(track_tiles) <<
"\n";
814 file <<
"track_stop_tiles=" << FormatHexUintList(track_stop_tiles) <<
"\n";
815 file <<
"track_switch_tiles=" << FormatHexUintList(track_switch_tiles)
817 file <<
"track_object_ids=" << FormatHexUintList(track_object_ids) <<
"\n";
818 file <<
"minecart_sprite_ids=" << FormatHexUintList(minecart_sprite_ids)
822 file <<
"[rom_addresses]\n";
824 file << key <<
"=" << FormatHexUint32(value) <<
"\n";
830 file <<
"[custom_objects]\n";
832 file << absl::StrFormat(
"object_0x%X", object_id) <<
"="
833 << absl::StrJoin(files,
",") <<
"\n";
839 file <<
"[agent_settings]\n";
844 file <<
"custom_system_prompt="
846 file <<
"use_custom_prompt="
848 file <<
"show_reasoning="
856 file <<
"stream_responses="
858 file <<
"favorite_models="
863 file <<
"enable_tool_resources="
865 file <<
"enable_tool_dungeon="
867 file <<
"enable_tool_overworld="
869 file <<
"enable_tool_messages="
871 file <<
"enable_tool_dialogue="
873 file <<
"enable_tool_gui="
875 file <<
"enable_tool_music="
877 file <<
"enable_tool_sprite="
879 file <<
"enable_tool_emulator="
881 file <<
"enable_tool_memory_inspector="
889 file <<
"[keybindings]\n";
891 file << key <<
"=" << value <<
"\n";
898 file <<
"[editor_visibility]\n";
900 file << key <<
"=" << (value ?
"true" :
"false") <<
"\n";
907 if (!labels.empty()) {
908 file <<
"[labels_" << type <<
"]\n";
909 for (
const auto& [key, value] : labels) {
910 file << key <<
"=" << value <<
"\n";
921 file <<
"track_changes=" << (
track_changes ?
"true" :
"false") <<
"\n";
926 file <<
"asm_sources=" << absl::StrJoin(
asm_sources,
",") <<
"\n";
932 file <<
"persist_custom_music="
939 file <<
"[zscream_compatibility]\n";
942 file << key <<
"=" << value <<
"\n";
947 file <<
"# End of YAZE Project File\n";
952 std::istringstream stream(content);
954 std::string current_section;
956 while (std::getline(stream, line)) {
957 if (line.empty() || line[0] ==
'#')
960 if (line.front() ==
'[' && line.back() ==
']') {
961 current_section = line.substr(1, line.length() - 2);
965 auto [key, value] = ParseKeyValue(line);
969 if (current_section ==
"project") {
972 else if (key ==
"description")
974 else if (key ==
"author")
976 else if (key ==
"license")
978 else if (key ==
"version")
980 else if (key ==
"created_date")
982 else if (key ==
"last_modified")
984 else if (key ==
"yaze_version")
986 else if (key ==
"created_by")
988 else if (key ==
"tags")
990 else if (key ==
"project_id")
992 }
else if (current_section ==
"files") {
993 if (key ==
"rom_filename")
995 else if (key ==
"rom_backup_folder")
997 else if (key ==
"code_folder")
999 else if (key ==
"assets_folder")
1001 else if (key ==
"patches_folder")
1003 else if (key ==
"labels_filename")
1005 else if (key ==
"symbols_filename")
1007 else if (key ==
"output_folder")
1009 else if (key ==
"custom_objects_folder")
1011 else if (key ==
"hack_manifest_file")
1013 else if (key ==
"additional_roms")
1015 }
else if (current_section ==
"rom") {
1018 else if (key ==
"expected_hash")
1020 else if (key ==
"write_policy")
1022 }
else if (current_section ==
"feature_flags") {
1023 if (key ==
"load_custom_overworld")
1025 else if (key ==
"apply_zs_custom_overworld_asm")
1027 else if (key ==
"save_dungeon_maps")
1029 else if (key ==
"save_overworld_maps")
1031 else if (key ==
"save_overworld_entrances")
1033 else if (key ==
"save_overworld_exits")
1035 else if (key ==
"save_overworld_items")
1037 else if (key ==
"save_overworld_properties")
1039 else if (key ==
"save_dungeon_objects")
1041 else if (key ==
"save_dungeon_sprites")
1043 else if (key ==
"save_dungeon_room_headers")
1045 else if (key ==
"save_dungeon_torches")
1047 else if (key ==
"save_dungeon_pits")
1049 else if (key ==
"save_dungeon_blocks")
1051 else if (key ==
"save_dungeon_collision")
1053 else if (key ==
"save_dungeon_chests")
1055 else if (key ==
"save_dungeon_pot_items")
1057 else if (key ==
"save_dungeon_entrances")
1059 else if (key ==
"save_dungeon_palettes")
1061 else if (key ==
"save_graphics_sheet")
1063 else if (key ==
"save_all_palettes")
1065 else if (key ==
"save_gfx_groups")
1067 else if (key ==
"save_messages")
1069 else if (key ==
"enable_custom_objects")
1071 }
else if (current_section ==
"workspace") {
1072 if (key ==
"font_global_scale")
1074 else if (key ==
"dark_mode")
1076 else if (key ==
"ui_theme")
1078 else if (key ==
"autosave_enabled")
1080 else if (key ==
"autosave_interval_secs")
1082 else if (key ==
"backup_on_save")
1084 else if (key ==
"backup_retention_count")
1086 else if (key ==
"backup_keep_daily")
1088 else if (key ==
"backup_keep_daily_days")
1090 else if (key ==
"show_grid")
1092 else if (key ==
"show_collision")
1094 else if (key ==
"prefer_hmagic_names")
1096 else if (key ==
"last_layout_preset")
1098 else if (key ==
"saved_layouts")
1100 else if (key ==
"recent_files")
1102 }
else if (current_section ==
"dungeon_overlay") {
1103 if (key ==
"track_tiles")
1105 else if (key ==
"track_stop_tiles")
1107 else if (key ==
"track_switch_tiles")
1109 else if (key ==
"track_object_ids")
1111 else if (key ==
"minecart_sprite_ids")
1113 }
else if (current_section ==
"rom_addresses") {
1114 auto parsed = ParseHexUint32(value);
1115 if (parsed.has_value()) {
1118 }
else if (current_section ==
"custom_objects") {
1119 std::string id_token = key;
1120 if (absl::StartsWith(id_token,
"object_")) {
1121 id_token = id_token.substr(7);
1123 auto parsed = ParseHexUint32(id_token);
1124 if (parsed.has_value()) {
1127 }
else if (current_section ==
"agent_settings") {
1128 if (key ==
"ai_provider")
1130 else if (key ==
"ai_model")
1132 else if (key ==
"ollama_host")
1134 else if (key ==
"gemini_api_key")
1136 else if (key ==
"custom_system_prompt")
1138 else if (key ==
"use_custom_prompt")
1140 else if (key ==
"show_reasoning")
1142 else if (key ==
"verbose")
1144 else if (key ==
"max_tool_iterations")
1146 else if (key ==
"max_retry_attempts")
1148 else if (key ==
"temperature")
1150 else if (key ==
"top_p")
1152 else if (key ==
"max_output_tokens")
1154 else if (key ==
"stream_responses")
1156 else if (key ==
"favorite_models")
1158 else if (key ==
"model_chain")
1160 else if (key ==
"chain_mode")
1162 else if (key ==
"enable_tool_resources")
1164 else if (key ==
"enable_tool_dungeon")
1166 else if (key ==
"enable_tool_overworld")
1168 else if (key ==
"enable_tool_messages")
1170 else if (key ==
"enable_tool_dialogue")
1172 else if (key ==
"enable_tool_gui")
1174 else if (key ==
"enable_tool_music")
1176 else if (key ==
"enable_tool_sprite")
1178 else if (key ==
"enable_tool_emulator")
1180 else if (key ==
"enable_tool_memory_inspector")
1182 else if (key ==
"builder_blueprint_path")
1184 }
else if (current_section ==
"build") {
1185 if (key ==
"build_script")
1187 else if (key ==
"output_folder")
1189 else if (key ==
"git_repository")
1191 else if (key ==
"track_changes")
1193 else if (key ==
"build_configurations")
1195 else if (key ==
"build_target")
1197 else if (key ==
"asm_entry_point")
1199 else if (key ==
"asm_sources")
1201 else if (key ==
"last_build_hash")
1203 else if (key ==
"build_number")
1205 }
else if (current_section.rfind(
"labels_", 0) == 0) {
1206 std::string label_type = current_section.substr(7);
1208 }
else if (current_section ==
"keybindings") {
1210 }
else if (current_section ==
"editor_visibility") {
1212 }
else if (current_section ==
"zscream_compatibility") {
1213 if (key ==
"original_project_file")
1217 }
else if (current_section ==
"music") {
1218 if (key ==
"persist_custom_music")
1220 else if (key ==
"storage_key")
1222 else if (key ==
"last_saved_at")
1237 return absl::OkStatus();
1241#ifdef __EMSCRIPTEN__
1243 auto storage_or = platform::WasmStorage::LoadProject(storage_key);
1244 if (storage_or.ok()) {
1249 std::ifstream file(project_path);
1250 if (!file.is_open()) {
1251 return absl::InvalidArgumentError(
1252 absl::StrFormat(
"Cannot open project file: %s", project_path));
1255 std::stringstream buffer;
1256 buffer << file.rdbuf();
1263 auto now = std::chrono::system_clock::now();
1264 auto time_t = std::chrono::system_clock::to_time_t(now);
1265 std::stringstream ss;
1266 ss << std::put_time(std::localtime(&time_t),
"%Y-%m-%d %H:%M:%S");
1278#ifdef __EMSCRIPTEN__
1279 auto storage_status = platform::WasmStorage::SaveProject(
1281 if (!storage_status.ok()) {
1282 return storage_status;
1291 return absl::OkStatus();
1295 const std::string& zscream_project_path) {
1301 std::filesystem::path zs_path(zscream_project_path);
1302 name = zs_path.stem().string() +
"_imported";
1314 return absl::OkStatus();
1319 std::ofstream file(target_path);
1320 if (!file.is_open()) {
1321 return absl::InvalidArgumentError(
1322 absl::StrFormat(
"Cannot create ZScream project file: %s", target_path));
1326 file <<
"# ZScream Compatible Project File\n";
1328 file <<
"name=" <<
name <<
"\n";
1336 return absl::OkStatus();
1356 std::vector<std::string> errors;
1359 errors.push_back(
"Project name is required");
1361 errors.push_back(
"Project file path is required");
1363 errors.push_back(
"ROM file is required");
1365#ifndef __EMSCRIPTEN__
1369 errors.push_back(
"ROM file does not exist: " +
rom_filename);
1374 errors.push_back(
"Code folder does not exist: " +
code_folder);
1384 errors.push_back(
"Hack manifest file does not exist: " +
1387 errors.push_back(
"Hack manifest file failed to load: " +
1393 if (!errors.empty()) {
1394 return absl::InvalidArgumentError(absl::StrJoin(errors,
"; "));
1397 return absl::OkStatus();
1401 std::vector<std::string> missing;
1403#ifndef __EMSCRIPTEN__
1426#ifdef __EMSCRIPTEN__
1428 return absl::OkStatus();
1435 for (
const auto& folder : folders) {
1436 if (!folder.empty()) {
1438 if (!std::filesystem::exists(abs_path)) {
1439 std::filesystem::create_directories(abs_path);
1447 if (!std::filesystem::exists(abs_labels)) {
1448 std::ofstream labels_file(abs_labels);
1449 labels_file <<
"# yaze Resource Labels\n";
1450 labels_file <<
"# Format: [type] key=value\n\n";
1451 labels_file.close();
1455 return absl::OkStatus();
1463 return name.empty() ?
"Untitled Project" :
name;
1467 const std::string& absolute_path)
const {
1468 if (absolute_path.empty() ||
filepath.empty())
1469 return absolute_path;
1471 std::filesystem::path project_dir =
1472 std::filesystem::path(
filepath).parent_path();
1473 std::filesystem::path abs_path(absolute_path);
1476 std::filesystem::path relative =
1477 std::filesystem::relative(abs_path.lexically_normal(), project_dir);
1479 return relative.generic_string();
1482 return abs_path.lexically_normal().generic_string();
1487 const std::string& relative_path)
const {
1488 if (relative_path.empty() ||
filepath.empty())
1489 return relative_path;
1491 std::filesystem::path project_dir =
1492 std::filesystem::path(
filepath).parent_path();
1493 std::filesystem::path abs_path(relative_path);
1494 if (abs_path.is_absolute()) {
1495 abs_path = abs_path.lexically_normal();
1496 abs_path.make_preferred();
1497 return abs_path.string();
1499 abs_path = (project_dir / abs_path).lexically_normal();
1500 abs_path.make_preferred();
1502 return abs_path.string();
1506#ifdef __EMSCRIPTEN__
1514 auto normalize = [
this](std::string* path) {
1515 if (!path || path->empty()) {
1533 if (!rom_path.empty()) {
1544 const std::string& project_path) {
1548 std::filesystem::path zs_path(project_path);
1549 name = zs_path.stem().string() +
"_imported";
1554 return absl::OkStatus();
1566 absl::string_view artifact_name)
const {
1567 std::filesystem::path base_dir;
1575 base_dir = std::filesystem::path(
filepath).parent_path();
1578 if (base_dir.empty()) {
1579 return std::string(artifact_name);
1581 return (base_dir / std::string(artifact_name)).lexically_normal().string();
1587#if defined(YAZE_WITH_Z3DK) && __has_include("z3dk_core/config.h")
1588 std::vector<std::filesystem::path> candidates;
1589 auto add_candidate = [&candidates](
const std::filesystem::path& candidate) {
1590 if (candidate.empty()) {
1593 auto normalized = candidate.lexically_normal();
1594 if (std::find(candidates.begin(), candidates.end(), normalized) ==
1596 candidates.push_back(normalized);
1602 if (!std::filesystem::is_directory(code_path)) {
1603 code_path = code_path.parent_path();
1605 add_candidate(code_path /
"z3dk.toml");
1614 add_candidate(std::filesystem::path(
filepath).parent_path() /
"z3dk.toml");
1617 for (
const auto& candidate : candidates) {
1618 if (!std::filesystem::exists(candidate)) {
1623 z3dk::Config config = z3dk::LoadConfigFile(candidate.string(), &error);
1624 if (!error.empty()) {
1625 LOG_WARN(
"Project",
"Failed to parse z3dk config '%s': %s",
1626 candidate.string().c_str(), error.c_str());
1630 const std::filesystem::path base_dir = candidate.parent_path();
1633 if (config.preset.has_value()) {
1638 for (
const auto& include_path : config.include_paths) {
1640 ResolveOptionalPath(base_dir, include_path));
1644 for (
const auto& define : config.defines) {
1649 for (
const auto& main_file : config.main_files) {
1651 ResolveOptionalPath(base_dir, main_file));
1654 if (config.std_includes_path.has_value()) {
1656 ResolveOptionalPath(base_dir, *config.std_includes_path);
1658 if (config.std_defines_path.has_value()) {
1660 ResolveOptionalPath(base_dir, *config.std_defines_path);
1662 if (config.mapper.has_value()) {
1665 if (config.rom_size.has_value()) {
1668 if (config.symbols_format.has_value()) {
1672 if (config.lsp_log_path.has_value()) {
1674 ResolveOptionalPath(base_dir, *config.lsp_log_path);
1678 for (
const auto& emit_path : config.emits) {
1682 for (
const auto& range : config.prohibited_memory_ranges) {
1684 {.start = range.start, .end = range.end, .reason = range.reason});
1688 config.warn_unused_symbols.value_or(
true);
1690 config.warn_branch_outside_bank.value_or(
true);
1694 config.warn_unauthorized_hook.value_or(
true);
1698 if (config.rom_path.has_value()) {
1701 if (config.symbols_path.has_value()) {
1703 ResolveOptionalPath(base_dir, *config.symbols_path);
1707 const std::string basename = BasenameLower(emit_path);
1708 if (basename.ends_with(
".mlb") &&
1711 }
else if (basename ==
"sourcemap.json") {
1713 }
else if (basename ==
"annotations.json") {
1715 }
else if (basename ==
"hooks.json") {
1717 }
else if (basename ==
"lint.json") {
1748 "Loaded z3dk config from %s (%zu include paths, %zu defines)",
1757#ifdef __EMSCRIPTEN__
1767 std::filesystem::path loaded_manifest_path;
1768 auto load_manifest = [&](
const std::filesystem::path& candidate,
1769 bool update_project_setting) ->
bool {
1770 if (candidate.empty() || !std::filesystem::exists(candidate)) {
1775 LOG_WARN(
"Project",
"Failed to load hack manifest %s: %s",
1776 candidate.string().c_str(),
1777 std::string(status.message()).c_str());
1780 loaded_manifest_path = candidate;
1781 if (update_project_setting) {
1784 LOG_DEBUG(
"Project",
"Loaded hack manifest: %s",
1785 candidate.string().c_str());
1794 if (has_explicit_manifest) {
1802 auto candidate = std::filesystem::path(code_path) /
"hack_manifest.json";
1803 (void)load_manifest(candidate,
true);
1808 const std::filesystem::path project_dir =
1809 std::filesystem::path(
filepath).parent_path();
1810 (void)load_manifest(project_dir /
"hack_manifest.json",
true);
1812 (void)load_manifest(project_dir.parent_path() /
"hack_manifest.json",
1821 auto try_load_registry = [&](
const std::filesystem::path& base) ->
bool {
1825 const auto planning = base /
"Docs" /
"Dev" /
"Planning";
1826 if (!std::filesystem::exists(planning)) {
1831 LOG_WARN(
"Project",
"Failed to load project registry from %s: %s",
1832 base.string().c_str(), std::string(status.message()).c_str());
1838 bool registry_loaded =
false;
1847 if (!registry_loaded && !loaded_manifest_path.empty()) {
1848 registry_loaded = try_load_registry(loaded_manifest_path.parent_path());
1852 if (!registry_loaded && !
filepath.empty()) {
1854 try_load_registry(std::filesystem::path(
filepath).parent_path());
1857 if (!registry_loaded) {
1862 "Hack manifest loaded but project registry was not found "
1863 "(code_folder='%s', manifest='%s')",
1864 code_folder.c_str(), loaded_manifest_path.string().c_str());
1869 size_t injected = 0;
1870 for (
const auto& [type_key, labels] :
1872 for (
const auto& [id_str, label] : labels) {
1877 LOG_DEBUG(
"Project",
"Loaded project registry: %zu resource labels injected",
1919 for (uint16_t tile = 0xB0; tile <= 0xBE; ++tile) {
1951 auto now = std::chrono::system_clock::now().time_since_epoch();
1953 std::chrono::duration_cast<std::chrono::milliseconds>(now).count();
1954 return absl::StrFormat(
"yaze_project_%lld", timestamp);
1958std::vector<ProjectManager::ProjectTemplate>
1960 std::vector<ProjectTemplate> templates;
1969 t.
name =
"Vanilla ROM Hack";
1971 "Standard ROM editing without custom ASM. Limited to vanilla features.";
1980 templates.push_back(t);
1986 t.
name =
"ZSCustomOverworld v2";
1988 "Basic overworld expansion: custom BG colors, main palettes, parent "
2001 templates.push_back(t);
2007 t.
name =
"ZSCustomOverworld v3 (Recommended)";
2009 "Full overworld expansion: wide/tall areas, animated GFX, overlays, "
2026 templates.push_back(t);
2032 t.
name =
"Randomizer Compatible";
2034 "Compatible with ALttP Randomizer. Minimal custom features to avoid "
2043 templates.push_back(t);
2053 t.
name =
"Dungeon Designer";
2054 t.
description =
"Focused on dungeon creation and modification.";
2061 templates.push_back(t);
2067 t.
name =
"Graphics Pack";
2069 "Project focused on graphics, sprites, and visual modifications.";
2078 templates.push_back(t);
2084 t.
name =
"Complete Overhaul";
2085 t.
description =
"Full-scale ROM hack with all features enabled.";
2100 templates.push_back(t);
2107 const std::string& template_name,
const std::string& project_name,
2108 const std::string& base_path) {
2110 auto status = project.
Create(project_name, base_path);
2116 if (template_name ==
"Full Overworld Mod") {
2120 project.
metadata.
tags = {
"overworld",
"maps",
"graphics"};
2121 }
else if (template_name ==
"Dungeon Designer") {
2125 project.
metadata.
tags = {
"dungeons",
"rooms",
"design"};
2126 }
else if (template_name ==
"Graphics Pack") {
2130 project.
metadata.
tags = {
"graphics",
"sprites",
"palettes"};
2131 }
else if (template_name ==
"Complete Overhaul") {
2137 project.
metadata.
tags = {
"complete",
"overhaul",
"full-mod"};
2140 status = project.
Save();
2149 const std::string& directory) {
2150#ifdef __EMSCRIPTEN__
2154 std::vector<std::string> projects;
2157 for (
const auto& entry : std::filesystem::directory_iterator(directory)) {
2158 if (entry.is_regular_file()) {
2159 std::string filename = entry.path().filename().string();
2160 if (filename.ends_with(
".yaze") || filename.ends_with(
".zsproj")) {
2161 projects.push_back(entry.path().string());
2163 }
else if (entry.is_directory()) {
2164 std::string filename = entry.path().filename().string();
2165 if (filename.ends_with(
".yazeproj")) {
2166 projects.push_back(entry.path().string());
2170 }
catch (
const std::filesystem::filesystem_error& e) {
2179#ifdef __EMSCRIPTEN__
2181 return absl::UnimplementedError(
2182 "Project backups are not supported in the web build");
2185 return absl::InvalidArgumentError(
"Project has no file path");
2188 std::filesystem::path project_path(project.
filepath);
2189 std::filesystem::path backup_dir = project_path.parent_path() /
"backups";
2190 std::filesystem::create_directories(backup_dir);
2192 auto now = std::chrono::system_clock::now();
2193 auto time_t = std::chrono::system_clock::to_time_t(now);
2194 std::stringstream ss;
2195 ss << std::put_time(std::localtime(&time_t),
"%Y%m%d_%H%M%S");
2197 std::string backup_filename = project.
name +
"_backup_" + ss.str() +
".yaze";
2198 std::filesystem::path backup_path = backup_dir / backup_filename;
2201 std::filesystem::copy_file(project.
filepath, backup_path);
2202 }
catch (
const std::filesystem::filesystem_error& e) {
2203 return absl::InternalError(
2204 absl::StrFormat(
"Failed to backup project: %s", e.what()));
2207 return absl::OkStatus();
2218 std::vector<std::string> recommendations;
2221 recommendations.push_back(
"Add a ROM file to begin editing");
2225 recommendations.push_back(
"Set up a code folder for assembly patches");
2229 recommendations.push_back(
"Create a labels file for better organization");
2233 recommendations.push_back(
"Add a project description for documentation");
2237 recommendations.push_back(
2238 "Consider setting up version control for your project");
2242 if (!missing_files.empty()) {
2243 recommendations.push_back(
2244 "Some project files are missing - use Project > Repair to fix");
2247 return recommendations;
2253 std::ifstream file(filename);
2254 if (!file.is_open()) {
2261 std::string current_type =
"";
2263 while (std::getline(file, line)) {
2264 if (line.empty() || line[0] ==
'#')
2268 if (line[0] ==
'[' && line.back() ==
']') {
2269 current_type = line.substr(1, line.length() - 2);
2274 size_t eq_pos = line.find(
'=');
2275 if (eq_pos != std::string::npos && !current_type.empty()) {
2276 std::string key = line.substr(0, eq_pos);
2277 std::string value = line.substr(eq_pos + 1);
2278 labels_[current_type][key] = value;
2292 if (!file.is_open())
2295 file <<
"# yaze Resource Labels\n";
2296 file <<
"# Format: [type] followed by key=value pairs\n\n";
2298 for (
const auto& [type, type_labels] :
labels_) {
2299 if (!type_labels.empty()) {
2300 file <<
"[" << type <<
"]\n";
2301 for (
const auto& [key, value] : type_labels) {
2302 file << key <<
"=" << value <<
"\n";
2313 if (!p_open || !*p_open)
2317 if (ImGui::Begin(
"Resource Labels", p_open)) {
2318 ImGui::Text(
"Resource Labels Manager");
2320 ImGui::Text(
"Total types: %zu",
labels_.size());
2322 for (
const auto& [type, type_labels] :
labels_) {
2323 if (ImGui::TreeNode(type.c_str())) {
2324 ImGui::Text(
"Labels: %zu", type_labels.size());
2325 for (
const auto& [key, value] : type_labels) {
2326 ImGui::Text(
"%s = %s", key.c_str(), value.c_str());
2336 const std::string& key,
2337 const std::string& newValue) {
2338 labels_[type][key] = newValue;
2342 bool selected,
const std::string& type,
const std::string& key,
2343 const std::string& defaultValue) {
2345 if (ImGui::Selectable(
2346 absl::StrFormat(
"%s: %s", key.c_str(),
GetLabel(type, key).c_str())
2354 const std::string& key) {
2355 auto type_it =
labels_.find(type);
2359 auto label_it = type_it->second.find(key);
2360 if (label_it == type_it->second.end())
2363 return label_it->second;
2367 const std::string& type,
const std::string& key,
2368 const std::string& defaultValue) {
2369 auto existing =
GetLabel(type, key);
2370 if (!existing.empty())
2373 labels_[type][key] = defaultValue;
2374 return defaultValue;
2382 const std::unordered_map<
2383 std::string, std::unordered_map<std::string, std::string>>& labels) {
2412 LOG_DEBUG(
"Project",
"Initialized embedded labels:");
2414 LOG_DEBUG(
"Project",
" - %d entrance names",
2416 LOG_DEBUG(
"Project",
" - %d sprite names",
2418 LOG_DEBUG(
"Project",
" - %d overlord names",
2421 LOG_DEBUG(
"Project",
" - %d music names",
2423 LOG_DEBUG(
"Project",
" - %d graphics names",
2425 LOG_DEBUG(
"Project",
" - %d room effect names",
2427 LOG_DEBUG(
"Project",
" - %d room tag names",
2429 LOG_DEBUG(
"Project",
" - %d tile type names",
2432 return absl::OkStatus();
2433 }
catch (
const std::exception& e) {
2434 return absl::InternalError(
2435 absl::StrCat(
"Failed to initialize embedded labels: ", e.what()));
2440 const std::string& default_value)
const {
2444 auto label_it = type_it->second.find(std::to_string(
id));
2445 if (label_it != type_it->second.end()) {
2446 return label_it->second;
2450 return default_value.empty() ? resource_type +
"_" + std::to_string(
id)
2455#ifdef __EMSCRIPTEN__
2457 return absl::UnimplementedError(
2458 "File-based label import is not supported in the web build");
2461 if (!file.is_open()) {
2462 return absl::InvalidArgumentError(
2463 absl::StrFormat(
"Cannot open labels file: %s",
filepath));
2466 std::stringstream buffer;
2467 buffer << file.rdbuf();
2475 const std::string& content) {
2482 auto status = provider.ImportFromZScreamFormat(content);
2487 LOG_DEBUG(
"Project",
"Imported ZScream labels:");
2488 LOG_DEBUG(
"Project",
" - %d sprite labels",
2492 LOG_DEBUG(
"Project",
" - %d room tag labels",
2495 return absl::OkStatus();
2504 LOG_DEBUG(
"Project",
"Initialized ResourceLabelProvider with project labels");
2505 LOG_DEBUG(
"Project",
" - prefer_hmagic_names: %s",
2507 LOG_DEBUG(
"Project",
" - hack_manifest: %s",
2515#ifdef YAZE_ENABLE_JSON_PROJECT_FORMAT
2517absl::Status YazeProject::LoadFromJsonFormat(
const std::string& project_path) {
2518#ifdef __EMSCRIPTEN__
2519 return absl::UnimplementedError(
2520 "JSON project format loading is not supported in the web build");
2522 std::ifstream file(project_path);
2523 if (!file.is_open()) {
2524 return absl::InvalidArgumentError(
2525 absl::StrFormat(
"Cannot open JSON project file: %s", project_path));
2533 if (j.contains(
"yaze_project")) {
2534 auto& proj = j[
"yaze_project"];
2536 if (proj.contains(
"name"))
2537 name = proj[
"name"].get<std::string>();
2538 if (proj.contains(
"description"))
2540 if (proj.contains(
"author"))
2542 if (proj.contains(
"version"))
2544 if (proj.contains(
"created"))
2546 if (proj.contains(
"modified"))
2548 if (proj.contains(
"created_by"))
2552 if (proj.contains(
"rom_filename"))
2553 rom_filename = proj[
"rom_filename"].get<std::string>();
2554 if (proj.contains(
"rom_backup_folder"))
2556 if (proj.contains(
"code_folder"))
2557 code_folder = proj[
"code_folder"].get<std::string>();
2558 if (proj.contains(
"assets_folder"))
2560 if (proj.contains(
"patches_folder"))
2562 if (proj.contains(
"labels_filename"))
2564 if (proj.contains(
"symbols_filename"))
2566 if (proj.contains(
"hack_manifest_file"))
2569 if (proj.contains(
"rom") && proj[
"rom"].is_object()) {
2570 auto& rom = proj[
"rom"];
2571 if (rom.contains(
"role"))
2573 if (rom.contains(
"expected_hash"))
2575 if (rom.contains(
"write_policy"))
2581 if (proj.contains(
"use_embedded_labels")) {
2586 if (proj.contains(
"feature_flags")) {
2587 auto& flags = proj[
"feature_flags"];
2590 if (flags.contains(
"kSaveDungeonMaps"))
2592 flags[
"kSaveDungeonMaps"].get<
bool>();
2593 if (flags.contains(
"kSaveOverworldMaps"))
2595 flags[
"kSaveOverworldMaps"].get<
bool>();
2596 if (flags.contains(
"kSaveOverworldEntrances"))
2598 flags[
"kSaveOverworldEntrances"].get<
bool>();
2599 if (flags.contains(
"kSaveOverworldExits"))
2601 flags[
"kSaveOverworldExits"].get<
bool>();
2602 if (flags.contains(
"kSaveOverworldItems"))
2604 flags[
"kSaveOverworldItems"].get<
bool>();
2605 if (flags.contains(
"kSaveOverworldProperties"))
2607 flags[
"kSaveOverworldProperties"].get<
bool>();
2608 if (flags.contains(
"kSaveDungeonObjects"))
2610 flags[
"kSaveDungeonObjects"].get<
bool>();
2611 if (flags.contains(
"kSaveDungeonSprites"))
2613 flags[
"kSaveDungeonSprites"].get<
bool>();
2614 if (flags.contains(
"kSaveDungeonRoomHeaders"))
2616 flags[
"kSaveDungeonRoomHeaders"].get<
bool>();
2617 if (flags.contains(
"kSaveDungeonTorches"))
2619 flags[
"kSaveDungeonTorches"].get<
bool>();
2620 if (flags.contains(
"kSaveDungeonPits"))
2622 flags[
"kSaveDungeonPits"].get<
bool>();
2623 if (flags.contains(
"kSaveDungeonBlocks"))
2625 flags[
"kSaveDungeonBlocks"].get<
bool>();
2626 if (flags.contains(
"kSaveDungeonCollision"))
2628 flags[
"kSaveDungeonCollision"].get<
bool>();
2629 if (flags.contains(
"kSaveDungeonWaterFillZones"))
2631 flags[
"kSaveDungeonWaterFillZones"].get<
bool>();
2632 if (flags.contains(
"kSaveDungeonChests"))
2634 flags[
"kSaveDungeonChests"].get<
bool>();
2635 if (flags.contains(
"kSaveDungeonPotItems"))
2637 flags[
"kSaveDungeonPotItems"].get<
bool>();
2638 if (flags.contains(
"kSaveDungeonEntrances"))
2640 flags[
"kSaveDungeonEntrances"].get<
bool>();
2641 if (flags.contains(
"kSaveDungeonPalettes"))
2643 flags[
"kSaveDungeonPalettes"].get<
bool>();
2644 if (flags.contains(
"kSaveGraphicsSheet"))
2646 flags[
"kSaveGraphicsSheet"].get<
bool>();
2647 if (flags.contains(
"kSaveAllPalettes"))
2649 flags[
"kSaveAllPalettes"].get<
bool>();
2650 if (flags.contains(
"kSaveGfxGroups"))
2652 if (flags.contains(
"kSaveMessages"))
2657 if (proj.contains(
"workspace_settings")) {
2658 auto& ws = proj[
"workspace_settings"];
2659 if (ws.contains(
"auto_save_enabled"))
2661 ws[
"auto_save_enabled"].get<
bool>();
2662 if (ws.contains(
"auto_save_interval"))
2664 ws[
"auto_save_interval"].get<
float>();
2665 if (ws.contains(
"backup_on_save"))
2667 if (ws.contains(
"backup_retention_count"))
2669 ws[
"backup_retention_count"].get<
int>();
2670 if (ws.contains(
"backup_keep_daily"))
2672 ws[
"backup_keep_daily"].get<
bool>();
2673 if (ws.contains(
"backup_keep_daily_days"))
2675 ws[
"backup_keep_daily_days"].get<
int>();
2678 if (proj.contains(
"rom_addresses") && proj[
"rom_addresses"].is_object()) {
2680 for (
auto it = proj[
"rom_addresses"].begin();
2681 it != proj[
"rom_addresses"].end(); ++it) {
2682 if (it.value().is_number_unsigned()) {
2684 it.value().get<uint32_t>();
2685 }
else if (it.value().is_string()) {
2687 if (parsed.has_value()) {
2694 if (proj.contains(
"custom_objects") &&
2695 proj[
"custom_objects"].is_object()) {
2697 for (
auto it = proj[
"custom_objects"].begin();
2698 it != proj[
"custom_objects"].end(); ++it) {
2699 if (!it.value().is_array())
2702 if (!parsed.has_value()) {
2705 std::vector<std::string> files;
2706 for (
const auto& entry : it.value()) {
2707 if (entry.is_string()) {
2708 files.push_back(entry.get<std::string>());
2711 if (!files.empty()) {
2717 if (proj.contains(
"agent_settings") &&
2718 proj[
"agent_settings"].is_object()) {
2719 auto& agent = proj[
"agent_settings"];
2746 if (agent.contains(
"favorite_models") &&
2747 agent[
"favorite_models"].is_array()) {
2749 for (
const auto& model : agent[
"favorite_models"]) {
2750 if (model.is_string())
2752 model.get<std::string>());
2755 if (agent.contains(
"model_chain") && agent[
"model_chain"].is_array()) {
2757 for (
const auto& model : agent[
"model_chain"]) {
2758 if (model.is_string())
2783 agent.value(
"enable_tool_memory_inspector",
2790 if (proj.contains(
"build_script"))
2791 build_script = proj[
"build_script"].get<std::string>();
2792 if (proj.contains(
"output_folder"))
2794 if (proj.contains(
"git_repository"))
2796 if (proj.contains(
"track_changes"))
2800 return absl::OkStatus();
2801 }
catch (
const json::exception& e) {
2802 return absl::InvalidArgumentError(
2803 absl::StrFormat(
"JSON parse error: %s", e.what()));
2807absl::Status YazeProject::SaveToJsonFormat() {
2808#ifdef __EMSCRIPTEN__
2809 return absl::UnimplementedError(
2810 "JSON project format saving is not supported in the web build");
2813 auto& proj = j[
"yaze_project"];
2817 proj[
"name"] =
name;
2837 proj[
"rom"][
"write_policy"] =
2846 proj[
"feature_flags"][
"kSaveOverworldMaps"] =
2848 proj[
"feature_flags"][
"kSaveOverworldEntrances"] =
2850 proj[
"feature_flags"][
"kSaveOverworldExits"] =
2852 proj[
"feature_flags"][
"kSaveOverworldItems"] =
2854 proj[
"feature_flags"][
"kSaveOverworldProperties"] =
2856 proj[
"feature_flags"][
"kSaveDungeonObjects"] =
2858 proj[
"feature_flags"][
"kSaveDungeonSprites"] =
2860 proj[
"feature_flags"][
"kSaveDungeonRoomHeaders"] =
2862 proj[
"feature_flags"][
"kSaveDungeonTorches"] =
2865 proj[
"feature_flags"][
"kSaveDungeonBlocks"] =
2867 proj[
"feature_flags"][
"kSaveDungeonCollision"] =
2869 proj[
"feature_flags"][
"kSaveDungeonWaterFillZones"] =
2871 proj[
"feature_flags"][
"kSaveDungeonChests"] =
2873 proj[
"feature_flags"][
"kSaveDungeonPotItems"] =
2875 proj[
"feature_flags"][
"kSaveDungeonEntrances"] =
2877 proj[
"feature_flags"][
"kSaveDungeonPalettes"] =
2879 proj[
"feature_flags"][
"kSaveGraphicsSheet"] =
2886 proj[
"workspace_settings"][
"auto_save_enabled"] =
2888 proj[
"workspace_settings"][
"auto_save_interval"] =
2890 proj[
"workspace_settings"][
"backup_on_save"] =
2892 proj[
"workspace_settings"][
"backup_retention_count"] =
2894 proj[
"workspace_settings"][
"backup_keep_daily"] =
2896 proj[
"workspace_settings"][
"backup_keep_daily_days"] =
2899 auto& agent = proj[
"agent_settings"];
2926 agent[
"enable_tool_memory_inspector"] =
2931 auto& addrs = proj[
"rom_addresses"];
2938 auto& objs = proj[
"custom_objects"];
2940 objs[absl::StrFormat(
"0x%X", object_id)] = files;
2951 if (!file.is_open()) {
2952 return absl::InvalidArgumentError(
2953 absl::StrFormat(
"Cannot write JSON project file: %s",
filepath));
2957 return absl::OkStatus();
2965 if (!config_dir.ok()) {
2972#ifdef __EMSCRIPTEN__
2973 auto status = platform::WasmStorage::SaveProject(
2976 LOG_WARN(
"RecentFilesManager",
"Could not persist recent files: %s",
2977 status.ToString().c_str());
2983 if (!config_dir_status.ok()) {
2984 LOG_ERROR(
"Project",
"Failed to get or create config directory: %s",
2985 config_dir_status.status().ToString().c_str());
2990 std::ofstream file(filepath);
2991 if (!file.is_open()) {
2992 LOG_WARN(
"RecentFilesManager",
"Could not save recent files to %s",
2998 file << file_path << std::endl;
3003#ifdef __EMSCRIPTEN__
3005 if (!storage_or.ok()) {
3009 std::istringstream stream(storage_or.value());
3011 while (std::getline(stream, line)) {
3012 if (!line.empty()) {
3020 std::ifstream file(filepath);
3021 if (!file.is_open()) {
3028 while (std::getline(file, line)) {
3029 if (!line.empty()) {
void Clear()
Clear any loaded manifest state.
const ProjectRegistry & project_registry() const
bool HasProjectRegistry() const
absl::Status LoadProjectRegistry(const std::string &code_folder)
Load project registry data from the code folder.
absl::Status LoadFromFile(const std::string &filepath)
Load manifest from a JSON file path.
bool loaded() const
Check if the manifest has been loaded.
static std::vector< std::string > FindProjectsInDirectory(const std::string &directory)
static absl::Status ValidateProjectStructure(const YazeProject &project)
static absl::StatusOr< YazeProject > CreateFromTemplate(const std::string &template_name, const std::string &project_name, const std::string &base_path)
static std::vector< std::string > GetRecommendedFixesForProject(const YazeProject &project)
static std::vector< ProjectTemplate > GetProjectTemplates()
static absl::Status BackupProject(const YazeProject &project)
std::string GetFilePath() const
std::vector< std::string > recent_files_
void SetHackManifest(const core::HackManifest *manifest)
Set the hack manifest reference for ASM-defined labels.
#define YAZE_VERSION_STRING
#define ICON_MD_VIDEOGAME_ASSET
#define LOG_DEBUG(category, format,...)
#define LOG_ERROR(category, format,...)
#define LOG_WARN(category, format,...)
#define LOG_INFO(category, format,...)
#define ASSIGN_OR_RETURN(type_variable_name, expression)
float ParseFloat(const std::string &value)
std::string ResolveOptionalPath(const std::filesystem::path &base_dir, const std::string &value)
void RemoveProjectSaveTempFile(const std::filesystem::path &temp_path)
absl::Status WriteProjectFileAtomicallyImpl(const std::filesystem::path &target_path, absl::string_view contents, bool replace_existing)
std::vector< uint16_t > ParseHexUintList(const std::string &value)
std::string ToLowerCopy(std::string value)
bool ParseBool(const std::string &value)
std::pair< std::string, std::string > ParseDefineToken(const std::string &value)
std::optional< uint32_t > ParseHexUint32(const std::string &value)
std::string FormatHexUint32(uint32_t value)
std::string SanitizeStorageKey(absl::string_view input)
std::filesystem::path MakeProjectSaveTempPath(const std::filesystem::path &target_path)
uint64_t CurrentProcessIdForProjectSave()
std::string FormatHexUintList(const std::vector< uint16_t > &values)
std::string BasenameLower(const std::string &path)
std::vector< std::string > ParseStringList(const std::string &value)
std::string RomRoleToString(RomRole role)
absl::Status WriteProjectFileAtomically(absl::string_view target_path, absl::string_view contents, bool replace_existing)
RomRole ParseRomRole(absl::string_view value)
const std::string kRecentFilesFilename
RomWritePolicy ParseRomWritePolicy(absl::string_view value)
std::string RomWritePolicyToString(RomWritePolicy policy)
ResourceLabelProvider & GetResourceLabels()
Get the global ResourceLabelProvider instance.
#define RETURN_IF_ERROR(expr)
bool kSaveOverworldProperties
bool kApplyZSCustomOverworldASM
bool kLoadCustomOverworld
bool kSaveOverworldEntrances
bool kEnableCustomObjects
struct yaze::core::FeatureFlags::Flags::Dungeon dungeon
struct yaze::core::FeatureFlags::Flags::Overworld overworld
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > all_resource_labels
std::unordered_map< std::string, uint32_t > addresses
std::vector< uint16_t > track_object_ids
std::vector< uint16_t > minecart_sprite_ids
std::vector< uint16_t > track_stop_tiles
std::vector< uint16_t > track_tiles
std::vector< uint16_t > track_switch_tiles
YazeProject template_project
std::string CreateOrGetLabel(const std::string &type, const std::string &key, const std::string &defaultValue)
void DisplayLabels(bool *p_open)
std::string GetLabel(const std::string &type, const std::string &key)
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
bool LoadLabels(const std::string &filename)
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
int backup_keep_daily_days
std::string last_layout_preset
std::map< std::string, std::string > custom_keybindings
int backup_retention_count
std::vector< std::string > saved_layouts
std::map< std::string, bool > editor_visibility
float autosave_interval_secs
std::vector< std::string > recent_files
std::string custom_system_prompt
std::string gemini_api_key
bool enable_tool_emulator
bool enable_tool_memory_inspector
std::vector< std::string > favorite_models
bool enable_tool_resources
bool enable_tool_messages
std::vector< std::string > model_chain
std::string builder_blueprint_path
bool enable_tool_dialogue
bool enable_tool_overworld
std::string last_saved_at
bool persist_custom_music
Modern project structure with comprehensive settings consolidation.
std::string rom_backup_folder
std::unordered_map< int, std::vector< std::string > > custom_object_files
absl::Status ResetToDefaults()
std::string custom_objects_folder
absl::Status RepairProject()
std::string MakeStorageKey(absl::string_view suffix) const
static std::string ResolveBundleRoot(const std::string &path)
struct yaze::project::YazeProject::MusicPersistence music_persistence
absl::StatusOr< std::string > SerializeToString() const
std::string zscream_project_file
absl::Status ExportForZScream(const std::string &target_path)
absl::Status SaveToYazeFormat(bool replace_existing=true)
absl::Status ImportZScreamProject(const std::string &zscream_project_path)
absl::Status SaveAllSettings()
absl::Status LoadFromString(const std::string &content, const std::string &project_path)
void NormalizePathsToAbsolute()
absl::Status ImportLabelsFromZScreamContent(const std::string &content)
Import labels from ZScream format content directly.
std::string git_repository
core::HackManifest hack_manifest
void InitializeResourceLabelProvider()
Initialize the global ResourceLabelProvider with this project's labels.
absl::Status ParseFromString(const std::string &content)
std::vector< std::string > additional_roms
std::string patches_folder
absl::Status LoadFromYazeFormat(const std::string &project_path)
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > resource_labels
std::string GenerateProjectId() const
absl::Status Create(const std::string &project_name, const std::string &base_path)
std::string assets_folder
void ReloadHackManifest()
absl::Status LoadAllSettings()
std::string labels_filename
std::vector< std::string > asm_sources
std::string hack_manifest_file
std::string GetDisplayName() const
std::vector< std::string > GetMissingFiles() const
WorkspaceSettings workspace_settings
std::string GetZ3dkArtifactPath(absl::string_view artifact_name) const
std::string output_folder
std::string asm_entry_point
std::string GetRelativePath(const std::string &absolute_path) const
absl::Status InitializeEmbeddedLabels(const std::unordered_map< std::string, std::unordered_map< std::string, std::string > > &labels)
absl::Status SaveAs(const std::string &new_path)
struct yaze::project::YazeProject::AgentSettings agent_settings
DungeonOverlaySettings dungeon_overlay
absl::Status ImportFromZScreamFormat(const std::string &project_path)
void InitializeDefaults()
std::string GetAbsolutePath(const std::string &relative_path) const
std::string GetLabel(const std::string &resource_type, int id, const std::string &default_value="") const
absl::Status Open(const std::string &project_path)
absl::Status ImportLabelsFromZScream(const std::string &filepath)
Import labels from a ZScream DefaultNames.txt file.
std::string last_build_hash
void TryLoadHackManifest()
std::map< std::string, std::string > zscream_mappings
absl::Status Validate() const
core::FeatureFlags::Flags feature_flags
std::vector< std::string > build_configurations
void ReloadZ3dkSettings()
core::RomAddressOverrides rom_address_overrides
std::string symbols_filename
Z3dkSettings z3dk_settings
std::string annotations_json
std::string sourcemap_json
std::vector< std::string > include_paths
std::string std_includes_path
std::vector< std::string > main_files
std::vector< std::string > emits
std::vector< std::pair< std::string, std::string > > defines
std::string symbols_format
Z3dkArtifactPaths artifact_paths
bool warn_branch_outside_bank
std::optional< bool > lsp_log_enabled
bool warn_unauthorized_hook
std::vector< Z3dkMemoryRange > prohibited_memory_ranges
std::string std_defines_path