extends Control @export var dice_configuration: DiceConfiguration var rotate_tween: Tween func _ready() -> void: %FaceFront.texture = DiceFace.get_face_type_icon(dice_configuration.front_face.type) %FaceBack.texture = DiceFace.get_face_type_icon(dice_configuration.back_face.type) %FaceLeft.texture = DiceFace.get_face_type_icon(dice_configuration.left_face.type) %FaceRight.texture = DiceFace.get_face_type_icon(dice_configuration.right_face.type) %FaceTop.texture = DiceFace.get_face_type_icon(dice_configuration.top_face.type) %FaceBottom.texture = DiceFace.get_face_type_icon(dice_configuration.bottom_face.type) rotate_tween = get_tree().create_tween() %DiceConfigurationFacePreviewFront.grab_focus() func set_face_active(face: Control) -> void: for node in %DiceConfigurationPreview.get_children(): node.active = false face.active = true func rotate_dice(target: Vector3) -> void: rotate_tween.stop() rotate_tween = get_tree().create_tween() rotate_tween.tween_property(%Dice, "rotation", target, 0.5) func _on_dice_configuration_face_preview_front_focus_entered() -> void: rotate_dice(Vector3.ZERO) set_face_active(%DiceConfigurationFacePreviewFront) func _on_dice_configuration_face_preview_back_focus_entered() -> void: rotate_dice(Vector3(0, deg_to_rad(180), 0)) set_face_active(%DiceConfigurationFacePreviewBack) func _on_dice_configuration_face_preview_left_focus_entered() -> void: rotate_dice(Vector3(0, deg_to_rad(90), 0)) set_face_active(%DiceConfigurationFacePreviewLeft) func _on_dice_configuration_face_preview_right_focus_entered() -> void: rotate_dice(Vector3(0, deg_to_rad(-90), 0)) set_face_active(%DiceConfigurationFacePreviewRight) func _on_dice_configuration_face_preview_top_focus_entered() -> void: rotate_dice(Vector3(deg_to_rad(90), 0, 0)) set_face_active(%DiceConfigurationFacePreviewTop) func _on_dice_configuration_face_preview_bottom_focus_entered() -> void: rotate_dice(Vector3(deg_to_rad(-90), 0, 0)) set_face_active(%DiceConfigurationFacePreviewBottom)