Tool mode: Is it possible to be notified if a TileMap cell was changed in the editor?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kerskuchen
:warning: Old Version Published before Godot 3 was released.

Hey!

I need to make a tool script that detects if a TileMap cell was changed by the user in the editor (not in the game). This would allow for features like autotiling.

Unfortunately when I tried subclassing TileMap and overriding the set_cell method to emit a signal, neither the signal nor the print-statement is called:

tool
extends TileMap

signal cell_changed(tilemap, x, y, value)

func set_cell(x, y, value, flip_x = false, flip_y = false, transpose = false):
	print("cell changed")
	.set_cell(x, y, value, flip_x, flip_y, transpose)
	emit_signal("cell_changed", x, y, value, flip_x, flip_y, transpose)
	pass

Does anyone know how to realize it without going down c++ road? If not how can adjust tile_map.cpp to add a signal on edit?

I tried to put

 emit_signal("cell_changed", p_x, p_y, p_tile, p_flip_x, p_flip_y, p_transpose);

into the set_cell method and

ADD_SIGNAL(MethodInfo("cell_changed", PropertyInfo(Variant::INT, "x:Int"),  PropertyInfo(Variant::INT, "y:Int"),  PropertyInfo(Variant::INT, "value:Int"),  PropertyInfo(Variant::BOOL, "flip_x:Bool"),  PropertyInfo(Variant::BOOL, "flip_y:Bool"),  PropertyInfo(Variant::BOOL, "transpose:Bool")));

at the bottom of the .cpp file where the other signal is. But compiler says:

tile_map.cpp
scene\2d\tile_map.cpp(706): error C2661: 'Object::emit_signal': no overloaded function takes 7 arguments
scene\2d\tile_map.cpp(1315): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'MethodInfo'
scene\2d\tile_map.cpp(1315): note: No constructor could take the source type, or constructor overload resolution was ambiguous
scene\2d\tile_map.cpp(1315): error C2660: 'ClassDB::add_signal': function does not take 1 arguments
scons: *** [scene\2d\tile_map.windows.opt.tools.64.obj] Error 2
scons: building terminated because of errors.

How could I adjust the above to make it work. Sorry I am very new to the .cpp side of Godot and cannot yet grasp all the property and variants stuff.

Thank you for your time!

Did you ever figure this out? Trying to make a similar tool. Thanks!

yahwhey | 2022-09-07 06:06