yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
inventory.cc
Go to the documentation of this file.
1#include "inventory.h"
2
4#include "app/gfx/bitmap.h"
5#include "app/gfx/snes_tile.h"
6#include "app/gui/canvas.h"
7#include "app/rom.h"
8
9namespace yaze {
10namespace app {
11namespace zelda3 {
12namespace screen {
13
14using core::Renderer;
15
16absl::Status Inventory::Create() {
17 data_.reserve(256 * 256);
18 for (int i = 0; i < 256 * 256; i++) {
19 data_.push_back(0xFF);
20 }
22 for (int i = 0; i < 0x500; i += 0x08) {
23 tiles_.push_back(gfx::GetTilesInfo(rom()->toint16(i + kBowItemPos)));
24 tiles_.push_back(gfx::GetTilesInfo(rom()->toint16(i + kBowItemPos + 0x02)));
25 tiles_.push_back(gfx::GetTilesInfo(rom()->toint16(i + kBowItemPos + 0x04)));
26 tiles_.push_back(gfx::GetTilesInfo(rom()->toint16(i + kBowItemPos + 0x08)));
27 }
28 const int offsets[] = {0x00, 0x08, 0x800, 0x808};
29 auto xx = 0;
30 auto yy = 0;
31
32 int i = 0;
33 for (const auto& tile : tiles_) {
34 int offset = offsets[i];
35 for (auto y = 0; y < 0x08; ++y) {
36 for (auto x = 0; x < 0x08; ++x) {
37 int mx = x;
38 int my = y;
39
40 if (tile.horizontal_mirror_ != 0) {
41 mx = 0x07 - x;
42 }
43
44 if (tile.vertical_mirror_ != 0) {
45 my = 0x07 - y;
46 }
47
48 int xpos = ((tile.id_ % 0x10) * 0x08);
49 int ypos = (((tile.id_ / 0x10)) * 0x400);
50 int source = ypos + xpos + (x + (y * 0x80));
51
52 auto destination = xx + yy + offset + (mx + (my * 0x100));
53 data_[destination] = (test_[source] & 0x0F) + tile.palette_ * 0x08;
54 }
55 }
56
57 if (i == 4) {
58 i = 0;
59 xx += 0x10;
60 if (xx >= 0x100) {
61 yy += 0x1000;
62 xx = 0;
63 }
64 } else {
65 i++;
66 }
67 }
68
69 bitmap_.Create(256, 256, 8, data_);
72 return absl::OkStatus();
73}
74
76 tilesheets_.reserve(6 * 0x2000);
77 for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
78 ASSIGN_OR_RETURN(tilesheets_, rom()->Load2BppGraphics())
79 std::vector<uint8_t> test;
80 for (int i = 0; i < 0x4000; i++) {
81 test_.push_back(tilesheets_[i]);
82 }
83 for (int i = 0x8000; i < +0x8000 + 0x2000; i++) {
84 test_.push_back(tilesheets_[i]);
85 }
86 tilesheets_bmp_.Create(128, 0x130, 64, test_);
87 auto hud_pal_group = rom()->palette_group().hud;
88 palette_ = hud_pal_group[0];
91 return absl::OkStatus();
92}
93
94} // namespace screen
95} // namespace zelda3
96} // namespace app
97} // namespace yaze
static Renderer & GetInstance()
Definition renderer.h:27
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
Definition renderer.h:49
absl::Status ApplyPalette(const SnesPalette &palette)
Copy color data from the SnesPalette into the SDL_Palette.
Definition bitmap.cc:327
void Create(int width, int height, int depth, const std::vector< uint8_t > &data)
Creates a bitmap object with the provided graphical data.
Definition bitmap.cc:230
std::vector< uint8_t > test_
Definition inventory.h:33
std::vector< uint8_t > tilesheets_
Definition inventory.h:32
std::vector< uint8_t > data_
Definition inventory.h:29
std::vector< gfx::TileInfo > tiles_
Definition inventory.h:38
#define RETURN_IF_ERROR(expression)
Definition constants.h:62
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition constants.h:70
TileInfo GetTilesInfo(uint16_t tile)
Definition snes_tile.cc:377
constexpr int kBowItemPos
Definition inventory.h:16
Definition common.cc:22