yaze 0.2.0
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 <cstdio>
4
5#include "app/rom.h"
7
8void yaze_check_version(const char* version) {
9 printf("Yaze version: %s\n", version);
10 auto version_check = yaze::app::core::CheckVersion(version);
11 if (!version_check.ok()) {
12 printf("%s\n", version_check.status().message().data());
13 exit(1);
14 }
15 return;
16}
17
19 if (yaze_ctx->project->rom_filename == nullptr) {
20 return -1;
21 }
22
23 yaze_ctx->rom = yaze_load_rom(yaze_ctx->project->rom_filename);
24 if (yaze_ctx->rom == nullptr) {
25 return -1;
26 }
27
28 return 0;
29}
30
32 if (yaze_ctx->rom) {
33 yaze_unload_rom(yaze_ctx->rom);
34 }
35}
36
37yaze_project yaze_load_project(const char* filename) {
38 yaze_project project;
39 project.filepath = filename;
40 return project;
41}
42
43z3_rom* yaze_load_rom(const char* filename) {
44 yaze::app::Rom* internal_rom;
45 internal_rom = new yaze::app::Rom();
46 if (!internal_rom->LoadFromFile(filename).ok()) {
47 delete internal_rom;
48 return nullptr;
49 }
50
51 z3_rom* rom = new z3_rom();
52 rom->filename = filename;
53 rom->impl = internal_rom;
54 rom->data = internal_rom->data();
55 rom->size = internal_rom->size();
56 return rom;
57}
58
60 if (rom->impl) {
61 delete static_cast<yaze::app::Rom*>(rom->impl);
62 }
63
64 if (rom) {
65 delete rom;
66 }
67}
68
69yaze_bitmap yaze_load_bitmap(const char* filename) {
70 yaze_bitmap bitmap;
71 bitmap.width = 0;
72 bitmap.height = 0;
73 bitmap.bpp = 0;
74 bitmap.data = nullptr;
75 return bitmap;
76}
77
79 int palette, int color) {
80 snes_color color_struct;
81 color_struct.red = 0;
82 color_struct.green = 0;
83 color_struct.blue = 0;
84
85 if (rom->impl) {
86 yaze::app::Rom* internal_rom = static_cast<yaze::app::Rom*>(rom->impl);
87 auto get_color =
88 internal_rom->palette_group()
89 .get_group(yaze::app::gfx::kPaletteGroupAddressesKeys[palette_set])
90 ->palette(palette)
91 .GetColor(color);
92 if (!get_color.ok()) {
93 return color_struct;
94 }
95 color_struct = get_color.value().rom_color();
96
97 return color_struct;
98 }
99
100 return color_struct;
101}
102
104 if (rom->impl == nullptr) {
105 return nullptr;
106 }
107
108 yaze::app::Rom* internal_rom = static_cast<yaze::app::Rom*>(rom->impl);
109 auto internal_overworld = new yaze::app::zelda3::overworld::Overworld();
110 if (!internal_overworld->Load(*internal_rom).ok()) {
111 return nullptr;
112 }
113
114 z3_overworld* overworld = new z3_overworld();
115 overworld->impl = internal_overworld;
116 int map_id = 0;
117 for (const auto& ow_map : internal_overworld->overworld_maps()) {
118 overworld->maps[map_id] = new z3_overworld_map();
119 overworld->maps[map_id]->id = map_id;
120 map_id++;
121 }
122 return overworld;
123}
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:136
auto palette_group()
Definition rom.h:474
auto size() const
Definition rom.h:460
auto data()
Definition rom.h:463
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
Definition rom.cc:168
Represents the full Overworld data, light and dark world.
Definition overworld.h:461
struct z3_overworld z3_overworld
Primitive of the overworld.
struct z3_overworld_map z3_overworld_map
Primitive of an overworld map.
absl::StatusOr< std::string > CheckVersion(const char *version)
Definition common.cc:327
constexpr const char * kPaletteGroupAddressesKeys[]
Primitive of 16-bit RGB SNES color.
Definition snes_color.h:13
uint16_t green
Definition snes_color.h:16
uint16_t red
Definition snes_color.h:14
uint16_t blue
Definition snes_color.h:15
Primitive of a Bitmap.
Definition yaze.h:79
uint8_t * data
Definition yaze.h:83
int height
Definition yaze.h:81
uint8_t bpp
Definition yaze.h:82
int width
Definition yaze.h:80
Extension editor context.
Definition yaze.h:25
yaze_project * project
Definition yaze.h:27
z3_rom * rom
Definition yaze.h:26
Primitive of a Yaze project.
Definition yaze.h:46
const char * rom_filename
Definition yaze.h:49
const char * filepath
Definition yaze.h:48
Primitive of the overworld.
Definition overworld.h:33
void * impl
Definition overworld.h:34
z3_overworld_map ** maps
Definition overworld.h:40
Primitive of a Zelda3 ROM.
Definition yaze.h:59
const char * filename
Definition yaze.h:60
void * impl
Definition yaze.h:63
size_t size
Definition yaze.h:62
const uint8_t * data
Definition yaze.h:61
void yaze_cleanup(yaze_editor_context *yaze_ctx)
Clean up the Yaze library.
Definition yaze.cc:31
yaze_bitmap yaze_load_bitmap(const char *filename)
Load a bitmap from a file.
Definition yaze.cc:69
void yaze_unload_rom(z3_rom *rom)
Unload a Zelda3 ROM.
Definition yaze.cc:59
void yaze_check_version(const char *version)
Check the version of the Yaze library.
Definition yaze.cc:8
z3_overworld * yaze_load_overworld(const z3_rom *rom)
Load the overworld from a Zelda3 ROM.
Definition yaze.cc:103
yaze_project yaze_load_project(const char *filename)
Definition yaze.cc:37
z3_rom * yaze_load_rom(const char *filename)
Load a Zelda3 ROM from a file.
Definition yaze.cc:43
snes_color yaze_get_color_from_paletteset(const z3_rom *rom, int palette_set, int palette, int color)
Get a color from a palette set.
Definition yaze.cc:78
int yaze_init(yaze_editor_context *yaze_ctx)
Initialize the Yaze library.
Definition yaze.cc:18
struct z3_rom z3_rom
Definition yaze.h:16