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 <sstream>
5
6#include "app/rom.h"
8#include "dungeon.h"
9#include "yaze_config.h"
10
11void yaze_check_version(const char *version) {
12 std::string current_version;
13 std::stringstream ss;
14 ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "."
15 << YAZE_VERSION_PATCH;
16 ss >> current_version;
17
18 if (version != current_version) {
19 std::cout << "Yaze version mismatch: expected " << current_version
20 << ", got " << version << std::endl;
21 exit(1);
22 }
23}
24
26 if (yaze_ctx->project->rom_filename == nullptr) {
27 yaze_ctx->error_message = "ROM filename is null";
28 return yaze_status::YAZE_ERROR;
29 }
30
31 yaze_ctx->rom = yaze_load_rom(yaze_ctx->project->rom_filename);
32 if (yaze_ctx->rom == nullptr) {
33 yaze_ctx->error_message = "Failed to load ROM";
34 return yaze_status::YAZE_ERROR;
35 }
36
37 return yaze_status::YAZE_OK;
38}
39
41 if (yaze_ctx->rom) {
42 yaze_unload_rom(yaze_ctx->rom);
43 }
44 return yaze_status::YAZE_OK;
45}
46
47yaze_project yaze_load_project(const char *filename) {
48 yaze_project project;
49 project.filepath = filename;
50 return project;
51}
52
53zelda3_rom *yaze_load_rom(const char *filename) {
54 yaze::Rom *internal_rom;
55 internal_rom = new yaze::Rom();
56 if (!internal_rom->LoadFromFile(filename).ok()) {
57 delete internal_rom;
58 return nullptr;
59 }
60
61 zelda3_rom *rom = new zelda3_rom();
62 rom->filename = filename;
63 rom->impl = internal_rom;
64 rom->data = internal_rom->data();
65 rom->size = internal_rom->size();
66 return rom;
67}
68
70 if (rom->impl) {
71 delete static_cast<yaze::Rom *>(rom->impl);
72 }
73
74 if (rom) {
75 delete rom;
76 }
77}
78
79void yaze_save_rom(zelda3_rom *rom, const char *filename) {
80 if (rom->impl) {
81 yaze::Rom *internal_rom = static_cast<yaze::Rom *>(rom->impl);
82 internal_rom->SaveToFile(false, false, filename);
83 }
84}
85
86yaze_bitmap yaze_load_bitmap(const char *filename) {
87 yaze_bitmap bitmap;
88 bitmap.width = 0;
89 bitmap.height = 0;
90 bitmap.bpp = 0;
91 bitmap.data = nullptr;
92 return bitmap;
93}
94
96 int palette_set, int palette,
97 int color) {
98 snes_color color_struct;
99 color_struct.red = 0;
100 color_struct.green = 0;
101 color_struct.blue = 0;
102
103 if (rom->impl) {
104 yaze::Rom *internal_rom = static_cast<yaze::Rom *>(rom->impl);
105 auto get_color =
106 internal_rom->palette_group()
107 .get_group(yaze::gfx::kPaletteGroupAddressesKeys[palette_set])
108 ->palette(palette)
109 .GetColor(color);
110 if (!get_color.ok()) {
111 return color_struct;
112 }
113 color_struct = get_color.value().rom_color();
114
115 return color_struct;
116 }
117
118 return color_struct;
119}
120
122 if (rom->impl == nullptr) {
123 return nullptr;
124 }
125
126 yaze::Rom *internal_rom = static_cast<yaze::Rom *>(rom->impl);
127 auto internal_overworld = new yaze::zelda3::Overworld(*internal_rom);
128 if (!internal_overworld->Load(*internal_rom).ok()) {
129 return nullptr;
130 }
131
132 zelda3_overworld *overworld = new zelda3_overworld();
133 overworld->impl = internal_overworld;
134 int map_id = 0;
135 for (const auto &ow_map : internal_overworld->overworld_maps()) {
136 overworld->maps[map_id] = new zelda3_overworld_map();
137 overworld->maps[map_id]->id = map_id;
138 map_id++;
139 }
140 return overworld;
141}
142
144 if (rom->impl == nullptr) {
145 return nullptr;
146 }
147 yaze::Rom *internal_rom = static_cast<yaze::Rom *>(rom->impl);
149 return rooms;
150}
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:173
auto palette_group() const
Definition rom.h:176
absl::Status SaveToFile(bool backup, bool save_new=false, std::string filename="")
Saves the Rom data to a file.
Definition rom.cc:408
auto data() const
Definition rom.h:164
auto size() const
Definition rom.h:163
Represents the full Overworld data, light and dark world.
Definition overworld.h:111
struct zelda3_overworld_map zelda3_overworld_map
Primitive of an overworld map.
struct zelda3_overworld zelda3_overworld
Primitive of the overworld.
constexpr const char * kPaletteGroupAddressesKeys[]
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:49
int height
Definition yaze.h:47
uint8_t bpp
Definition yaze.h:48
int width
Definition yaze.h:46
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:38
const char * filepath
Definition yaze.h:37
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:121
void yaze_unload_rom(zelda3_rom *rom)
Definition yaze.cc:69
yaze_status yaze_shutdown(yaze_editor_context *yaze_ctx)
Definition yaze.cc:40
yaze_bitmap yaze_load_bitmap(const char *filename)
Definition yaze.cc:86
yaze_status yaze_init(yaze_editor_context *yaze_ctx)
Definition yaze.cc:25
zelda3_dungeon_room * yaze_load_all_rooms(const zelda3_rom *rom)
Definition yaze.cc:143
void yaze_check_version(const char *version)
Definition yaze.cc:11
snes_color yaze_get_color_from_paletteset(const zelda3_rom *rom, int palette_set, int palette, int color)
Definition yaze.cc:95
yaze_project yaze_load_project(const char *filename)
Definition yaze.cc:47
zelda3_rom * yaze_load_rom(const char *filename)
Definition yaze.cc:53
void yaze_save_rom(zelda3_rom *rom, const char *filename)
Definition yaze.cc:79
yaze_status
Definition yaze.h:24
struct zelda3_rom zelda3_rom