yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
gfx.cc
Go to the documentation of this file.
1#include "absl/flags/declare.h"
2#include "absl/flags/flag.h"
5#include "cli/cli.h"
6
7ABSL_DECLARE_FLAG(std::string, rom);
8
9namespace yaze {
10namespace cli {
11
12// Legacy GfxExport class removed - using new CommandHandler system
13// TODO: Implement GfxExportCommandHandler
14absl::Status HandleGfxExportLegacy(const std::vector<std::string>& arg_vec) {
15 if (arg_vec.size() < 2) {
16 return absl::InvalidArgumentError(
17 "Usage: gfx export-sheet <sheet_id> --to <file>");
18 }
19
20 int sheet_id = std::stoi(arg_vec[0]);
21 std::string output_file = arg_vec[1];
22
23 std::string rom_file = absl::GetFlag(FLAGS_rom);
24 if (rom_file.empty()) {
25 return absl::InvalidArgumentError(
26 "ROM file must be provided via --rom flag.");
27 }
28
29 Rom rom;
30 rom.LoadFromFile(rom_file);
31 if (!rom.is_loaded()) {
32 return absl::AbortedError("Failed to load ROM.");
33 }
34
35 auto& arena = gfx::Arena::Get();
36 auto sheet = arena.gfx_sheet(sheet_id);
37 if (!sheet.is_active()) {
38 return absl::NotFoundError("Graphics sheet not found.");
39 }
40
41 // For now, we will just save the raw 8bpp data.
42 // TODO: Convert the 8bpp data to the correct SNES bpp format.
43 std::vector<uint8_t> header; // Empty header for now
44 auto status =
45 gfx::SaveCgx(sheet.depth(), output_file, sheet.vector(), header);
46 if (!status.ok()) {
47 return status;
48 }
49
50 std::cout << "Successfully exported graphics sheet " << sheet_id << " to "
51 << output_file << std::endl;
52
53 return absl::OkStatus();
54}
55
56// Legacy GfxImport class removed - using new CommandHandler system
57// TODO: Implement GfxImportCommandHandler
58absl::Status HandleGfxImportLegacy(const std::vector<std::string>& arg_vec) {
59 if (arg_vec.size() < 2) {
60 return absl::InvalidArgumentError(
61 "Usage: gfx import-sheet <sheet_id> --from <file>");
62 }
63
64 int sheet_id = std::stoi(arg_vec[0]);
65 std::string input_file = arg_vec[1];
66
67 std::string rom_file = absl::GetFlag(FLAGS_rom);
68 if (rom_file.empty()) {
69 return absl::InvalidArgumentError(
70 "ROM file must be provided via --rom flag.");
71 }
72
73 Rom rom;
74 rom.LoadFromFile(rom_file);
75 if (!rom.is_loaded()) {
76 return absl::AbortedError("Failed to load ROM.");
77 }
78
79 std::vector<uint8_t> cgx_data, cgx_loaded, cgx_header;
80 auto status = gfx::LoadCgx(8, input_file, cgx_data, cgx_loaded, cgx_header);
81 if (!status.ok()) {
82 return status;
83 }
84
85 auto& arena = gfx::Arena::Get();
86 auto sheet = arena.gfx_sheet(sheet_id);
87 if (!sheet.is_active()) {
88 return absl::NotFoundError("Graphics sheet not found.");
89 }
90
91 // TODO: Convert the 8bpp data to the correct SNES bpp format before writing.
92 // For now, we just replace the data directly.
93 sheet.set_data(cgx_loaded);
94
95 // TODO: Implement saving the modified graphics sheet back to the ROM.
96 auto save_status = rom.SaveToFile({.save_new = false});
97 if (!save_status.ok()) {
98 return save_status;
99 }
100
101 std::cout << "Successfully imported graphics sheet " << sheet_id << " from "
102 << input_file << std::endl;
103 std::cout << "✅ ROM saved to: " << rom.filename() << std::endl;
104
105 return absl::OkStatus();
106}
107
108} // namespace cli
109} // namespace yaze
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
absl::Status LoadFromFile(const std::string &filename, const LoadOptions &options=LoadOptions::Defaults())
Definition rom.cc:74
auto filename() const
Definition rom.h:141
absl::Status SaveToFile(const SaveSettings &settings)
Definition rom.cc:164
bool is_loaded() const
Definition rom.h:128
static Arena & Get()
Definition arena.cc:19
ABSL_DECLARE_FLAG(std::string, rom)
absl::Status HandleGfxExportLegacy(const std::vector< std::string > &arg_vec)
Definition gfx.cc:14
absl::Status HandleGfxImportLegacy(const std::vector< std::string > &arg_vec)
Definition gfx.cc:58
absl::Status LoadCgx(uint8_t bpp, std::string_view filename, std::vector< uint8_t > &cgx_data, std::vector< uint8_t > &cgx_loaded, std::vector< uint8_t > &cgx_header)
Load Cgx file (graphical content)
absl::Status SaveCgx(uint8_t bpp, std::string_view filename, const std::vector< uint8_t > &cgx_data, const std::vector< uint8_t > &cgx_header)
Save Cgx file (graphical content)