extends TileMapLayer
class_name Bridge

@export_category("Objects")
@export var bellow_bridge_area: Area2D
@export var on_bridge_area: Area2D


func _process(_delta: float) -> void:
	var character_body_bellow_bridge: Node2D = bellow_bridge_area.get_body()
	var character_body_on_bridge: Node2D = on_bridge_area.get_body()
	
	if character_body_bellow_bridge:
		if bellow_bridge_area.get_character_body_bellow_bridge():
			character_body_bellow_bridge.set_collision_layer_value(4, false)
			character_body_bellow_bridge.set_collision_mask_value(4, false)
			self.z_index = 2
		else:
			character_body_bellow_bridge.set_collision_layer_value(4, true)
			character_body_bellow_bridge.set_collision_mask_value(4, false)
			self.z_index = 0

	if character_body_on_bridge:
		if on_bridge_area.get_character_body_on_bridge():
			character_body_on_bridge.set_collision_layer_value(8, false)
			character_body_on_bridge.set_collision_mask_value(8, false)
			character_body_on_bridge.set_collision_layer_value(1, false)
			character_body_on_bridge.set_collision_mask_value(1, false)
			character_body_on_bridge.set_collision_layer_value(2, true)
			character_body_on_bridge.set_collision_mask_value(2, true)

		else:
			character_body_on_bridge.set_collision_layer_value(8, true)
			character_body_on_bridge.set_collision_mask_value(8, true)
			character_body_on_bridge.set_collision_layer_value(1, true)
			character_body_on_bridge.set_collision_mask_value(1, true)
			character_body_on_bridge.set_collision_layer_value(2, false)
			character_body_on_bridge.set_collision_mask_value(2, false)
			
