-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ttslua
233 lines (197 loc) · 6.67 KB
/
main.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
-- In the global file of your game, simply add this line
-- #include main
-- Then, in Atom package settings, go to the TTS package and define the path
-- to this folder. Since this main file already includes the others no further
-- operation is required for scripts. The XML needs to be copied manually
-- however.
#include scripts/data/data_settings
#include scripts/data/data_tables
#include scripts/data/data_terrain
#include scripts/data/data_troops
#include scripts/data/data_troops_greek_successors
#include scripts/data/data_cheat_sheet
#include scripts/base_cache
#include scripts/log
#include scripts/logic_decorations
#include scripts/utilities_lua
#include scripts/utilities
#include scripts/logic_base_obj
#include scripts/logic_terrain
#include scripts/logic_gizmos
#include scripts/logic_spawn_army
#include scripts/logic_dead
#include scripts/logic_dice
#include scripts/logic_history_stack
#include scripts/logic_history_snapshot
#include scripts/logic_tool_tips
#include scripts/logic
#include scripts/uievents
#include fake_meshwesh/army_data/all_armies
#include scripts/data/data_models
function onSave()
local saved_data = JSON.encode(g_decorations)
return saved_data
end
function onload(saved_data)
print_info('\n---------------------------------\nTriumph! v 2.0 build 20210430\n---------------------------------\n\nCheck the Notebook for instructions.')
Wait.time(main_loop, g_seconds_main_loop, -1)
make_scenery_non_interactable()
reset_state()
spawn_proxy_bases()
spawn_all_dice()
print_tool_tip_status()
restore_extra_data(saved_data)
-- Shuffle the terrain cards
local card = getObjectFromGUID("f46bb5")
if card then
card.shuffle()
else
print_error("Unable to find terraom card")
end
set_tablet_homepage("red tablet")
set_tablet_homepage("blue tablet")
end
function set_tablet_homepage(tablet_name)
local tablet = get_object_by_name(tablet_name)
if tablet == nil then
print_error("Unable to find " .. tablet_name)
else
tablet.Browser.url = "https://meshwesh.wgcwar.com"
end
end
function restore_extra_data(saved_data)
if saved_data == nil then
return
end
local extra = JSON.decode(saved_data)
if extra == nil then
return
end
if type(extra) ~= 'table' then
return
end
g_decorations = extra
end
function make_scenery_non_interactable()
-- Main table
getObjectFromGUID('558717').interactable = false
-- Chairs
getObjectFromGUID('e149a5').interactable = false
getObjectFromGUID('daff99').interactable = false
-- Floor
getObjectFromGUID('83a7b8').interactable = false
-- Walls
getObjectFromGUID('77e020').interactable = false
getObjectFromGUID('6880f1').interactable = false
getObjectFromGUID('a2475b').interactable = false
getObjectFromGUID('0d0857').interactable = false
-- Main point light
getObjectFromGUID('c0f8eb').interactable = false
-- Key light
getObjectFromGUID('4a9adf').interactable = false
-- Back lights
getObjectFromGUID('3b5c97').interactable = false
getObjectFromGUID('018fac').interactable = false
-- Top light for shadows
getObjectFromGUID('bc09bc').interactable = false
end
function update()
check_picked_base()
end
function print_help()
print_info([[Write commands in the chat by writting !command.
A extended description can be found on the Notebook.
Available commands:
!triumph_help: Print this help
!triumph_print_state: Prints the current global vars of bases and table
!triumph_reset: Recalculates the bases and tables using heuristics on the existing objects
!triumph_load_army <id> <player>
id is the identifier on Meshwesh. e.g. 5fb1b9f1e1af06001770a195
player is one of 'red' or 'blue'
Example: !triumph_load_army 5fb1b9f1e1af06001770a195 red
]])
end
-- parse and execute the command '!triumph_load_army'
function triumph_load_army_command(message)
local ok, error = pcall( function()
local match = message:split(' ')
local player = match[3]
local id = match[2]
if (player == nil) or (player ~= 'red' and player ~= 'blue') then
print_error("player must be read or blue")
return false
end
if id == nil then
print_error("army identifier must be set.")
return false
end
spawn_meshesh_army(id, player)
end)
if not ok then
print_error(error)
end
return false
end
function onChat(message, player)
if message == '!triumph_help' then
print_info(player.get_steam_name() .. ': ' .. message)
print_help()
return false
end
if message == '!triumph_reset' then
print_info(player.get_steam_name() .. ': ' .. message)
print_important('Resetting the state of the board, check the chat')
reset_state()
return false
end
if message == '!triumph_print_state' then
print_info(player.get_steam_name() .. ': ' .. message)
print_state()
return false
end
if message == '!triumph_debug' then
print_info(player.get_steam_name() .. ': ' .. message)
if g_debug_mode then
print_info('Disabling debug mode')
g_debug_mode = false
else
print_info('Enabling debug mode, will take effect in three seconds. Note, this will cause decreased performance.')
Wait.time(function()
g_debug_mode = true
print_info('Debug mode ON')
end, 3)
end
return false
end
if message == '!triumph_3dterrain' then
print_info(player.get_steam_name() .. ': ' .. message)
g_use_3d_terrain = true
print_info('3D Terrain enabled, when doing a fix&lock on the table 3D objects will load.')
return false
end
if message == '!triumph_regen_dice' then
print_info(player.get_steam_name() .. ': ' .. message)
spawn_all_dice()
return false
end
if message == '!triumph_random_army' then
print_info(player.get_steam_name() .. ': ' .. message)
local _,book = random_kv(armies)
local army_name, army = random_kv(book)
print_important('Army selected: ' .. army_name .. '')
print_info('List: ' .. army['data']['list'])
print_info('Invasion: ' .. army['data']['Invasion']
.. ' Maneuver ' .. army['data']['maneuver']
.. ' Terrain: ' .. army['data']['terrain'])
return false
end
if str_starts_with(message, '!triumph_load_army') then
triumph_load_army_command(message)
return false
end
if str_starts_with(message, '!triumph') then
print_info(player.get_steam_name() .. ': ' .. message)
print_error('Command not recognized. Please, use !triumph_help: ', message)
end
return true
end