summaryrefslogtreecommitdiff
path: root/scenes/levels/typeracer.gd
blob: c17e1bc692be31930642363a8f422b611186ee05 (plain)
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
extends Level

onready var timer_label = $TimeLabel

var timer = 0
var total = 0

func start():
	.start()
	total = _total_time()
	running = true
	$Incorrect.visible = false


func _total_time():
	if Settings.difficulty == Settings.Difficulty.HARD:
		return 10
	return 60
	
func _process(delta):
	if not running:
		return
	timer += delta
	timer_label.text = str(total - timer)
	if timer >= total:
		eval()

func eval():
	if $Label.text.replace('\r\n', '\n').replace('\r', '\n') == $TextEdit.text.replace('\r\n', '\n').replace('\r', '\n'):
		$TextEdit.readonly = true
		$Button.disabled = true
		$Incorrect.visible = false
		finish_level()
	else:
		lose_heart()
		timer = 0
		$TextEdit.text = ""
		$Incorrect.visible = true

func eval_corr():
	if $Label.text.replace('\r\n', '\n').replace('\r', '\n') == $TextEdit.text.replace('\r\n', '\n').replace('\r', '\n'):
		$TextEdit.readonly = true
		$Button.disabled = true
		$Incorrect.visible = false
		finish_level()

func _on_Button_on_click():
	eval()


func _on_TextEdit_text_changed():
	eval_corr()