forked from sionar/Botc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeatTool.ttslua
189 lines (163 loc) · 7.21 KB
/
SeatTool.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
--[[
Seat Tool
Made by Sionar
--]]
------------------Constants
VERSION = '1.0.4'
COLORS_ALL = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink', 'Magenta', 'Lavender', 'Navy', 'Cyan', 'Mint', 'Lime', 'Peach', 'Coral', 'Maroon', 'Silver'}
COLORS_ORDER = {White = 1, Brown = 2, Red = 3, Orange = 4, Yellow = 5, Green = 6, Teal = 7, Blue = 8, Purple = 9, Pink = 10, Magenta = 11, Lavender = 12, Navy = 13, Cyan = 14, Mint = 15, Lime = 16, Peach = 17, Coral = 18, Maroon = 19, Silver = 20}
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 = {99/255,109/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},}
Z_START = -6
Z_INC = 0.6
#include GUIDs.ttslua
------------------Variables
objects = {}
usedColors = {}
removedColors = {}
------------------Functions
function onLoad()
TABLE_OFFSET = Global.getVar('TABLE_OFFSET')
STORYTELLER_TABLE_DIST = Global.getVar('STORYTELLER_TABLE_DIST')
usedColors = Global.getTable('usedColors')
removedColors = Global.getTable('removedColors')
assignObjects()
moveBoard()
render()
self.setDescription('v ' .. VERSION .. '\nMade by Sionar')
end
function assignObjects()
objects.toolBag = getObjectFromGUID(TOOL_BAG_GUID)
objects.tableControls = getObjectFromGUID(TABLE_CONTROLS_GUID)
end
function moveBoard()
self.setPositionSmooth({-21,1.2,27 + TABLE_OFFSET + STORYTELLER_TABLE_DIST})
self.setRotationSmooth({0,0,0})
self.setLock(true)
end
function destroySelf(clickedObject, playerColor)
if Player[playerColor].admin or playerColor == 'Black' then
objects.toolBag.putObject(self)
end
end
function used(clickedObject, playerColor, i)
if playerColor ~= 'Black' then
return
end
local color = usedColors[i]
local found = false
table.remove(usedColors, i)
if #removedColors == 0 then
table.insert(removedColors, color)
else
for i,v in ipairs(removedColors) do
if COLORS_ORDER[v] > COLORS_ORDER[color] then
table.insert(removedColors, i, color)
found = true
break
end
end
if not found then
table.insert(removedColors, color)
end
end
render()
end
for i = 1,20 do
_G['used'..i] = function(clickedObject, playerColor)
used(clickedObject, playerColor, i)
end
end
function removed(clickedObject, playerColor, i)
if playerColor ~= 'Black' then
return
end
local color = removedColors[i]
local found = false
table.remove(removedColors, i)
if #usedColors == 0 then
table.insert(removedColors, color)
else
for i,v in ipairs(usedColors) do
if COLORS_ORDER[v] > COLORS_ORDER[color] then
table.insert(usedColors, i, color)
found = true
break
end
end
if not found then
table.insert(usedColors, color)
end
end
render()
end
for i = 1,20 do
_G['removed'..i] = function(clickedObject, playerColor)
removed(clickedObject, playerColor, i)
end
end
function reset(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
usedColors = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink', 'Magenta', 'Lavender', 'Navy', 'Cyan', 'Mint', 'Lime', 'Peach', 'Coral', 'Maroon', 'Silver'}
removedColors = {}
render()
end
function apply(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
if #usedColors < 5 then
Player['Black'].print('Error: You need at least 5 seats enabled.', {1,0,0})
return
end
local tableSize = Global.getVar('tableSize')
local prevUsedColors = Global.getTable('usedColors')
local lastNum = COLORS_ORDER[prevUsedColors[tableSize]]
local numColors = 0
for k,v in pairs(usedColors) do
if COLORS_ORDER[v] <= lastNum then
numColors = numColors + 1
end
end
local maxSeats = #usedColors
Global.setTable('usedColors', usedColors)
Global.setTable('removedColors', removedColors)
Global.call('setTokenTable')
Global.call('setDecalTable')
Global.setVar('tableSize', numColors)
Global.call('resizeTable')
Global.call('moveTokens')
Global.call('moveDecals')
objects.tableControls.setVar('tableSize', numColors)
objects.tableControls.setVar('maxSeats', maxSeats)
objects.tableControls.call('refreshUI')
end
function render()
self.clearButtons()
local z
params = {click_function = 'destroySelf', function_owner = self, label = '☒', position = {8,0.1,-8}, scale = {1.5, 1.5, 1.5}, width = 600, height = 600, font_size = 400, font_color = {1,0.4,0.4}, color = {0,0,0,0.6}}
self.createButton(params)
params = {click_function = 'null', function_owner = self, label = 'Seat Tool', position = {0,0.1,-8}, width = 0, height = 0, font_size = 400, font_color = {1,1,1}, color = {0,0,0,0.6}}
self.createButton(params)
params = {click_function = 'null', function_owner = self, label = 'Available Colors', position = {-4,0.1,-7}, width = 0, height = 0, font_size = 300, font_color = {1,1,1}, color = {0,0,0,0.6}}
self.createButton(params)
params = {click_function = 'null', function_owner = self, label = 'Removed Colors', position = {4,0.1,-7}, width = 0, height = 0, font_size = 300, font_color = {1,1,1}, color = {0,0,0,0.6}}
self.createButton(params)
params = {click_function = 'reset', function_owner = self, label = 'Reset', position = {-2.5,0.1,8}, width = 800, height = 400, font_size = 300, scale = {2,2,2}, font_color = {1,1,1}, color = {0,0,0,0.6}, tooltip = 'Reset to default settings.'}
self.createButton(params)
params = {click_function = 'apply', function_owner = self, label = 'Apply', position = {2.5,0.1,8}, width = 800, height = 400, font_size = 300, scale = {2,2,2}, font_color = {1,1,1}, color = {0,0,0,0.6}, tooltip = 'Apply the changes to the seats.'}
self.createButton(params)
z = Z_START
for i,v in ipairs(usedColors) do
params = {click_function = 'used'..i, function_owner = self, label = v, position = {-4,0.1,z}, width = 800, height = 130, font_size = 100, scale = {2,2,2}, font_color = COLORS_RGB[v], color = {0,0,0}, tooltip = 'Remove the ' .. v .. ' seat.'}
self.createButton(params)
z = z + Z_INC
end
z = Z_START
for i,v in ipairs(removedColors) do
params = {click_function = 'removed'..i, function_owner = self, label = v, position = {4,0.1,z}, width = 800, height = 130, font_size = 100, scale = {2,2,2}, font_color = COLORS_RGB[v], color = {0,0,0}, tooltip = 'Add the ' .. v .. ' seat.'}
self.createButton(params)
z = z + Z_INC
end
end