-
Notifications
You must be signed in to change notification settings - Fork 4
/
PlayerDistribution.ttslua
156 lines (134 loc) · 4.89 KB
/
PlayerDistribution.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
--[[
Player Distribution Chart
Made by Sionar
--]]
------------------Constants
VERSION = '1.2.1'
DIST = {{0,0,0,0,0},{1,0,0,0,1},{2,1,0,0,1},{3,2,0,0,1},{4,3,0,0,1},{5,3,0,1,1},{6,3,1,1,1},{7,5,0,1,1},{8,5,1,1,1},{9,5,2,1,1},{10,7,0,2,1},{11,7,1,2,1},{12,7,2,2,1},{13,9,0,3,1},{14,9,1,3,1},{15,9,2,3,1},{16,9,2,3,1},{17,9,2,3,1},{18,9,2,3,1},{19,9,2,3,1},{20,9,2,3,1}}
ROW_SPACING = 0.4
COL_SPACING = 0.4
ROW_START = -0.8
COL_START = -2
NUM_ROWS = 5
NUM_COLS = 11
COL = {}
ROW = {}
CHART_LABEL = '[FFFFFF]Players, [1E87FF]Townsfolk, [20B09A]Outsiders, [F3631C]Minions, [DA1917]Demons'
ROW_COLORS = {'[FFFFFF]', '[1E87FF]', '[20B09A]', '[F3631C]', '[DA1917]'}
HIGHLIGHT_COLOR = '[E6E42B]'
COL_P = {-1.5, 1}
PLAYER_LABELS = {'Players: ', 'Townsfolk: ', 'Outsiders: ', 'Minions: ', 'Demons: '}
ALIVE_COLORS = {'[1E87FF]', '[30B22A]', '[E6E42B]', '[F3631C]', '[DA1917]'}
ALIVE_LABELS = {'Total players: ', 'Living players: ', 'Living non-travelers: ', 'Players with votes: ', 'Votes to execute: '}
ROW_P_START = -1
ROW_P = {}
for i = 1, NUM_COLS do
COL[i] = COL_START + COL_SPACING * (i-1)
end
for i = 1, NUM_ROWS do
ROW[i] = ROW_START + ROW_SPACING * (i-1)
end
for i = 1, NUM_ROWS do
ROW_P[i] = ROW_P_START + ROW_SPACING * (i-1)
end
------------------Variables
players = {0,0,0,0,0}
alive = {0,0,0,0,0}
showPlayers = true
------------------Functions
function onLoad(saveString)
self.setDescription('v ' .. VERSION .. '\nMade by Sionar')
if not (saveString == '') then
local save = JSON.decode(saveString)
players = save['p']
alive = save['a']
showPlayers = save['sh']
end
if showPlayers then
displayPlayers()
else
displayChart()
end
end
function onSave()
local save = {}
save['p'] = players
save['a'] = alive
save['s'] = started
save['sh'] = showPlayers
local saveString = JSON.encode(save)
return saveString
end
function nullFunc() end
function updatePlayerDist(params)
local num = params.num
local started = Global.getVar('started')
if not started then
players = DIST[num+1]
if showPlayers then
displayPlayers()
else
displayChart()
end
end
end
function updatePlayerDistST(params)
local num = params.num
local started = Global.getVar('started')
if started then
players = DIST[num+1]
if showPlayers then
displayPlayers()
else
displayChart()
end
end
end
function updateAlive(params)
alive = {params.numP, params.living, params.nonTrav, params.withVotes, params.needed}
if showPlayers then
displayPlayers()
else
displayChart()
end
end
------------------User Interface
function displayChart()
self.clearButtons()
showPlayers = false
local params
params = {click_function = 'nullFunc', function_owner = self, label = CHART_LABEL, color = {0,0,0,1},
position = {0,0.2,-1.1}, width = 0, height = 0, font_size = 1000, scale = {0.1,0.1,0.1}}
self.createButton(params)
for i = 1, NUM_COLS do
for j = 1, NUM_ROWS do
params = {click_function = 'nullFunc', function_owner = self, label = ROW_COLORS[j]..DIST[i+5][j], color = {0,0,0,1},
position = {COL[i],0.2,ROW[j]}, width = 0, height = 0, font_size = 1000, scale = {0.1,0.1,0.1}}
if (players[1] >= 5 and i == players[1] - 4) or i == 11 and players[1] >= 15 then
params.label = HIGHLIGHT_COLOR..DIST[i+5][j]
end
self.createButton(params)
end
end
params = {click_function = 'displayPlayers', function_owner = self, label = "Display Player Count", tooltip = "Display Player Count", color = {0,0,0,0.2}, font_color = {1,1,1,1},
position = {0,0.2,1.1}, width = 10000, height = 1500, font_size = 1000, scale = {0.1,0.1,0.1}}
self.createButton(params)
end
function displayPlayers()
self.clearButtons()
showPlayers = true
local params
for i = 1, 5 do
params = {click_function = 'nullFunc', function_owner = self, label = ROW_COLORS[i] .. PLAYER_LABELS[i] .. players[i], color = {0,0,0,1},
position = {COL_P[1],0.2,ROW_P[i]}, width = 0, height = 0, font_size = 800, scale = {0.15,0.15,0.15}}
self.createButton(params)
end
for i = 1, 5 do
params = {click_function = 'nullFunc', function_owner = self, label = ALIVE_COLORS[i] .. ALIVE_LABELS[i] .. alive[i], color = {0,0,0,1},
position = {COL_P[2],0.2,ROW_P[i]}, width = 0, height = 0, font_size = 800, scale = {0.15,0.15,0.15}}
self.createButton(params)
end
params = {click_function = 'displayChart', function_owner = self, label = "Display Distribution Chart", tooltip = "Display Distribution Chart", color = {0,0,0,0.2}, font_color = {1,1,1,1},
position = {0,0.2,1.1}, width = 10000, height = 1500, font_size = 1500, scale = {0.1,0.1,0.1}}
self.createButton(params)
end