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