56 lines
1.4 KiB
GDScript
56 lines
1.4 KiB
GDScript
extends Control
|
|
|
|
# Signal senden, wenn der Code stimmt
|
|
signal access_granted
|
|
|
|
@export var correct_code = "1 7 9 1" # Dein Code hier!
|
|
var current_input = ""
|
|
|
|
@onready var display_label = $PanelContainer/VBoxContainer/Label
|
|
@onready var grid = $PanelContainer/VBoxContainer/GridContainer
|
|
|
|
func _ready():
|
|
# Alle Buttons im Grid automatisch verbinden
|
|
for button in grid.get_children():
|
|
if button is Button:
|
|
button.pressed.connect(_on_button_pressed.bind(button.text))
|
|
|
|
update_display()
|
|
|
|
func _on_button_pressed(value: String):
|
|
if value.ends_with("C") or value.ends_with(" C"):
|
|
current_input = ""
|
|
|
|
elif value.ends_with("E") or value.ends_with(" E"):
|
|
check_code()
|
|
|
|
else:
|
|
# Zahl hinzufügen (maximal 4 Stellen)
|
|
if current_input.length() < 8:
|
|
current_input += value
|
|
if current_input.length() < 6:
|
|
current_input += " "
|
|
|
|
update_display()
|
|
|
|
func update_display():
|
|
if current_input == "":
|
|
display_label.text = "- - - -"
|
|
else:
|
|
display_label.text = current_input
|
|
|
|
func check_code():
|
|
if current_input == correct_code:
|
|
display_label.text = "OPEN"
|
|
display_label.modulate = Color.GREEN
|
|
# Signal feuern!
|
|
emit_signal("access_granted")
|
|
else:
|
|
display_label.text = "ERR"
|
|
display_label.modulate = Color.RED
|
|
current_input = ""
|
|
# Kurzer Timer um Fehler anzuzeigen, dann reset
|
|
await get_tree().create_timer(1.0).timeout
|
|
display_label.modulate = Color.WHITE
|
|
update_display()
|