105 const fs::path& json_path) {
106 if (replacement_rom ==
nullptr || !replacement_rom->
is_loaded()) {
107 return absl::FailedPreconditionError(
"No replacement ROM loaded");
110 if (!source.has_value()) {
111 return absl::FailedPreconditionError(absl::StrFormat(
112 "Configured collision source %s is missing; restore it before "
113 "swapping the project ROM. The project binding was not changed.",
114 json_path.string()));
119 const bool source_matches,
120 CollisionSourcesMatch(*source, replacement_source, json_path));
121 if (!source_matches) {
122 return absl::FailedPreconditionError(absl::StrFormat(
123 "Replacement ROM %s does not match configured collision source %s. "
124 "Swap ROM does not publish collision changes. Select a ROM matching "
125 "this source. For collision edits, use Save ROM on the bound project "
126 "and then Build Project. The saved copy and project binding were kept.",
127 replacement_rom->
filename(), json_path.string()));
129 return absl::OkStatus();
134 return absl::FailedPreconditionError(
"No ROM file to save");
137 const fs::path rom_path(rom->
filename());
144 if (disk_json.has_value()) {
146 CollisionSourcesMatch(*disk_json, new_json, json_path));
147 if (source_matches) {
154 .
subject =
"ROM and custom collision source",
155 .published_file =
"custom collision source"};
157 {rom_path, json_path}, labels));
161 if (!disk_rom.has_value()) {
162 return absl::FailedPreconditionError(absl::StrFormat(
163 "Cannot pair a custom collision source with %s: the ROM file does "
168 if (locked_json != disk_json) {
169 return absl::AbortedError(absl::StrFormat(
170 "%s changed while saving; nothing was written. Save again.",
171 json_path.string()));
173 if (locked_json.has_value()) {
175 CollisionSourceOfRomBytes(*disk_rom));
177 const bool source_matches,
178 CollisionSourcesMatch(*locked_json, disk_source, json_path));
179 if (!source_matches) {
180 return absl::FailedPreconditionError(absl::StrFormat(
181 "%s does not match the custom collision in %s. It was changed "
182 "outside yaze, or the two were already out of step. Nothing was "
183 "written; reconcile them first (Oracle: "
184 "Scripts/Generate/validate_custom_collision_source.py).",
185 json_path.string(), rom_path.string()));
189 const std::vector<uint8_t>& bytes = rom->
vector();
190 std::vector<core::SourceArtifactUpdate> updates;
194 .after = std::string(bytes.begin(), bytes.end())});
196 .
target = json_path, .before = locked_json, .after = new_json});
200 return absl::OkStatus();