Files
godot-4-key-rhythm-game/rhythm_game/note/note_array.gd

45 lines
1.1 KiB
GDScript3
Raw Normal View History

2026-01-25 03:26:34 +08:00
## An array of notes, stored as arrays of data.
## Notes are assumed to be sorted in ascending order by beat.
class_name NoteArray extends Node
## The ID of the note at [param index].
func id_at(index: int) -> int:
return index
## The beat of the note at [param index].
func beat_at(index: int) -> float:
return _beats.get(index)
## The type of the note at [param index].
func type_at(index: int) -> Note.TYPE:
return _types.get(index)
## The lane of the note at [param index].
func lane_at(index: int) -> int:
return _lanes.get(index)
## The number of notes in the array.
func size() -> int:
return _beats.size()
## Remove all notes in the array.
func clear() -> void:
_beats = []
_types = []
_lanes = []
# ======= IMPLEMENTATION ======= #
var _beats: Array[float] = []
var _types: Array[Note.TYPE] = []
var _lanes: Array[int] = []
func _append_note(note: Note) -> void:
_beats.append(note.hit_beat)
_types.append(note.type)
_lanes.append(note.lane)
func _append_note_data(beat: float, type: Note.TYPE, lane: int) -> void:
_beats.append(beat)
_types.append(type)
_lanes.append(lane)