yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze.cc
Go to the documentation of this file.
1#include "yaze.h"
2
3#include <iostream>
4#include <memory>
5#include <sstream>
6
8#include "app/rom.h"
10#include "dungeon.h"
11#include "util/flag.h"
12#include "yaze_config.h"
13
14int yaze_app_main(int argc, char **argv) {
16 RETURN_IF_EXCEPTION(parser.Parse(argc, argv));
17 std::string rom_filename = "";
18 if (!FLAGS_rom_file->Get().empty()) {
19 rom_filename = FLAGS_rom_file->Get();
20 }
21
22#ifdef __APPLE__
23 return yaze_run_cocoa_app_delegate(rom_filename.c_str());
24#endif
25
26 auto controller = std::make_unique<core::Controller>();
27 EXIT_IF_ERROR(controller->OnEntry(rom_filename))
28 while (controller->IsActive()) {
29 controller->OnInput();
30 if (auto status = controller->OnLoad(); !status.ok()) {
31 std::cerr << status.message() << std::endl;
32 break;
33 }
34 controller->DoRender();
35 }
36 controller->OnExit();
37 return EXIT_SUCCESS;
38}
39
40void yaze_check_version(const char *version) {
41 std::string current_version;
42 std::stringstream ss;
43 ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "."
44 << YAZE_VERSION_PATCH;
45 ss >> current_version;
46
47 if (version != current_version) {
48 std::cout << "Yaze version mismatch: expected " << current_version
49 << ", got " << version << std::endl;
50 exit(1);
51 }
52}
53
55 if (yaze_ctx->project->rom_filename == nullptr) {
56 yaze_ctx->error_message = "ROM filename is null";
57 return yaze_status::YAZE_ERROR;
58 }
59
60 yaze_ctx->rom = yaze_load_rom(yaze_ctx->project->rom_filename);
61 if (yaze_ctx->rom == nullptr) {
62 yaze_ctx->error_message = "Failed to load ROM";
63 return yaze_status::YAZE_ERROR;
64 }
65
66 return yaze_status::YAZE_OK;
67}
68
70 if (yaze_ctx->rom) {
71 yaze_unload_rom(yaze_ctx->rom);
72 }
73 return yaze_status::YAZE_OK;
74}
75
76yaze_project yaze_load_project(const char *filename) {
77 yaze_project project;
78 project.filepath = filename;
79 return project;
80}
81
82zelda3_rom *yaze_load_rom(const char *filename) {
83 yaze::Rom *internal_rom;
84 internal_rom = new yaze::Rom();
85 if (!internal_rom->LoadFromFile(filename).ok()) {
86 delete internal_rom;
87 return nullptr;
88 }
89
90 zelda3_rom *rom = new zelda3_rom();
91 rom->filename = filename;
92 rom->impl = internal_rom;
93 rom->data = internal_rom->data();
94 rom->size = internal_rom->size();
95 return rom;
96}
97
99 if (rom->impl) {
100 delete static_cast<yaze::Rom *>(rom->impl);
101 }
102
103 if (rom) {
104 delete rom;
105 }
106}
107
108void yaze_save_rom(zelda3_rom *rom, const char *filename) {
109 if (rom->impl) {
110 yaze::Rom *internal_rom = static_cast<yaze::Rom *>(rom->impl);
111 internal_rom->SaveToFile(false, false, filename);
112 }
113}
114
115yaze_bitmap yaze_load_bitmap(const char *filename) {
116 yaze_bitmap bitmap;
117 bitmap.width = 0;
118 bitmap.height = 0;
119 bitmap.bpp = 0;
120 bitmap.data = nullptr;
121 return bitmap;
122}
123
125 int palette_set, int palette,
126 int color) {
127 snes_color color_struct;
128 color_struct.red = 0;
129 color_struct.green = 0;
130 color_struct.blue = 0;
131
132 if (rom->impl) {
133 yaze::Rom *internal_rom = static_cast<yaze::Rom *>(rom->impl);
134 auto get_color =
135 internal_rom->palette_group()
136 .get_group(yaze::gfx::kPaletteGroupAddressesKeys[palette_set])
137 ->palette(palette)
138 .GetColor(color);
139 if (!get_color.ok()) {
140 return color_struct;
141 }
142 color_struct = get_color.value().rom_color();
143
144 return color_struct;
145 }
146
147 return color_struct;
148}
149
151 if (rom->impl == nullptr) {
152 return nullptr;
153 }
154
155 yaze::Rom *internal_rom = static_cast<yaze::Rom *>(rom->impl);
156 auto internal_overworld = new yaze::zelda3::Overworld(*internal_rom);
157 if (!internal_overworld->Load(*internal_rom).ok()) {
158 return nullptr;
159 }
160
161 zelda3_overworld *overworld = new zelda3_overworld();
162 overworld->impl = internal_overworld;
163 int map_id = 0;
164 for (const auto &ow_map : internal_overworld->overworld_maps()) {
165 overworld->maps[map_id] = new zelda3_overworld_map();
166 overworld->maps[map_id]->id = map_id;
167 map_id++;
168 }
169 return overworld;
170}
171
173 if (rom->impl == nullptr) {
174 return nullptr;
175 }
176 yaze::Rom *internal_rom = static_cast<yaze::Rom *>(rom->impl);
178 return rooms;
179}
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:172
auto palette_group() const
Definition rom.h:175
absl::Status SaveToFile(bool backup, bool save_new=false, std::string filename="")
Saves the Rom data to a file.
Definition rom.cc:407
auto data() const
Definition rom.h:163
auto size() const
Definition rom.h:162
void Parse(int argc, char **argv)
Definition flag.h:121
Represents the full Overworld data, light and dark world.
Definition overworld.h:112
struct zelda3_overworld_map zelda3_overworld_map
Primitive of an overworld map.
struct zelda3_overworld zelda3_overworld
Primitive of the overworld.
#define RETURN_IF_EXCEPTION(expression)
Definition macro.h:101
#define EXIT_IF_ERROR(expression)
Definition macro.h:33
constexpr const char * kPaletteGroupAddressesKeys[]
FlagRegistry * global_flag_registry()
Definition flag.h:99
Primitive of 16-bit RGB SNES color.
Definition snes.h:14
uint16_t green
Definition snes.h:17
uint16_t red
Definition snes.h:15
uint16_t blue
Definition snes.h:16
uint8_t * data
Definition yaze.h:50
int height
Definition yaze.h:48
uint8_t bpp
Definition yaze.h:49
int width
Definition yaze.h:47
yaze_project * project
Definition yaze.h:20
zelda3_rom * rom
Definition yaze.h:19
const char * error_message
Definition yaze.h:21
const char * rom_filename
Definition yaze.h:39
const char * filepath
Definition yaze.h:38
Primitive of the overworld.
Definition overworld.h:31
zelda3_overworld_map ** maps
Definition overworld.h:33
const char * filename
Definition zelda.h:87
size_t size
Definition zelda.h:89
void * impl
Definition zelda.h:90
const uint8_t * data
Definition zelda.h:88
zelda3_overworld * yaze_load_overworld(const zelda3_rom *rom)
Definition yaze.cc:150
void yaze_unload_rom(zelda3_rom *rom)
Definition yaze.cc:98
yaze_status yaze_shutdown(yaze_editor_context *yaze_ctx)
Definition yaze.cc:69
yaze_bitmap yaze_load_bitmap(const char *filename)
Definition yaze.cc:115
int yaze_app_main(int argc, char **argv)
Definition yaze.cc:14
yaze_status yaze_init(yaze_editor_context *yaze_ctx)
Definition yaze.cc:54
zelda3_dungeon_room * yaze_load_all_rooms(const zelda3_rom *rom)
Definition yaze.cc:172
void yaze_check_version(const char *version)
Definition yaze.cc:40
snes_color yaze_get_color_from_paletteset(const zelda3_rom *rom, int palette_set, int palette, int color)
Definition yaze.cc:124
yaze_project yaze_load_project(const char *filename)
Definition yaze.cc:76
zelda3_rom * yaze_load_rom(const char *filename)
Definition yaze.cc:82
void yaze_save_rom(zelda3_rom *rom, const char *filename)
Definition yaze.cc:108
yaze_status
Definition yaze.h:24
struct zelda3_rom zelda3_rom