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 "cli/cli.h"
3#include "app/gfx/arena.h"
4#include "absl/flags/flag.h"
5#include "absl/flags/declare.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("Usage: gfx export-sheet <sheet_id> --to <file>");
17 }
18
19 int sheet_id = std::stoi(arg_vec[0]);
20 std::string output_file = arg_vec[1];
21
22 std::string rom_file = absl::GetFlag(FLAGS_rom);
23 if (rom_file.empty()) {
24 return absl::InvalidArgumentError("ROM file must be provided via --rom flag.");
25 }
26
27 Rom rom;
28 rom.LoadFromFile(rom_file);
29 if (!rom.is_loaded()) {
30 return absl::AbortedError("Failed to load ROM.");
31 }
32
33 auto& arena = gfx::Arena::Get();
34 auto sheet = arena.gfx_sheet(sheet_id);
35 if (!sheet.is_active()) {
36 return absl::NotFoundError("Graphics sheet not found.");
37 }
38
39 // For now, we will just save the raw 8bpp data.
40 // TODO: Convert the 8bpp data to the correct SNES bpp format.
41 std::vector<uint8_t> header; // Empty header for now
42 auto status = gfx::SaveCgx(sheet.depth(), output_file, sheet.vector(), header);
43 if (!status.ok()) {
44 return status;
45 }
46
47 std::cout << "Successfully exported graphics sheet " << sheet_id << " to " << output_file << std::endl;
48
49 return absl::OkStatus();
50}
51
52// Legacy GfxImport class removed - using new CommandHandler system
53// TODO: Implement GfxImportCommandHandler
54absl::Status HandleGfxImportLegacy(const std::vector<std::string>& arg_vec) {
55 if (arg_vec.size() < 2) {
56 return absl::InvalidArgumentError("Usage: gfx import-sheet <sheet_id> --from <file>");
57 }
58
59 int sheet_id = std::stoi(arg_vec[0]);
60 std::string input_file = arg_vec[1];
61
62 std::string rom_file = absl::GetFlag(FLAGS_rom);
63 if (rom_file.empty()) {
64 return absl::InvalidArgumentError("ROM file must be provided via --rom flag.");
65 }
66
67 Rom rom;
68 rom.LoadFromFile(rom_file);
69 if (!rom.is_loaded()) {
70 return absl::AbortedError("Failed to load ROM.");
71 }
72
73 std::vector<uint8_t> cgx_data, cgx_loaded, cgx_header;
74 auto status = gfx::LoadCgx(8, input_file, cgx_data, cgx_loaded, cgx_header);
75 if (!status.ok()) {
76 return status;
77 }
78
79 auto& arena = gfx::Arena::Get();
80 auto sheet = arena.gfx_sheet(sheet_id);
81 if (!sheet.is_active()) {
82 return absl::NotFoundError("Graphics sheet not found.");
83 }
84
85 // TODO: Convert the 8bpp data to the correct SNES bpp format before writing.
86 // For now, we just replace the data directly.
87 sheet.set_data(cgx_loaded);
88
89 // TODO: Implement saving the modified graphics sheet back to the ROM.
90 auto save_status = rom.SaveToFile({.save_new = false});
91 if (!save_status.ok()) {
92 return save_status;
93 }
94
95 std::cout << "Successfully imported graphics sheet " << sheet_id << " from " << input_file << std::endl;
96 std::cout << "✅ ROM saved to: " << rom.filename() << std::endl;
97
98 return absl::OkStatus();
99}
100
101} // namespace cli
102} // namespace yaze
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
Definition rom.cc:289
auto filename() const
Definition rom.h:208
absl::Status SaveToFile(const SaveSettings &settings)
Definition rom.cc:536
bool is_loaded() const
Definition rom.h:197
static Arena & Get()
Definition arena.cc:15
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:54
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)
Main namespace for the application.