feat(editor): brush amb preview snap-to-grid i pintura per clic

This commit is contained in:
JailDesigner committed 2026-04-23 12:11:54 +02:00
1 parent a612a8255f
commit 05cdcfa660
3 files changed
+86 -11

No files matched your search

+24
View File
@@ -127,6 +127,30 @@ void Tilemap::setTileAt(int col, int row, int index) {
auto Tilemap::save(const std::string& yaml_path) const -> bool {
return TilemapWriter::saveDataBlock(yaml_path, data_);
}
void Tilemap::renderTilePreview(int canvas_x, int canvas_y, int tile_index) const {
if (tile_index < 0) { return; }
const auto TILESET = Resource::Cache::get().getSurface(tileset_path_);
if (TILESET == nullptr) { return; }
auto& screen = Screen::get();
auto* buf = screen.getCanvasArgb();
const int CW = screen.getCanvasWidth();
const int CH = screen.getCanvasHeight();
const auto TRANSPARENT = TILESET->getTransparentColor();
const int SX0 = (tile_index % tileset_cols_) * tile_size_;
const int SY0 = (tile_index / tileset_cols_) * tile_size_;
for (int y = 0; y < tile_size_; ++y) {
const int DY = canvas_y + y;
if (DY < 0 || DY >= CH) { continue; }
for (int x = 0; x < tile_size_; ++x) {
const int DX = canvas_x + x;
if (DX < 0 || DX >= CW) { continue; }
const auto IDX = TILESET->getPixel(SX0 + x, SY0 + y);
if (IDX == TRANSPARENT) { continue; }
buf[(static_cast<std::size_t>(DY) * static_cast<std::size_t>(CW)) + static_cast<std::size_t>(DX)] = TILESET->getPaletteColor(IDX);
}
}
}
#endif
void Tilemap::render() const {