-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Demo.gd
79 lines (64 loc) · 2 KB
/
Demo.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
extends CanvasLayer
# ******************************************************************************
onready var DictBox = find_node('DictBox')
onready var DictEntry = find_node('DictEntry')
onready var Key = find_node('Key')
onready var Value = find_node('Value')
onready var Add = find_node('Add')
var demo_vars := {
'test': 'beep',
'wallet': 100,
'last_meal': 'pizza',
}
var demo_var_path = 'demo_vars.json'
# ******************************************************************************
func _ready():
randomize()
Add.disabled = false
Key.connect('text_changed', self, 'key_text_changed')
Value.connect('text_changed', self, 'value_text_changed')
Add.connect('pressed', self, 'add_pressed')
update_add_button()
demo_vars = Skein.load_json(demo_var_path, demo_vars)
DictBox.remove_child(DictEntry)
Skein.sandbox.add_locals(demo_vars)
Skein.sandbox.add_local('Skein', Skein)
for key in demo_vars:
create_entry(key, demo_vars[key])
func key_text_changed(new_text):
update_add_button()
func value_text_changed(new_text):
update_add_button()
func update_add_button():
Add.disabled = !(Key.text and Value.text)
func check_string_types(text):
var value = text
if text.is_valid_integer():
value = text.to_int()
elif text.is_valid_integer():
value = text.to_float()
return value
func add_pressed():
var value = check_string_types(Value.text)
create_entry(Key.text, value)
Key.clear()
Value.clear()
save_demo_vars()
func create_entry(key, value):
demo_vars[key] = value
var entry = DictEntry.duplicate(true)
var entry_key = entry.get_node('DictKey')
var entry_value = entry.get_node('DictValue')
entry_key.text = key
entry_value.text = str(value)
entry_value.connect('text_changed', self, 'entry_changed', [key])
DictBox.add_child(entry)
entry.show()
func entry_changed(new_text, key):
var value = check_string_types(new_text)
demo_vars[key] = value
save_demo_vars()
func save_demo_vars():
print(demo_vars)
Skein.save_json(demo_var_path, demo_vars)
Skein.sandbox.add_locals(demo_vars)