-
Notifications
You must be signed in to change notification settings - Fork 0
/
villainsaverconfigv2.ttslua
198 lines (184 loc) · 7.69 KB
/
villainsaverconfigv2.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
function onLoad()
KEEPER = getObjectFromGUID("165258")
create_buttons()
end
SELECTED = ""
URL = "https://raw.githubusercontent.com/Eldinnie/Villainous/main/customsv1.ttslua"
EVERYTHING = {}
-- #include villainsv6
function create_buttons()
self.clearButtons()
self.clearInputs()
local buttons = {}
table.insert(buttons, {click_function = "INSERT_FUNCTION", function_owner = self, label = "Data URL:", position = {-1.4, 0.100000001490116, -0.85}, scale = {0.5, 0.5, 0.5}, width = 0, height = 0, tooltip = "Data URL", alignment = 3})
table.insert(buttons, {click_function = "nil", function_owner = self, label = "Choose Subsection", position = {-0.9, 0.1, -0.5}, scale = {0.5, 0.5, 0.5}, width = 0, height = 0, alignment = 3})
table.insert(buttons, {click_function = "get_data", function_owner = self, label = "Get Data", position = {1.3, 0.100000001490116, -0.850000023841858}, scale = {0.5, 0.5, 0.5}, width = 500, color = {0.856, 0.1, 0.094, 1}, alignment = 3, tooltip="OVERWRITES EVERYTHING"})
table.insert(buttons, {click_function = "publish_everything", function_owner = self, label = "Create factions save", position = {0.7, 0.100000001490116, 0.65}, scale = {0.5, 0.5, 0.5}, width = 1000, tooltip = "Save all current loaded data to the web", alignment = 3, color=Color.green})
local counter = 0
for section, component in pairs(EVERYTHING) do
_G["click_"..section] = function() load_section(section) end
table.insert(buttons, {click_function = "click_"..section, function_owner = self, label = section, position = {-0.9, 0.1, -0.3+counter*0.15}, scale = {0.5, 0.5, 0.5}, width = 1100, alignment = 3, color=SELECTED==section and Color.green or Color.white})
counter = counter +1
end
for _, button in ipairs(buttons) do
self.createButton(button)
end
local input = {input_function = "set_url", function_owner = self, label = "Data URL", position = {-0.1, 0.100000001490116, -0.850000023841858}, scale = {0.5, 0.5, 0.5}, width = 1900, height = 150, font_size = 60, tooltip = "Data URL", alignment = 3, value = URL}
self.createInput(input)
local input = {input_function = "none", function_owner = self, label = "Saved data", position = {0.7, 0.100000001490116, 0.850000023841858}, scale = {0.5, 0.5, 0.5}, width = 1200, height = 120, font_size = 60, alignment = 3}
self.createInput(input)
end
function none() end
function set_url(_, _, value)
URL = value
end
function load_section(section)
-- print("load "..section)
-- print("load - saving boards")
save_boards()
-- print("load - boards saved")
-- print("load - gathering boards")
local boards = gather_boards()
-- print("load - boards gathered")
for num, board in ipairs(boards) do
-- print("load - board "..tostring(num).." call empty")
board.call('empty')
-- print("load - board "..tostring(num).." emptied")
board.editInput({index=0, value=""})
board.editInput({index=1, value=""})
board.editInput({index=2, value=""})
board.editInput({index=3, value=""})
end
-- print("load - emptied all boards")
for villain, info in pairs(EVERYTHING[section]) do
-- print("load - loading villain "..villain)
-- print("load - getting a board")
board = table.remove(boards, 1)
-- print(board)
board.editInput({index=0, value=section})
board.editInput({index=1, value=villain})
board.editInput({index=2, value=info.tooltip})
board.editInput({index=3, value=info.image})
-- print("load - Spawning "..villain)
board.call('spawn_here', info.data)
-- print("load - "..villain.." spawned")
end
SELECTED = section
create_buttons()
end
function gather_boards()
-- print("Gather boards - enter")
local ret = {}
for _, obj in ipairs(getAllObjects()) do
if obj.getName() == "Editor Board" then
table.insert(ret, obj)
end
end
-- print("Gather boards - done")
return ret
end
function get_data()
function callback(wr)
repeat
--
until wr.is_done
if wr.is_error then
-- print(wr.error)
else
KEEPER.setLuaScript(wr.text)
KEEPER = KEEPER.reload()
Wait.condition(function() EVERYTHING=KEEPER.getTable('EVERYTHING') end, ||not KEEPER.spawning)
Wait.time(create_buttons, 1)
end
end
WebRequest.get(URL, callback)
end
function onChat(message, player)
save_data()
end
function save_board(board, as_string)
-- print("save board - enter")
local objects = {}
local my_pos = board.positionToLocal(board.getPosition())
local my_rot = board.getRotation()
local scale = board.getScale()
local objs = Physics.cast({
origin = board.getPosition(),
type = 3,
size = board.getBoundsNormalized().size,
direction = {0,1,0},
max_distance = 0.5,
debug = true,
})
for _, v in ipairs(objs) do
ob = v.hit_object
if not (ob == board) and not (ob.tag=="Surface") and not (ob.tag == "Board") then
ob_pos = board.positionToLocal(ob.getPosition()) *scale
-- ob_pos.y = ob_pos.y+0.2
move_to = ob_pos-my_pos
move_to = Vector(move_to:rotateOver("y", -my_rot.y))
objects[#objects+1] = {move_to=move_to, json=ob.getJSON():gsub("%\r%\n%s+", "")}
end
end
-- print("save board - exit, objects: "..tostring(#objects))
return objects
end
function save_boards()
-- print("Save boards - enter")
-- print("Save boards - gathering boards")
local boards = gather_boards()
-- print("Save boards - boards gathered")
for num, board in ipairs(boards) do
-- print("Save boards - board "..tostring(num))
if board.getInputs()[1].value ~= "" then
-- print("Save boards - board "..tostring(num).." has data, saving")
local group = board.getInputs()[1].value
local name = board.getInputs()[2].value
local tooltip = board.getInputs()[3].value
local image = board.getInputs()[4].value
if image==nil then image="" end
local objects = save_board(board)
if EVERYTHING[group] == nil then
EVERYTHING[group] = {}
end
EVERYTHING[group][name] = {image=image, tooltip=tooltip, data=objects}
-- print("Save boards - board "..tostring(num).." saved")
end
end
-- print("Save boards - exit")
end
function onChat()
publish_everything()
end
function publish_everything()
self.editInput({index=1, value="", color=Color.red})
save_boards()
local body = "EVERYTHING = {}\n"
for section, factions in pairs(EVERYTHING) do
body = body.."EVERYTHING['"..section.."'] = {}\n"
for faction, info in pairs(factions) do
body = body.."EVERYTHING['"..section.."']['"..faction.."'] = {image='"..info.image.."', tooltip='"..info.tooltip.."', data={\n"
for _,ob in ipairs(info.data) do
body = body.."{move_to="..Vector(ob.move_to):string()..", "
body = body.."json=[["..ob.json.."]]},"
end
body = body.."}}\n"
end
body = body.."\n"
end
function callback(wr)
repeat
--
until wr.is_done
if wr.is_error then
log(wr.url)
log(wr.error)
else
log(wr.url)
local result = JSON.decode(wr.text)
log(result.paste_link)
self.editInput({index=1, value=result.paste_link, color=Color.green})
end
end
WebRequest.post("https://psty.io/api", {code=body, lang="lua"}, callback)
end