@tool
extends Node3D

@export var spin_speed: float = 7.0

var speed: float = 0.0

@onready var saw_skin: Node3D = $SawSkin


func _ready() -> void:
	if Engine.is_editor_hint() and _editor_is_scene_root():
		return

	saw_skin.rotation.z = randf() * TAU


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
	if Engine.is_editor_hint() and _editor_is_scene_root():
		return

	speed = move_toward(speed, spin_speed, delta)
	saw_skin.rotate_z(speed * delta)


func _editor_is_scene_root() -> bool:
	var ed_interface: Object = Engine.get_singleton(&"EditorInterface")
	return Engine.is_editor_hint() and ed_interface.get_edited_scene_root() == self
