Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change TileMapEditor to TileMapLayerEditor #87379

Conversation

groud
Copy link
Member

@groud groud commented Jan 19, 2024

This is the continuation of my work on moving TileMap layers to individual nodes.

This PR does several things:

  • Implement TileMapGroup class, that holds the TileSet and a few editor things for TileMapLayers
  • Replace the TileMapEditor by a TileMapLayerEditor, basically changing the logic to act at the layer-level instead of the TileMap one.

Things should work more or less the same for now. The only difference should be in the display of the grid, as it will consider only the currently selected layer instead of the whole TileMap.

@groud groud added this to the 4.3 milestone Jan 19, 2024
@groud groud requested a review from a team as a code owner January 19, 2024 16:52
@AThousandShips
Copy link
Member

Are we okay with major compatibility breakage for tilemap at this point? I'd say changing the inheritance even by inserting a different class between a class and it's parent is breaking compatibility

@groud
Copy link
Member Author

groud commented Jan 19, 2024

Are we okay with major compatibility breakage for tilemap at this point? I'd say changing the inheritance even by inserting a different class between a class and it's parent is breaking compatibility

I don't know if it has any implication, but I guess it's pretty limited? At least loading a project works it seems.
I am not sure it is breaking anything.

I am not sure where we are in the dev cycles anyway, so I guess it's up to the prod team to decide.

@AThousandShips
Copy link
Member

AThousandShips commented Jan 19, 2024

I'll tag it as such for now, as per the general concept of it, and we'll see if it's desirable, unsure what areas it might affect elsewhere

Might be implications for extensions when moving properties from one class to another

@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch from c834322 to 139b74f Compare January 19, 2024 19:08
@groud groud requested a review from a team as a code owner January 19, 2024 19:08
scene/2d/tile_map_group.cpp Outdated Show resolved Hide resolved
editor/plugins/tiles/tiles_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/tiles/tiles_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/tiles/tiles_editor_plugin.cpp Outdated Show resolved Hide resolved
@KoBeWi

This comment was marked as resolved.

@KoBeWi

This comment was marked as resolved.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 19, 2024

Unlike the previous PR, this one introduces an unimplemented functionality in the form of TileMapGroup. You can create it, but it's completely useless and has no documentation. It's not really a problem at this stage, but it puts more pressure to have the new workflow finished in time.

I wonder if there is a way to do what you are planning without adding a new node. From what I understand, the only difference between TileMap and TileMapGroup is that the former doesn't expose its layer nodes, so you have to edit them in the inspector. But since it will create the layer internally anyway, it should work fine if it happens when the user opens an old scene for the first time, no? It would require a bit of compatibility code, but the TileMap can be converted automatically to TileMapGroup, thus the new node is not really needed.

@groud
Copy link
Member Author

groud commented Jan 21, 2024

Unlike the previous PR, this one introduces an unimplemented functionality in the form of TileMapGroup. You can create it, but it's completely useless and has no documentation. It's not really a problem at this stage, but it puts more pressure to have the new workflow finished in time.

I could make it an abstract class I guess, that would work.

I wonder if there is a way to do what you are planning without adding a new node. From what I understand, the only difference between TileMap and TileMapGroup is that the former doesn't expose its layer nodes, so you have to edit them in the inspector. But since it will create the layer internally anyway, it should work fine if it happens when the user opens an old scene for the first time, no? It would require a bit of compatibility code, but the TileMap can be converted automatically to TileMapGroup, thus the new node is not really needed.

Hmm. That is good question. There are several problem to solve, but I am not 100% sure of what is doable:

  • if we keep only one node, that means we will have to keep the TileMap API as is, but deprecate a lot of its methods. I guess that's acceptable, but it might be a bit more confusing than deprecating the node.
  • Some parts of the to-be-deprecated API rely on the child nodes having values controlled by the parent TileMap. For example, the collision_animatable property requires the children TileMapLayer nodes to be set as use_kinematic_body. Also, I moved some settings to individual layers, like the rendering_quadrant_size. This means that some of those will have no effect anymore on the children nodes (or it could have, but it might be weird in the editor that a parent node modifies its children properties)
  • The deprecated API will be slowed down as every call will have to iterate over children nodes to find the layer corresponding to a given index (in case you have nodes as child which are not TileMapLayers). That might be acceptable, idk.
  • In general, that would keep a lot of bloat in the TileMap API, so not sure what is worth. This might be solvable by keeping the TileMapGroup we have now, but not expose it to users though. That would simplify the work needed the day be remove the deprecated part basically.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 21, 2024

idk then. The day when we remove deprecated stuff is very far away, so when redesigning the API we need to keep in mind that this will stay for a long while. Also another concern is what we want to be the default name of the node. I think TileMap is more intuitive/familiar than TileMapGroup and making the latter default would be a bit odd. It would be best if we could rename the old node to e.g. TileMapOld, but it's not possible unfortunately :/

If we go the route of adding a new class (which can be abstract for now), I think at least it should have a better name.
LayeredTileMap? TileManager? TileLayerArray? TileLayerMap? No idea tbh.

