Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions editor/scene/2d/tiles/tile_data_editors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ TileData *TileDataEditor::_get_tile_data(TileMapCell p_cell) {
TileSetSource *source = *tile_set->get_source(p_cell.source_id);
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
ERR_FAIL_COND_V(!atlas_source->has_tile(p_cell.get_atlas_coords()), nullptr);
ERR_FAIL_COND_V(!atlas_source->has_alternative_tile(p_cell.get_atlas_coords(), p_cell.alternative_tile), nullptr);
ERR_FAIL_COND_V(!atlas_source->has_tile_with_alternative(p_cell.get_atlas_coords(), p_cell.alternative_tile), nullptr);
td = atlas_source->get_tile_data(p_cell.get_atlas_coords(), p_cell.alternative_tile);
}

Expand Down
31 changes: 13 additions & 18 deletions editor/scene/2d/tiles/tile_map_layer_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,7 @@ void TileMapLayerEditorTilesPlugin::_update_fix_selected_and_hovered() {
// Clear hovered if needed.
if (source_id != hovered_tile.source_id ||
!tile_set->has_source(hovered_tile.source_id) ||
!tile_set->get_source(hovered_tile.source_id)->has_tile(hovered_tile.get_atlas_coords()) ||
!tile_set->get_source(hovered_tile.source_id)->has_alternative_tile(hovered_tile.get_atlas_coords(), hovered_tile.alternative_tile)) {
!tile_set->get_source(hovered_tile.source_id)->has_tile_with_alternative(hovered_tile.get_atlas_coords(), hovered_tile.alternative_tile)) {
hovered_tile.source_id = TileSet::INVALID_SOURCE;
hovered_tile.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS);
hovered_tile.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE;
Expand All @@ -1610,8 +1609,7 @@ void TileMapLayerEditorTilesPlugin::_update_fix_selected_and_hovered() {
RBSet<TileMapCell>::Element *N = E->next();
const TileMapCell *selected = &(E->get());
if (!tile_set->has_source(selected->source_id) ||
!tile_set->get_source(selected->source_id)->has_tile(selected->get_atlas_coords()) ||
!tile_set->get_source(selected->source_id)->has_alternative_tile(selected->get_atlas_coords(), selected->alternative_tile)) {
!tile_set->get_source(selected->source_id)->has_tile_with_alternative(selected->get_atlas_coords(), selected->alternative_tile)) {
tile_set_selection.erase(E);
}
E = N;
Expand All @@ -1622,8 +1620,7 @@ void TileMapLayerEditorTilesPlugin::_update_fix_selected_and_hovered() {
const Vector2i key = E.key;
const TileMapCell &selected = E.value;
if (!tile_set->has_source(selected.source_id) ||
!tile_set->get_source(selected.source_id)->has_tile(selected.get_atlas_coords()) ||
!tile_set->get_source(selected.source_id)->has_alternative_tile(selected.get_atlas_coords(), selected.alternative_tile)) {
!tile_set->get_source(selected.source_id)->has_tile_with_alternative(selected.get_atlas_coords(), selected.alternative_tile)) {
selection_pattern->remove_cell(key);
}
}
Expand Down Expand Up @@ -4312,20 +4309,18 @@ void TileMapLayerEditor::_draw_overlay() {
float scale_fading = MIN(1, (MIN(hint_distance.x, hint_distance.y) - 5) / 5);
if (scale_fading > 0) {
// Draw tiles with invalid IDs in the grid.
TypedArray<Vector2i> used_cells = edited_layer->get_used_cells();
for (int i = 0; i < used_cells.size(); i++) {
Vector2i coords = used_cells[i];
int tile_source_id = edited_layer->get_cell_source_id(coords);
if (tile_source_id >= 0) {
Vector2i tile_atlas_coords = edited_layer->get_cell_atlas_coords(coords);
int tile_alternative_tile = edited_layer->get_cell_alternative_tile(coords);
const HashMap<Vector2i, CellData> &tile_map_layer_data = edited_layer->get_tile_map_layer_data();

TileSetSource *source = nullptr;
if (tile_set->has_source(tile_source_id)) {
source = *tile_set->get_source(tile_source_id);
}
for (const KeyValue<Vector2i, CellData> &E : tile_map_layer_data) {
const TileMapCell &c = E.value.cell;
const Vector2i &coords = E.key;
int tile_source_id = c.source_id;
if (tile_source_id >= 0) {
Vector2i tile_atlas_coords = c.get_atlas_coords();
int tile_alternative_tile = c.alternative_tile;

if (!source || !source->has_tile(tile_atlas_coords) || !source->has_alternative_tile(tile_atlas_coords, tile_alternative_tile)) {
TileSetSource *source = tile_set->get_source_ptr(tile_source_id);
if (!source || !source->has_tile_with_alternative(tile_atlas_coords, tile_alternative_tile)) {
// Generate a random color from the hashed identifier of the tiles.
Array to_hash = { tile_source_id, tile_atlas_coords, tile_alternative_tile };
uint32_t hash = RandomPCG(to_hash.hash()).rand();
Expand Down
10 changes: 5 additions & 5 deletions editor/scene/2d/tiles/tile_set_atlas_source_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::edit(Ref<TileSetAtlasSource
const Vector2i &coords = E.tile;
const int &alternative = E.alternative;

if (tile_set_atlas_source.is_valid() && tile_set_atlas_source->has_tile(coords) && tile_set_atlas_source->has_alternative_tile(coords, alternative)) {
if (tile_set_atlas_source.is_valid() && tile_set_atlas_source->has_tile_with_alternative(coords, alternative)) {
TileData *tile_data = tile_set_atlas_source->get_tile_data(coords, alternative);
if (tile_data->is_connected(CoreStringName(property_list_changed), callable_mp((Object *)this, &Object::notify_property_list_changed))) {
tile_data->disconnect(CoreStringName(property_list_changed), callable_mp((Object *)this, &Object::notify_property_list_changed));
Expand All @@ -529,7 +529,7 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::edit(Ref<TileSetAtlasSource
const Vector2i &coords = E.tile;
const int &alternative = E.alternative;

if (tile_set_atlas_source->has_tile(coords) && tile_set_atlas_source->has_alternative_tile(coords, alternative)) {
if (tile_set_atlas_source->has_tile_with_alternative(coords, alternative)) {
TileData *tile_data = tile_set_atlas_source->get_tile_data(coords, alternative);
if (!tile_data->is_connected(CoreStringName(property_list_changed), callable_mp((Object *)this, &Object::notify_property_list_changed))) {
tile_data->connect(CoreStringName(property_list_changed), callable_mp((Object *)this, &Object::notify_property_list_changed));
Expand Down Expand Up @@ -571,7 +571,7 @@ void TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles() {
for (RBSet<TileSelection>::Element *E = selection.front(); E;) {
RBSet<TileSelection>::Element *N = E->next();
TileSelection selected = E->get();
if (!tile_set_atlas_source->has_tile(selected.tile) || !tile_set_atlas_source->has_alternative_tile(selected.tile, selected.alternative)) {
if (!tile_set_atlas_source->has_tile_with_alternative(selected.tile, selected.alternative)) {
selection.erase(E);
}
E = N;
Expand All @@ -583,7 +583,7 @@ void TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles() {
}
Vector2i coords = Vector2i(hovered_alternative_tile_coords.x, hovered_alternative_tile_coords.y);
int alternative = hovered_alternative_tile_coords.z;
if (!tile_set_atlas_source->has_tile(coords) || !tile_set_atlas_source->has_alternative_tile(coords, alternative)) {
if (!tile_set_atlas_source->has_tile_with_alternative(coords, alternative)) {
hovered_alternative_tile_coords = Vector3i(TileSetSource::INVALID_ATLAS_COORDS.x, TileSetSource::INVALID_ATLAS_COORDS.y, TileSetSource::INVALID_TILE_ALTERNATIVE);
}
}
Expand Down Expand Up @@ -1715,7 +1715,7 @@ void TileSetAtlasSourceEditor::_set_selection_from_array(const Array &p_selectio
selection.clear();
for (int i = 0; i < p_selection.size() / 2; i++) {
TileSelection selected = { p_selection[i * 2], p_selection[i * 2 + 1] };
if (tile_set_atlas_source->has_tile(selected.tile) && tile_set_atlas_source->has_alternative_tile(selected.tile, selected.alternative)) {
if (tile_set_atlas_source->has_tile_with_alternative(selected.tile, selected.alternative)) {
selection.insert(selected);
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/scene/2d/tiles/tiles_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void TilesEditorUtils::_thread() {
Vector2i coords = tile_map_layer->get_cell_atlas_coords(cell);
int alternative = tile_map_layer->get_cell_alternative_tile(cell);

if (atlas_source->has_tile(coords) && atlas_source->has_alternative_tile(coords, alternative)) {
if (atlas_source->has_tile_with_alternative(coords, alternative)) {
Vector2 center = world_pos - atlas_source->get_tile_data(coords, alternative)->get_texture_origin();
encompassing_rect.expand_to(center - atlas_source->get_tile_texture_region(coords).size / 2);
encompassing_rect.expand_to(center + atlas_source->get_tile_texture_region(coords).size / 2);
Expand Down
23 changes: 11 additions & 12 deletions scene/2d/tile_map_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ void TileMapLayer::_rendering_quadrants_update_cell(CellData &r_cell_data, SelfL
if (tile_set->has_source(r_cell_data.cell.source_id)) {
source = *tile_set->get_source(r_cell_data.cell.source_id);
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source && atlas_source->has_tile(r_cell_data.cell.get_atlas_coords()) && atlas_source->has_alternative_tile(r_cell_data.cell.get_atlas_coords(), r_cell_data.cell.alternative_tile)) {
if (atlas_source && atlas_source->has_tile_with_alternative(r_cell_data.cell.get_atlas_coords(), r_cell_data.cell.alternative_tile)) {
is_valid = true;
const TileData *tile_data;
if (r_cell_data.runtime_tile_data_cache) {
Expand Down Expand Up @@ -638,7 +638,7 @@ void TileMapLayer::_rendering_occluders_update_cell(CellData &r_cell_data) {
if (tile_set->has_source(r_cell_data.cell.source_id)) {
source = *tile_set->get_source(r_cell_data.cell.source_id);

if (source->has_tile(r_cell_data.cell.get_atlas_coords()) && source->has_alternative_tile(r_cell_data.cell.get_atlas_coords(), r_cell_data.cell.alternative_tile)) {
if (source->has_tile_with_alternative(r_cell_data.cell.get_atlas_coords(), r_cell_data.cell.alternative_tile)) {
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
// Get the tile data.
Expand Down Expand Up @@ -722,7 +722,7 @@ void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Ve
if (tile_set->has_source(c.source_id)) {
source = *tile_set->get_source(c.source_id);

if (source->has_tile(c.get_atlas_coords()) && source->has_alternative_tile(c.get_atlas_coords(), c.alternative_tile)) {
if (source->has_tile_with_alternative(c.get_atlas_coords(), c.alternative_tile)) {
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
Vector2i grid_size = atlas_source->get_atlas_grid_size();
Expand Down Expand Up @@ -990,7 +990,7 @@ void TileMapLayer::_physics_quadrants_update_cell(CellData &r_cell_data, SelfLis
if (tile_set->has_source(r_cell_data.cell.source_id)) {
source = *tile_set->get_source(r_cell_data.cell.source_id);
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source && atlas_source->has_tile(r_cell_data.cell.get_atlas_coords()) && atlas_source->has_alternative_tile(r_cell_data.cell.get_atlas_coords(), r_cell_data.cell.alternative_tile)) {
if (atlas_source && atlas_source->has_tile_with_alternative(r_cell_data.cell.get_atlas_coords(), r_cell_data.cell.alternative_tile)) {
is_valid = true;
}
}
Expand Down Expand Up @@ -1400,7 +1400,7 @@ void TileMapLayer::_navigation_update_cell(CellData &r_cell_data) {
if (tile_set->has_source(c.source_id)) {
source = *tile_set->get_source(c.source_id);

if (source->has_tile(c.get_atlas_coords()) && source->has_alternative_tile(c.get_atlas_coords(), c.alternative_tile)) {
if (source->has_tile_with_alternative(c.get_atlas_coords(), c.alternative_tile)) {
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
const TileData *tile_data;
Expand Down Expand Up @@ -1504,7 +1504,7 @@ void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const V
if (tile_set->has_source(c.source_id)) {
source = *tile_set->get_source(c.source_id);

if (source->has_tile(c.get_atlas_coords()) && source->has_alternative_tile(c.get_atlas_coords(), c.alternative_tile)) {
if (source->has_tile_with_alternative(c.get_atlas_coords(), c.alternative_tile)) {
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
const TileData *tile_data;
Expand Down Expand Up @@ -1629,7 +1629,7 @@ void TileMapLayer::_scenes_update_cell(CellData &r_cell_data) {
if (tile_set->has_source(c.source_id)) {
source = *tile_set->get_source(c.source_id);

if (source->has_tile(c.get_atlas_coords()) && source->has_alternative_tile(c.get_atlas_coords(), c.alternative_tile)) {
if (source->has_tile_with_alternative(c.get_atlas_coords(), c.alternative_tile)) {
TileSetScenesCollectionSource *scenes_collection_source = Object::cast_to<TileSetScenesCollectionSource>(source);
if (scenes_collection_source) {
Ref<PackedScene> packed_scene = scenes_collection_source->get_scene_tile_scene(c.alternative_tile);
Expand Down Expand Up @@ -1679,7 +1679,7 @@ void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vecto
if (tile_set->has_source(c.source_id)) {
source = *tile_set->get_source(c.source_id);

if (!source->has_tile(c.get_atlas_coords()) || !source->has_alternative_tile(c.get_atlas_coords(), c.alternative_tile)) {
if (!source->has_tile_with_alternative(c.get_atlas_coords(), c.alternative_tile)) {
return;
}

Expand Down Expand Up @@ -1766,7 +1766,7 @@ void TileMapLayer::_build_runtime_update_tile_data_for_cell(CellData &r_cell_dat
if (tile_set->has_source(c.source_id)) {
source = *tile_set->get_source(c.source_id);

if (source->has_tile(c.get_atlas_coords()) && source->has_alternative_tile(c.get_atlas_coords(), c.alternative_tile)) {
if (source->has_tile_with_alternative(c.get_atlas_coords(), c.alternative_tile)) {
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
bool ret = false;
Expand Down Expand Up @@ -2666,8 +2666,7 @@ TileMapCell TileMapLayer::get_cell(const Vector2i &p_coords) const {
void TileMapLayer::draw_tile(RID p_canvas_item, const Vector2 &p_position, const Ref<TileSet> p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame, const TileData *p_tile_data_override, real_t p_normalized_animation_offset) {
ERR_FAIL_COND(p_tile_set.is_null());
ERR_FAIL_COND(!p_tile_set->has_source(p_atlas_source_id));
ERR_FAIL_COND(!p_tile_set->get_source(p_atlas_source_id)->has_tile(p_atlas_coords));
ERR_FAIL_COND(!p_tile_set->get_source(p_atlas_source_id)->has_alternative_tile(p_atlas_coords, p_alternative_tile));
ERR_FAIL_COND(!p_tile_set->get_source(p_atlas_source_id)->has_tile_with_alternative(p_atlas_coords, p_alternative_tile));
TileSetSource *source = *p_tile_set->get_source(p_atlas_source_id);
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
Expand Down Expand Up @@ -2834,7 +2833,7 @@ void TileMapLayer::fix_invalid_tiles() {
RBSet<Vector2i> coords;
for (const KeyValue<Vector2i, CellData> &E : tile_map_layer_data) {
TileSetSource *source = *tile_set->get_source(E.value.cell.source_id);
if (!source || !source->has_tile(E.value.cell.get_atlas_coords()) || !source->has_alternative_tile(E.value.cell.get_atlas_coords(), E.value.cell.alternative_tile)) {
if (!source || !source->has_tile_with_alternative(E.value.cell.get_atlas_coords(), E.value.cell.alternative_tile)) {
coords.insert(E.key);
}
}
Expand Down
23 changes: 21 additions & 2 deletions scene/resources/2d/tile_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,16 @@ bool TileSet::has_source(int p_source_id) const {
return sources.has(p_source_id);
}

#ifdef TOOLS_ENABLED
TileSetSource *TileSet::get_source_ptr(int p_source_id) const {
const Ref<TileSetSource> *source_ptr = sources.getptr(p_source_id);
if (source_ptr == nullptr) {
return nullptr;
}
return **source_ptr;
}
#endif

Ref<TileSetSource> TileSet::get_source(int p_source_id) const {
ERR_FAIL_COND_V_MSG(!sources.has(p_source_id), nullptr, vformat("No TileSet atlas source with id %d.", p_source_id));

Expand Down Expand Up @@ -1298,7 +1308,7 @@ Array TileSet::map_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_a
// Check if the tile is valid, and if so, don't map the tile and return the input.
if (has_source(p_source_from)) {
Ref<TileSetSource> source = get_source(p_source_from);
if (source->has_tile(p_coords_from) && source->has_alternative_tile(p_coords_from, p_alternative_from)) {
if (source->has_tile_with_alternative(p_coords_from, p_alternative_from)) {
return from;
}
}
Expand Down Expand Up @@ -1353,7 +1363,7 @@ void TileSet::cleanup_invalid_tile_proxies() {
Vector<Array> alternative_to_remove;
for (const KeyValue<Array, Array> &E : alternative_level_proxies) {
Array a = E.key;
if (has_source(a[0]) && get_source(a[0])->has_tile(a[1]) && get_source(a[0])->has_alternative_tile(a[1], a[2])) {
if (has_source(a[0]) && get_source(a[0])->has_tile_with_alternative(a[1], a[2])) {
alternative_to_remove.push_back(a);
}
}
Expand Down Expand Up @@ -5460,6 +5470,11 @@ bool TileSetAtlasSource::has_alternative_tile(const Vector2i p_atlas_coords, int
return tiles[p_atlas_coords].alternatives.has(alternative_no_transform(p_alternative_tile));
}

bool TileSetAtlasSource::has_tile_with_alternative(const Vector2i p_atlas_coords, int p_alternative_tile) const {
const TileAlternativesData *tile_data = tiles.getptr(p_atlas_coords);
return tile_data && tile_data->alternatives.has(alternative_no_transform(p_alternative_tile));
}

int TileSetAtlasSource::get_next_alternative_tile_id(const Vector2i p_atlas_coords) const {
ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), TileSetSource::INVALID_TILE_ALTERNATIVE, vformat("The TileSetAtlasSource atlas has no tile at %s.", String(p_atlas_coords)));
return tiles[p_atlas_coords].next_alternative_id;
Expand Down Expand Up @@ -5799,6 +5814,10 @@ bool TileSetScenesCollectionSource::has_alternative_tile(const Vector2i p_atlas_
return scenes.has(TileSetAtlasSource::alternative_no_transform(p_alternative_tile));
}

bool TileSetScenesCollectionSource::has_tile_with_alternative(const Vector2i p_atlas_coords, int p_alternative_tile) const {
return p_atlas_coords == Vector2i() && scenes.has(p_alternative_tile);
}

int TileSetScenesCollectionSource::create_scene_tile(Ref<PackedScene> p_packed_scene, int p_id_override) {
ERR_FAIL_COND_V_MSG(p_id_override >= 0 && scenes.has(p_id_override), INVALID_TILE_ALTERNATIVE, vformat("Cannot create scene tile. Another scene tile exists with id %d.", p_id_override));

Expand Down
Loading
Loading