class_name HoldNote extends NoteVisual

@export var start: Node2D

@export var end: Node2D

var start_id: int
var end_id: int
var start_beat: float
var end_beat: float

func reset() -> void:
	start_id = -1
	end_id = -1
	start_beat = -999.0
	end_beat = -999.0

func in_use() -> bool:
	return start_id >= 0 or end_id >= 0

func update(beat: float) -> void:
	var start_scroll: float
	if start_beat:
		start_scroll = _calculate_scroll(start_beat, beat)
	else:
		start_scroll = 999.0 # Decently up. (TODO Replace with offset_begin).
	_set_start_scroll(start_scroll)
	
	var end_scroll: float
	if end_beat:
		end_scroll = _calculate_scroll(end_beat, beat)
	else:
		end_scroll = -999.0 # Decently down. (TODO Replace with offset_end).
	_set_end_scroll(end_scroll)

# ======== IMPLEMENTATION ======== #
func _set_start_scroll(scroll: float) -> void:
	start.y = scroll

func _set_end_scroll(scroll: float) -> void:
	end.y = scroll
