-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParameterInputHandler.gd
52 lines (40 loc) · 2.06 KB
/
ParameterInputHandler.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
extends VBoxContainer
@onready var param_display_scene = preload("res://ParameterDisplay.tscn")
@onready var type_option_button = %ParamTypeDropdown
@onready var add_param_button = %AddParamButton
@onready var param_input = %ParamInput
@onready var parameter_container = %ParameterContainer
func _ready():
add_param_button.button_down.connect(_on_add_param)
Global.add_parameter_to_track.connect(_track_param)
for key in Global.sol_types_to_string:
type_option_button.add_item(Global.sol_types_to_string[key], key)
func _on_add_param():
var param_name = param_input.text
var param_type = type_option_button.get_item_id(type_option_button.selected)
if param_name == "":
return
if not Global.vm_state.has("parameters"):
Global.vm_state["parameters"] = {}
var sol_param = SolParameter.new(param_name, param_type)
Global.vm_state["parameters"][param_name] = sol_param
var param_displayer = param_display_scene.instantiate()
parameter_container.add_child(param_displayer)
param_displayer.get_node("NameLabel").text = sol_param.name
param_displayer.get_node("TypeLabel").text = Global.sol_types_to_string[sol_param.type]
param_displayer.get_node("Value").text = str(sol_param.value)
Global.add_parameter_to_node_list(param_name)
param_input.clear()
func _process(_delta):
for child in parameter_container.get_children():
child.get_node("Value").text = str(Global.vm_state["parameters"][child.get_node("NameLabel").text].value)
func _track_param(parameter_name: String):
for child in parameter_container.get_children():
if child.get_node("NameLabel").text == parameter_name:
return
var sol_param = Global.vm_state["parameters"][parameter_name]
var param_displayer = param_display_scene.instantiate()
parameter_container.add_child(param_displayer)
param_displayer.get_node("NameLabel").text = sol_param.name
param_displayer.get_node("TypeLabel").text = Global.sol_types_to_string[sol_param.type]
param_displayer.get_node("Value").text = str(sol_param.value)