You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-17 14:11:06 +00:00
Fixes TileSet set as local to scene
This commit is contained in:
@@ -479,6 +479,11 @@ int TileSet::add_source(Ref<TileSetSource> p_tile_set_source, int p_atlas_source
|
||||
sources[new_source_id] = p_tile_set_source;
|
||||
source_ids.push_back(new_source_id);
|
||||
source_ids.sort();
|
||||
TileSet *old_tileset = p_tile_set_source->get_tile_set();
|
||||
if (old_tileset != this && old_tileset != nullptr) {
|
||||
// If the source is already in a TileSet (might happen when duplicating), remove it from the other TileSet.
|
||||
old_tileset->remove_source_ptr(p_tile_set_source.ptr());
|
||||
}
|
||||
p_tile_set_source->set_tile_set(this);
|
||||
_compute_next_source_id();
|
||||
|
||||
@@ -504,6 +509,16 @@ void TileSet::remove_source(int p_source_id) {
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
void TileSet::remove_source_ptr(TileSetSource *p_tile_set_source) {
|
||||
for (const KeyValue<int, Ref<TileSetSource>> &kv : sources) {
|
||||
if (kv.value.ptr() == p_tile_set_source) {
|
||||
remove_source(kv.key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ERR_FAIL_MSG(vformat("Attempting to remove source from a tileset, but the tileset doesn't have it: %s", p_tile_set_source));
|
||||
}
|
||||
|
||||
void TileSet::set_source_id(int p_source_id, int p_new_source_id) {
|
||||
ERR_FAIL_COND(p_new_source_id < 0);
|
||||
ERR_FAIL_COND_MSG(!sources.has(p_source_id), vformat("Cannot change TileSet atlas source ID. No tileset atlas source with id %d.", p_source_id));
|
||||
@@ -3140,9 +3155,10 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
|
||||
// Create source only if it does not exists.
|
||||
int source_id = components[1].to_int();
|
||||
|
||||
if (!has_source(source_id)) {
|
||||
add_source(p_value, source_id);
|
||||
if (has_source(source_id)) {
|
||||
remove_source(source_id);
|
||||
}
|
||||
add_source(p_value, source_id);
|
||||
return true;
|
||||
} else if (components.size() == 2 && components[0] == "tile_proxies") {
|
||||
ERR_FAIL_COND_V(p_value.get_type() != Variant::ARRAY, false);
|
||||
@@ -3587,6 +3603,10 @@ void TileSetSource::set_tile_set(const TileSet *p_tile_set) {
|
||||
tile_set = p_tile_set;
|
||||
}
|
||||
|
||||
TileSet *TileSetSource::get_tile_set() const {
|
||||
return (TileSet *)tile_set;
|
||||
}
|
||||
|
||||
void TileSetSource::reset_state() {
|
||||
tile_set = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user