yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tile16_transfer.cc
Go to the documentation of this file.
1#include <string>
2#include <vector>
3
4#include "absl/status/status.h"
5#include "util/macro.h"
6#include "app/rom.h"
7#include "cli/z3ed.h"
8
9namespace yaze {
10namespace cli {
11
12absl::Status Tile16Transfer::handle(const std::vector<std::string>& arg_vec) {
13 // Load the source rom
14 RETURN_IF_ERROR(rom_.LoadFromFile(arg_vec[0]))
15
16 // Load the destination rom
17 Rom dest_rom;
18 RETURN_IF_ERROR(dest_rom.LoadFromFile(arg_vec[1]))
19
20 std::vector<uint32_t> tileIDs;
21
22 // Parse the CSV list of tile16 IDs.
23 std::stringstream ss(arg_vec[2].data());
24 for (std::string tileID; std::getline(ss, tileID, ',');) {
25 if (tileID == "*") {
26 // for (uint32_t i = 0; i <= rom_.GetMaxTileID(); ++i) {
27 // tileIDs.push_back(i);
28 // }
29 break; // No need to continue parsing if * is used
30 } else if (tileID.find('-') != std::string::npos) {
31 // Handle range: split by hyphen and add all tile IDs in the range.
32 std::stringstream rangeSS(tileID);
33 std::string start;
34 std::string end;
35 std::getline(rangeSS, start, '-');
36 std::getline(rangeSS, end);
37 uint32_t startID = std::stoi(start, nullptr, 16);
38 uint32_t endID = std::stoi(end, nullptr, 16);
39 for (uint32_t i = startID; i <= endID; ++i) {
40 tileIDs.push_back(i);
41 }
42 } else {
43 // Handle single tile ID
44 uint32_t tileID_int = std::stoi(tileID, nullptr, 16);
45 tileIDs.push_back(tileID_int);
46 }
47 }
48
49 for (const auto& tile16_id_int : tileIDs) {
50 // Compare the tile16 data between source and destination ROMs.
51 // auto source_tile16_data = rom_.ReadTile16(tile16_id_int);
52 // auto dest_tile16_data = dest_rom.ReadTile16(tile16_id_int);
53 ASSIGN_OR_RETURN(auto source_tile16_data, rom_.ReadTile16(tile16_id_int))
54 ASSIGN_OR_RETURN(auto dest_tile16_data, dest_rom.ReadTile16(tile16_id_int))
55 if (source_tile16_data != dest_tile16_data) {
56 // Notify user of difference
57 std::cout << "Difference detected in tile16 ID " << tile16_id_int
58 << ". Do you want to transfer it to dest rom? (y/n): ";
59 char userChoice;
60 std::cin >> userChoice;
61
62 // Transfer if user confirms
63 if (userChoice == 'y' || userChoice == 'Y') {
65 dest_rom.WriteTile16(tile16_id_int, source_tile16_data));
66 std::cout << "Transferred tile16 ID " << tile16_id_int
67 << " to dest rom." << std::endl;
68 } else {
69 std::cout << "Skipped transferring tile16 ID " << tile16_id_int << "."
70 << std::endl;
71 }
72 }
73 }
74
76 dest_rom.SaveToFile(/*backup=*/true, /*save_new=*/false, arg_vec[1]))
77
78 std::cout << "Successfully transferred tile16" << std::endl;
79
80 return absl::OkStatus();
81}
82
83} // namespace cli
84} // namespace yaze
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:59
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
Definition rom.cc:173
absl::StatusOr< gfx::Tile16 > ReadTile16(uint32_t tile16_id)
Definition rom.cc:271
absl::Status SaveToFile(bool backup, bool save_new=false, std::string filename="")
Saves the Rom data to a file.
Definition rom.cc:408
absl::Status WriteTile16(int tile16_id, const gfx::Tile16 &tile)
Definition rom.cc:289
absl::Status handle(const std::vector< std::string > &arg_vec) override
#define RETURN_IF_ERROR(expression)
Definition macro.h:62
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:70
Namespace for the command line interface.
Definition compress.cc:4
Main namespace for the application.
Definition controller.cc:18