63 lines
1.1 KiB
GDScript
63 lines
1.1 KiB
GDScript
class_name LineHeader
|
|
extends Label
|
|
|
|
|
|
signal line_completed
|
|
|
|
|
|
var answer_line : Array
|
|
var completed := false
|
|
var pixList
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pixList = get_tree().get_nodes_in_group(name)
|
|
|
|
for pix in pixList:
|
|
pix.connect("value_changed", self, "_pix_clicked")
|
|
|
|
|
|
func _pix_clicked():
|
|
var result = true
|
|
|
|
for i in range(0, pixList.size()):
|
|
if answer_line[i] != pixList[i].value && !(answer_line[i] == 0 && pixList[i].value != 1):
|
|
result = false
|
|
break
|
|
|
|
completed = result
|
|
|
|
if completed:
|
|
emit_signal("line_completed")
|
|
|
|
|
|
func set_answer_line(answers : Array, separator : String):
|
|
answer_line = answers
|
|
|
|
# Add a value at the end of the array to purge the result text
|
|
answers.push_back(0)
|
|
|
|
var result : String = ""
|
|
var count : int = 0
|
|
var last : int = 0
|
|
for value in answers:
|
|
if value == 1:
|
|
count += 1
|
|
last = 1
|
|
else:
|
|
if last != 0:
|
|
if !result.empty():
|
|
result += separator
|
|
result += str(count)
|
|
count = 0
|
|
last = 0
|
|
|
|
# Remove the last value used to purge the result text
|
|
answers.pop_back()
|
|
|
|
if result.empty():
|
|
text = "0"
|
|
else:
|
|
text = result
|