@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch 4 times, most recently from 3a457c4 to 5fc96e9 Compare January 22, 2024 14:47
@groud groud requested review from a team as code owners January 22, 2024 14:47
@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch 2 times, most recently from dcfdd5e to ceb983e Compare January 22, 2024 15:00
@groud groud requested a review from a team as a code owner January 22, 2024 15:00
@groud
Copy link
Member Author

groud commented Jan 22, 2024

Alright. According to @dsnopek, adding the detected API changes in the .expected file should work.
I also renamed TileMapGroup to TileMapLayerGroup and made it abstract.

@AThousandShips
Copy link
Member

You seem to have generated your documentation on an out of date branch and deleted some content

@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch from ceb983e to 6d756a5 Compare January 22, 2024 15:10
@AThousandShips AThousandShips removed the request for review from a team January 22, 2024 15:10
@groud
Copy link
Member Author

groud commented Jan 23, 2024

You seem to have generated your documentation on an out of date branch and deleted some content

It should be fixed now, the PR should be ready.

scene/resources/tile_set.h Outdated Show resolved Hide resolved
@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch from 6d756a5 to 8a22879 Compare January 23, 2024 16:16
scene/2d/tile_map_layer.h Outdated Show resolved Hide resolved
scene/2d/tile_map_layer.h Outdated Show resolved Hide resolved
@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch from 8a22879 to ff1903e Compare January 24, 2024 10:44
@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch 2 times, most recently from de434e8 to 6428975 Compare January 30, 2024 17:12
@YuriSizov
Copy link
Contributor

We should merge it soon (but probably not for dev3, which we plan to have tomorrow). But before we do, I wanted someone to take a look at the changes so we have two approvals. It can be me or Remi, but volunteers are also welcome!

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, did some basic testing but haven't done extensive use of it yet, but the changes to the map itself seems reasonable, and most of the editor side is renaming

Edit: this might worsen threading issues due to making the queuing unique to each layer, but the threading should be simple to fix, see:

editor/plugins/tiles/tile_map_layer_editor.cpp Outdated Show resolved Hide resolved
editor/plugins/tiles/tile_map_layer_editor.cpp Outdated Show resolved Hide resolved
Copy link
Member

@kleonc kleonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skimmed though the code, mostly looks fine to me. 👍

scene/resources/tile_set.h Outdated Show resolved Hide resolved
editor/plugins/tiles/tile_map_layer_editor.cpp Outdated Show resolved Hide resolved
editor/plugins/tiles/tile_map_layer_editor.cpp Outdated Show resolved Hide resolved
editor/plugins/tiles/tile_map_layer_editor.cpp Outdated Show resolved Hide resolved
scene/2d/tile_map_layer_group.h Show resolved Hide resolved
scene/2d/tile_map_layer_group.cpp Outdated Show resolved Hide resolved
scene/2d/tile_map_layer.cpp Show resolved Hide resolved
@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch from 6428975 to 96c22b8 Compare February 8, 2024 17:31
@AThousandShips
Copy link
Member

Unsure if this is exactly what's intended here but applied this to fix the compilation issues on my end:

diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp
index 5e351293b3c42..e866d82c03564 100644
--- a/scene/2d/tile_map_layer.cpp
+++ b/scene/2d/tile_map_layer.cpp
@@ -198,6 +198,7 @@ void TileMapLayer::_rendering_update() {
 
 		// Modulate the layer.
 		Color layer_modulate = get_modulate();
+#ifdef TOOLS_ENABLED
 		const Vector<StringName> selected_layers = tile_map_node->get_selected_layers();
 		if (tile_map_node->is_highlighting_selected_layer() && selected_layers.size() == 1 && get_name() != selected_layers[0]) {
 			TileMapLayer *selected_layer = Object::cast_to<TileMapLayer>(tile_map_node->get_node_or_null(String(selected_layers[0])));
@@ -212,6 +213,7 @@ void TileMapLayer::_rendering_update() {
 				}
 			}
 		}
+#endif // TOOLS_ENABLED
 		rs->canvas_item_set_modulate(get_canvas_item(), layer_modulate);
 	}
 
@@ -2965,4 +2967,4 @@ TerrainConstraint::TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_
 		}
 	}
 	terrain = p_terrain;
-}
\ No newline at end of file
+}
diff --git a/scene/2d/tile_map_layer_group.cpp b/scene/2d/tile_map_layer_group.cpp
index be522e2aa9c0d..7ddafc12104ca 100644
--- a/scene/2d/tile_map_layer_group.cpp
+++ b/scene/2d/tile_map_layer_group.cpp
@@ -101,7 +101,9 @@ bool TileMapLayerGroup::is_highlighting_selected_layer() const {
 #endif // TOOLS_ENABLED
 
 void TileMapLayerGroup::remove_child_notify(Node *p_child) {
+#ifdef TOOLS_ENABLED
 	_cleanup_selected_layers();
+#endif
 }
 
 void TileMapLayerGroup::_bind_methods() {

Would be good to get that out of the way and this merged

@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch from 96c22b8 to e35b889 Compare February 12, 2024 09:08
@groud groud force-pushed the change_tilemap_editor_to_tilemaplayer_editor branch from e35b889 to 5a999d6 Compare February 12, 2024 09:11
@akien-mga akien-mga merged commit 687f840 into godotengine:master Feb 12, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants