-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyablesBox.gd
57 lines (47 loc) · 1.5 KB
/
CopyablesBox.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
extends VBoxContainer
var displaybox := preload("res://LabeledCopyableDisplay.tscn")
@onready var strip_toggle := %StripToggle
@onready var title_toggle := %TitlesToggle
@onready var flip_toggle := %FlipToggle
func _ready()-> void:
EventBus.initialize.connect(_on_initialize)
func _on_initialize(inString:String, delimiter:String)->void:
for child in get_children():
child.queue_free()
var inStringArr
if delimiter == "":
inStringArr = inString.split("\n", false)
else:
inStringArr = inString.split(delimiter, false)
if !inStringArr is Array and inStringArr.size()==0:## Unhappy early return.
return
if title_toggle.button_pressed:
if inStringArr.size()%2: ## Unhappy early return.
var newchild:= displaybox.instantiate()
add_child(newchild)
newchild.initialize("Error, not all titles have a matching content block.", "")
else:
for i in inStringArr.size():
var s:String
var t:String
if i%2:
continue ## We are in a content. Early Return.
if strip_toggle.button_pressed:
s = inStringArr[i+1].strip_edges()
t = inStringArr[i].strip_edges()
else:
s = inStringArr[i+1]
t = inStringArr[i]
var newchild:= displaybox.instantiate()
add_child(newchild)
if flip_toggle.button_pressed:
newchild.initialize(t, s)
else:
newchild.initialize(s, t)
else:
for s in inStringArr:
if strip_toggle.button_pressed:
s = s.strip_edges()
var newchild:= displaybox.instantiate()
add_child(newchild)
newchild.initialize(s)