2019-11-10 15:09:14 +10:30
|
|
|
#extends Object
|
|
|
|
extends Node
|
|
|
|
|
|
|
|
#class_name Note
|
|
|
|
|
|
|
|
enum {NOTE_TAP, NOTE_HOLD, NOTE_SLIDE, NOTE_ARROW, NOTE_TOUCH, NOTE_TOUCH_HOLD}
|
2019-11-13 00:48:06 +10:30
|
|
|
enum SlideType {CHORD, ARC_CW, ARC_ACW}
|
2019-11-10 15:09:14 +10:30
|
|
|
const DEATH_DELAY := 0.45
|
|
|
|
|
2019-11-14 22:27:30 +10:30
|
|
|
class NoteBase:
|
|
|
|
var time_hit: float
|
|
|
|
var time_death: float
|
|
|
|
var column: int
|
|
|
|
var double_hit := false
|
|
|
|
|
|
|
|
class NoteSlide extends NoteBase:
|
|
|
|
var type := NOTE_SLIDE
|
|
|
|
var time_release: float
|
|
|
|
var duration: float
|
|
|
|
var column_release: int
|
|
|
|
var slide_type: int
|
|
|
|
var slide_id: int
|
|
|
|
var values: Dictionary
|
|
|
|
|
|
|
|
func _init(time_hit: float, duration: float, column: int, column_release: int, slide_type: int):
|
|
|
|
self.time_hit = time_hit
|
|
|
|
self.duration = duration
|
|
|
|
self.time_release = time_hit + duration
|
|
|
|
self.time_death = time_release + DEATH_DELAY
|
|
|
|
self.column = column
|
|
|
|
self.column_release = column_release
|
|
|
|
self.slide_type = slide_type
|
|
|
|
self.values = {}
|
|
|
|
update_slide_variables()
|
|
|
|
|
|
|
|
func update_slide_variables():
|
|
|
|
match slide_type:
|
|
|
|
Note.SlideType.CHORD:
|
|
|
|
values.start = theme.RADIAL_UNIT_VECTORS[column] * theme.receptor_ring_radius
|
|
|
|
values.end = theme.RADIAL_UNIT_VECTORS[column_release] * theme.receptor_ring_radius
|
|
|
|
values.angle = (values.end - values.start).angle()
|
|
|
|
Note.SlideType.ARC_CW:
|
|
|
|
values.start_a = theme.RADIAL_COL_ANGLES[column]
|
|
|
|
values.end_a = theme.RADIAL_COL_ANGLES[column_release]
|
|
|
|
if values.end_a < values.start_a:
|
|
|
|
values.end_a += TAU
|
|
|
|
Note.SlideType.ARC_ACW:
|
|
|
|
values.start_a = theme.RADIAL_COL_ANGLES[column]
|
|
|
|
values.end_a = theme.RADIAL_COL_ANGLES[column_release]
|
|
|
|
if values.end_a > values.start_a:
|
|
|
|
values.end_a -= TAU
|
|
|
|
|
|
|
|
func get_position(progress: float) -> Vector2:
|
|
|
|
match slide_type:
|
|
|
|
Note.SlideType.CHORD:
|
|
|
|
return lerp(values.start, values.end, progress)
|
|
|
|
Note.SlideType.ARC_CW:
|
|
|
|
var circle_angle : float = lerp(values.start_a, values.end_a, progress)
|
|
|
|
return polar2cartesian(theme.receptor_ring_radius, circle_angle)
|
|
|
|
Note.SlideType.ARC_ACW:
|
|
|
|
var circle_angle : float = lerp(values.start_a, values.end_a, progress)
|
|
|
|
return polar2cartesian(theme.receptor_ring_radius, circle_angle)
|
|
|
|
|
|
|
|
func get_angle(progress: float) -> float:
|
|
|
|
match slide_type:
|
|
|
|
Note.SlideType.CHORD:
|
|
|
|
return values.angle
|
|
|
|
Note.SlideType.ARC_CW:
|
|
|
|
var circle_angle : float = lerp(values.start_a, values.end_a, progress)
|
|
|
|
return circle_angle + PI/2.0
|
|
|
|
Note.SlideType.ARC_ACW:
|
|
|
|
var circle_angle : float = lerp(values.start_a, values.end_a, progress)
|
|
|
|
return circle_angle - PI/2.0
|
|
|
|
|
2019-11-14 22:49:36 +10:30
|
|
|
func get_slide_length() -> float:
|
|
|
|
# Return unit-circle (r=1) length of slide trail
|
|
|
|
match slide_type:
|
|
|
|
Note.SlideType.CHORD:
|
|
|
|
return 2*abs(sin((theme.RADIAL_COL_ANGLES[column_release] - theme.RADIAL_COL_ANGLES[column])/2))
|
|
|
|
Note.SlideType.ARC_CW:
|
|
|
|
return fposmod(theme.RADIAL_COL_ANGLES[column_release] - theme.RADIAL_COL_ANGLES[column], TAU)
|
|
|
|
Note.SlideType.ARC_ACW:
|
|
|
|
return fposmod(theme.RADIAL_COL_ANGLES[column] - theme.RADIAL_COL_ANGLES[column_release], TAU)
|
|
|
|
|
2019-11-14 22:27:30 +10:30
|
|
|
|
|
|
|
|
2019-11-10 15:09:14 +10:30
|
|
|
static func make_tap(time_hit: float, column: int) -> Dictionary:
|
|
|
|
return {type=NOTE_TAP, time_hit=time_hit, time_death=time_hit+DEATH_DELAY, column=column, double_hit=false}
|
|
|
|
|
|
|
|
static func make_break(time_hit: float, column: int) -> Dictionary:
|
|
|
|
return {type=NOTE_TAP, time_hit=time_hit, time_death=time_hit+DEATH_DELAY, column=column, double_hit=false}
|
|
|
|
|
|
|
|
static func make_hold(time_hit: float, duration: float, column: int) -> Dictionary:
|
|
|
|
var time_release := time_hit + duration
|
|
|
|
return {type=NOTE_HOLD, time_hit=time_hit, time_release=time_release, time_death=time_release+DEATH_DELAY, column=column, double_hit=false}
|
|
|
|
|
2019-11-14 22:27:30 +10:30
|
|
|
static func make_slide(time_hit: float, duration: float, column: int, column_release: int, slide_type:=SlideType.CHORD) -> NoteSlide:
|
|
|
|
# var time_release := time_hit + duration
|
|
|
|
# return {type=NOTE_SLIDE, time_hit=time_hit, time_release=time_release, duration=duration,
|
|
|
|
# time_death=time_release+DEATH_DELAY, column=column, column_release=column_release, double_hit=false}
|
|
|
|
return NoteSlide.new(time_hit, duration, column, column_release, slide_type)
|
2019-11-10 15:09:14 +10:30
|
|
|
|
|
|
|
static func make_touch(time_hit: float, location: Vector2) -> Dictionary:
|
|
|
|
return {type=NOTE_TOUCH, time_hit=time_hit, time_death=time_hit+DEATH_DELAY, location=location, double_hit=false}
|
|
|
|
|
|
|
|
static func make_touch_hold(time_hit: float, duration: float, location: Vector2) -> Dictionary:
|
|
|
|
var time_release := time_hit + duration
|
|
|
|
return {type=NOTE_TOUCH_HOLD, time_hit=time_hit, time_release=time_release, time_death=time_release+DEATH_DELAY, location=location, double_hit=false}
|
|
|
|
|
2019-11-14 19:12:49 +10:30
|
|
|
static func process_note_list(note_array: Array):
|
|
|
|
# Preprocess double hits, assign Slide IDs
|
|
|
|
# If this were performance-critical, we'd single iterate it
|
|
|
|
# It's not though, so we lay it out simply
|
|
|
|
var slide_id := 0
|
2019-11-10 15:09:14 +10:30
|
|
|
if len(note_array):
|
2019-11-14 19:12:49 +10:30
|
|
|
# Doubles
|
|
|
|
for i in len(note_array)-1:
|
2019-11-10 15:09:14 +10:30
|
|
|
if note_array[i].time_hit == note_array[i+1].time_hit:
|
|
|
|
note_array[i].double_hit = true
|
|
|
|
note_array[i+1].double_hit = true
|
2019-11-14 19:12:49 +10:30
|
|
|
# Slides
|
|
|
|
for i in len(note_array):
|
|
|
|
if note_array[i].type == NOTE_SLIDE:
|
|
|
|
note_array[i].slide_id = slide_id
|
|
|
|
slide_id += 1
|
2019-11-14 22:27:30 +10:30
|
|
|
|