-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.gd
115 lines (94 loc) · 3.15 KB
/
Main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
extends Control
enum {
RAW,
BBCODE,
HTML
}
var terminal : String = ""
var rawterm : String = ""
var export_flag : int = RAW
# Called when the node enters the scene tree for the first time.
func alephone_to_bbcode(term : String) -> String:
term = '[color=lime]' + term
term = term.replace("$C0", '[/color][color=lime]')
term = term.replace("$C1", '[/color][color=white]')
term = term.replace("$C2", '[/color][color=red]')
term = term.replace("$C3", '[/color][color=green]')
term = term.replace("$C4", '[/color][color=aqua]')
term = term.replace("$C5", '[/color][color=yellow]')
term = term.replace("$C6", '[/color][color=maroon]')
term = term.replace("$C7", '[/color][color=blue]')
term = term.replace("$I", "[i]") # Replaces italics
term = term.replace("$i", "[/i]")
term = term.replace("$B", "[b]") # Replaces bold
term = term.replace("$b", "[/b]")
term = term.replace("$U", "[u]") # Replaces underlined
term = term.replace("$u", "[/u]")
print(term.count("[b]"))
print(term.count("[/b]"))
term = term.replace("[/b][/color]", "[/color][/b]")
term = fix_bolds(term)
term = term + "[/color]"
terminal = term
return term
#0 Light Green Color0
#1 White Color1
#2 Red Color2
#3 Dark Green Color3
#4 Light Blue Color4
#5 Yellow Color5
#6 Dark Red Color6
#7 Dark Blue Color7
#8 No color Color8
#9 No color Color9
func fix_bolds(term : String):
var colors = ["lime", "white", "red", "green", "aqua", "yellow",
"maroon", "blue"]
var labels = ["[b]","[u]","[i]"]
# var Exp : RegEx = RegEx.new()
# Exp.compile("\\[\\/color\\]\\[color\\=([a-z]*)\\]\\[b\\]")
# var result : RegExMatch = Exp.search(term)
for color in colors:
for label in labels:
term = term.replace("[/color][color="+color+"]"+label, "[/color]"+label+"[color="+color+"]")
for color in colors:
for label in labels:
term = term.replace(label+"[/color][color="+color+"]", "[/color]"+label+"[color="+color+"]")
return term
func _on_Open_pressed():
$OpenDialog.popup()
func _on_FileDialog_file_selected(path):
var current : FileAccess = FileAccess.open(path, FileAccess.READ)
var text : String
text = current.get_as_text()
$VBoxContainer/HBoxContainer/SplitContainer/Editor/Inline.text = text
update_terms()
func _on_Button_pressed():
$HBoxContainer/SplitContainer/Editor/Inline.text = terminal
func _on_Update_pressed():
update_terms()
func update_terms():
rawterm = $VBoxContainer/HBoxContainer/SplitContainer/Editor/Inline.text
$VBoxContainer/HBoxContainer/SplitContainer/Previewer.split_terminals(alephone_to_bbcode(rawterm))
func _on_Toolbar_file_option_selected(id : int):
if id == 0:
$OpenDialog.popup_centered()
else:
if id == 1:
export_flag = RAW
$SaveDialog.filters = ["*.txt ; raw terminal markdown"]
elif id == 2:
export_flag = BBCODE
$SaveDialog.filters = ["*.bbcode ; parseable bbcode"]
$SaveDialog.popup_centered()
func _on_SaveDialog_file_selected(path):
var file :FileAccess = FileAccess.open(path, FileAccess.WRITE)
file.seek_end()
if export_flag == RAW:
file.store_line(rawterm)
elif export_flag == BBCODE:
file.store_line(terminal)
file.close()
func _on_Toolbar_about_option_selected(id):
if id == 0:
$About.popup_centered()