53 lines
1.8 KiB
GDScript
53 lines
1.8 KiB
GDScript
extends Node2D
|
|
|
|
onready var expression = Expression.new()
|
|
|
|
func _ready():
|
|
gameController.logCall("DebugConsole","_ready",null)
|
|
$Background/Input.modulate = Color8(255,255,255,255)
|
|
$Background/Input.add_color_override("font_color",Color8(255,255,255,255))
|
|
|
|
func execute(text):
|
|
gameController.logCall("DebugConsole","execute",text)
|
|
if checkCompletion(text) != OK:
|
|
disappear()
|
|
return
|
|
else:
|
|
$Background/Input.modulate = Color8(255,255,255,127)
|
|
yield(get_tree().create_timer(2),"timeout")
|
|
expression.execute([], null, false)
|
|
disappear()
|
|
|
|
func checkCompletion(text):
|
|
gameController.logCall("DebugConsole","checkCompletion",text)
|
|
return expression.parse(text, [])
|
|
|
|
func pressed():
|
|
gameController.logCall("DebugConsole","pressed",null)
|
|
execute($Background/Input.text)
|
|
|
|
func inputChanged():
|
|
gameController.logCall("DebugConsole","inputChanged",null)
|
|
var text = $Background/Input.text
|
|
$Background/Input.text = ""
|
|
$Background/Input.insert_text_at_cursor(text.replace("\n",""))
|
|
if $Background/Input.text == "":
|
|
$Background/Input.add_color_override("font_color",Color8(255,255,255,255))
|
|
else:
|
|
var completion = checkCompletion($Background/Input.text)
|
|
if completion == OK:
|
|
$Background/Input.add_color_override("font_color",Color8(0,255,75,255))
|
|
else:
|
|
$Background/Input.add_color_override("font_color",Color8(255,150,0,255))
|
|
|
|
func disappear():
|
|
gameController.logCall("DebugConsole","disappear",null)
|
|
call_deferred("_disappear_deferred")
|
|
|
|
func _disappear_deferred():
|
|
gameController.logCall("DebugConsole","_disappear_deferred",null)
|
|
$Background/Input.modulate = Color8(255,255,255,255)
|
|
$Background/Input.add_color_override("font_color",Color8(255,255,255,255))
|
|
for child in get_tree().get_root().get_children():
|
|
if child.name == "DebugConsole":
|
|
get_tree().get_root().remove_child(child)
|