clockwork-city/prefabs/scene_tile_map_layer.gd

31 lines
725 B
GDScript3
Raw Normal View History

2026-04-13 11:34:00 -05:00
class_name SceneTileMapLayer extends TileMapLayer
signal child_registered
var scene_coords: Dictionary[Vector2i, Node] = {}
func _enter_tree() -> void:
2026-04-13 11:34:00 -05:00
child_entered_tree.connect(_register_child)
child_exiting_tree.connect(_unregister_child)
func _register_child(child: Node) -> void:
2026-04-13 11:34:00 -05:00
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-13 11:34:00 -05:00
func _unregister_child(child):
scene_coords.erase(child.get_meta("tile_coords"))
2026-04-13 11:34:00 -05:00
func get_cell_scene(coords: Vector2i) -> Node:
return scene_coords.get(coords, null)
2026-04-13 11:34:00 -05:00
func get_scene_coords(scene: Node) -> Vector2i:
return scene_coords.find_key(scene)