-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrks 6 materiel.587dc5.lua
More file actions
150 lines (137 loc) · 4.25 KB
/
Orks 6 materiel.587dc5.lua
File metadata and controls
150 lines (137 loc) · 4.25 KB
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
-- Universal Counter Tokens coded by: MrStump
--Saves the count value into a table (data_to_save) then encodes it into the Tabletop save
function onSave()
local data_to_save = {saved_count = count}
saved_data = JSON.encode(data_to_save)
return saved_data
end
--Loads the saved data then creates the buttons
function onload(saved_data)
generateButtonParameters()
--Checks if there is a saved data. If there is, it gets the saved value for 'count'
if not saved_data == '' then
local loaded_data = JSON.decode(saved_data)
count = loaded_data.saved_count
else
--If there wasn't saved data, the default value is set to 10.
count = 10
end
--Generates the buttons after putting the count value onto the 'display' button
b_display.label = tostring(count)
if count >= 100 then
b_display.font_size = 360
else
b_display.font_size = 500
end
updateName()
self.createButton(b_display)
self.createButton(b_plus)
self.createButton(b_minus)
self.createButton(b_plus5)
self.createButton(b_minus5)
end
function setCount(newCount)
count = newCount
updateDisplay()
end
function getCount()
return count
end
function logManualChange(old)
print("Orks: materiel "..old.." -> "..count)
end
function updateName()
self.setName("Orks: "..count.." materiel")
end
--Activates when + is hit. Adds 1 to 'count' then updates the display button.
function increase()
--Prevents count from going above 14
if count < 14 then
old = count
count = count + 1
updateDisplay()
logManualChange(old)
end
end
--Activates when - is hit. Subtracts 1 from 'count' then updates the display button.
function decrease()
--Prevents count from going below 0
if count > 0 then
old = count
count = count - 1
updateDisplay()
logManualChange(old)
end
end
--Activates when + is hit. Adds 5 to 'count' then updates the display button.
function increase5()
if count < 14 then
old = count
if count < 9 then
count = count + 5
else
count = 14
end
updateDisplay()
logManualChange(old)
end
end
--Activates when - is hit. Subtracts 5 from 'count' then updates the display button.
function decrease5()
--Prevents count from going below 0
if count > 0 then
old = count
if count > 5 then
count = count - 5
else
count = 0
end
updateDisplay()
logManualChange(old)
end
end
function customSet()
local description = self.getDescription()
local descriptionNEmpty = description == ''
if not descriptionNEmpty and type(tonumber(description)) == 'number' then
self.setDescription('')
count = tonumber(description)
updateDisplay()
end
end
--function that updates the display. I trigger it whenever I change 'count'
function updateDisplay()
--If statement to resize font size if it gets too long
if count >= 100 then
b_display.font_size = 360
else
b_display.font_size = 500
end
b_display.label = tostring(count)
self.editButton(b_display)
updateName()
end
--This is activated when onload runs. This sets all parameters for our buttons.
--I do not have to put this all into a function, but I prefer to do it this way.
function generateButtonParameters()
b_display = {
index = 0, click_function = 'customSet', function_owner = self, label = '',
position = {0,0.1,0}, width = 600, height = 600, font_size = 500
}
b_plus = {
click_function = 'increase', function_owner = self, label = '+',
position = {0.9,0.1,0.3}, width = 300, height = 300, font_size = 400
}
b_minus = {
click_function = 'decrease', function_owner = self, label = '-',
position = {-0.9,0.1,0.3}, width = 300, height = 300, font_size = 400
}
b_plus5 = {
click_function = 'increase5', function_owner = self, label = '+5',
position = {0.9,0.1,-0.29}, width = 230, height = 230, font_size = 150
}
b_minus5 = {
click_function = 'decrease5', function_owner = self, label = '-5',
position = {-0.9,0.1,-0.29}, width = 230, height = 230, font_size = 150
}
end