Skip to content

Commit

Permalink
Merge pull request #51327 from kleonc/tile_map-ensure-tile-is-in_tile…
Browse files Browse the repository at this point in the history
…_set

[3.x] TileMap Fix trying to get data for tile not existing in attached TileSet
  • Loading branch information
akien-mga authored Aug 7, 2021
2 parents 030bdc5 + 2eeed26 commit 92d5614
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions editor/plugins/tile_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p
return;
}

if (manual_autotile || (p_value != -1 && node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE)) {
if (manual_autotile || (p_value != -1 && node->get_tileset()->has_tile(p_value) && node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE)) {
if (current != -1) {
node->set_cell_autotile_coord(p_pos.x, p_pos.y, position);
} else if (node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE && priority_atlastile) {
Expand Down Expand Up @@ -542,7 +542,7 @@ void TileMapEditor::_update_palette() {
sel_tile = palette->get_selected_items().get(0);
}

if (sel_tile != TileMap::INVALID_CELL && ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || (!priority_atlastile && tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE))) {
if (sel_tile != TileMap::INVALID_CELL && tileset->has_tile(sel_tile) && ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || (!priority_atlastile && tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE))) {
const Map<Vector2, uint32_t> &tiles2 = tileset->autotile_get_bitmask_map(sel_tile);

Vector<Vector2> entries2;
Expand Down Expand Up @@ -592,7 +592,7 @@ void TileMapEditor::_update_palette() {
manual_palette->show();
}

if (sel_tile != TileMap::INVALID_CELL && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) {
if (sel_tile != TileMap::INVALID_CELL && tileset->has_tile(sel_tile) && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) {
manual_button->show();
priority_button->hide();
} else {
Expand All @@ -604,7 +604,7 @@ void TileMapEditor::_update_palette() {
void TileMapEditor::_pick_tile(const Point2 &p_pos) {
int id = node->get_cell(p_pos.x, p_pos.y);

if (id == TileMap::INVALID_CELL) {
if (id == TileMap::INVALID_CELL || !node->get_tileset()->has_tile(id)) {
return;
}

Expand Down Expand Up @@ -800,8 +800,11 @@ void TileMapEditor::_erase_selection() {
}

void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord, const Transform2D &p_xform) {
Ref<Texture> t = node->get_tileset()->tile_get_texture(p_cell);
if (!node->get_tileset()->has_tile(p_cell)) {
return;
}

Ref<Texture> t = node->get_tileset()->tile_get_texture(p_cell);
if (t.is_null()) {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions scene/2d/tile_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ void TileMap::update_dirty_quadrants() {
Ref<ShaderMaterial> mat = tile_set->tile_get_material(c.id);
int z_index = tile_set->tile_get_z_index(c.id);

if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE ||
tile_set->tile_get_tile_mode(c.id) == TileSet::ATLAS_TILE) {
if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE || tile_set->tile_get_tile_mode(c.id) == TileSet::ATLAS_TILE) {
z_index += tile_set->autotile_get_z_index(c.id, Vector2(c.autotile_coord_x, c.autotile_coord_y));
}

Expand Down Expand Up @@ -939,6 +938,9 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) {
Map<PosKey, Cell>::Element *E = tile_map.find(p);
if (E != nullptr) {
int id = get_cell(p_x, p_y);
if (!tile_set->has_tile(id)) {
return;
}
if (tile_set->tile_get_tile_mode(id) == TileSet::AUTO_TILE) {
uint16_t mask = 0;
if (tile_set->autotile_get_bitmask_mode(id) == TileSet::BITMASK_2X2) {
Expand Down

0 comments on commit 92d5614

Please sign in to comment.