-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.gd
126 lines (88 loc) · 2.46 KB
/
Main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
extends Node2D
const speedTexts = [ "w", "h", "q", "e", "t", "s" ]
const speedIndexes = [ 0.25, 0.5, 1, 2, 3, 4 ]
onready var BPM = $Container/BPM/LineEdit
onready var Time = $Container/Time/LineEdit
onready var Hz = $Container/Hz/LineEdit
onready var Speed = $Speed/current
onready var TimeUnitButton = $Container/Time/HBoxContainer/Button
var speed = 1
var timeUnit = 1
func _notification(what):
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
SM.config.speedIndex = $Speed/HSlider.value
SM.config.timeUnit = timeUnit
SM.config.BPM = BPM.text
SM.config.Time = Time.text
SM.config.Hz = Hz.text
SM.save_config()
get_tree().quit()
func _ready():
SM.load_config()
set_speed( SM.config.speedIndex )
if( timeUnit != SM.config.timeUnit ):
switchTimeUnit()
BPM.text = SM.config.BPM
Time.text = SM.config.Time
Hz.text = SM.config.Hz
func check_validity( text ):
if( text.is_valid_float() or text == "" ):
$Error.hide()
return true
$Error.show()
return false
func update():
var bpm = BPM.text.to_float() * speed
if( bpm == 0 ):
Time.text = ""
Hz.text = ""
else:
Time.text = str( ( 60 * timeUnit ) / bpm ).substr( 0, 7 )
Hz.text = str( bpm / 60 ).substr( 0, 7 )
func BPM_text_changed( text ):
text = text.replace( ",", "." )
if( !check_validity( text ) ):
return
var value = text.to_float() * speed
if( value == 0 ):
Time.text = ""
else:
Time.text = str( ( 60 * timeUnit ) / value ).substr( 0, 7 )
Hz.text = str( value / 60 ).substr( 0, 7 )
func MS_text_changed( text ):
text = text.replace( ",", "." )
if( !check_validity( text ) ):
return
var value = text.to_float()
if( value == 0 ):
BPM.text = ""
Hz.text = ""
else:
BPM.text = str( ( 60 * timeUnit ) / ( value * speed ) ).substr( 0, 7 )
Hz.text = str( timeUnit / value ).substr( 0, 7 )
func HZ_text_changed( text ):
text = text.replace( ",", "." )
if( !check_validity( text ) ):
return
var value = text.to_float()
BPM.text = str( 60 * value / speed ).substr( 0, 7 )
if( value == 0 ):
Time.text = ""
else:
Time.text = str( timeUnit / value ).substr( 0, 7 )
func set_speed( value ):
var idx = int( value )
$Speed/HSlider.value = idx
speed = speedIndexes[ idx ]
Speed.text = speedTexts[ idx ]
update()
func switchTimeUnit():
if( timeUnit == 1 ):
TimeUnitButton.text = "Ms"
$Container/Time/Sub.text = "Milliseconds"
timeUnit = 1000
else:
TimeUnitButton.text = "S"
$Container/Time/Sub.text = "Seconds"
timeUnit = 1
update()