remove app namespace
This commit is contained in:
53
src/app/zelda3/screen/dungeon_map.cc
Normal file
53
src/app/zelda3/screen/dungeon_map.cc
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "dungeon_map.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "app/core/platform/renderer.h"
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/gfx/snes_tile.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace zelda3 {
|
||||
namespace screen {
|
||||
|
||||
absl::Status LoadDungeonMapGfxFromBinary(Rom &rom,
|
||||
std::array<gfx::Bitmap, 4> &sheets,
|
||||
gfx::Tilesheet &tile16_sheet,
|
||||
std::vector<uint8_t> &gfx_bin_data) {
|
||||
std::string bin_file = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (bin_file.empty()) {
|
||||
return absl::InternalError("No file selected");
|
||||
}
|
||||
|
||||
std::ifstream file(bin_file, std::ios::binary);
|
||||
if (file.is_open()) {
|
||||
// Read the gfx data into a buffer
|
||||
std::vector<uint8_t> bin_data((std::istreambuf_iterator<char>(file)),
|
||||
std::istreambuf_iterator<char>());
|
||||
auto converted_bin = gfx::SnesTo8bppSheet(bin_data, 4, 4);
|
||||
gfx_bin_data = converted_bin;
|
||||
tile16_sheet.clear();
|
||||
if (LoadDungeonMapTile16(converted_bin, true).ok()) {
|
||||
std::vector<std::vector<uint8_t>> gfx_sheets;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000),
|
||||
converted_bin.begin() + ((i + 1) * 0x1000));
|
||||
sheets[i] = gfx::Bitmap(128, 32, 8, gfx_sheets[i]);
|
||||
sheets[i].ApplyPalette(*rom.mutable_dungeon_palette(3));
|
||||
core::Renderer::GetInstance().RenderBitmap(&sheets[i]);
|
||||
}
|
||||
} else {
|
||||
return absl::InternalError("Failed to load dungeon map tile16");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace screen
|
||||
} // namespace zelda3
|
||||
|
||||
} // namespace yaze
|
||||
Reference in New Issue
Block a user