forked from sionar/Botc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableText.ttslua
201 lines (172 loc) · 7.49 KB
/
TableText.ttslua
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
--[[
Table Text
Made by Sionar
--]]
------------------Constants
COLORS_ALL = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink', 'Magenta', 'Lavender', 'Navy', 'Cyan', 'Mint', 'Lime', 'Peach', 'Coral', 'Maroon', 'Silver'}
COLORS_TYPE = {White = true, Brown = true, Red = true, Orange = true, Yellow = true, Green = true, Teal = true, Blue = true, Purple = true, Pink = true, Magenta = false, Lavender = false, Navy = false, Cyan = false, Mint = false, Lime = false, Peach = false, Coral = false, Maroon = false, Silver = false}
COLORS_BBC = {White = '[FFFFFF]', Brown = '[703A16]', Red = '[DA1917]', Orange = '[F3631C]', Yellow = '[E6E42B]', Green = '[30B22A]', Teal = '[20B09A]', Blue = '[1E87FF]', Purple = '[9F1FEF]', Pink = '[F46FCD]', Magenta = '[FF007F]', Lavender = '[967BB6]', Navy = '[616BD4]', Cyan = '[49D5FD]', Mint = '[89C381]', Lime = '[B8F161]', Peach = '[F1D4A2]', Coral = '[E29A8A]', Maroon = '[800000]', Silver = '[BEBEBE]'}
COLORS_INDEX = {White = 0, Brown = 1, Red = 2, Orange = 3, Yellow = 4, Green = 5, Teal = 6, Blue = 7, Purple = 8, Pink = 9, Magenta = 10, Lavender = 11, Navy = 12, Cyan = 13, Mint = 14, Lime = 15, Peach = 16, Coral = 17, Maroon = 18, Silver = 19}
COLORS_RGB = {White = {1,1,1}, Brown = {113/255,59/255,23/255}, Red = {219/255,26/255,24/255}, Orange = {244/255,100/255,29/255}, Yellow = {231/255,229/255,44/255}, Green = {49/255,179/255,43/255}, Teal = {33/255,177/255,155/255}, Blue = {31/255,136/255,255/255}, Purple = {160/255,32/255,240/255}, Pink = {245/255,112/255,206/255}, Magenta = {255/255,0/255,127/255}, Lavender = {150/255,123/255,182/255}, Navy = {97/255,107/255,212/255}, Cyan = {73/255,213/255,253/255}, Mint = {137/255,195/255,129/255}, Lime = {184/255,241/255,97/255}, Peach = {241/255,212/255,162/255}, Coral = {226/255,154/255,138/255}, Maroon = {128/255,0,0}, Silver = {190/255,190/255,190/255},}
TEXT_RAD = 36
NAME_RAD = 82
INDEX = {White = 0, Brown = 1, Red = 2, Orange = 3, Yellow = 4, Green = 5, Teal = 6, Blue = 7, Purple = 8, Pink = 9, Magenta = 10, Lavender = 11, Navy = 12, Cyan = 13, Mint = 14, Lime = 15, Peach = 16, Coral = 17, Maroon = 18, Silver = 19}
------------------Variables
text = {}
names = {}
for i = 1,20 do
text[COLORS_ALL[i]] = ''
names[COLORS_ALL[i]] = ''
end
------------------Functions
function onLoad(saveString)
if not (saveString == '') then
local save = JSON.decode(saveString)
text = save['t'] or text
names = save['n'] or names
end
local tableSize = Global.getVar('tableSize')
local colors = Global.getTable('colors')
local unusedColors = Global.getTable('unusedColors')
local angle = Global.getTable('angle')
local fontSize
if tableSize <= 10 then
fontSize = 810
elseif tableSize <= 15 then
fontSize = 540
else
fontSize = 270
end
for i = 1,20 do
params = {click_function = 'null', function_owner = self, label = '', position = {0,0,0}, rotation = {0,0,0}, font_color = COLORS_RGB[COLORS_ALL[i]], width = 0, height = 0, font_size = fontSize}
self.createButton(params)
end
for i = 11,20 do
params = {click_function = 'null', function_owner = self, label = '', position = {0,0,5}, font_color = COLORS_RGB[COLORS_ALL[i]], width = 0, height = 0, font_size = 800, scale = {2,2,2}}
self.createButton(params)
end
for k,color in pairs(colors) do
self.editButton({index = INDEX[color], label = text[color], position = radius(TEXT_RAD, angle[color], 1.1), rotation = {0, angle[color], 0}})
end
for k,color in pairs(colors) do
if COLORS_TYPE[color] == false then
self.editButton({index = INDEX[color] + 10, label = names[color], position = radius(NAME_RAD, angle[color], 5), rotation = {0, angle[color] + 180, 0}})
end
end
end
function onSave()
local save = {}
save['t'] = text
save['n'] = names
local saveString = JSON.encode(save)
return saveString
end
function radius(rad, angle, height)
return {-1 * rad*math.sin(angle*math.pi/180), height, rad*math.cos(angle*math.pi/180)}
end
function moveText(params)
local tableSize = params.tableSize
local colors = Global.getTable('colors')
local unusedColors = Global.getTable('unusedColors')
local angle = Global.getTable('angle')
local fontSize
if tableSize <= 10 then
fontSize = 810
elseif tableSize <= 15 then
fontSize = 540
else
fontSize = 270
end
for k,color in pairs(colors) do --table text for used colors
self.editButton({index = INDEX[color], position = radius(TEXT_RAD, angle[color], 1.1), rotation = {0, angle[color], 0}})
end
for color,unused in pairs(unusedColors) do --table text for unused colors
if unused then
self.editButton({index = INDEX[color], position = {0,0,0}})
end
end
for color, unused in pairs(unusedColors) do --name text for used colors
if unused == false and COLORS_TYPE[color] == false then
self.editButton({index = INDEX[color] + 10, position = radius(NAME_RAD, angle[color], 2), rotation = {0, angle[color] + 180, 0}})
end
end
for color,unused in pairs(unusedColors) do --name text for unused colors
if unused == true and COLORS_TYPE[color] == false then
self.editButton({index = INDEX[color] + 10, position = {0,0,0}})
end
end
end
function clearText()
for i = 1,20 do
self.editButton({index = i-1, label = ' '})
end
end
function setText(params)
local color = params.color
local txt = params.text
self.editButton({index = COLORS_INDEX[color], label = formatTableText(txt)})
text[color] = txt
end
function setName(params)
local color = params.color
local name = params.name
self.editButton({index = COLORS_INDEX[color] + 10, label = name})
names[color] = name
end
function formatTableText(text)
local output = ''
local lineLen = 0
local LINE_WIDTH = 30
local wordLen = 0
local colorizedWord
for newL in text:gmatch("[^\r\n]+") do
lineLen = 0
for word in string.gmatch(newL, '%g+') do
wordLen = stripBBCLength(word)
colorizedWord = colorFormat(word)
if lineLen + wordLen > LINE_WIDTH then
while lineLen < LINE_WIDTH do
output = output .. ' '
lineLen = lineLen + 1
end
output = output .. '\n' .. colorizedWord .. ' '
lineLen = wordLen + 1
else
output = output .. colorizedWord .. ' '
lineLen = lineLen + wordLen + 1
end
end
output = output .. '\n'
end
return output
end
function colorFormat(str)
function capitalize(str)
str = string.lower(str)
return (str:gsub("^%l", string.upper))
end
local capStr = capitalize(str)
local capStrSymbolStripped = string.match(capStr, '%a+')
if (COLORS_BBC[capStrSymbolStripped]) then
return COLORS_BBC[capStrSymbolStripped] .. capStr .. '[-]'
end
return str
end
function stripBBCLength(str)
local len = string.len(str)
local found = true
local idx = 1
local foundIdx
while (found) do
found = false
if idx <= string.len(str) then
foundIdx = string.find(string.sub(str, idx), '%[%x%x%x%x%x%x%]')
if (foundIdx) then
found = true
idx = idx + 8
len = len - 8
end
end
end
return len
end