yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_map.cc
Go to the documentation of this file.
1#include "dungeon_map.h"
2
3#include <fstream>
4#include <vector>
5
8#include "app/gfx/bitmap.h"
9#include "app/gfx/snes_tile.h"
10
11namespace yaze {
12namespace zelda3 {
13
15 std::array<gfx::Bitmap, 4> &sheets,
16 gfx::Tilesheet &tile16_sheet,
17 std::vector<uint8_t> &gfx_bin_data) {
18 std::string bin_file = core::FileDialogWrapper::ShowOpenFileDialog();
19 if (bin_file.empty()) {
20 return absl::InternalError("No file selected");
21 }
22
23 std::ifstream file(bin_file, std::ios::binary);
24 if (file.is_open()) {
25 // Read the gfx data into a buffer
26 std::vector<uint8_t> bin_data((std::istreambuf_iterator<char>(file)),
27 std::istreambuf_iterator<char>());
28 auto converted_bin = gfx::SnesTo8bppSheet(bin_data, 4, 4);
29 gfx_bin_data = converted_bin;
30 tile16_sheet.clear();
31 if (LoadDungeonMapTile16(converted_bin, true).ok()) {
32 std::vector<std::vector<uint8_t>> gfx_sheets;
33 for (int i = 0; i < 4; i++) {
34 gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000),
35 converted_bin.begin() + ((i + 1) * 0x1000));
36 sheets[i] = gfx::Bitmap(128, 32, 8, gfx_sheets[i]);
38 sheets[i].ApplyPalette(*rom.mutable_dungeon_palette(3)));
40 }
41 } else {
42 return absl::InternalError("Failed to load dungeon map tile16");
43 }
44 file.close();
45 }
46
47 return absl::OkStatus();
48}
49
50} // namespace zelda3
51} // namespace yaze
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:59
auto mutable_dungeon_palette(int i)
Definition rom.h:179
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
static Renderer & GetInstance()
Definition renderer.h:26
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
Definition renderer.h:48
Represents a bitmap image.
Definition bitmap.h:66
Represents a tilesheet, which is a collection of tiles stored in a bitmap.
Definition tilesheet.h:28
#define RETURN_IF_ERROR(expression)
Definition macro.h:62
std::vector< uint8_t > SnesTo8bppSheet(const std::vector< uint8_t > &sheet, int bpp, int num_sheets)
Definition snes_tile.cc:151
Zelda 3 specific classes and functions.
absl::Status LoadDungeonMapTile16(const std::vector< uint8_t > &gfx_data, bool bin_mode)
absl::Status LoadDungeonMapGfxFromBinary(Rom &rom, std::array< gfx::Bitmap, 4 > &sheets, gfx::Tilesheet &tile16_sheet, std::vector< uint8_t > &gfx_bin_data)
Main namespace for the application.
Definition controller.cc:18