2026-04-13 11:34:00 -05:00
|
|
|
class_name SceneTileMapLayer extends TileMapLayer
|
|
|
|
|
|
|
|
|
|
signal child_registered
|
|
|
|
|
|
|
|
|
|
var scene_coords: Dictionary[Vector2i, Node] = {}
|
|
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
func _enter_tree():
|
|
|
|
|
child_entered_tree.connect(_register_child)
|
|
|
|
|
child_exiting_tree.connect(_unregister_child)
|
|
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
func _register_child(child):
|
|
|
|
|
await child.ready
|
|
|
|
|
var coords = local_to_map(to_local(child.global_position))
|
|
|
|
|
scene_coords[coords] = child
|
|
|
|
|
child.set_meta("tile_coords", coords)
|
|
|
|
|
child_registered.emit()
|
|
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
func _unregister_child(child):
|
|
|
|
|
scene_coords.erase(child.get_meta("tile_coords"))
|
|
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
func get_cell_scene(coords: Vector2i) -> Node:
|
|
|
|
|
return scene_coords.get(coords, null)
|
|
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
func get_scene_coords(scene: Node) -> Vector2i:
|
|
|
|
|
return scene_coords.find_key(scene)
|