| 21 | } |
| 22 | |
| 23 | void ImagePartReader::forEachTile(TileCallback const& callback) const { |
| 24 | for (auto const& entry : m_images) { |
| 25 | String const& file = entry.first; |
| 26 | ImageConstPtr const& image = entry.second; |
| 27 | for (size_t y = 0; y < image->height(); y++) { |
| 28 | for (size_t x = 0; x < image->width(); x++) { |
| 29 | |
| 30 | Vec2I position(x, y); |
| 31 | Vec4B tileColor = image->get(x, y); |
| 32 | |
| 33 | if (auto const& tile = m_tileset->getTile(tileColor)) { |
| 34 | bool exitEarly = callback(position, *tile); |
| 35 | if (exitEarly) |
| 36 | return; |
| 37 | } else { |
| 38 | throw StarException::format("Dungeon image {} uses unknown tile color: #{:02x}{:02x}{:02x}{:02x}", |
| 39 | file, |
| 40 | tileColor[0], |
| 41 | tileColor[1], |
| 42 | tileColor[2], |
| 43 | tileColor[3]); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void ImagePartReader::forEachTileAt(Vec2I pos, TileCallback const& callback) const { |
| 51 | for (auto const& entry : m_images) { |