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