void TilemapLayer::SetMapData(const std::vector<short>& nmap_data) { if (map_data != nmap_data) { // Create the tiles data cache CreateTileCache(nmap_data); if (layer == 0) { autotiles_ab_map.clear(); autotiles_d_map.clear(); autotiles_ab_next = 0; autotiles_d_next = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (data_cache[x][y].ID < BLOCK_C) { // If blocks A and B GenerateAutotileAB(data_cache[x][y].ID, 0); GenerateAutotileAB(data_cache[x][y].ID, 1); GenerateAutotileAB(data_cache[x][y].ID, 2); } else if (data_cache[x][y].ID >= BLOCK_D && data_cache[x][y].ID < BLOCK_E) { // If block D GenerateAutotileD(data_cache[x][y].ID); } } } autotiles_ab_screen = GenerateAutotiles(autotiles_ab_next, autotiles_ab_map); autotiles_d_screen = GenerateAutotiles(autotiles_d_next, autotiles_d_map); } } map_data = nmap_data; }
void TilemapLayer::SetPassable(const std::vector<unsigned char>& npassable) { passable = npassable; if (substitutions.size() < passable.size()) { substitutions.resize(passable.size()); for (uint8_t i = 0; i < substitutions.size(); i++) substitutions[i] = i; } // Recalculate z values of all tiles CreateTileCache(map_data); }
void TilemapLayer::Substitute(int old_id, int new_id) { int subst_count = 0; for (size_t i = 0; i < substitutions.size(); ++i) { if (substitutions[i] == old_id) { ++subst_count; substitutions[i] = (uint8_t) new_id; } } if (subst_count > 0) { // Recalculate z values of all tiles CreateTileCache(map_data); } }