53 const fs::path& json_path) {
54 if (replacement_rom ==
nullptr || !replacement_rom->
is_loaded()) {
55 return absl::FailedPreconditionError(
"No replacement ROM loaded");
58 if (!source.has_value()) {
59 return absl::FailedPreconditionError(absl::StrFormat(
60 "Configured collision source %s is missing; restore it before "
61 "swapping the project ROM. The project binding was not changed.",
66 if (*source != replacement_source) {
67 return absl::FailedPreconditionError(absl::StrFormat(
68 "Replacement ROM %s does not match configured collision source %s. "
69 "Swap ROM does not publish collision changes. Select a ROM matching "
70 "this source. For collision edits, use Save ROM on the bound project "
71 "and then Build Project. The saved copy and project binding were kept.",
72 replacement_rom->
filename(), json_path.string()));
74 return absl::OkStatus();
79 return absl::FailedPreconditionError(
"No ROM file to save");
82 const fs::path rom_path(rom->
filename());
89 if (disk_json.has_value() && *disk_json == new_json) {
95 .
subject =
"ROM and custom collision source",
96 .published_file =
"custom collision source"};
98 {rom_path, json_path}, labels));
102 if (!disk_rom.has_value()) {
103 return absl::FailedPreconditionError(absl::StrFormat(
104 "Cannot pair a custom collision source with %s: the ROM file does "
109 if (locked_json != disk_json) {
110 return absl::AbortedError(absl::StrFormat(
111 "%s changed while saving; nothing was written. Save again.",
112 json_path.string()));
114 if (locked_json.has_value()) {
116 CollisionSourceOfRomBytes(*disk_rom));
117 if (*locked_json != disk_source) {
118 return absl::FailedPreconditionError(absl::StrFormat(
119 "%s does not match the custom collision in %s. It was changed "
120 "outside yaze, or the two were already out of step. Nothing was "
121 "written; reconcile them first (Oracle: "
122 "Scripts/Generate/validate_custom_collision_source.py).",
123 json_path.string(), rom_path.string()));
127 const std::vector<uint8_t>& bytes = rom->
vector();
128 std::vector<core::SourceArtifactUpdate> updates;
132 .after = std::string(bytes.begin(), bytes.end())});
134 .
target = json_path, .before = locked_json, .after = new_json});
138 return absl::OkStatus();